summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/replication_recovery.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/repl/replication_recovery.cpp')
-rw-r--r--src/mongo/db/repl/replication_recovery.cpp27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/mongo/db/repl/replication_recovery.cpp b/src/mongo/db/repl/replication_recovery.cpp
index 80388fd2f3e..276d877ca67 100644
--- a/src/mongo/db/repl/replication_recovery.cpp
+++ b/src/mongo/db/repl/replication_recovery.cpp
@@ -334,7 +334,7 @@ void ReplicationRecoveryImpl::recoverFromOplogAsStandalone(OperationContext* opC
// Initialize the cached pointer to the oplog collection.
acquireOplogCollectionForLogging(opCtx);
-
+ boost::optional<Timestamp> stableTimestamp = boost::none;
if (recoveryTS || startupRecoveryForRestore) {
if (startupRecoveryForRestore && !recoveryTS) {
LOGV2_WARNING(5576601,
@@ -345,8 +345,7 @@ 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.
- const auto stableTimestamp = boost::none;
- recoverFromOplog(opCtx, stableTimestamp);
+ stableTimestamp = recoverFromOplog(opCtx, boost::none);
} else {
if (gTakeUnstableCheckpointOnShutdown) {
// Ensure 'recoverFromOplogAsStandalone' with 'takeUnstableCheckpointOnShutdown'
@@ -366,7 +365,10 @@ void ReplicationRecoveryImpl::recoverFromOplogAsStandalone(OperationContext* opC
if (!_duringInitialSync) {
// Initial sync will reconstruct prepared transactions when it is completely done.
- reconstructPreparedTransactions(opCtx, OplogApplication::Mode::kRecovering);
+ reconstructPreparedTransactions(opCtx,
+ stableTimestamp
+ ? OplogApplication::Mode::kStableRecovering
+ : OplogApplication::Mode::kUnstableRecovering);
// 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.
@@ -438,14 +440,14 @@ void ReplicationRecoveryImpl::recoverFromOplogUpTo(OperationContext* opCtx, Time
invariant(appliedUpTo <= endPoint);
}
- reconstructPreparedTransactions(opCtx, OplogApplication::Mode::kRecovering);
+ reconstructPreparedTransactions(opCtx, OplogApplication::Mode::kStableRecovering);
}
-void ReplicationRecoveryImpl::recoverFromOplog(OperationContext* opCtx,
- boost::optional<Timestamp> stableTimestamp) try {
+boost::optional<Timestamp> ReplicationRecoveryImpl::recoverFromOplog(
+ OperationContext* opCtx, boost::optional<Timestamp> stableTimestamp) try {
if (_consistencyMarkers->getInitialSyncFlag(opCtx)) {
LOGV2(21542, "No recovery needed. Initial sync flag set");
- return; // Initial Sync will take over so no cleanup is needed.
+ return stableTimestamp; // Initial Sync will take over so no cleanup is needed.
}
const auto serviceCtx = getGlobalServiceContext();
@@ -487,7 +489,7 @@ void ReplicationRecoveryImpl::recoverFromOplog(OperationContext* opCtx,
// 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;
+ return stableTimestamp;
}
fassert(40290, topOfOplogSW);
const auto topOfOplog = topOfOplogSW.getValue();
@@ -501,6 +503,7 @@ void ReplicationRecoveryImpl::recoverFromOplog(OperationContext* opCtx,
_recoverFromUnstableCheckpoint(
opCtx, _consistencyMarkers->getAppliedThrough(opCtx), topOfOplog);
}
+ return stableTimestamp;
} catch (...) {
LOGV2_FATAL_CONTINUE(21570,
"Caught exception during replication recovery: {error}",
@@ -713,6 +716,10 @@ 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,
@@ -721,7 +728,7 @@ Timestamp ReplicationRecoveryImpl::_applyOplogOperations(OperationContext* opCtx
replCoord,
_consistencyMarkers,
_storageInterface,
- OplogApplier::Options(OplogApplication::Mode::kRecovering),
+ OplogApplier::Options(oplogApplicationMode),
writerPool.get());
OplogApplier::BatchLimits batchLimits;