diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-01-20 11:40:42 -0500 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-01-20 17:07:06 -0500 |
commit | 403a992daa205f2b43469ef45b5008d817a38fb6 (patch) | |
tree | 222c4db089330a33ce26c2a77010d28db55a67dd | |
parent | 37398ff1063d8a42d075822ead009e761703fb9d (diff) | |
download | mongo-403a992daa205f2b43469ef45b5008d817a38fb6.tar.gz |
SERVER-16923 Create the system.profile collection if under DB X lock
-rw-r--r-- | src/mongo/db/catalog/database_holder.cpp | 11 | ||||
-rw-r--r-- | src/mongo/db/introspect.cpp | 7 |
2 files changed, 11 insertions, 7 deletions
diff --git a/src/mongo/db/catalog/database_holder.cpp b/src/mongo/db/catalog/database_holder.cpp index 83006f7d60e..5fca8d11c71 100644 --- a/src/mongo/db/catalog/database_holder.cpp +++ b/src/mongo/db/catalog/database_holder.cpp @@ -136,12 +136,13 @@ namespace { *justCreated = !exists; } - // Only one thread can be inside this method for the same DB name, because of the - // requirement for X-lock on the database. So there is no way we can insert two different - // databases for the same name. - SimpleMutex::scoped_lock lk(_m); - + // Do this outside of the scoped lock, because database creation does transactional + // operations which may block. Only one thread can be inside this method for the same DB + // name, because of the requirement for X-lock on the database when we enter. So there is + // no way we can insert two different databases for the same name. db = new Database(txn, dbname, entry); + + SimpleMutex::scoped_lock lk(_m); _dbs[dbname] = db; return db; diff --git a/src/mongo/db/introspect.cpp b/src/mongo/db/introspect.cpp index f90dec52159..a43e92edc66 100644 --- a/src/mongo/db/introspect.cpp +++ b/src/mongo/db/introspect.cpp @@ -94,7 +94,9 @@ namespace { AuthorizationSession * authSession = txn->getClient()->getAuthorizationSession(); _appendUserInfo(*txn->getCurOp(), b, authSession); - BSONObj p = b.done(); + const BSONObj p = b.done(); + + const bool wasLocked = txn->lockState()->isLocked(); const string dbName(nsToDatabase(txn->getCurOp()->getNS())); @@ -132,7 +134,8 @@ namespace { break; } - else if (!acquireDbXLock && !txn->lockState()->isLocked()) { + else if (!acquireDbXLock && + (!wasLocked || txn->lockState()->isDbLockedForMode(dbName, MODE_X))) { // Try to create the collection only if we are not under lock, in order to // avoid deadlocks due to lock conversion. This would only be hit if someone // deletes the profiler collection after setting profile level. |