summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/bgsync.cpp
diff options
context:
space:
mode:
authorLingzhi Deng <lingzhi.deng@mongodb.com>2019-10-30 23:24:58 +0000
committerevergreen <evergreen@mongodb.com>2019-10-30 23:24:58 +0000
commit39187be9d1175f5ef52ffca858c5e9489fd6cedf (patch)
treea2cd41a98a5a5223c2cadf34844018d3ec6b1a64 /src/mongo/db/repl/bgsync.cpp
parent10106ec4192c91a54fd8b7c260ae1031843785c4 (diff)
downloadmongo-39187be9d1175f5ef52ffca858c5e9489fd6cedf.tar.gz
SERVER-44061: Fix race between setting replication maintenance mode and concurrent election
Diffstat (limited to 'src/mongo/db/repl/bgsync.cpp')
-rw-r--r--src/mongo/db/repl/bgsync.cpp7
1 files changed, 6 insertions, 1 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()) {
{