summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVesselina Ratcheva <vesselina.ratcheva@10gen.com>2018-06-07 16:46:10 -0400
committerVesselina Ratcheva <vesselina.ratcheva@10gen.com>2018-06-11 18:44:05 -0400
commitff650c07cf0ef56f1621a257a354fa09038ff01e (patch)
treee4120ca01bc773f18169eb5baa1201eb070f7d65
parentcf23944c65308fe36d98a8a04647647f1b902200 (diff)
downloadmongo-ff650c07cf0ef56f1621a257a354fa09038ff01e.tar.gz
SERVER-34215 Clear oplog truncate after point when clearing initial sync flag
(cherry picked from commit f320f151e0a709dafc8f8359ab7fab303a7f74a9)
-rw-r--r--src/mongo/db/repl/replication_consistency_markers_impl.cpp5
-rw-r--r--src/mongo/db/repl/replication_consistency_markers_impl_test.cpp26
-rw-r--r--src/mongo/dbtests/storage_timestamp_tests.cpp1
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);