diff options
author | Gregory Wlodarek <gregory.wlodarek@mongodb.com> | 2019-10-25 01:27:01 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-10-25 01:27:01 +0000 |
commit | 4403da71126ea32e37f059ce848898dfab22f720 (patch) | |
tree | cfda4a48674ed6fc19bf6da24c57837109446e57 | |
parent | a7578d36790d5668798b05ed56709e34356c38ca (diff) | |
download | mongo-4403da71126ea32e37f059ce848898dfab22f720.tar.gz |
SERVER-44027 Replace accidental database lock with a collection lock for the source target when renaming collections across databases
-rw-r--r-- | src/mongo/db/catalog/rename_collection.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/mongo/db/catalog/rename_collection.cpp b/src/mongo/db/catalog/rename_collection.cpp index 603dd15f9f1..97ab22d144b 100644 --- a/src/mongo/db/catalog/rename_collection.cpp +++ b/src/mongo/db/catalog/rename_collection.cpp @@ -446,9 +446,11 @@ Status renameBetweenDBs(OperationContext* opCtx, const RenameCollectionOptions& options) { invariant(source.db() != target.db()); - boost::optional<Lock::DBLock> sourceCollLock; + boost::optional<Lock::DBLock> sourceDbLock; + boost::optional<Lock::CollectionLock> sourceCollLock; if (!opCtx->lockState()->isCollectionLockedForMode(source, MODE_S)) { - sourceCollLock.emplace(opCtx, source.db(), MODE_S); + sourceDbLock.emplace(opCtx, source.db(), MODE_IS); + sourceCollLock.emplace(opCtx, source, MODE_S); } boost::optional<Lock::DBLock> targetDBLock; @@ -704,6 +706,7 @@ Status renameBetweenDBs(OperationContext* opCtx, } } sourceCollLock.reset(); + sourceDbLock.reset(); // Getting here means we successfully built the target copy. We now do the final // in-place rename and remove the source collection. |