diff options
author | Vesselina Ratcheva <vesselina.ratcheva@10gen.com> | 2019-01-14 19:22:35 -0500 |
---|---|---|
committer | Vesselina Ratcheva <vesselina.ratcheva@10gen.com> | 2019-01-23 22:25:43 -0500 |
commit | b023cfd4db379092f7642dd825d79652d905f847 (patch) | |
tree | 2857f2d63874d9d79910e6b91ef044de1aacef23 /src/mongo/db/repl/topology_coordinator_v1_test.cpp | |
parent | 84b142d5123c06212ce7a2e495ae8afe48eb65cb (diff) | |
download | mongo-b023cfd4db379092f7642dd825d79652d905f847.tar.gz |
SERVER-37846 Disallow using arbiters to satisfy numeric write concern when writes commit
Diffstat (limited to 'src/mongo/db/repl/topology_coordinator_v1_test.cpp')
-rw-r--r-- | src/mongo/db/repl/topology_coordinator_v1_test.cpp | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/mongo/db/repl/topology_coordinator_v1_test.cpp b/src/mongo/db/repl/topology_coordinator_v1_test.cpp index 38ce44142c6..c44f572fe3b 100644 --- a/src/mongo/db/repl/topology_coordinator_v1_test.cpp +++ b/src/mongo/db/repl/topology_coordinator_v1_test.cpp @@ -5005,6 +5005,102 @@ TEST_F(TopoCoordTest, TwoNodesEligibleForElectionHandoffEqualPriorityResolveByMe ASSERT_EQUALS(1, getTopoCoord().chooseElectionHandoffCandidate()); } +TEST_F(TopoCoordTest, ArbiterNotIncludedInW3WriteInPSSAReplSet) { + // In a PSSA set, a w:3 write should only be acknowledged if both secondaries can satisfy it. + updateConfig(BSON("_id" + << "rs0" + << "version" + << 2 + << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "host0:27017") + << BSON("_id" << 1 << "host" + << "host1:27017") + << BSON("_id" << 2 << "host" + << "host2:27017" + << "priority" + << 0 + << "votes" + << 0) + << BSON("_id" << 3 << "host" + << "host3:27017" + << "arbiterOnly" + << true))), + 0); + + const auto term = getTopoCoord().getTerm(); + makeSelfPrimary(); + + auto caughtUpOpTime = OpTime(Timestamp(100, 0), term); + auto laggedOpTime = OpTime(Timestamp(50, 0), term); + + setMyOpTime(caughtUpOpTime); + + // One secondary is caught up. + heartbeatFromMember(HostAndPort("host1"), "rs0", MemberState::RS_SECONDARY, caughtUpOpTime); + + // The other is not. + heartbeatFromMember(HostAndPort("host2"), "rs0", MemberState::RS_SECONDARY, laggedOpTime); + + // The arbiter is caught up, but should not count towards the w:3. + heartbeatFromMember(HostAndPort("host3"), "rs0", MemberState::RS_ARBITER, caughtUpOpTime); + + ASSERT_FALSE(getTopoCoord().haveNumNodesReachedOpTime( + caughtUpOpTime, 3 /* numNodes */, false /* durablyWritten */)); +} + +TEST_F(TopoCoordTest, ArbitersNotIncludedInW2WriteInPSSAAReplSet) { + // In a PSSAA set, a w:2 write should only be acknowledged if at least one of the secondaries + // can satisfy it. + updateConfig(BSON("_id" + << "rs0" + << "version" + << 2 + << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "host0:27017") + << BSON("_id" << 1 << "host" + << "host1:27017" + << "priority" + << 0 + << "votes" + << 0) + << BSON("_id" << 2 << "host" + << "host2:27017" + << "priority" + << 0 + << "votes" + << 0) + << BSON("_id" << 3 << "host" + << "host3:27017" + << "arbiterOnly" + << true) + << BSON("_id" << 4 << "host" + << "host4:27017" + << "arbiterOnly" + << true))), + 0); + + const auto term = getTopoCoord().getTerm(); + makeSelfPrimary(); + + auto caughtUpOpTime = OpTime(Timestamp(100, 0), term); + auto laggedOpTime = OpTime(Timestamp(50, 0), term); + + setMyOpTime(caughtUpOpTime); + + // Neither secondary is caught up. + heartbeatFromMember(HostAndPort("host1"), "rs0", MemberState::RS_SECONDARY, laggedOpTime); + heartbeatFromMember(HostAndPort("host2"), "rs0", MemberState::RS_SECONDARY, laggedOpTime); + + // Both arbiters arae caught up, but neither should count towards the w:2. + heartbeatFromMember(HostAndPort("host3"), "rs0", MemberState::RS_ARBITER, caughtUpOpTime); + heartbeatFromMember(HostAndPort("host4"), "rs0", MemberState::RS_ARBITER, caughtUpOpTime); + + ASSERT_FALSE(getTopoCoord().haveNumNodesReachedOpTime( + caughtUpOpTime, 2 /* numNodes */, false /* durablyWritten */)); +} + TEST_F(HeartbeatResponseTestV1, ScheduleACatchupTakeoverWhenElectableAndReceiveHeartbeatFromPrimaryInCatchup) { updateConfig(BSON("_id" |