summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorWilliam Schultz <william.schultz@mongodb.com>2017-08-10 11:00:02 -0400
committerWilliam Schultz <william.schultz@mongodb.com>2017-08-10 18:41:15 -0400
commit3a6f7017c2577af96c377f1500998565737952e6 (patch)
tree3c67267c71a350af3aab04f0b80a2c9e2b8c3cd0 /src/mongo/db
parente1978af38dff725f0a0a60bca39a21b072751218 (diff)
downloadmongo-3a6f7017c2577af96c377f1500998565737952e6.tar.gz
SERVER-30589 Don't add stable timestamp candidates when in master slave mode
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl.cpp14
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_test.cpp37
2 files changed, 44 insertions, 7 deletions
diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp
index 2ea7ee7b3fb..9b6e53ef76f 100644
--- a/src/mongo/db/repl/replication_coordinator_impl.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl.cpp
@@ -1036,9 +1036,17 @@ void ReplicationCoordinatorImpl::_setMyLastAppliedOpTime_inlock(const OpTime& op
_updateLastCommittedOpTime_inlock();
// Add the new applied timestamp to the list of stable timestamp candidates and then set the
- // last stable timestamp.
- _stableTimestampCandidates.insert(opTime.getTimestamp());
- _setStableTimestampForStorage_inlock();
+ // last stable timestamp. Stable timestamps are used to determine the last timestamp that it is
+ // safe to revert the database to, in the event of a rollback. Note that master-slave mode has
+ // no automatic fail over, and so rollbacks never occur. Additionally, the commit point for a
+ // master-slave set will never advance, since it doesn't use any consensus protocol. Since the
+ // set of stable timestamp candidates can only get cleaned up when the commit point advances, we
+ // should refrain from updating stable timestamp candidates in master-slave mode, to avoid the
+ // candidates list from growing unbounded.
+ if (getReplicationMode() == Mode::modeReplSet) {
+ _stableTimestampCandidates.insert(opTime.getTimestamp());
+ _setStableTimestampForStorage_inlock();
+ }
_opTimeWaiterList.signalAndRemoveIf_inlock(
[opTime](Waiter* waiter) { return waiter->opTime <= opTime; });
diff --git a/src/mongo/db/repl/replication_coordinator_impl_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_test.cpp
index babe8fdbc42..9a7ed34f44e 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_test.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_test.cpp
@@ -3559,10 +3559,16 @@ protected:
return ss.str();
}
-private:
- virtual void setUp() {
- ReplCoordTest::setUp();
- init(ReplSettings());
+ void initReplSetMode() {
+ auto settings = ReplSettings();
+ settings.setReplSetString("replset");
+ init(settings);
+ }
+
+ void initMasterSlaveMode() {
+ auto settings = ReplSettings();
+ settings.setSlave(true);
+ init(settings);
}
};
@@ -3577,6 +3583,7 @@ TEST_F(StableTimestampTest, CalculateStableTimestamp) {
* Tests the 'ReplicationCoordinatorImpl::_calculateStableTimestamp' method.
*/
+ initReplSetMode();
auto repl = getReplCoord();
Timestamp commitPoint;
boost::optional<Timestamp> expectedStableTimestamp, stableTimestamp;
@@ -3621,6 +3628,7 @@ TEST_F(StableTimestampTest, CleanupStableTimestampCandidates) {
* Tests the 'ReplicationCoordinatorImpl::_cleanupStableTimestampCandidates' method.
*/
+ initReplSetMode();
auto repl = getReplCoord();
Timestamp stableTimestamp;
std::set<Timestamp> timestampCandidates, expectedTimestampCandidates;
@@ -3656,6 +3664,7 @@ TEST_F(StableTimestampTest, SetMyLastAppliedSetsStableTimestampForStorage) {
* timestamp calculation logic.
*/
+ initReplSetMode();
auto repl = getReplCoord();
Timestamp stableTimestamp;
@@ -3686,6 +3695,7 @@ TEST_F(StableTimestampTest, AdvanceCommitPointSetsStableTimestampForStorage) {
* calculation logic.
*/
+ initReplSetMode();
auto repl = getReplCoord();
Timestamp stableTimestamp;
@@ -3709,6 +3719,25 @@ TEST_F(StableTimestampTest, AdvanceCommitPointSetsStableTimestampForStorage) {
ASSERT_TIMESTAMP_SET_EQ(expectedTimestampCandidates, timestampCandidates);
}
+TEST_F(StableTimestampTest, SetMyLastAppliedDoesntAddTimestampCandidateInMasterSlaveMode) {
+
+ /**
+ * Test that 'setMyLastAppliedOpTime' doesn't add timestamp candidates to the stable timestamp
+ * list when running in master-slave mode.
+ */
+
+ initMasterSlaveMode();
+ auto repl = getReplCoord();
+ Timestamp stableTimestamp;
+
+ ASSERT(repl->getStableTimestampCandidates_forTest().empty());
+
+ repl->setMyLastAppliedOpTime(OpTime({0, 1}, 0));
+ repl->setMyLastAppliedOpTime(OpTime({0, 2}, 0));
+
+ // Make sure no timestamps candidates were added.
+ ASSERT(repl->getStableTimestampCandidates_forTest().empty());
+}
TEST_F(ReplCoordTest, NodeReturnsShutdownInProgressWhenWaitingUntilAnOpTimeDuringShutdown) {
assertStartSuccess(BSON("_id"