summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierlauro Sciarelli <pierlauro.sciarelli@mongodb.com>2022-07-13 10:31:06 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-07-13 10:59:49 +0000
commit47f99d9faa45b2fdf86082fc1221c6fc16536c3f (patch)
tree64797c6800f496951db11b2dd7bf1016384c1805
parent8109993be980df50d937b4eec0c500605bc0dc82 (diff)
downloadmongo-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.cpp38
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;