diff options
author | Gregory Noma <gregory.noma@gmail.com> | 2020-04-10 11:22:34 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-04-10 15:34:40 +0000 |
commit | 4adcb62e1be77edfd448e3091d307a368181cc9e (patch) | |
tree | 2cdfc98988e76374c6b6695d4b0fef799caf3931 /src/mongo/db/commands/collection_to_capped.cpp | |
parent | da923cf72003a34a45ce7775dd66ccd944da7d11 (diff) | |
download | mongo-4adcb62e1be77edfd448e3091d307a368181cc9e.tar.gz |
SERVER-47423 Take collection MODE_X locks instead of databse MODE_X lock in cloneCollectionAsCapped
Diffstat (limited to 'src/mongo/db/commands/collection_to_capped.cpp')
-rw-r--r-- | src/mongo/db/commands/collection_to_capped.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/mongo/db/commands/collection_to_capped.cpp b/src/mongo/db/commands/collection_to_capped.cpp index 42b1ff38dfe..9cefe29e593 100644 --- a/src/mongo/db/commands/collection_to_capped.cpp +++ b/src/mongo/db/commands/collection_to_capped.cpp @@ -35,6 +35,7 @@ #include "mongo/db/client.h" #include "mongo/db/commands.h" #include "mongo/db/db_raii.h" +#include "mongo/db/namespace_string.h" #include "mongo/db/op_observer.h" #include "mongo/db/query/find.h" #include "mongo/db/query/internal_plans.h" @@ -112,22 +113,25 @@ public: return false; } - AutoGetDb autoDb(opCtx, dbname, MODE_X); + NamespaceString fromNs(dbname, from); + NamespaceString toNs(dbname, to); - NamespaceString nss(dbname, to); - if (!repl::ReplicationCoordinator::get(opCtx)->canAcceptWritesFor(opCtx, nss)) { + AutoGetCollection autoColl(opCtx, fromNs, MODE_X); + Lock::CollectionLock collLock(opCtx, toNs, MODE_X); + + if (!repl::ReplicationCoordinator::get(opCtx)->canAcceptWritesFor(opCtx, toNs)) { uasserted(ErrorCodes::NotMaster, str::stream() << "Not primary while cloning collection " << from << " to " << to << " (as capped)"); } - Database* const db = autoDb.getDb(); + Database* const db = autoColl.getDb(); if (!db) { uasserted(ErrorCodes::NamespaceNotFound, str::stream() << "database " << dbname << " not found"); } - cloneCollectionAsCapped(opCtx, db, from.toString(), to.toString(), size, temp); + cloneCollectionAsCapped(opCtx, db, fromNs, toNs, size, temp); return true; } |