summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorLingzhi Deng <lingzhi.deng@mongodb.com>2019-06-03 18:09:48 -0400
committerLingzhi Deng <lingzhi.deng@mongodb.com>2019-06-06 13:13:23 -0400
commitfbb3e0b7299d0b14ebff5641b3a6c672c18ad96d (patch)
tree8ad69d3dc25c22717783bae6dbb633ac918c83fe /src/mongo
parentd60d7d2985f8a75ed08a7836cb5e460415f2e26d (diff)
downloadmongo-fbb3e0b7299d0b14ebff5641b3a6c672c18ad96d.tar.gz
SERVER-41479: replSetStepUp on primary should return errors if the node is stepping down
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp
index e0d3a2b6dac..87eea64b6c1 100644
--- a/src/mongo/db/repl/replication_coordinator_impl.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl.cpp
@@ -3952,11 +3952,17 @@ Status ReplicationCoordinatorImpl::stepUpIfEligible(bool skipDryRun) {
if (finishEvent.isValid()) {
_replExecutor->waitForEvent(finishEvent);
}
- auto state = getMemberState();
- if (state.primary()) {
- return Status::OK();
+ {
+ // Step up is considered successful only if we are currently a primary and we are not in the
+ // process of stepping down. If we know we are going to step down, we should fail the
+ // replSetStepUp command so caller can retry if necessary.
+ stdx::lock_guard<stdx::mutex> lk(_mutex);
+ if (!_getMemberState_inlock().primary())
+ return Status(ErrorCodes::CommandFailed, "Election failed.");
+ else if (_topCoord->isSteppingDown())
+ return Status(ErrorCodes::CommandFailed, "Election failed due to concurrent stepdown.");
}
- return Status(ErrorCodes::CommandFailed, "Election failed.");
+ return Status::OK();
}
executor::TaskExecutor::EventHandle ReplicationCoordinatorImpl::_cancelElectionIfNeeded_inlock() {