diff options
author | Jordi Serra Torrens <jordi.serra-torrens@mongodb.com> | 2022-03-16 08:32:15 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-03-16 09:00:08 +0000 |
commit | ceca8a9f7fb4c89af6ce2cd84379f049c4d4c19e (patch) | |
tree | ec3b1a4b8f04b107d287624f83434996adfe9fe3 /src/mongo/db/s/user_writes_recoverable_critical_section_service.cpp | |
parent | 4b4a334cf67eba2abaaca1854eac5a8a03bee3e7 (diff) | |
download | mongo-ceca8a9f7fb4c89af6ce2cd84379f049c4d4c19e.tar.gz |
SERVER-63523 Drain ongoing sharded DDL operations before enabling write blocking on shards
Diffstat (limited to 'src/mongo/db/s/user_writes_recoverable_critical_section_service.cpp')
-rw-r--r-- | src/mongo/db/s/user_writes_recoverable_critical_section_service.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/mongo/db/s/user_writes_recoverable_critical_section_service.cpp b/src/mongo/db/s/user_writes_recoverable_critical_section_service.cpp index 6215032f7b0..c1457176934 100644 --- a/src/mongo/db/s/user_writes_recoverable_critical_section_service.cpp +++ b/src/mongo/db/s/user_writes_recoverable_critical_section_service.cpp @@ -37,6 +37,7 @@ #include "mongo/db/dbdirectclient.h" #include "mongo/db/persistent_task_store.h" #include "mongo/db/s/global_user_write_block_state.h" +#include "mongo/db/s/sharding_ddl_coordinator_service.h" #include "mongo/db/s/user_writes_critical_section_document_gen.h" #include "mongo/logv2/log.h" #include "mongo/s/catalog/sharding_catalog_client.h" @@ -177,6 +178,11 @@ void UserWritesRecoverableCriticalSectionService:: // Take the user writes critical section blocking only ShardingDDLCoordinators. acquireRecoverableCriticalSection( opCtx, nss, true /* blockShardedDDL */, false /* blockUserWrites */); + + // Wait for ongoing ShardingDDLCoordinators to finish. This ensures that all coordinators that + // started before enabling blocking have finish, and that any new coordinator that is started + // after this point will see the blocking is enabled. + ShardingDDLCoordinatorService::getService(opCtx)->waitForOngoingCoordinatorsToFinish(opCtx); } void UserWritesRecoverableCriticalSectionService:: @@ -333,6 +339,7 @@ void UserWritesRecoverableCriticalSectionService::recoverRecoverableCriticalSect OperationContext* opCtx) { LOGV2_DEBUG(6351912, 2, "Recovering all user writes recoverable critical sections"); + GlobalUserWriteBlockState::get(opCtx)->disableUserShardedDDLBlocking(opCtx); GlobalUserWriteBlockState::get(opCtx)->disableUserWriteBlocking(opCtx); // Read the persisted critical section documents and restore the state into memory. @@ -340,6 +347,11 @@ void UserWritesRecoverableCriticalSectionService::recoverRecoverableCriticalSect NamespaceString::kUserWritesCriticalSectionsNamespace); store.forEach(opCtx, BSONObj{}, [&opCtx](const UserWriteBlockingCriticalSectionDocument& doc) { invariant(doc.getNss().isEmpty()); + + if (doc.getBlockNewUserShardedDDL()) { + GlobalUserWriteBlockState::get(opCtx)->enableUserShardedDDLBlocking(opCtx); + } + if (doc.getBlockUserWrites()) { GlobalUserWriteBlockState::get(opCtx)->enableUserWriteBlocking(opCtx); } |