diff options
author | Judah Schvimer <judah@mongodb.com> | 2017-08-01 10:58:04 -0400 |
---|---|---|
committer | Judah Schvimer <judah@mongodb.com> | 2017-08-01 10:58:04 -0400 |
commit | 3394652848101167fdc16e30e98f99ea9c57c3f4 (patch) | |
tree | e4619e1f0098a3cf0b260d63471987dfaf3cf416 /src/mongo | |
parent | 49f9a6b840d3a56fc1947290d9f5834e6ea370a7 (diff) | |
download | mongo-3394652848101167fdc16e30e98f99ea9c57c3f4.tar.gz |
SERVER-30185 Call setInitialDataTimestamp at the beginning and end of initial sync
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/bson/timestamp.cpp | 2 | ||||
-rw-r--r-- | src/mongo/bson/timestamp.h | 3 | ||||
-rw-r--r-- | src/mongo/db/repl/initial_syncer.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/repl/initial_syncer_test.cpp | 19 | ||||
-rw-r--r-- | src/mongo/db/storage/snapshot_name.h | 6 |
5 files changed, 36 insertions, 0 deletions
diff --git a/src/mongo/bson/timestamp.cpp b/src/mongo/bson/timestamp.cpp index b7958f16ff0..24d78241dfc 100644 --- a/src/mongo/bson/timestamp.cpp +++ b/src/mongo/bson/timestamp.cpp @@ -39,6 +39,8 @@ namespace mongo { +const Timestamp Timestamp::kAllowUnstableCheckpointsSentinal = Timestamp(0, 1); + Timestamp Timestamp::max() { unsigned int t = static_cast<unsigned int>(std::numeric_limits<uint32_t>::max()); unsigned int i = std::numeric_limits<uint32_t>::max(); diff --git a/src/mongo/bson/timestamp.h b/src/mongo/bson/timestamp.h index 39c0eb572a8..2c1f96e3caa 100644 --- a/src/mongo/bson/timestamp.h +++ b/src/mongo/bson/timestamp.h @@ -41,6 +41,9 @@ class BSONObj; */ class Timestamp { public: + // Timestamp to signal that the storage engine should take unstable checkpoints. + static const Timestamp kAllowUnstableCheckpointsSentinal; + // Maximum Timestamp value. static Timestamp max(); diff --git a/src/mongo/db/repl/initial_syncer.cpp b/src/mongo/db/repl/initial_syncer.cpp index a92e16b8013..cdba4798a16 100644 --- a/src/mongo/db/repl/initial_syncer.cpp +++ b/src/mongo/db/repl/initial_syncer.cpp @@ -394,6 +394,9 @@ void InitialSyncer::setScheduleDbWorkFn_forTest(const CollectionCloner::Schedule void InitialSyncer::_setUp_inlock(OperationContext* opCtx, std::uint32_t initialSyncMaxAttempts) { // 'opCtx' is passed through from startup(). _replicationProcess->getConsistencyMarkers()->setInitialSyncFlag(opCtx); + _storage->setInitialDataTimestamp(opCtx, + SnapshotName(Timestamp::kAllowUnstableCheckpointsSentinal)); + _storage->setStableTimestamp(opCtx, SnapshotName::min()); LOG(1) << "Creating oplogBuffer."; _oplogBuffer = _dataReplicatorExternalState->makeInitialSyncOplogBuffer(opCtx); @@ -415,6 +418,9 @@ void InitialSyncer::_tearDown_inlock(OperationContext* opCtx, if (!lastApplied.isOK()) { return; } + + _storage->setInitialDataTimestamp(opCtx, + SnapshotName(lastApplied.getValue().opTime.getTimestamp())); _replicationProcess->getConsistencyMarkers()->clearInitialSyncFlag(opCtx); _opts.setMyLastOptime(lastApplied.getValue().opTime); log() << "initial sync done; took " diff --git a/src/mongo/db/repl/initial_syncer_test.cpp b/src/mongo/db/repl/initial_syncer_test.cpp index af745d5359c..c43be289add 100644 --- a/src/mongo/db/repl/initial_syncer_test.cpp +++ b/src/mongo/db/repl/initial_syncer_test.cpp @@ -619,6 +619,22 @@ TEST_F(InitialSyncerTest, StartupSetsInitialSyncFlagOnSuccess) { ASSERT_TRUE(_replicationProcess->getConsistencyMarkers()->getInitialSyncFlag(opCtx.get())); } +TEST_F(InitialSyncerTest, StartupSetsInitialDataTimestampAndStableTimestampOnSuccess) { + auto initialSyncer = &getInitialSyncer(); + auto opCtx = makeOpCtx(); + + // Set initial data timestamp forward first. + _storageInterface->setInitialDataTimestamp(opCtx.get(), SnapshotName(Timestamp(5, 5))); + _storageInterface->setStableTimestamp(opCtx.get(), SnapshotName(Timestamp(6, 6))); + + ASSERT_OK(initialSyncer->startup(opCtx.get(), maxAttempts)); + ASSERT_TRUE(initialSyncer->isActive()); + + ASSERT_EQUALS(SnapshotName(Timestamp::kAllowUnstableCheckpointsSentinal), + _storageInterface->getInitialDataTimestamp()); + ASSERT_EQUALS(SnapshotName::min(), _storageInterface->getStableTimestamp()); +} + TEST_F(InitialSyncerTest, InitialSyncerReturnsCallbackCanceledIfShutdownImmediatelyAfterStartup) { auto initialSyncer = &getInitialSyncer(); auto opCtx = makeOpCtx(); @@ -3018,6 +3034,9 @@ TEST_F(InitialSyncerTest, initialSyncer->join(); ASSERT_EQUALS(lastOp.getOpTime(), unittest::assertGet(_lastApplied).opTime); ASSERT_EQUALS(lastOp.getHash(), unittest::assertGet(_lastApplied).value); + + ASSERT_EQUALS(SnapshotName(lastOp.getOpTime().getTimestamp()), + _storageInterface->getInitialDataTimestamp()); } TEST_F(InitialSyncerTest, diff --git a/src/mongo/db/storage/snapshot_name.h b/src/mongo/db/storage/snapshot_name.h index 5038d11c74f..2805d7467e7 100644 --- a/src/mongo/db/storage/snapshot_name.h +++ b/src/mongo/db/storage/snapshot_name.h @@ -31,6 +31,7 @@ #include <cstdint> #include <limits> +#include "mongo/bson/timestamp.h" #include "mongo/util/mongoutils/str.h" namespace mongo { @@ -38,6 +39,7 @@ namespace mongo { class SnapshotName { public: explicit SnapshotName(uint64_t value) : _value(value) {} + explicit SnapshotName(Timestamp ts) : SnapshotName(ts.asULL()) {} /** * Returns a SnapshotName guaranteed to compare < all names of actual snapshots. @@ -82,6 +84,10 @@ public: return _value >= rhs._value; } + friend std::ostream& operator<<(std::ostream& out, const SnapshotName& snapshotName) { + return out << snapshotName.toString(); + } + private: uint64_t _value; }; |