diff options
3 files changed, 32 insertions, 0 deletions
diff --git a/src/mongo/db/repl/replication_consistency_markers_impl.cpp b/src/mongo/db/repl/replication_consistency_markers_impl.cpp index 5d0b1f70a4a..1486d1ab397 100644 --- a/src/mongo/db/repl/replication_consistency_markers_impl.cpp +++ b/src/mongo/db/repl/replication_consistency_markers_impl.cpp @@ -162,6 +162,11 @@ void ReplicationConsistencyMarkersImpl::clearInitialSyncFlag(OperationContext* o _updateMinValidDocument(opCtx, update); + // Make sure to clear the oplogTrucateAfterPoint in case it is stale. Otherwise, we risk the + // possibility of deleting oplog entries that we want to keep. It is safe to clear this + // here since we are consistent at the top of our oplog at this point. + setOplogTruncateAfterPoint(opCtx, Timestamp()); + if (getGlobalServiceContext()->getStorageEngine()->isDurable()) { opCtx->recoveryUnit()->waitUntilDurable(); replCoord->setMyLastDurableOpTime(time); diff --git a/src/mongo/db/repl/replication_consistency_markers_impl_test.cpp b/src/mongo/db/repl/replication_consistency_markers_impl_test.cpp index 864a5b6601f..d20a8d64423 100644 --- a/src/mongo/db/repl/replication_consistency_markers_impl_test.cpp +++ b/src/mongo/db/repl/replication_consistency_markers_impl_test.cpp @@ -193,6 +193,32 @@ TEST_F(ReplicationConsistencyMarkersTest, GetMinValidAfterSettingInitialSyncFlag ASSERT(consistencyMarkers.getOplogTruncateAfterPoint(opCtx).isNull()); } +TEST_F(ReplicationConsistencyMarkersTest, ClearInitialSyncFlagResetsOplogTruncateAfterPoint) { + auto minValidNss = makeNamespace(_agent, "minValid"); + auto oplogTruncateAfterPointNss = makeNamespace(_agent, "oplogTruncateAfterPoint"); + + ReplicationConsistencyMarkersImpl consistencyMarkers( + getStorageInterface(), minValidNss, oplogTruncateAfterPointNss); + auto opCtx = getOperationContext(); + ASSERT(consistencyMarkers.createInternalCollections(opCtx).isOK()); + consistencyMarkers.initializeMinValidDocument(opCtx); + + ASSERT(consistencyMarkers.getOplogTruncateAfterPoint(opCtx).isNull()); + ASSERT_FALSE(consistencyMarkers.getInitialSyncFlag(opCtx)); + + // Set the oplog truncate after point and verify it has been set correctly. + OpTime endOpTime({Seconds(456), 0}, 1LL); + consistencyMarkers.setOplogTruncateAfterPoint(opCtx, endOpTime.getTimestamp()); + ASSERT_EQ(consistencyMarkers.getOplogTruncateAfterPoint(opCtx), endOpTime.getTimestamp()); + + // Clear the initial sync flag. + consistencyMarkers.clearInitialSyncFlag(opCtx); + ASSERT_FALSE(consistencyMarkers.getInitialSyncFlag(opCtx)); + + // Make sure the oplog truncate after point no longer exists. + ASSERT(consistencyMarkers.getOplogTruncateAfterPoint(opCtx).isNull()); +} + TEST_F(ReplicationConsistencyMarkersTest, ReplicationConsistencyMarkers) { auto minValidNss = makeNamespace(_agent, "minValid"); auto oplogTruncateAfterPointNss = makeNamespace(_agent, "oplogTruncateAfterPoint"); diff --git a/src/mongo/dbtests/storage_timestamp_tests.cpp b/src/mongo/dbtests/storage_timestamp_tests.cpp index f2ac40ad101..ecb3acea951 100644 --- a/src/mongo/dbtests/storage_timestamp_tests.cpp +++ b/src/mongo/dbtests/storage_timestamp_tests.cpp @@ -1568,6 +1568,7 @@ public: repl::ReplicationConsistencyMarkersImpl consistencyMarkers( repl::StorageInterface::get(_opCtx)); + ASSERT(consistencyMarkers.createInternalCollections(_opCtx).isOK()); consistencyMarkers.initializeMinValidDocument(_opCtx); consistencyMarkers.setInitialSyncFlag(_opCtx); |