From 07ecc05d44c2a4f443bccf96004a1da16b2e3984 Mon Sep 17 00:00:00 2001 From: jannaerin Date: Mon, 10 Sep 2018 13:13:04 -0700 Subject: SERVER-31892 moveChunk with should wait for majority write concern --- src/mongo/db/s/move_chunk_command.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/mongo/db/s/move_chunk_command.cpp b/src/mongo/db/s/move_chunk_command.cpp index d90b4b2dddf..5297f161948 100644 --- a/src/mongo/db/s/move_chunk_command.cpp +++ b/src/mongo/db/s/move_chunk_command.cpp @@ -64,6 +64,15 @@ void uassertStatusOKWithWarning(const Status& status) { } } +const WriteConcernOptions kMajorityWriteConcern(WriteConcernOptions::kMajority, + // Note: Even though we're setting UNSET here, + // kMajority implies JOURNAL if journaling is + // supported by mongod and + // writeConcernMajorityJournalDefault is set to true + // in the ReplSetConfig. + WriteConcernOptions::SyncMode::UNSET, + -1); + // Tests can pause and resume moveChunk's progress at each step by enabling/disabling each failpoint MONGO_FAIL_POINT_DEFINE(moveChunkHangAtStep1); MONGO_FAIL_POINT_DEFINE(moveChunkHangAtStep2); @@ -154,7 +163,19 @@ public: // OperationContext. // TODO (SERVER-30183): If this moveChunk joined an active moveChunk that did not have // waitForDelete=true, the captured opTime may not reflect all the deletes. - repl::ReplClientInfo::forClient(opCtx->getClient()).setLastOpToSystemLastOpTime(opCtx); + auto& replClient = repl::ReplClientInfo::forClient(opCtx->getClient()); + replClient.setLastOpToSystemLastOpTime(opCtx); + + WriteConcernResult writeConcernResult; + writeConcernResult.wTimedOut = false; + Status majorityStatus = waitForWriteConcern( + opCtx, replClient.getLastOp(), kMajorityWriteConcern, &writeConcernResult); + if (!majorityStatus.isOK()) { + if (!writeConcernResult.wTimedOut) { + uassertStatusOK(majorityStatus); + } + return false; + } } return true; -- cgit v1.2.1