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 21:18:43 +0000 |
commit | 125df05d1eece8053fb77ed7ba7e87083bd08554 (patch) | |
tree | f3e2a57d525a7d52b0601d5516cf01d697faf40a | |
parent | 436d659132e7ec8bc38afc1b5ee0ba568c860a8c (diff) | |
download | mongo-125df05d1eece8053fb77ed7ba7e87083bd08554.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 0c6f02fe4d1..667170bc97f 100644 --- a/src/mongo/db/repl/replication_recovery.cpp +++ b/src/mongo/db/repl/replication_recovery.cpp @@ -358,34 +358,34 @@ void ReplicationRecoveryImpl::recoverFromOplogUpTo(OperationContext* opCtx, Time // This may take an IS lock on the oplog collection. _truncateOplogIfNeededAndThenClearOplogTruncateAfterPoint(opCtx, recoveryTS); - Timestamp startPoint = _consistencyMarkers->getAppliedThrough(opCtx).getTimestamp(); - if (startPoint.isNull()) { - LOGV2(21539, "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) { LOGV2(21540, "No oplog entries to apply for recovery. Start point '{startPoint}' is at the end " "point '{endPoint}' in the oplog.", "startPoint"_attr = startPoint, "endPoint"_attr = endPoint); 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()) { LOGV2(21541, "No stored oplog entries to apply for recovery between {startPoint} (inclusive) and " "{endPoint} (inclusive).", - "startPoint"_attr = startPoint.toString(), + "startPoint"_attr = startPoint->toString(), "endPoint"_attr = endPoint.toString()); } 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 e946b535c0d..e9766b6b472 100644 --- a/src/mongo/db/repl/replication_recovery_test.cpp +++ b/src/mongo/db/repl/replication_recovery_test.cpp @@ -1273,7 +1273,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)); @@ -1292,7 +1291,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)); @@ -1306,21 +1304,20 @@ 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(); @@ -1328,7 +1325,7 @@ TEST_F(ReplicationRecoveryTest, RecoverFromOplogUpToWithEmptyOplog) { stopCapturingLogMessages(); ASSERT_EQUALS( - 1, countTextFormatLogLinesContaining("No stored oplog entries to apply for recovery.")); + 1, countTextFormatLogLinesContaining("No stored oplog entries to apply for recovery")); _assertDocsInTestCollection(opCtx, {}); ASSERT_EQ(getConsistencyMarkers()->getAppliedThrough(opCtx), OpTime(Timestamp(0, 0), 1)); } @@ -1351,7 +1348,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)); @@ -1366,7 +1362,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)); @@ -1383,7 +1378,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); @@ -1426,7 +1420,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); |