diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
| commit | 4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch) | |
| tree | 1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/db/repl/replication_recovery.cpp | |
| parent | aa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff) | |
| parent | 8f0827553e09872941945a093b647a4211a9db7f (diff) | |
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0'
with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/db/repl/replication_recovery.cpp')
| -rw-r--r-- | src/mongo/db/repl/replication_recovery.cpp | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/src/mongo/db/repl/replication_recovery.cpp b/src/mongo/db/repl/replication_recovery.cpp index f8f983e936f..80388fd2f3e 100644 --- a/src/mongo/db/repl/replication_recovery.cpp +++ b/src/mongo/db/repl/replication_recovery.cpp @@ -332,7 +332,9 @@ void ReplicationRecoveryImpl::recoverFromOplogAsStandalone(OperationContext* opC // We support only recovery from stable checkpoints during initial sync. invariant(!_duringInitialSync || recoveryTS); - boost::optional<Timestamp> stableTimestamp = boost::none; + // Initialize the cached pointer to the oplog collection. + acquireOplogCollectionForLogging(opCtx); + if (recoveryTS || startupRecoveryForRestore) { if (startupRecoveryForRestore && !recoveryTS) { LOGV2_WARNING(5576601, @@ -343,7 +345,8 @@ void ReplicationRecoveryImpl::recoverFromOplogAsStandalone(OperationContext* opC // We pass in "none" for the stable timestamp so that recoverFromOplog asks storage // for the recoveryTimestamp just like on replica set recovery. - stableTimestamp = recoverFromOplog(opCtx, boost::none); + const auto stableTimestamp = boost::none; + recoverFromOplog(opCtx, stableTimestamp); } else { if (gTakeUnstableCheckpointOnShutdown) { // Ensure 'recoverFromOplogAsStandalone' with 'takeUnstableCheckpointOnShutdown' @@ -363,10 +366,7 @@ void ReplicationRecoveryImpl::recoverFromOplogAsStandalone(OperationContext* opC if (!_duringInitialSync) { // Initial sync will reconstruct prepared transactions when it is completely done. - reconstructPreparedTransactions(opCtx, - stableTimestamp - ? OplogApplication::Mode::kStableRecovering - : OplogApplication::Mode::kUnstableRecovering); + reconstructPreparedTransactions(opCtx, OplogApplication::Mode::kRecovering); // Two-phase index builds are built in the background, which may still be in-progress after // recovering from the oplog. To prevent crashing the server, skip enabling read-only mode. @@ -392,6 +392,9 @@ void ReplicationRecoveryImpl::recoverFromOplogUpTo(OperationContext* opCtx, Time "Cannot use 'recoverToOplogTimestamp' without a stable checkpoint"); } + // Initialize the cached pointer to the oplog collection. + acquireOplogCollectionForLogging(opCtx); + // This may take an IS lock on the oplog collection. _truncateOplogIfNeededAndThenClearOplogTruncateAfterPoint(opCtx, &recoveryTS); @@ -435,14 +438,14 @@ void ReplicationRecoveryImpl::recoverFromOplogUpTo(OperationContext* opCtx, Time invariant(appliedUpTo <= endPoint); } - reconstructPreparedTransactions(opCtx, OplogApplication::Mode::kStableRecovering); + reconstructPreparedTransactions(opCtx, OplogApplication::Mode::kRecovering); } -boost::optional<Timestamp> ReplicationRecoveryImpl::recoverFromOplog( - OperationContext* opCtx, boost::optional<Timestamp> stableTimestamp) try { +void ReplicationRecoveryImpl::recoverFromOplog(OperationContext* opCtx, + boost::optional<Timestamp> stableTimestamp) try { if (_consistencyMarkers->getInitialSyncFlag(opCtx)) { LOGV2(21542, "No recovery needed. Initial sync flag set"); - return stableTimestamp; // Initial Sync will take over so no cleanup is needed. + return; // Initial Sync will take over so no cleanup is needed. } const auto serviceCtx = getGlobalServiceContext(); @@ -484,7 +487,7 @@ boost::optional<Timestamp> ReplicationRecoveryImpl::recoverFromOplog( // Oplog is empty. There are no oplog entries to apply, so we exit recovery and go into // initial sync. LOGV2(21543, "No oplog entries to apply for recovery. Oplog is empty"); - return stableTimestamp; + return; } fassert(40290, topOfOplogSW); const auto topOfOplog = topOfOplogSW.getValue(); @@ -498,7 +501,6 @@ boost::optional<Timestamp> ReplicationRecoveryImpl::recoverFromOplog( _recoverFromUnstableCheckpoint( opCtx, _consistencyMarkers->getAppliedThrough(opCtx), topOfOplog); } - return stableTimestamp; } catch (...) { LOGV2_FATAL_CONTINUE(21570, "Caught exception during replication recovery: {error}", @@ -711,10 +713,6 @@ Timestamp ReplicationRecoveryImpl::_applyOplogOperations(OperationContext* opCtx RecoveryOplogApplierStats stats; - auto oplogApplicationMode = (recoveryMode == RecoveryMode::kStartupFromStableTimestamp || - recoveryMode == RecoveryMode::kRollbackFromStableTimestamp) - ? OplogApplication::Mode::kStableRecovering - : OplogApplication::Mode::kUnstableRecovering; auto writerPool = makeReplWriterPool(); auto* replCoord = ReplicationCoordinator::get(opCtx); OplogApplierImpl oplogApplier(nullptr, @@ -723,7 +721,7 @@ Timestamp ReplicationRecoveryImpl::_applyOplogOperations(OperationContext* opCtx replCoord, _consistencyMarkers, _storageInterface, - OplogApplier::Options(oplogApplicationMode), + OplogApplier::Options(OplogApplication::Mode::kRecovering), writerPool.get()); OplogApplier::BatchLimits batchLimits; |
