summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorGeert Bosch <geert@mongodb.com>2014-09-30 09:56:21 -0400
committerGeert Bosch <geert@mongodb.com>2014-09-30 22:02:04 -0400
commitda599844c97ef6d290c03e073a9bafe41c1a914e (patch)
tree4b942aba73479a433b371db0dd713b3f0bd375f8 /src/mongo/db
parent068b1d23bb513bfc819de61514262a12cb75bcbb (diff)
downloadmongo-da599844c97ef6d290c03e073a9bafe41c1a914e.tar.gz
SERVER-14668: Replace uses of DBWrite lock with DBLock
This reverts commit 8e83e72512fcb8eb8f06987927766c0b77cea23e. This reinstates commit ae333bc94a7d89d3220dcae9579fcaf68aa2e290 and commit 962f959a09b63aa0482d7e0c9bad89363d1e1194, and fixes three cases where the wrong database name was locked.
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/client.cpp2
-rw-r--r--src/mongo/db/client.h2
-rw-r--r--src/mongo/db/cloner.cpp12
-rw-r--r--src/mongo/db/commands/apply_ops.cpp26
-rw-r--r--src/mongo/db/commands/clone.cpp2
-rw-r--r--src/mongo/db/commands/collection_to_capped.cpp2
-rw-r--r--src/mongo/db/commands/compact.cpp4
-rw-r--r--src/mongo/db/commands/copydb.cpp15
-rw-r--r--src/mongo/db/commands/cpuprofile.cpp4
-rw-r--r--src/mongo/db/commands/create_indexes.cpp2
-rw-r--r--src/mongo/db/commands/drop_indexes.cpp4
-rw-r--r--src/mongo/db/commands/find_and_modify.cpp6
-rw-r--r--src/mongo/db/commands/mr.cpp16
-rw-r--r--src/mongo/db/commands/test_commands.cpp2
-rw-r--r--src/mongo/db/commands/write_commands/batch_executor.cpp12
-rw-r--r--src/mongo/db/concurrency/d_concurrency.cpp5
-rw-r--r--src/mongo/db/concurrency/d_concurrency.h19
-rw-r--r--src/mongo/db/concurrency/d_concurrency_test.cpp4
-rw-r--r--src/mongo/db/dbcommands.cpp10
-rw-r--r--src/mongo/db/exec/stagedebug_cmd.cpp2
-rw-r--r--src/mongo/db/index_rebuilder.cpp2
-rw-r--r--src/mongo/db/instance.cpp6
-rw-r--r--src/mongo/db/introspect.cpp9
-rw-r--r--src/mongo/db/repl/minvalid.cpp6
-rw-r--r--src/mongo/db/repl/oplog.cpp6
-rw-r--r--src/mongo/db/repl/repl_coordinator_external_state_impl.cpp6
-rw-r--r--src/mongo/db/repl/rs_initialsync.cpp2
-rw-r--r--src/mongo/db/repl/sync_tail.cpp6
28 files changed, 95 insertions, 99 deletions
diff --git a/src/mongo/db/client.cpp b/src/mongo/db/client.cpp
index 17901be98de..812e062ede9 100644
--- a/src/mongo/db/client.cpp
+++ b/src/mongo/db/client.cpp
@@ -238,7 +238,7 @@ namespace mongo {
Client::WriteContext::WriteContext(
OperationContext* opCtx, const std::string& ns, bool doVersion)
- : _lk(opCtx->lockState(), ns),
+ : _lk(opCtx->lockState(), nsToDatabaseSubstring(ns), newlm::MODE_X),
_wunit(opCtx),
_c(opCtx, ns, doVersion) {
}
diff --git a/src/mongo/db/client.h b/src/mongo/db/client.h
index ef78f899154..265b8439037 100644
--- a/src/mongo/db/client.h
+++ b/src/mongo/db/client.h
@@ -204,7 +204,7 @@ namespace mongo {
Context& ctx() { return _c; }
private:
- Lock::DBWrite _lk;
+ Lock::DBLock _lk;
WriteUnitOfWork _wunit;
Context _c;
};
diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp
index 1686cfe2c10..67c76b071e9 100644
--- a/src/mongo/db/cloner.cpp
+++ b/src/mongo/db/cloner.cpp
@@ -308,15 +308,15 @@ namespace mongo {
bool logForRepl) {
const NamespaceString nss(ns);
- Lock::DBWrite dbWrite(txn->lockState(), nss.db());
+ const string dbname = nss.db().toString();
- const string dbName = nss.db().toString();
+ Lock::DBLock dbWrite(txn->lockState(), dbname, newlm::MODE_X);
bool unused;
- Database* db = dbHolder().getOrCreate(txn, dbName, unused);
+ Database* db = dbHolder().getOrCreate(txn, dbname, unused);
// config
- string temp = dbName + ".system.namespaces";
+ string temp = dbname + ".system.namespaces";
BSONObj config = _conn->findOne(temp , BSON("name" << ns));
if (config["options"].isABSONObj()) {
WriteUnitOfWork wunit(txn);
@@ -329,7 +329,7 @@ namespace mongo {
}
// main data
- copy(txn, dbName,
+ copy(txn, dbname,
nss, nss,
logForRepl, false, true, mayYield, mayBeInterrupted,
Query(query).snapshot());
@@ -340,7 +340,7 @@ namespace mongo {
}
// indexes
- copyIndexes(txn, dbName,
+ copyIndexes(txn, dbname,
NamespaceString(ns), NamespaceString(ns),
logForRepl, false, true, mayYield,
mayBeInterrupted);
diff --git a/src/mongo/db/commands/apply_ops.cpp b/src/mongo/db/commands/apply_ops.cpp
index c0a1f398e56..cc760412120 100644
--- a/src/mongo/db/commands/apply_ops.cpp
+++ b/src/mongo/db/commands/apply_ops.cpp
@@ -126,26 +126,26 @@ namespace mongo {
string ns = temp["ns"].String();
- // Run operations under a nested lock as a hack to prevent them from yielding.
+ // Run operations under a nested lock as a hack to prevent yielding.
//
- // The list of operations is supposed to be applied atomically; yielding would break
- // atomicity by allowing an interruption or a shutdown to occur after only some
- // operations are applied. We are already locked globally at this point, so taking
- // a DBWrite on the namespace creates a nested lock, and yields are disallowed for
- // operations that hold a nested lock.
+ // The list of operations is supposed to be applied atomically; yielding
+ // would break atomicity by allowing an interruption or a shutdown to occur
+ // after only some operations are applied. We are already locked globally
+ // at this point, so taking a DBLock on the namespace creates a nested lock,
+ // and yields are disallowed for operations that hold a nested lock.
//
- // We do not have a wrapping WriteUnitOfWork so it is possible for a journal commit
- // to happen with a subset of ops applied.
+ // We do not have a wrapping WriteUnitOfWork so it is possible for a journal
+ // commit to happen with a subset of ops applied.
// TODO figure out what to do about this.
- Lock::DBWrite lk(txn->lockState(), ns);
+ Lock::DBLock lk(txn->lockState(), nsToDatabaseSubstring(ns), newlm::MODE_X);
invariant(txn->lockState()->isRecursive());
Client::Context ctx(txn, ns);
bool failed = repl::applyOperation_inlock(txn,
- ctx.db(),
- temp,
- false,
- alwaysUpsert);
+ ctx.db(),
+ temp,
+ false,
+ alwaysUpsert);
ab.append(!failed);
if ( failed )
errors++;
diff --git a/src/mongo/db/commands/clone.cpp b/src/mongo/db/commands/clone.cpp
index a25deba9e32..0b73001e559 100644
--- a/src/mongo/db/commands/clone.cpp
+++ b/src/mongo/db/commands/clone.cpp
@@ -115,7 +115,7 @@ namespace mongo {
set<string> clonedColls;
- Lock::DBWrite dbXLock(txn->lockState(), dbname);
+ Lock::DBLock dbXLock(txn->lockState(), dbname, newlm::MODE_X);
Cloner cloner;
bool rval = cloner.go(txn, dbname, from, opts, &clonedColls, errmsg);
diff --git a/src/mongo/db/commands/collection_to_capped.cpp b/src/mongo/db/commands/collection_to_capped.cpp
index 2a4f60cee31..24439e82b9b 100644
--- a/src/mongo/db/commands/collection_to_capped.cpp
+++ b/src/mongo/db/commands/collection_to_capped.cpp
@@ -161,7 +161,7 @@ namespace mongo {
return false;
}
- Lock::DBWrite dbXLock(txn->lockState(), dbname);
+ Lock::DBLock dbXLock(txn->lockState(), dbname, newlm::MODE_X);
Client::Context ctx(txn, dbname);
Status status = cloneCollectionAsCapped( txn, ctx.db(), from, to, size, temp, true );
diff --git a/src/mongo/db/commands/compact.cpp b/src/mongo/db/commands/compact.cpp
index 5ed0ac16aca..8ffac0bff38 100644
--- a/src/mongo/db/commands/compact.cpp
+++ b/src/mongo/db/commands/compact.cpp
@@ -97,7 +97,7 @@ namespace mongo {
return false;
}
- NamespaceString ns(db,coll);
+ NamespaceString ns(db, coll);
if ( !ns.isNormal() ) {
errmsg = "bad namespace name";
return false;
@@ -144,7 +144,7 @@ namespace mongo {
compactOptions.validateDocuments = cmdObj["validate"].trueValue();
- Lock::DBWrite lk(txn->lockState(), ns.ns());
+ Lock::DBLock lk(txn->lockState(), db, newlm::MODE_X);
BackgroundOperation::assertNoBgOpInProgForNs(ns.ns());
Client::Context ctx(txn, ns);
diff --git a/src/mongo/db/commands/copydb.cpp b/src/mongo/db/commands/copydb.cpp
index 208d792c59e..58f733e02b0 100644
--- a/src/mongo/db/commands/copydb.cpp
+++ b/src/mongo/db/commands/copydb.cpp
@@ -182,15 +182,14 @@ namespace mongo {
cloner.setConnection(conn);
}
-
- // SERVER-4328 todo lock just the two db's not everything for the fromself case
- scoped_ptr<Lock::ScopedLock> lk( fromSelf ?
- static_cast<Lock::ScopedLock*>(new Lock::GlobalWrite(txn->lockState())) :
- static_cast<Lock::ScopedLock*>(new Lock::DBWrite(txn->lockState(), todb)));
- if (!cloner.go(txn, todb, fromhost, cloneOptions, NULL, errmsg )) {
- return false;
+ if (fromSelf) {
+ // SERVER-4328 todo lock just the two db's not everything for the fromself case
+ Lock::GlobalWrite lk(txn->lockState());
+ return cloner.go(txn, todb, fromhost, cloneOptions, NULL, errmsg);
}
- return true;
+
+ Lock::DBLock lk (txn->lockState(), todb, newlm::MODE_X);
+ return cloner.go(txn, todb, fromhost, cloneOptions, NULL, errmsg);
}
} cmdCopyDB;
diff --git a/src/mongo/db/commands/cpuprofile.cpp b/src/mongo/db/commands/cpuprofile.cpp
index 884e43d0c29..b1c81ca3584 100644
--- a/src/mongo/db/commands/cpuprofile.cpp
+++ b/src/mongo/db/commands/cpuprofile.cpp
@@ -133,7 +133,7 @@ namespace mongo {
std::string &errmsg,
BSONObjBuilder &result,
bool fromRepl ) {
- Lock::DBWrite dbXLock(txn->lockState(), db);
+ Lock::DBLock dbXLock(txn->lockState(), db, newlm::MODE_X);
// The lock here is just to prevent concurrency, nothing will write.
Client::Context ctx(txn, db);
@@ -152,7 +152,7 @@ namespace mongo {
std::string &errmsg,
BSONObjBuilder &result,
bool fromRepl ) {
- Lock::DBWrite dbXLock(txn->lockState(), db);
+ Lock::DBLock dbXLock(txn->lockState(), db, newlm::MODE_X);
WriteUnitOfWork wunit(txn);
Client::Context ctx(txn, db);
diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp
index 58791dea990..43ff03f26e4 100644
--- a/src/mongo/db/commands/create_indexes.cpp
+++ b/src/mongo/db/commands/create_indexes.cpp
@@ -134,7 +134,7 @@ namespace mongo {
// now we know we have to create index(es)
// Note: createIndexes command does not currently respect shard versioning.
- Lock::DBWrite lk(txn->lockState(), ns.ns());
+ Lock::DBLock lk(txn->lockState(), ns.db(), newlm::MODE_X);
Client::Context ctx(txn, ns.ns(), false /* doVersion */ );
Database* db = ctx.db();
diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp
index ba93d95bc54..122ed26cc9a 100644
--- a/src/mongo/db/commands/drop_indexes.cpp
+++ b/src/mongo/db/commands/drop_indexes.cpp
@@ -103,7 +103,7 @@ namespace mongo {
CmdDropIndexes() : Command("dropIndexes", false, "deleteIndexes") { }
bool run(OperationContext* txn, const string& dbname, BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& anObjBuilder, bool fromRepl) {
- Lock::DBWrite dbXLock(txn->lockState(), dbname);
+ Lock::DBLock dbXLock(txn->lockState(), dbname, newlm::MODE_X);
WriteUnitOfWork wunit(txn);
bool ok = wrappedRun(txn, dbname, jsobj, errmsg, anObjBuilder);
if (!ok) {
@@ -239,7 +239,7 @@ namespace mongo {
LOG(0) << "CMD: reIndex " << toDeleteNs << endl;
- Lock::DBWrite dbXLock(txn->lockState(), dbname);
+ Lock::DBLock dbXLock(txn->lockState(), dbname, newlm::MODE_X);
Client::Context ctx(txn, toDeleteNs);
Collection* collection = ctx.db()->getCollection( txn, toDeleteNs );
diff --git a/src/mongo/db/commands/find_and_modify.cpp b/src/mongo/db/commands/find_and_modify.cpp
index 4477e62bec0..0e05feb5a71 100644
--- a/src/mongo/db/commands/find_and_modify.cpp
+++ b/src/mongo/db/commands/find_and_modify.cpp
@@ -97,7 +97,7 @@ namespace mongo {
return false;
}
- Lock::DBWrite dbXLock(txn->lockState(), dbname);
+ Lock::DBLock dbXLock(txn->lockState(), dbname, newlm::MODE_X);
Client::Context ctx(txn, ns);
return runNoDirectClient( txn, ns ,
@@ -137,7 +137,7 @@ namespace mongo {
BSONObjBuilder& result,
string& errmsg) {
- Lock::DBWrite lk(txn->lockState(), ns);
+ Lock::DBLock lk(txn->lockState(), nsToDatabaseSubstring(ns), newlm::MODE_X);
WriteUnitOfWork wunit(txn);
Client::Context cx(txn, ns);
@@ -335,7 +335,7 @@ namespace mongo {
}
}
- Lock::DBWrite dbXLock(txn->lockState(), dbname);
+ Lock::DBLock dbXLock(txn->lockState(), dbname, newlm::MODE_X);
WriteUnitOfWork wunit(txn);
Client::Context ctx(txn, ns);
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index e58e001a221..81ed57a285d 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -332,7 +332,9 @@ namespace mongo {
if (_useIncremental) {
// We don't want to log the deletion of incLong as it isn't replicated. While
// harmless, this would lead to a scary looking warning on the secondaries.
- Lock::DBWrite lk(_txn->lockState(), _config.incLong);
+ Lock::DBLock lk(_txn->lockState(),
+ nsToDatabaseSubstring(_config.incLong),
+ newlm::MODE_X);
if (Database* db = dbHolder().get(_txn, _config.incLong)) {
WriteUnitOfWork wunit(_txn);
db->dropCollection(_txn, _config.incLong);
@@ -591,9 +593,11 @@ namespace mongo {
op->setMessage("m/r: merge post processing",
"M/R Merge Post Processing Progress",
_safeCount(_db, _config.tempNamespace, BSONObj()));
- auto_ptr<DBClientCursor> cursor = _db.query( _config.tempNamespace , BSONObj() );
- while ( cursor->more() ) {
- Lock::DBWrite lock(_txn->lockState(), _config.outputOptions.finalNamespace);
+ auto_ptr<DBClientCursor> cursor = _db.query(_config.tempNamespace , BSONObj());
+ while (cursor->more()) {
+ Lock::DBLock lock(_txn->lockState(),
+ nsToDatabaseSubstring(_config.outputOptions.finalNamespace),
+ newlm::MODE_X);
WriteUnitOfWork wunit(_txn);
BSONObj o = cursor->nextSafe();
Helpers::upsert( _txn, _config.outputOptions.finalNamespace , o );
@@ -1110,7 +1114,9 @@ namespace mongo {
if ( ! _onDisk )
return;
- Lock::DBWrite kl(_txn->lockState(), _config.incLong);
+ Lock::DBLock kl(_txn->lockState(),
+ nsToDatabaseSubstring(_config.incLong),
+ newlm::MODE_X);
WriteUnitOfWork wunit(_txn);
for ( InMemory::iterator i=_temp->begin(); i!=_temp->end(); i++ ) {
diff --git a/src/mongo/db/commands/test_commands.cpp b/src/mongo/db/commands/test_commands.cpp
index 316d763babf..204be07b75b 100644
--- a/src/mongo/db/commands/test_commands.cpp
+++ b/src/mongo/db/commands/test_commands.cpp
@@ -64,7 +64,7 @@ namespace mongo {
string ns = dbname + "." + coll;
BSONObj obj = cmdObj[ "obj" ].embeddedObjectUserCheck();
- Lock::DBWrite lk(txn->lockState(), ns);
+ Lock::DBLock lk(txn->lockState(), dbname, newlm::MODE_X);
WriteUnitOfWork wunit(txn);
Client::Context ctx(txn, ns );
Database* db = ctx.db();
diff --git a/src/mongo/db/commands/write_commands/batch_executor.cpp b/src/mongo/db/commands/write_commands/batch_executor.cpp
index 8b21578ce89..f5e372359b0 100644
--- a/src/mongo/db/commands/write_commands/batch_executor.cpp
+++ b/src/mongo/db/commands/write_commands/batch_executor.cpp
@@ -696,7 +696,7 @@ namespace mongo {
/**
* Gets the lock-holding object. Only valid if hasLock().
*/
- Lock::DBWrite& getLock() { return *_writeLock; }
+ Lock::DBLock& getLock() { return *_writeLock; }
/**
* Gets the target collection for the batch operation. Value is undefined
@@ -721,7 +721,7 @@ namespace mongo {
bool _lockAndCheckImpl(WriteOpResult* result);
// Guard object for the write lock on the target database.
- scoped_ptr<Lock::DBWrite> _writeLock;
+ scoped_ptr<Lock::DBLock> _writeLock;
// Context object on the target database. Must appear after writeLock, so that it is
// destroyed in proper order.
@@ -919,7 +919,9 @@ namespace mongo {
}
invariant(!_context.get());
- _writeLock.reset(new Lock::DBWrite(txn->lockState(), request->getNS()));
+ _writeLock.reset(new Lock::DBLock(txn->lockState(),
+ nsToDatabase(request->getNS()),
+ newlm::MODE_X));
if (!checkIsMasterForDatabase(request->getNS(), result)) {
return false;
}
@@ -1124,7 +1126,7 @@ namespace mongo {
}
///////////////////////////////////////////
- Lock::DBWrite writeLock(txn->lockState(), nsString.ns());
+ Lock::DBLock writeLock(txn->lockState(), nsString.db(), newlm::MODE_X);
///////////////////////////////////////////
if (!checkShardVersion(txn, &shardingState, *updateItem.getRequest(), result))
@@ -1179,7 +1181,7 @@ namespace mongo {
}
///////////////////////////////////////////
- Lock::DBWrite writeLock(txn->lockState(), nss.ns());
+ Lock::DBLock writeLock(txn->lockState(), nss.db(), newlm::MODE_X);
///////////////////////////////////////////
// Check version once we're locked
diff --git a/src/mongo/db/concurrency/d_concurrency.cpp b/src/mongo/db/concurrency/d_concurrency.cpp
index 15e108a53f2..6701159a420 100644
--- a/src/mongo/db/concurrency/d_concurrency.cpp
+++ b/src/mongo/db/concurrency/d_concurrency.cpp
@@ -313,7 +313,7 @@ namespace {
if (supportsDocLocking()) {
_lockState->lock(_id, mode);
}
- else if (isRead) {
+ else {
_lockState->lock(_id, isRead ? newlm::MODE_S : newlm::MODE_X);
}
}
@@ -322,9 +322,6 @@ namespace {
_lockState->unlock(_id);
}
- Lock::DBWrite::DBWrite(Locker* lockState, const StringData& dbOrNs) :
- DBLock(lockState, nsToDatabaseSubstring(dbOrNs), newlm::MODE_X) { }
-
Lock::DBRead::DBRead(Locker* lockState, const StringData& dbOrNs) :
DBLock(lockState, nsToDatabaseSubstring(dbOrNs), newlm::MODE_S) { }
diff --git a/src/mongo/db/concurrency/d_concurrency.h b/src/mongo/db/concurrency/d_concurrency.h
index d4f11bb28d4..a55eaa077f3 100644
--- a/src/mongo/db/concurrency/d_concurrency.h
+++ b/src/mongo/db/concurrency/d_concurrency.h
@@ -196,9 +196,10 @@ namespace mongo {
* MODE_S: shared read access to the collection, blocking any writers
* MODE_X: exclusive access to the collection, blocking all other readers and writers
*
- * An appropriate DBLock must already be held before locking a collection.
- * For storage engines that do not support document-level locking, MODE_IS will be
- * upgraded to MODE_S and MODE_IX will be upgraded to MODE_X.
+ * An appropriate DBLock must already be held before locking a collection: it is an error,
+ * checked with a dassert(), to not have a suitable database lock before locking the
+ * collection. For storage engines that do not support document-level locking, MODE_IS
+ * will be upgraded to MODE_S and MODE_IX will be upgraded to MODE_X.
*/
class CollectionLock : boost::noncopyable {
public:
@@ -210,18 +211,6 @@ namespace mongo {
};
/**
- * Exclusive database lock -- DEPRECATED, please transition to DBLock and collection locks
- *
- * Allows exclusive write access to the given database, blocking any other access.
- * Allows further (recursive) acquisition of database locks for this database in any mode.
- * Also acquires the global lock in intent-exclusive (IX) mode.
- */
- class DBWrite : public DBLock {
- public:
- DBWrite(Locker* lockState, const StringData& dbOrNs);
- };
-
- /**
* Shared database lock -- DEPRECATED, please transition to DBLock and collection locks
*
* Allows concurrent read access to the given database, blocking any writers.
diff --git a/src/mongo/db/concurrency/d_concurrency_test.cpp b/src/mongo/db/concurrency/d_concurrency_test.cpp
index 3391eab52a7..ddc59b17bd7 100644
--- a/src/mongo/db/concurrency/d_concurrency_test.cpp
+++ b/src/mongo/db/concurrency/d_concurrency_test.cpp
@@ -133,10 +133,10 @@ namespace mongo {
ASSERT(ls.getLockMode(resIdDb) == newlm::MODE_S);
}
- TEST(DConcurrency, DBWriteTakesX) {
+ TEST(DConcurrency, DBLockTakesX) {
LockState ls;
- Lock::DBWrite dbWrite(&ls, "db");
+ Lock::DBLock dbWrite(&ls, "db", newlm::MODE_X);
const newlm::ResourceId resIdDb(newlm::RESOURCE_DATABASE, string("db"));
ASSERT(ls.getLockMode(resIdDb) == newlm::MODE_X);
diff --git a/src/mongo/db/dbcommands.cpp b/src/mongo/db/dbcommands.cpp
index 4b7e698f1ed..793cb492604 100644
--- a/src/mongo/db/dbcommands.cpp
+++ b/src/mongo/db/dbcommands.cpp
@@ -349,7 +349,7 @@ namespace mongo {
// Needs to be locked exclusively, because creates the system.profile collection
// in the local database.
//
- Lock::DBWrite dbXLock(txn->lockState(), dbname);
+ Lock::DBLock dbXLock(txn->lockState(), dbname, newlm::MODE_X);
WriteUnitOfWork wunit(txn);
Client::Context ctx(txn, dbname);
@@ -405,7 +405,7 @@ namespace mongo {
// This doesn't look like it requires exclusive DB lock, because it uses its own diag
// locking, but originally the lock was set to be WRITE, so preserving the behaviour.
//
- Lock::DBWrite dbXLock(txn->lockState(), dbname);
+ Lock::DBLock dbXLock(txn->lockState(), dbname, newlm::MODE_X);
Client::Context ctx(txn, dbname);
int was = _diaglog.setLevel( cmdObj.firstElement().numberInt() );
@@ -461,7 +461,7 @@ namespace mongo {
return false;
}
- Lock::DBWrite dbXLock(txn->lockState(), dbname);
+ Lock::DBLock dbXLock(txn->lockState(), dbname, newlm::MODE_X);
WriteUnitOfWork wunit(txn);
Client::Context ctx(txn, nsToDrop);
Database* db = ctx.db();
@@ -561,7 +561,7 @@ namespace mongo {
!options["capped"].trueValue() || options["size"].isNumber() ||
options.hasField("$nExtents"));
- Lock::DBWrite dbXLock(txn->lockState(), dbname);
+ Lock::DBLock dbXLock(txn->lockState(), dbname, newlm::MODE_X);
WriteUnitOfWork wunit(txn);
Client::Context ctx(txn, ns);
@@ -987,7 +987,7 @@ namespace mongo {
bool run(OperationContext* txn, const string& dbname, BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) {
const string ns = dbname + "." + jsobj.firstElement().valuestr();
- Lock::DBWrite dbXLock(txn->lockState(), dbname);
+ Lock::DBLock dbXLock(txn->lockState(), dbname, newlm::MODE_X);
WriteUnitOfWork wunit(txn);
Client::Context ctx(txn, ns );
diff --git a/src/mongo/db/exec/stagedebug_cmd.cpp b/src/mongo/db/exec/stagedebug_cmd.cpp
index 0f804e890ee..9a86fe82da8 100644
--- a/src/mongo/db/exec/stagedebug_cmd.cpp
+++ b/src/mongo/db/exec/stagedebug_cmd.cpp
@@ -121,7 +121,7 @@ namespace mongo {
// TODO A write lock is currently taken here to accommodate stages that perform writes
// (e.g. DeleteStage). This should be changed to use a read lock for read-only
// execution trees.
- Lock::DBWrite lk(txn->lockState(), dbname);
+ Lock::DBLock lk(txn->lockState(), dbname, newlm::MODE_X);
Client::Context ctx(txn, dbname);
// Make sure the collection is valid.
diff --git a/src/mongo/db/index_rebuilder.cpp b/src/mongo/db/index_rebuilder.cpp
index cbde00dbf04..8dd345de946 100644
--- a/src/mongo/db/index_rebuilder.cpp
+++ b/src/mongo/db/index_rebuilder.cpp
@@ -64,7 +64,7 @@ namespace {
// This write lock is held throughout the index building process
// for this namespace.
- Lock::DBWrite lk(txn->lockState(), ns);
+ Lock::DBLock lk(txn->lockState(), nsToDatabaseSubstring(ns), newlm::MODE_X);
Client::Context ctx(txn, ns);
Collection* collection = ctx.db()->getCollection(txn, ns);
diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp
index dd37aaf5b1e..2d8b189edc3 100644
--- a/src/mongo/db/instance.cpp
+++ b/src/mongo/db/instance.cpp
@@ -621,7 +621,7 @@ namespace mongo {
UpdateExecutor executor(&request, &op.debug());
uassertStatusOK(executor.prepare());
- Lock::DBWrite lk(txn->lockState(), ns.ns());
+ Lock::DBLock lk(txn->lockState(), ns.db(), newlm::MODE_X);
Client::Context ctx(txn, ns );
UpdateResult res = executor.execute(ctx.db());
@@ -655,7 +655,7 @@ namespace mongo {
DeleteExecutor executor(&request);
uassertStatusOK(executor.prepare());
- Lock::DBWrite lk(txn->lockState(), ns.ns());
+ Lock::DBLock lk(txn->lockState(), ns.db(), newlm::MODE_X);
Client::Context ctx(txn, ns);
long long n = executor.execute(ctx.db());
@@ -914,7 +914,7 @@ namespace mongo {
uassertStatusOK(status);
}
- Lock::DBWrite lk(txn->lockState(), ns);
+ Lock::DBLock lk(txn->lockState(), nsString.db(), newlm::MODE_X);
// CONCURRENCY TODO: is being read locked in big log sufficient here?
// writelock is used to synchronize stepdowns w/ writes
diff --git a/src/mongo/db/introspect.cpp b/src/mongo/db/introspect.cpp
index c2f11b34e6d..c84a1caafa0 100644
--- a/src/mongo/db/introspect.cpp
+++ b/src/mongo/db/introspect.cpp
@@ -135,10 +135,11 @@ namespace {
BufBuilder profileBufBuilder(1024);
try {
- // NOTE: It's kind of weird that we lock the op's namespace, but have to for now since
- // we're sometimes inside the lock already
- Lock::DBWrite lk(txn->lockState(), currentOp.getNS() );
- if (dbHolder().get(txn, nsToDatabase(currentOp.getNS())) != NULL) {
+ // NOTE: It's kind of weird that we lock the op's namespace, but have to for now
+ // since we're sometimes inside the lock already
+ const string dbname(nsToDatabase(currentOp.getNS()));
+ Lock::DBLock lk(txn->lockState(), dbname, newlm::MODE_X);
+ if (dbHolder().get(txn, dbname) != NULL) {
// We are ok with the profiling happening in a different WUOW from the actual op.
WriteUnitOfWork wunit(txn);
Client::Context cx(txn, currentOp.getNS(), false);
diff --git a/src/mongo/db/repl/minvalid.cpp b/src/mongo/db/repl/minvalid.cpp
index f2b0f4c189e..30f1d17c18d 100644
--- a/src/mongo/db/repl/minvalid.cpp
+++ b/src/mongo/db/repl/minvalid.cpp
@@ -49,14 +49,14 @@ namespace {
} // namespace
void clearInitialSyncFlag(OperationContext* txn) {
- Lock::DBWrite lk(txn->lockState(), "local");
+ Lock::DBLock lk(txn->lockState(), "local", newlm::MODE_X);
WriteUnitOfWork wunit(txn);
Helpers::putSingleton(txn, minvalidNS, BSON("$unset" << initialSyncFlag));
wunit.commit();
}
void setInitialSyncFlag(OperationContext* txn) {
- Lock::DBWrite lk(txn->lockState(), "local");
+ Lock::DBLock lk(txn->lockState(), "local", newlm::MODE_X);
WriteUnitOfWork wunit(txn);
Helpers::putSingleton(txn, minvalidNS, BSON("$set" << initialSyncFlag));
wunit.commit();
@@ -73,7 +73,7 @@ namespace {
}
void setMinValid(OperationContext* ctx, OpTime ts) {
- Lock::DBWrite lk(ctx->lockState(), "local");
+ Lock::DBLock lk(ctx->lockState(), "local", newlm::MODE_X);
WriteUnitOfWork wunit(ctx);
Helpers::putSingleton(ctx, minvalidNS, BSON("$set" << BSON("ts" << ts)));
wunit.commit();
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp
index e13ede3039c..bcc372ca86f 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -119,7 +119,7 @@ namespace repl {
todo : make _logOpRS() call this so we don't repeat ourself?
*/
OpTime _logOpObjRS(OperationContext* txn, const BSONObj& op) {
- Lock::DBWrite lk(txn->lockState(), "local");
+ Lock::DBLock lk(txn->lockState(), "local", newlm::MODE_X);
// XXX soon this needs to be part of an outer WUOW not its own.
// We can't do this yet due to locking limitations.
WriteUnitOfWork wunit(txn);
@@ -236,7 +236,7 @@ namespace repl {
BSONObj *o2,
bool *bb,
bool fromMigrate ) {
- Lock::DBWrite lk1(txn->lockState(), "local");
+ Lock::DBLock lk1(txn->lockState(), "local", newlm::MODE_X);
WriteUnitOfWork wunit(txn);
if ( strncmp(ns, "local.", 6) == 0 ) {
@@ -320,7 +320,7 @@ namespace repl {
BSONObj *o2,
bool *bb,
bool fromMigrate ) {
- Lock::DBWrite lk(txn->lockState(), "local");
+ Lock::DBLock lk(txn->lockState(), "local", newlm::MODE_X);
WriteUnitOfWork wunit(txn);
static BufBuilder bufbuilder(8*1024); // todo there is likely a mutex on this constructor
diff --git a/src/mongo/db/repl/repl_coordinator_external_state_impl.cpp b/src/mongo/db/repl/repl_coordinator_external_state_impl.cpp
index 69edf78b57f..9ec360369ab 100644
--- a/src/mongo/db/repl/repl_coordinator_external_state_impl.cpp
+++ b/src/mongo/db/repl/repl_coordinator_external_state_impl.cpp
@@ -56,7 +56,9 @@ namespace repl {
namespace {
// TODO: Change this to local.system.replset when we remove disable the hybrid coordinator.
const char configCollectionName[] = "local.new.replset";
+ const char configDatabaseName[] = "local";
const char meCollectionName[] = "local.me";
+ const char meDatabaseName[] = "local";
const char tsFieldName[] = "ts";
} // namespace
@@ -88,7 +90,7 @@ namespace {
std::string myname = getHostName();
OID myRID;
{
- Lock::DBWrite lock(txn->lockState(), meCollectionName);
+ Lock::DBLock lock(txn->lockState(), meDatabaseName, newlm::MODE_X);
BSONObj me;
// local.me is an identifier for a server for getLastError w:2+
@@ -135,7 +137,7 @@ namespace {
OperationContext* txn,
const BSONObj& config) {
try {
- Lock::DBWrite dbWriteLock(txn->lockState(), configCollectionName);
+ Lock::DBLock dbWriteLock(txn->lockState(), configDatabaseName, newlm::MODE_X);
Helpers::putSingleton(txn, configCollectionName, config);
return Status::OK();
}
diff --git a/src/mongo/db/repl/rs_initialsync.cpp b/src/mongo/db/repl/rs_initialsync.cpp
index 74273a40ba2..75b0bc6ecf9 100644
--- a/src/mongo/db/repl/rs_initialsync.cpp
+++ b/src/mongo/db/repl/rs_initialsync.cpp
@@ -84,7 +84,7 @@ namespace {
options.syncIndexes = ! dataPass;
// Make database stable
- Lock::DBWrite dbWrite(txn->lockState(), db);
+ Lock::DBLock dbWrite(txn->lockState(), db, newlm::MODE_X);
if (!cloner.go(txn, db, host, options, NULL, err, &errCode)) {
log() << "initial sync: error while "
diff --git a/src/mongo/db/repl/sync_tail.cpp b/src/mongo/db/repl/sync_tail.cpp
index 20c99e289d9..9cd57ae030c 100644
--- a/src/mongo/db/repl/sync_tail.cpp
+++ b/src/mongo/db/repl/sync_tail.cpp
@@ -123,7 +123,7 @@ namespace repl {
lk.reset(new Lock::GlobalWrite(txn->lockState()));
} else {
// DB level lock for this operation
- lk.reset(new Lock::DBWrite(txn->lockState(), ns));
+ lk.reset(new Lock::DBLock(txn->lockState(), nsToDatabaseSubstring(ns), newlm::MODE_X));
}
Client::Context ctx(txn, ns);
@@ -328,7 +328,7 @@ namespace {
BackgroundSync* bgsync = BackgroundSync::get();
if (bgsync->getInitialSyncRequestedFlag()) {
// got a resync command
- Lock::DBWrite lk(txn.lockState(), "local");
+ Lock::DBLock lk(txn.lockState(), "local", newlm::MODE_X);
WriteUnitOfWork wunit(&txn);
Client::Context ctx(&txn, "local");
@@ -481,7 +481,7 @@ namespace {
OpTime lastOpTime;
{
OperationContextImpl txn; // XXX?
- Lock::DBWrite lk(txn.lockState(), "local");
+ Lock::DBLock lk(txn.lockState(), "local", newlm::MODE_X);
WriteUnitOfWork wunit(&txn);
while (!ops->empty()) {