summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJudah Schvimer <judah@mongodb.com>2018-04-17 11:06:59 -0400
committerJudah Schvimer <judah@mongodb.com>2018-04-23 16:14:19 -0400
commit1d4dbff63e25c104760f730eccb01b85726e376a (patch)
treebf450bfda3ada7b8c0c5951b98e94ac5b53c56a5
parent41d77e2940fbcbd691d4b2f01e9ec1dd5ef67e47 (diff)
downloadmongo-1d4dbff63e25c104760f730eccb01b85726e376a.tar.gz
SERVER-34070 Fix invariant in replication recovery
-rw-r--r--src/mongo/db/repl/replication_recovery.cpp14
-rw-r--r--src/mongo/db/repl/replication_recovery_test.cpp14
2 files changed, 10 insertions, 18 deletions
diff --git a/src/mongo/db/repl/replication_recovery.cpp b/src/mongo/db/repl/replication_recovery.cpp
index 24bc1c8d60b..286841e070a 100644
--- a/src/mongo/db/repl/replication_recovery.cpp
+++ b/src/mongo/db/repl/replication_recovery.cpp
@@ -90,13 +90,6 @@ void ReplicationRecoveryImpl::recoverFromOplog(OperationContext* opCtx,
fassert(40290, topOfOplogSW);
const auto topOfOplog = topOfOplogSW.getValue();
- const auto appliedThrough = _consistencyMarkers->getAppliedThrough(opCtx);
- invariant(!stableTimestamp || appliedThrough.isNull() ||
- *stableTimestamp == appliedThrough.getTimestamp(),
- str::stream() << "Stable timestamp " << stableTimestamp->toString()
- << " does not equal appliedThrough timestamp "
- << appliedThrough.toString());
-
// If we were passed in a stable timestamp, we are in rollback recovery and should recover from
// that stable timestamp. Otherwise, we're recovering at startup. If this storage engine
// supports recover to stable timestamp, we ask it for the recovery timestamp. If the storage
@@ -109,6 +102,13 @@ void ReplicationRecoveryImpl::recoverFromOplog(OperationContext* opCtx,
stableTimestamp = _storageInterface->getRecoveryTimestamp(opCtx->getServiceContext());
}
+ const auto appliedThrough = _consistencyMarkers->getAppliedThrough(opCtx);
+ invariant(!stableTimestamp || appliedThrough.isNull() ||
+ *stableTimestamp == appliedThrough.getTimestamp(),
+ str::stream() << "Stable timestamp " << stableTimestamp->toString()
+ << " does not equal appliedThrough timestamp "
+ << appliedThrough.toString());
+
if (stableTimestamp) {
invariant(supportsRecoverToStableTimestamp);
_recoverFromStableTimestamp(opCtx, *stableTimestamp, appliedThrough, topOfOplog);
diff --git a/src/mongo/db/repl/replication_recovery_test.cpp b/src/mongo/db/repl/replication_recovery_test.cpp
index 6bac4e5a0d2..1a7cc5f8be8 100644
--- a/src/mongo/db/repl/replication_recovery_test.cpp
+++ b/src/mongo/db/repl/replication_recovery_test.cpp
@@ -532,26 +532,18 @@ TEST_F(ReplicationRecoveryTest,
testRecoveryToStableAppliesDocumentsWithNoAppliedThrough(false);
}
-TEST_F(ReplicationRecoveryTest,
- RecoveryAppliesDocumentsWithUnmatchedAppliedThroughAndStableCheckpointIsBehind) {
+DEATH_TEST_F(ReplicationRecoveryTest,
+ RecoveryFailsWithUnmatchedAppliedThrough,
+ "Invariant failure") {
ReplicationRecoveryImpl recovery(getStorageInterface(), getConsistencyMarkers());
auto opCtx = getOperationContext();
_setUpOplog(opCtx, getStorageInterface(), {1, 2, 3, 4, 5});
- // Fake applying op 3, which will be reapplied.
auto appliedThroughTS = Timestamp(4, 4);
getConsistencyMarkers()->setAppliedThrough(opCtx, OpTime(appliedThroughTS, 1));
- ASSERT_OK(getStorageInterface()->insertDocument(opCtx, testNs, {_makeInsertDocument(3)}, 1));
- _assertDocsInTestCollection(opCtx, {3});
-
getStorageInterfaceRecovery()->setRecoveryTimestamp(Timestamp(2, 2));
recovery.recoverFromOplog(opCtx, boost::none);
-
- _assertDocsInOplog(opCtx, {1, 2, 3, 4, 5});
- _assertDocsInTestCollection(opCtx, {3, 4, 5});
- ASSERT_EQ(getConsistencyMarkers()->getOplogTruncateAfterPoint(opCtx), Timestamp());
- ASSERT_EQ(getConsistencyMarkers()->getAppliedThrough(opCtx), OpTime(Timestamp(5, 5), 1));
}
TEST_F(ReplicationRecoveryTest, RecoveryIgnoresDroppedCollections) {