diff options
author | Andy Schwerin <schwerin@mongodb.com> | 2015-05-27 19:36:59 -0400 |
---|---|---|
committer | Andy Schwerin <schwerin@mongodb.com> | 2015-06-05 14:21:56 -0400 |
commit | 51c2064d518140fbeae62f9d7ba29f1d69fb530f (patch) | |
tree | b6d97eb91b4ac76279eb983234c6ec63ac44a8c6 /src/mongo/db/db_raii.cpp | |
parent | 1cf11a282870c26ce7d963fb3a6c3329b39d90a2 (diff) | |
download | mongo-51c2064d518140fbeae62f9d7ba29f1d69fb530f.tar.gz |
SERVER-18277 Stronger locking rules for CurOp and OpDebug.
Diffstat (limited to 'src/mongo/db/db_raii.cpp')
-rw-r--r-- | src/mongo/db/db_raii.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/mongo/db/db_raii.cpp b/src/mongo/db/db_raii.cpp index 5a78f2d7d90..a4c52b97cc6 100644 --- a/src/mongo/db/db_raii.cpp +++ b/src/mongo/db/db_raii.cpp @@ -31,6 +31,7 @@ #include "mongo/db/db_raii.h" #include "mongo/db/catalog/database_holder.h" +#include "mongo/db/client.h" #include "mongo/db/curop.h" #include "mongo/s/d_state.h" @@ -85,19 +86,21 @@ namespace mongo { void AutoGetCollectionForRead::_init(const std::string& ns, StringData coll) { massert(28535, "need a non-empty collection name", !coll.empty()); - // TODO: OldClientContext legacy, needs to be removed - CurOp::get(_txn)->ensureStarted(); - CurOp::get(_txn)->setNS(ns); - // We have both the DB and collection locked, which the prerequisite to do a stable shard // version check. ensureShardVersionOKOrThrow(ns); + auto curOp = CurOp::get(_txn); + stdx::lock_guard<Client> lk(*_txn->getClient()); + // TODO: OldClientContext legacy, needs to be removed + curOp->ensureStarted(); + curOp->setNS_inlock(ns); + // At this point, we are locked in shared mode for the database by the DB lock in the // constructor, so it is safe to load the DB pointer. if (_db.getDb()) { // TODO: OldClientContext legacy, needs to be removed - CurOp::get(_txn)->enter(ns.c_str(), _db.getDb()->getProfilingLevel()); + curOp->enter_inlock(ns.c_str(), _db.getDb()->getProfilingLevel()); _coll = _db.getDb()->getCollection(ns); } @@ -156,7 +159,8 @@ namespace mongo { _checkNotStale(); } - CurOp::get(_txn)->enter(_ns.c_str(), _db->getProfilingLevel()); + stdx::lock_guard<Client> lk(*_txn->getClient()); + CurOp::get(_txn)->enter_inlock(_ns.c_str(), _db->getProfilingLevel()); } void OldClientContext::_checkNotStale() const { |