diff options
Diffstat (limited to 'src/mongo/db')
4 files changed, 29 insertions, 6 deletions
diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp index 045deec2bae..151c7b4b275 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl.cpp @@ -2303,9 +2303,16 @@ Status ReplicationCoordinatorImpl::processReplSetInitiate(OperationContext* opCt return status; } + auto lastAppliedOpTime = getMyLastAppliedOpTime(); + // Since the JournalListener has not yet been set up, we must manually set our // durableOpTime. - setMyLastDurableOpTime(getMyLastAppliedOpTime()); + setMyLastDurableOpTime(lastAppliedOpTime); + + // Sets the initial data timestamp on the storage engine so it can assign a timestamp + // to data on disk. We do this after writing the "initiating set" oplog entry. + auto initialDataTS = SnapshotName(lastAppliedOpTime.getTimestamp().asULL()); + _storage->setInitialDataTimestamp(opCtx, initialDataTS); _finishReplSetInitiate(newConfig, myIndex.getValue()); diff --git a/src/mongo/db/repl/replication_coordinator_impl_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_test.cpp index 5a8a7ee8d0a..fee1eca4e1e 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_test.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_test.cpp @@ -53,6 +53,7 @@ #include "mongo/db/repl/replication_coordinator_external_state_mock.h" #include "mongo/db/repl/replication_coordinator_impl.h" #include "mongo/db/repl/replication_coordinator_test_fixture.h" +#include "mongo/db/repl/storage_interface_mock.h" #include "mongo/db/repl/topology_coordinator_impl.h" #include "mongo/db/repl/update_position_args.h" #include "mongo/db/server_options.h" @@ -381,6 +382,9 @@ TEST_F(ReplCoordTest, InitiateSucceedsWhenQuorumCheckPasses) { hbArgs.setSenderHost(HostAndPort("node1", 12345)); hbArgs.setSenderId(0); + auto appliedTS = Timestamp(3, 3); + getReplCoord()->setMyLastAppliedOpTime(OpTime(appliedTS, 1)); + Status status(ErrorCodes::InternalError, "Not set"); stdx::thread prsiThread(stdx::bind(doReplSetInitiate, getReplCoord(), &status)); const Date_t startDate = getNet()->now(); @@ -401,6 +405,9 @@ TEST_F(ReplCoordTest, InitiateSucceedsWhenQuorumCheckPasses) { prsiThread.join(); ASSERT_OK(status); ASSERT_EQUALS(ReplicationCoordinator::modeReplSet, getReplCoord()->getReplicationMode()); + + ASSERT_EQUALS(getStorageInterface()->getInitialDataTimestamp().asU64(), + SnapshotName(appliedTS.asULL()).asU64()); } TEST_F(ReplCoordTest, diff --git a/src/mongo/db/repl/replication_coordinator_test_fixture.cpp b/src/mongo/db/repl/replication_coordinator_test_fixture.cpp index b1a93ec2b24..5e8eac78138 100644 --- a/src/mongo/db/repl/replication_coordinator_test_fixture.cpp +++ b/src/mongo/db/repl/replication_coordinator_test_fixture.cpp @@ -121,14 +121,14 @@ void ReplCoordTest::init() { invariant(!_callShutdown); auto service = getGlobalServiceContext(); - StorageInterface* storageInterface = new StorageInterfaceMock(); - StorageInterface::set(service, std::unique_ptr<StorageInterface>(storageInterface)); - ASSERT_TRUE(storageInterface == StorageInterface::get(service)); + _storageInterface = new StorageInterfaceMock(); + StorageInterface::set(service, std::unique_ptr<StorageInterface>(_storageInterface)); + ASSERT_TRUE(_storageInterface == StorageInterface::get(service)); ReplicationProcess::set( service, stdx::make_unique<ReplicationProcess>( - storageInterface, stdx::make_unique<ReplicationConsistencyMarkersMock>())); + _storageInterface, stdx::make_unique<ReplicationConsistencyMarkersMock>())); auto replicationProcess = ReplicationProcess::get(service); // PRNG seed for tests. @@ -156,7 +156,7 @@ void ReplCoordTest::init() { std::move(replExec), std::move(topo), replicationProcess, - storageInterface, + _storageInterface, seed); service->setFastClockSource(stdx::make_unique<executor::NetworkInterfaceMockClockSource>(_net)); service->setPreciseClockSource( diff --git a/src/mongo/db/repl/replication_coordinator_test_fixture.h b/src/mongo/db/repl/replication_coordinator_test_fixture.h index 9f1b27aabea..e1aaa9ca6d1 100644 --- a/src/mongo/db/repl/replication_coordinator_test_fixture.h +++ b/src/mongo/db/repl/replication_coordinator_test_fixture.h @@ -112,6 +112,13 @@ protected: } /** + * Gets the storage interface. + */ + StorageInterfaceMock* getStorageInterface() { + return _storageInterface; + } + + /** * Gets the topology coordinator used by the replication coordinator under test. */ TopologyCoordinatorImpl& getTopoCoord() { @@ -267,6 +274,8 @@ private: ReplicationCoordinatorExternalStateMock* _externalState = nullptr; // Owned by ReplicationCoordinatorImpl executor::TaskExecutor* _replExec = nullptr; + // Owned by the ServiceContext + StorageInterfaceMock* _storageInterface = nullptr; ReplSettings _settings; bool _callShutdown = false; |