summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorMatthew Russotto <matthew.russotto@10gen.com>2019-07-31 15:35:31 -0400
committerMatthew Russotto <matthew.russotto@10gen.com>2019-08-23 16:47:57 -0400
commit7897a0a4ef9ee0e6beb9d384f5ea5a6e7c187fce (patch)
treee9632df480a6a4a4aa1ef84995487266ae94112e /src/mongo/db
parentadecec418601ccc2690c4e4750d06087ad43fb10 (diff)
downloadmongo-7897a0a4ef9ee0e6beb9d384f5ea5a6e7c187fce.tar.gz
SERVER-39776 Fix race between initial syncer startup, data replication thread startup and shutdown
(cherry picked from commit d362c1c39ca79dd20e0aa6e9f93171fc5bd2cdec)
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/repl/replication_coordinator_external_state_impl.cpp5
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl.cpp4
2 files changed, 8 insertions, 1 deletions
diff --git a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp
index b4896745912..f87f0f0681a 100644
--- a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp
+++ b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp
@@ -319,6 +319,9 @@ void ReplicationCoordinatorExternalStateImpl::startThreads(const ReplSettings& s
if (_startedThreads) {
return;
}
+ if (_inShutdown) {
+ log() << "Not starting replication storage threads because replication is shutting down.";
+ }
log() << "Starting replication storage threads";
_service->getStorageEngine()->setJournalListener(this);
@@ -336,11 +339,11 @@ void ReplicationCoordinatorExternalStateImpl::startThreads(const ReplSettings& s
void ReplicationCoordinatorExternalStateImpl::shutdown(OperationContext* opCtx) {
stdx::unique_lock<stdx::mutex> lk(_threadMutex);
+ _inShutdown = true;
if (!_startedThreads) {
return;
}
- _inShutdown = true;
_stopDataReplication_inlock(opCtx, lk);
if (_noopWriter) {
diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp
index 349e90eccc4..56c281e251c 100644
--- a/src/mongo/db/repl/replication_coordinator_impl.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl.cpp
@@ -756,6 +756,10 @@ void ReplicationCoordinatorImpl::_startDataReplication(OperationContext* opCtx,
{
// Must take the lock to set _initialSyncer, but not call it.
stdx::lock_guard<stdx::mutex> lock(_mutex);
+ if (_inShutdown) {
+ log() << "Initial Sync not starting because replication is shutting down.";
+ return;
+ }
initialSyncerCopy = std::make_shared<InitialSyncer>(
createInitialSyncerOptions(this, _externalState.get()),
stdx::make_unique<DataReplicatorExternalStateInitialSync>(this,