diff options
author | Benety Goh <benety@mongodb.com> | 2020-10-16 12:57:11 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-10-16 17:16:14 +0000 |
commit | af298544ba207890ef3dc9da9b5b7db8e17eb2bb (patch) | |
tree | dc8617d47d61f1a19f0fb51ec9ea2c502e696512 | |
parent | 46fc739089ad30affe64177e2c74cae32902f350 (diff) | |
download | mongo-af298544ba207890ef3dc9da9b5b7db8e17eb2bb.tar.gz |
SERVER-46995 add ReplIndexBuildState methods for updating vote request callback handle
-rw-r--r-- | src/mongo/db/index_builds_coordinator_mongod.cpp | 15 | ||||
-rw-r--r-- | src/mongo/db/repl_index_build_state.cpp | 17 | ||||
-rw-r--r-- | src/mongo/db/repl_index_build_state.h | 12 |
3 files changed, 32 insertions, 12 deletions
diff --git a/src/mongo/db/index_builds_coordinator_mongod.cpp b/src/mongo/db/index_builds_coordinator_mongod.cpp index 002bacc131a..5d75034fe7f 100644 --- a/src/mongo/db/index_builds_coordinator_mongod.cpp +++ b/src/mongo/db/index_builds_coordinator_mongod.cpp @@ -514,21 +514,12 @@ void IndexBuildsCoordinatorMongod::_signalPrimaryForCommitReadiness( Backoff exponentialBackoff(Seconds(1), Seconds(2)); - auto onRemoteCmdScheduled = [replState, - replCoord](executor::TaskExecutor::CallbackHandle handle) { - stdx::unique_lock<Latch> lk(replState->mutex); - // We have already received commit or abort signal, So skip voting. - if (replState->waitForNextAction->getFuture().isReady()) { - replCoord->cancelCbkHandle(handle); - } else { - invariant(!replState->voteCmdCbkHandle.isValid()); - replState->voteCmdCbkHandle = handle; - } + auto onRemoteCmdScheduled = [opCtx, replState](executor::TaskExecutor::CallbackHandle handle) { + replState->onVoteRequestScheduled(opCtx, handle); }; auto onRemoteCmdComplete = [replState](executor::TaskExecutor::CallbackHandle) { - stdx::unique_lock<Latch> lk(replState->mutex); - replState->voteCmdCbkHandle = executor::TaskExecutor::CallbackHandle(); + replState->clearVoteRequestCbk(); }; auto needToVote = [replState]() -> bool { diff --git a/src/mongo/db/repl_index_build_state.cpp b/src/mongo/db/repl_index_build_state.cpp index f297758121b..a05adeb21e8 100644 --- a/src/mongo/db/repl_index_build_state.cpp +++ b/src/mongo/db/repl_index_build_state.cpp @@ -342,6 +342,23 @@ ReplIndexBuildState::TryAbortResult ReplIndexBuildState::tryAbort(OperationConte return TryAbortResult::kContinueAbort; } +void ReplIndexBuildState::onVoteRequestScheduled(OperationContext* opCtx, + executor::TaskExecutor::CallbackHandle handle) { + stdx::unique_lock<Latch> lk(mutex); + if (waitForNextAction->getFuture().isReady()) { + auto replCoord = repl::ReplicationCoordinator::get(opCtx); + replCoord->cancelCbkHandle(handle); + } else { + invariant(!voteCmdCbkHandle.isValid(), str::stream() << buildUUID); + voteCmdCbkHandle = handle; + } +} + +void ReplIndexBuildState::clearVoteRequestCbk() { + stdx::unique_lock<Latch> lk(mutex); + voteCmdCbkHandle = executor::TaskExecutor::CallbackHandle(); +} + bool ReplIndexBuildState::isResumable() const { stdx::unique_lock<Latch> lk(mutex); return !_lastOpTimeBeforeInterceptors.isNull(); diff --git a/src/mongo/db/repl_index_build_state.h b/src/mongo/db/repl_index_build_state.h index 66fe15d13f9..d2b4a7918bc 100644 --- a/src/mongo/db/repl_index_build_state.h +++ b/src/mongo/db/repl_index_build_state.h @@ -313,6 +313,18 @@ public: std::string reason); /** + * Called when the vote request command is scheduled by the task executor. + * Skips voting if we have already received commit or abort signal. + */ + void onVoteRequestScheduled(OperationContext* opCtx, + executor::TaskExecutor::CallbackHandle handle); + + /** + * Clears vote request callback handle set in onVoteRequestScheduled(). + */ + void clearVoteRequestCbk(); + + /** * Accessor and mutator for last optime in the oplog before the interceptors were installed. * This supports resumable index builds. */ |