diff options
author | Gregory Wlodarek <gregory.wlodarek@mongodb.com> | 2020-02-28 14:35:48 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-02-28 20:25:50 +0000 |
commit | cfe950c5414837c78197d6ff1cc00975613f4fe2 (patch) | |
tree | 1e8d19a4fe1d8cc8f66e220f7e0cb659948c52cd | |
parent | 4226e47a720fbf861180828e4aa310ff9d9fe166 (diff) | |
download | mongo-cfe950c5414837c78197d6ff1cc00975613f4fe2.tar.gz |
SERVER-46488 recoverFromOplogUpTo should use the recovery timestamp
-rw-r--r-- | src/mongo/db/repl/replication_recovery.cpp | 18 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_recovery_test.cpp | 13 |
2 files changed, 12 insertions, 19 deletions
diff --git a/src/mongo/db/repl/replication_recovery.cpp b/src/mongo/db/repl/replication_recovery.cpp index 3219a171f7d..efbbfb8509b 100644 --- a/src/mongo/db/repl/replication_recovery.cpp +++ b/src/mongo/db/repl/replication_recovery.cpp @@ -324,28 +324,28 @@ void ReplicationRecoveryImpl::recoverFromOplogUpTo(OperationContext* opCtx, Time fassertFailedNoTrace(31399); } - Timestamp startPoint = _consistencyMarkers->getAppliedThrough(opCtx).getTimestamp(); - if (startPoint.isNull()) { - log() << "No stored oplog entries to apply for recovery."; - return; + boost::optional<Timestamp> startPoint = + _storageInterface->getRecoveryTimestamp(opCtx->getServiceContext()); + if (!startPoint) { + fassert(31436, "No recovery timestamp, cannot recover from the oplog."); } invariant(!endPoint.isNull()); - if (startPoint == endPoint) { + if (*startPoint == endPoint) { log() << "No oplog entries to apply for recovery. Start point '" << startPoint << "' is at the end point '" << endPoint << "' in the oplog."; return; - } else if (startPoint > endPoint) { + } else if (*startPoint > endPoint) { uasserted(ErrorCodes::BadValue, str::stream() << "No oplog entries to apply for recovery. Start point '" - << startPoint.toString() << "' is beyond the end point '" + << startPoint->toString() << "' is beyond the end point '" << endPoint.toString() << "' in the oplog."); } - Timestamp appliedUpTo = _applyOplogOperations(opCtx, startPoint, endPoint); + Timestamp appliedUpTo = _applyOplogOperations(opCtx, *startPoint, endPoint); if (appliedUpTo.isNull()) { - log() << "No stored oplog entries to apply for recovery between " << startPoint.toString() + log() << "No stored oplog entries to apply for recovery between " << startPoint->toString() << " (inclusive) and " << endPoint.toString() << " (inclusive)."; } else { invariant(appliedUpTo <= endPoint); diff --git a/src/mongo/db/repl/replication_recovery_test.cpp b/src/mongo/db/repl/replication_recovery_test.cpp index d3308a88e1d..618b344fb8c 100644 --- a/src/mongo/db/repl/replication_recovery_test.cpp +++ b/src/mongo/db/repl/replication_recovery_test.cpp @@ -1196,7 +1196,6 @@ TEST_F(ReplicationRecoveryTest, RecoverFromOplogUpToBeforeEndOfOplog) { _setUpOplog(opCtx, getStorageInterface(), {2, 3, 4, 5, 6, 7, 8, 9, 10}); getStorageInterfaceRecovery()->setRecoveryTimestamp(Timestamp(2, 2)); - getConsistencyMarkers()->setAppliedThrough(opCtx, OpTime(Timestamp(2, 2), 1)); // Recovers operations with timestamps: 3, 4, 5. recovery.recoverFromOplogUpTo(opCtx, Timestamp(5, 5)); @@ -1215,7 +1214,6 @@ TEST_F(ReplicationRecoveryTest, RecoverFromOplogUpToEndOfOplog) { _setUpOplog(opCtx, getStorageInterface(), {2, 3, 4, 5, 6, 7, 8, 9, 10}); getStorageInterfaceRecovery()->setRecoveryTimestamp(Timestamp(2, 2)); - getConsistencyMarkers()->setAppliedThrough(opCtx, OpTime(Timestamp(2, 2), 1)); // Recovers all operations recovery.recoverFromOplogUpTo(opCtx, Timestamp(10, 10)); @@ -1229,28 +1227,27 @@ TEST_F(ReplicationRecoveryTest, RecoverFromOplogUpToInvalidEndPoint) { _setUpOplog(opCtx, getStorageInterface(), {2, 3, 4, 5}); getStorageInterfaceRecovery()->setRecoveryTimestamp(Timestamp(2, 2)); - getConsistencyMarkers()->setAppliedThrough(opCtx, OpTime(Timestamp(2, 2), 1)); ASSERT_THROWS_CODE( recovery.recoverFromOplogUpTo(opCtx, Timestamp(1, 1)), DBException, ErrorCodes::BadValue); recovery.recoverFromOplogUpTo(opCtx, Timestamp(2, 2)); _assertDocsInTestCollection(opCtx, {}); - ASSERT_EQ(getConsistencyMarkers()->getAppliedThrough(opCtx), OpTime(Timestamp(2, 2), 1)); + ASSERT_EQ(getConsistencyMarkers()->getAppliedThrough(opCtx), OpTime(Timestamp(0, 0), 1)); } TEST_F(ReplicationRecoveryTest, RecoverFromOplogUpToWithEmptyOplog) { ReplicationRecoveryImpl recovery(getStorageInterface(), getConsistencyMarkers()); auto opCtx = getOperationContext(); - _setUpOplog(opCtx, getStorageInterface(), {}); + _setUpOplog(opCtx, getStorageInterface(), {2}); getStorageInterfaceRecovery()->setRecoveryTimestamp(Timestamp(2, 2)); startCapturingLogMessages(); recovery.recoverFromOplogUpTo(opCtx, Timestamp(5, 5)); stopCapturingLogMessages(); - ASSERT_EQUALS(1, countLogLinesContaining("No stored oplog entries to apply for recovery.")); + ASSERT_EQUALS(1, countLogLinesContaining("No stored oplog entries to apply for recovery")); _assertDocsInTestCollection(opCtx, {}); ASSERT_EQ(getConsistencyMarkers()->getAppliedThrough(opCtx), OpTime(Timestamp(0, 0), 1)); } @@ -1273,7 +1270,6 @@ TEST_F(ReplicationRecoveryTest, RecoverFromOplogUpToDoesNotExceedEndPoint) { _setUpOplog(opCtx, getStorageInterface(), {2, 5, 10}); getStorageInterfaceRecovery()->setRecoveryTimestamp(Timestamp(2, 2)); - getConsistencyMarkers()->setAppliedThrough(opCtx, OpTime(Timestamp(2, 2), 1)); recovery.recoverFromOplogUpTo(opCtx, Timestamp(9, 9)); ASSERT_EQ(getConsistencyMarkers()->getAppliedThrough(opCtx), OpTime(Timestamp(5, 5), 1)); @@ -1288,7 +1284,6 @@ TEST_F(ReplicationRecoveryTest, RecoverFromOplogUpToWithNoOperationsToRecover) { _setUpOplog(opCtx, getStorageInterface(), {1, 1580148188, std::numeric_limits<int>::max()}); getStorageInterfaceRecovery()->setRecoveryTimestamp(Timestamp(1580148188, 1580148188)); - getConsistencyMarkers()->setAppliedThrough(opCtx, OpTime(Timestamp(1580148188, 1580148188), 1)); startCapturingLogMessages(); recovery.recoverFromOplogUpTo(opCtx, Timestamp(1580148193, 1)); @@ -1304,7 +1299,6 @@ TEST_F(ReplicationRecoveryTest, RecoverFromOplogUpToReconstructsPreparedTransact _setUpOplog(opCtx, getStorageInterface(), {1, 2}); getStorageInterfaceRecovery()->setRecoveryTimestamp(Timestamp(1, 1)); - getConsistencyMarkers()->setAppliedThrough(opCtx, OpTime(Timestamp(1, 1), 1)); const auto sessionId = makeLogicalSessionIdForTest(); opCtx->setLogicalSessionId(sessionId); @@ -1347,7 +1341,6 @@ TEST_F(ReplicationRecoveryTest, _setUpOplog(opCtx, getStorageInterface(), {}); getStorageInterfaceRecovery()->setRecoveryTimestamp(Timestamp(1, 1)); - getConsistencyMarkers()->setAppliedThrough(opCtx, OpTime(Timestamp(1, 1), 1)); const auto sessionId = makeLogicalSessionIdForTest(); opCtx->setLogicalSessionId(sessionId); |