diff options
author | A. Jesse Jiryu Davis <jesse@mongodb.com> | 2020-12-02 13:52:21 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-12-14 03:27:43 +0000 |
commit | 265e3c7d0d40457f0e8483d3ed4161ac3896d04a (patch) | |
tree | 5585f533a56ed6c60e85c82a9f32d961e4d2656b /src/mongo | |
parent | e7df7aee5095174712f8b73ac2fa4c8d6afa0293 (diff) | |
download | mongo-265e3c7d0d40457f0e8483d3ed4161ac3896d04a.tar.gz |
SERVER-53026 Fix "resync" command
(cherry picked from commit a574d23ec0b7d06b8d872bf64136308f541a796d)
(cherry picked from commit 68bf17aa3b19d0b7f53b7a1b6fe1ebbafdf558d2)
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl.cpp | 20 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl.h | 3 |
2 files changed, 16 insertions, 7 deletions
diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp index 7f022cbb0e4..b355588bb0b 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl.cpp @@ -662,6 +662,11 @@ void ReplicationCoordinatorImpl::_stopDataReplication(OperationContext* opCtx) { std::shared_ptr<InitialSyncer> initialSyncerCopy; { stdx::lock_guard<Latch> lk(_mutex); + if (!_startedSteadyStateReplication) { + return; + } + + _startedSteadyStateReplication = false; _initialSyncer.swap(initialSyncerCopy); } if (initialSyncerCopy) { @@ -681,20 +686,24 @@ void ReplicationCoordinatorImpl::_stopDataReplication(OperationContext* opCtx) { void ReplicationCoordinatorImpl::_startDataReplication(OperationContext* opCtx, stdx::function<void()> startCompleted) { - if (_startedSteadyStateReplication.swap(true)) { - // This is not the first call. + stdx::unique_lock<Latch> lk(_mutex); + if (_startedSteadyStateReplication) { return; } + _startedSteadyStateReplication = true; + // Check to see if we need to do an initial sync. - const auto lastOpTime = getMyLastAppliedOpTime(); + const auto lastOpTime = _getMyLastAppliedOpTime_inlock(); const auto needsInitialSync = lastOpTime.isNull() || _externalState->isInitialSyncFlagSet(opCtx); if (!needsInitialSync) { // Start steady replication, since we already have data. // ReplSetConfig has been installed, so it's either in STARTUP2 or REMOVED. - auto memberState = getMemberState(); + auto memberState = _getMemberState_inlock(); invariant(memberState.startup2() || memberState.removed()); + + lk.unlock(); invariant(setFollowerMode(MemberState::RS_RECOVERING)); _externalState->startSteadyStateReplication(opCtx, this); return; @@ -748,8 +757,6 @@ void ReplicationCoordinatorImpl::_startDataReplication(OperationContext* opCtx, std::shared_ptr<InitialSyncer> initialSyncerCopy; try { { - // Must take the lock to set _initialSyncer, but not call it. - stdx::lock_guard<Latch> lock(_mutex); if (_inShutdown) { log() << "Initial Sync not starting because replication is shutting down."; return; @@ -766,6 +773,7 @@ void ReplicationCoordinatorImpl::_startDataReplication(OperationContext* opCtx, } // InitialSyncer::startup() must be called outside lock because it uses features (eg. // setting the initial sync flag) which depend on the ReplicationCoordinatorImpl. + lk.unlock(); uassertStatusOK(initialSyncerCopy->startup(opCtx, numInitialSyncAttempts.load())); } catch (...) { auto status = exceptionToStatus(); diff --git a/src/mongo/db/repl/replication_coordinator_impl.h b/src/mongo/db/repl/replication_coordinator_impl.h index 5fef76622b4..33d570c51eb 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.h +++ b/src/mongo/db/repl/replication_coordinator_impl.h @@ -1568,7 +1568,8 @@ private: // here so we can update our term to match as part of finishing stepdown. boost::optional<long long> _pendingTermUpdateDuringStepDown; // (M) - AtomicWord<bool> _startedSteadyStateReplication{false}; + // Whether data replication is active. + bool _startedSteadyStateReplication = false; // (M) // If we're in terminal shutdown. If true, we'll refuse to vote in elections. bool _inTerminalShutdown = false; // (M) |