diff options
author | Lingzhi Deng <lingzhi.deng@mongodb.com> | 2019-10-30 23:24:58 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-10-30 23:24:58 +0000 |
commit | 39187be9d1175f5ef52ffca858c5e9489fd6cedf (patch) | |
tree | a2cd41a98a5a5223c2cadf34844018d3ec6b1a64 /src/mongo | |
parent | 10106ec4192c91a54fd8b7c260ae1031843785c4 (diff) | |
download | mongo-39187be9d1175f5ef52ffca858c5e9489fd6cedf.tar.gz |
SERVER-44061: Fix race between setting replication maintenance mode and concurrent election
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/repl/bgsync.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl.cpp | 5 |
2 files changed, 10 insertions, 2 deletions
diff --git a/src/mongo/db/repl/bgsync.cpp b/src/mongo/db/repl/bgsync.cpp index 39cb42f86f7..e965c5a7298 100644 --- a/src/mongo/db/repl/bgsync.cpp +++ b/src/mongo/db/repl/bgsync.cpp @@ -341,7 +341,7 @@ void BackgroundSync::_produce() { return; } - if (_tooStale.swap(true)) { + if (_tooStale.load()) { // We had already marked ourselves too stale. return; } @@ -359,12 +359,17 @@ void BackgroundSync::_produce() { auto status = _replCoord->setMaintenanceMode(true); if (!status.isOK()) { warning() << "Failed to transition into maintenance mode: " << status; + // Do not mark ourselves too stale on errors so we can try again next time. + return; } status = _replCoord->setFollowerMode(MemberState::RS_RECOVERING); if (!status.isOK()) { warning() << "Failed to transition into " << MemberState(MemberState::RS_RECOVERING) << ". Current state: " << _replCoord->getMemberState() << causedBy(status); + // Do not mark ourselves too stale on errors so we can try again next time. + return; } + _tooStale.store(true); return; } else if (syncSourceResp.isOK() && !syncSourceResp.getSyncSource().empty()) { { diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp index 3f9dc990ec8..3fe72a5d6f1 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl.cpp @@ -99,6 +99,8 @@ namespace repl { MONGO_FAIL_POINT_DEFINE(stepdownHangBeforePerformingPostMemberStateUpdateActions); MONGO_FAIL_POINT_DEFINE(holdStableTimestampAtSpecificTimestamp); MONGO_FAIL_POINT_DEFINE(stepdownHangBeforeRSTLEnqueue); +// Fail setMaintenanceMode with ErrorCodes::NotSecondary to simulate a concurrent election. +MONGO_FAIL_POINT_DEFINE(setMaintenanceModeFailsWithNotSecondary); // Number of times we tried to go live as a secondary. Counter64 attemptsToBecomeSecondary; @@ -2481,7 +2483,8 @@ Status ReplicationCoordinatorImpl::setMaintenanceMode(bool activate) { } stdx::unique_lock<Latch> lk(_mutex); - if (_topCoord->getRole() == TopologyCoordinator::Role::kCandidate) { + if (_topCoord->getRole() == TopologyCoordinator::Role::kCandidate || + MONGO_unlikely(setMaintenanceModeFailsWithNotSecondary.shouldFail())) { return Status(ErrorCodes::NotSecondary, "currently running for election"); } |