diff options
author | Jordi Serra Torrens <jordi.serra-torrens@mongodb.com> | 2022-03-08 08:28:56 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-03-08 09:25:08 +0000 |
commit | 4a1f01267e8723f4eba6aa264466fd6b27cb2ab9 (patch) | |
tree | 2c48e0debc899c23554a8162ee0f7da171483ce5 /src/mongo/db/commands/set_user_write_block_mode_command.cpp | |
parent | f70e73ccc422499080cfb4163efe42a64a4e59e1 (diff) | |
download | mongo-4a1f01267e8723f4eba6aa264466fd6b27cb2ab9.tar.gz |
SERVER-63519 Extend RecoverableCriticalSectionService to accommodate global user write blocking
Diffstat (limited to 'src/mongo/db/commands/set_user_write_block_mode_command.cpp')
-rw-r--r-- | src/mongo/db/commands/set_user_write_block_mode_command.cpp | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/mongo/db/commands/set_user_write_block_mode_command.cpp b/src/mongo/db/commands/set_user_write_block_mode_command.cpp index b216597ef3e..3ecf129935a 100644 --- a/src/mongo/db/commands/set_user_write_block_mode_command.cpp +++ b/src/mongo/db/commands/set_user_write_block_mode_command.cpp @@ -32,10 +32,10 @@ #include "mongo/platform/basic.h" #include "mongo/db/auth/authorization_session.h" -#include "mongo/db/catalog_raii.h" #include "mongo/db/commands.h" #include "mongo/db/commands/set_user_write_block_mode_gen.h" -#include "mongo/db/s/global_user_write_block_state.h" +#include "mongo/db/repl/repl_client_info.h" +#include "mongo/db/s/user_writes_recoverable_critical_section_service.h" #include "mongo/logv2/log.h" @@ -62,12 +62,29 @@ public: void typedRun(OperationContext* opCtx) { { - Lock::GlobalLock lk(opCtx, MODE_X); if (request().getGlobal()) { - GlobalUserWriteBlockState::get(opCtx)->enableUserWriteBlocking(opCtx); + UserWritesRecoverableCriticalSectionService::get(opCtx) + ->acquireRecoverableCriticalSectionBlockingUserWrites( + opCtx, + UserWritesRecoverableCriticalSectionService:: + kGlobalUserWritesNamespace); } else { - GlobalUserWriteBlockState::get(opCtx)->disableUserWriteBlocking(opCtx); + UserWritesRecoverableCriticalSectionService::get(opCtx) + ->releaseRecoverableCriticalSection( + opCtx, + UserWritesRecoverableCriticalSectionService:: + kGlobalUserWritesNamespace); } + + // Wait for the writes to the UserWritesRecoverableCriticalSection collection to be + // majority commited. + auto& replClient = repl::ReplClientInfo::forClient(opCtx->getClient()); + WriteConcernResult writeConcernResult; + WriteConcernOptions majority(WriteConcernOptions::kMajority, + WriteConcernOptions::SyncMode::UNSET, + WriteConcernOptions::kWriteConcernTimeoutUserCommand); + uassertStatusOK(waitForWriteConcern( + opCtx, replClient.getLastOp(), majority, &writeConcernResult)); } } |