diff options
author | Pierlauro Sciarelli <pierlauro.sciarelli@mongodb.com> | 2022-07-13 10:31:06 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-07-13 10:59:49 +0000 |
commit | 47f99d9faa45b2fdf86082fc1221c6fc16536c3f (patch) | |
tree | 64797c6800f496951db11b2dd7bf1016384c1805 | |
parent | 8109993be980df50d937b4eec0c500605bc0dc82 (diff) | |
download | mongo-47f99d9faa45b2fdf86082fc1221c6fc16536c3f.tar.gz |
SERVER-67845 Acquire critical section in rename "check preconditions" phase only if target not sharded
-rw-r--r-- | src/mongo/db/s/rename_collection_coordinator.cpp | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/src/mongo/db/s/rename_collection_coordinator.cpp b/src/mongo/db/s/rename_collection_coordinator.cpp index 2df1f73ada5..bec561b6a2b 100644 --- a/src/mongo/db/s/rename_collection_coordinator.cpp +++ b/src/mongo/db/s/rename_collection_coordinator.cpp @@ -177,19 +177,27 @@ ExecutorFuture<void> RenameCollectionCoordinator::_runImpl( sharding_ddl_util::checkDbPrimariesOnTheSameShard(opCtx, fromNss, toNss); } - // (SERVER-67325) Acquire critical section on the target collection in order - // to disallow concurrent `createCollection` + const auto optTargetCollType = getShardedCollection(opCtx, toNss); + const bool targetIsSharded = (bool)optTargetCollType; + _doc.setTargetIsSharded(targetIsSharded); + _doc.setTargetUUID(getCollectionUUID( + opCtx, toNss, optTargetCollType, /*throwNotFound*/ false)); + auto criticalSection = RecoverableCriticalSectionService::get(opCtx); - criticalSection->acquireRecoverableCriticalSectionBlockWrites( - opCtx, - toNss, - criticalSectionReason, - ShardingCatalogClient::kLocalWriteConcern); - criticalSection->promoteRecoverableCriticalSectionToBlockAlsoReads( - opCtx, - toNss, - criticalSectionReason, - ShardingCatalogClient::kLocalWriteConcern); + if (!targetIsSharded) { + // (SERVER-67325) Acquire critical section on the target collection in order + // to disallow concurrent `createCollection` + criticalSection->acquireRecoverableCriticalSectionBlockWrites( + opCtx, + toNss, + criticalSectionReason, + ShardingCatalogClient::kLocalWriteConcern); + criticalSection->promoteRecoverableCriticalSectionToBlockAlsoReads( + opCtx, + toNss, + criticalSectionReason, + ShardingCatalogClient::kLocalWriteConcern); + } // Make sure the target namespace is not a view { @@ -199,12 +207,6 @@ ExecutorFuture<void> RenameCollectionCoordinator::_runImpl( !CollectionCatalog::get(opCtx)->lookupView(opCtx, toNss)); } - const auto optTargetCollType = getShardedCollection(opCtx, toNss); - const bool targetIsSharded = (bool)optTargetCollType; - _doc.setTargetIsSharded(targetIsSharded); - _doc.setTargetUUID(getCollectionUUID( - opCtx, toNss, optTargetCollType, /*throwNotFound*/ false)); - const bool targetExists = [&]() { if (targetIsSharded) { return true; |