summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp
diff options
context:
space:
mode:
authorSiyuan Zhou <siyuan.zhou@mongodb.com>2017-10-04 17:43:27 -0400
committerSiyuan Zhou <siyuan.zhou@mongodb.com>2017-10-13 16:23:30 -0400
commitcbafd0521cd94a26ce790787d7d220c707132a48 (patch)
tree06da13b81e190378136c5c8124f65797c60b9ef6 /src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp
parent0f9d6085526921dd8edaffce827ffd07653ee4cd (diff)
downloadmongo-cbafd0521cd94a26ce790787d7d220c707132a48.tar.gz
SERVER-27160 Narrow race at startup between RSSync setting RECOVERING and BGSync setting ROLLBACK state
Diffstat (limited to 'src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp')
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp b/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp
index 84ea786227a..75623b81b7c 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp
@@ -473,6 +473,7 @@ void ReplicationCoordinatorImpl::_heartbeatReconfigStore(
}
}
+ bool shouldStartDataReplication = false;
if (!myIndex.getStatus().isOK() && myIndex.getStatus() != ErrorCodes::NodeNotFound) {
warning() << "Not persisting new configuration in heartbeat response to disk because "
"it is invalid: "
@@ -504,14 +505,21 @@ void ReplicationCoordinatorImpl::_heartbeatReconfigStore(
bool isArbiter = myIndex.isOK() && myIndex.getValue() != -1 &&
newConfig.getMemberAt(myIndex.getValue()).isArbiter();
if (!isArbiter && isFirstConfig) {
- _externalState->startThreads(_settings);
- _startDataReplication(opCtx.get());
+ shouldStartDataReplication = true;
}
+
+ LOG_FOR_HEARTBEATS(2) << "New configuration with version " << newConfig.getConfigVersion()
+ << " persisted to local storage; installing new config in memory";
}
- LOG_FOR_HEARTBEATS(2) << "New configuration with version " << newConfig.getConfigVersion()
- << " persisted to local storage; installing new config in memory";
_heartbeatReconfigFinish(cbd, newConfig, myIndex);
+
+ // Start data replication after the config has been installed.
+ if (shouldStartDataReplication) {
+ _externalState->startThreads(_settings);
+ auto opCtx = cc().makeOperationContext();
+ _startDataReplication(opCtx.get());
+ }
}
void ReplicationCoordinatorImpl::_heartbeatReconfigFinish(