diff options
author | Yu Jin Kang Park <yujin.kang@mongodb.com> | 2023-02-06 10:24:15 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-02-06 11:03:34 +0000 |
commit | 44d44fc65f6cea228ddf6be48575d690457fac93 (patch) | |
tree | 139168a64086e9dec450588e8b0d4d84ef1622a1 /src/mongo/db/index_builds_coordinator_mongod.cpp | |
parent | 5b2fe7d1a17dbee9ab5ce3cf865415d72aeeb90c (diff) | |
download | mongo-44d44fc65f6cea228ddf6be48575d690457fac93.tar.gz |
SERVER-73292 Add voteAbortIndexBuild command
Diffstat (limited to 'src/mongo/db/index_builds_coordinator_mongod.cpp')
-rw-r--r-- | src/mongo/db/index_builds_coordinator_mongod.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/mongo/db/index_builds_coordinator_mongod.cpp b/src/mongo/db/index_builds_coordinator_mongod.cpp index 70d0965d490..b7b3a0cb173 100644 --- a/src/mongo/db/index_builds_coordinator_mongod.cpp +++ b/src/mongo/db/index_builds_coordinator_mongod.cpp @@ -445,6 +445,33 @@ IndexBuildsCoordinatorMongod::_startIndexBuild(OperationContext* opCtx, return replState->sharedPromise.getFuture(); } +Status IndexBuildsCoordinatorMongod::voteAbortIndexBuild(OperationContext* opCtx, + const UUID& buildUUID, + const HostAndPort& votingNode, + const StringData& reason) { + + auto memberConfig = + repl::ReplicationCoordinator::get(opCtx)->findConfigMemberByHostAndPort(votingNode); + if (!memberConfig || memberConfig->isArbiter()) { + return Status{ErrorCodes::Error{7329201}, + "Non-member and arbiter nodes cannot vote to abort an index build"}; + } + + bool aborted = abortIndexBuildByBuildUUID( + opCtx, + buildUUID, + IndexBuildAction::kPrimaryAbort, + fmt::format("'voteAbortIndexBuild' received from '{}': {}", votingNode.toString(), reason)); + + if (aborted) { + return Status::OK(); + } + + // Index build does not exist or cannot be aborted because it is committing. + // No need to wait for write concern. + return Status{ErrorCodes::Error{7329202}, "Index build cannot be aborted"}; +} + Status IndexBuildsCoordinatorMongod::voteCommitIndexBuild(OperationContext* opCtx, const UUID& buildUUID, const HostAndPort& votingNode) { |