0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 01:21:03 +01:00

Enable/disable DB-level locking at compile time.

Use the "--mongod-concurrency-level=db" flag to scons to enable db-level locking.  Defaults
to disabled, can be disabled explicitly with "--mongod-concurrency-level=global".
This commit is contained in:
Andy Schwerin 2012-03-19 11:12:25 -04:00
parent 8395e741a5
commit 0e0adf8855
2 changed files with 59 additions and 20 deletions

View File

@ -64,21 +64,23 @@ options = {}
options_topass = {}
def add_option( name, help , nargs , contibutesToVariantDir , dest=None ):
def add_option( name, help , nargs , contributesToVariantDir , dest=None,
type="string", choices=None ):
if dest is None:
dest = name
AddOption( "--" + name ,
dest=dest,
type="string",
type=type,
nargs=nargs,
action="store",
choices=choices,
help=help )
options[name] = { "help" : help ,
"nargs" : nargs ,
"contibutesToVariantDir" : contibutesToVariantDir ,
"contributesToVariantDir" : contributesToVariantDir ,
"dest" : dest }
def get_option( name ):
@ -115,7 +117,7 @@ def get_variant_dir():
o = options[name]
if not has_option( o["dest"] ):
continue
if not o["contibutesToVariantDir"]:
if not o["contributesToVariantDir"]:
continue
if o["nargs"] == 0:
@ -215,6 +217,9 @@ add_option( "use-cpu-profiler",
"Link against the google-perftools profiler library",
0, True )
add_option("mongod-concurrency-level", "Concurrency level, \"global\" or \"db\"", 1, True,
type="choice", choices=["global", "db"])
# don't run configure if user calls --help
if GetOption('help'):
Return()
@ -281,6 +286,9 @@ env = Environment( BUILD_DIR=variantDir,
PCRE_VERSION='8.30',
)
if has_option('mongod-concurrency-level'):
env.Append(CPPDEFINES=['MONGOD_CONCURRENCY_LEVEL=MONGOD_CONCURRENCY_LEVEL_%s' % get_option('mongod-concurrency-level').upper()])
print str(env['CPPDEFINES'])
libdeps.setup_environment( env )

View File

@ -20,6 +20,15 @@
// yielding
// commitIfNeeded
#define MONGOD_CONCURRENCY_LEVEL_GLOBAL 0
#define MONGOD_CONCURRENCY_LEVEL_DB 1
#ifndef MONGOD_CONCURRENCY_LEVEL
#define MONGOD_CONCURRENCY_LEVEL MONGOD_CONCURRENCY_LEVEL_GLOBAL
#endif
#define DB_LEVEL_LOCKING_ENABLED ( ( MONGOD_CONCURRENCY_LEVEL ) >= MONGOD_CONCURRENCY_LEVEL_DB )
namespace mongo {
Client* curopWaitingForLock( char type );
@ -562,14 +571,20 @@ namespace mongo {
LockState& ls = lockState();
if( isW(ls) )
return;
char db[MaxDatabaseNameLen];
nsToDatabase(ns.data(), db);
if( str::equals(db,"local") ) {
lockLocal();
} else {
lock(db);
if (DB_LEVEL_LOCKING_ENABLED) {
char db[MaxDatabaseNameLen];
nsToDatabase(ns.data(), db);
if( str::equals(db,"local") ) {
lockLocal();
} else {
lock(db);
}
lockTop(ls);
} else {
lock_W();
locked_w = true;
}
lockTop(ls);
}
Lock::DBWrite::~DBWrite() {
if( ourCounter ) {
@ -581,7 +596,11 @@ namespace mongo {
weLocked->unlock();
}
if( locked_w ) {
unlock_w();
if (DB_LEVEL_LOCKING_ENABLED) {
unlock_w();
} else {
unlock_W();
}
}
}
@ -660,14 +679,19 @@ namespace mongo {
LockState& ls = lockState();
if( isRW(ls) )
return;
char db[MaxDatabaseNameLen];
nsToDatabase(ns.data(), db);
if( str::equals(db,"local") ) {
lockLocal();
} else {
lock(db);
if (DB_LEVEL_LOCKING_ENABLED) {
char db[MaxDatabaseNameLen];
nsToDatabase(ns.data(), db);
if( str::equals(db,"local") ) {
lockLocal();
} else {
lock(db);
}
lockTop(ls);
} else {
lock_R();
locked_r = true;
}
lockTop(ls);
}
Lock::DBRead::~DBRead() {
if( ourCounter ) {
@ -679,7 +703,14 @@ namespace mongo {
weLocked->unlock_shared();
}
if( locked_r ) {
unlock_r();
if (DB_LEVEL_LOCKING_ENABLED) {
unlock_r();
} else {
unlock_R();
}
} else {
recursive()--;
dassert( recursive() >= 0 );
}
}
}