diff options
author | Geert Bosch <geert@mongodb.com> | 2017-07-07 13:39:42 -0400 |
---|---|---|
committer | Geert Bosch <geert@mongodb.com> | 2017-07-11 16:02:10 -0400 |
commit | 461d91da21c205a6a17476011c38fd4da246f592 (patch) | |
tree | 0c15a05ef29ffa1b965ccbe84f89a0dd52f18507 | |
parent | 00389c9de4d26c26d150084323580289ca89baa6 (diff) | |
download | mongo-461d91da21c205a6a17476011c38fd4da246f592.tar.gz |
SERVER-15723 Avoid G_X lock for renameCollection within database
-rw-r--r-- | src/mongo/db/catalog/rename_collection.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/mongo/db/catalog/rename_collection.cpp b/src/mongo/db/catalog/rename_collection.cpp index c22b05132fc..bc47f320443 100644 --- a/src/mongo/db/catalog/rename_collection.cpp +++ b/src/mongo/db/catalog/rename_collection.cpp @@ -80,7 +80,15 @@ Status renameCollectionCommon(OperationContext* opCtx, bool stayTemp) { DisableDocumentValidation validationDisabler(opCtx); - Lock::GlobalWrite globalWriteLock(opCtx); + boost::optional<Lock::GlobalWrite> globalWriteLock; + boost::optional<Lock::DBLock> dbWriteLock; + + // If the rename is known not to be a cross-database rename, just a database lock suffices. + if (source.db() == target.db()) + dbWriteLock.emplace(opCtx, source.db(), MODE_X); + else + globalWriteLock.emplace(opCtx); + // We stay in source context the whole time. This is mostly to set the CurOp namespace. OldClientContext ctx(opCtx, source.ns()); |