summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/topology_coordinator_impl_v1_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/repl/topology_coordinator_impl_v1_test.cpp')
-rw-r--r--src/mongo/db/repl/topology_coordinator_impl_v1_test.cpp65
1 files changed, 21 insertions, 44 deletions
diff --git a/src/mongo/db/repl/topology_coordinator_impl_v1_test.cpp b/src/mongo/db/repl/topology_coordinator_impl_v1_test.cpp
index 9e04bf8942d..684d39514a9 100644
--- a/src/mongo/db/repl/topology_coordinator_impl_v1_test.cpp
+++ b/src/mongo/db/repl/topology_coordinator_impl_v1_test.cpp
@@ -52,7 +52,6 @@
ASSERT_EQUALS(mongo::repl::HeartbeatResponseAction::NoAction, (EXPRESSION))
using std::unique_ptr;
-using mongo::rpc::ReplSetMetadata;
namespace mongo {
namespace repl {
@@ -149,20 +148,6 @@ protected:
_currentConfig = config;
}
- // Make the metadata coming from sync source.
- // Only set visibleOpTime, primaryIndex and syncSourceIndex
- ReplSetMetadata makeMetadata(OpTime opTime = OpTime(),
- int primaryIndex = -1,
- int syncSourceIndex = -1) {
- return ReplSetMetadata(_topo->getTerm(),
- OpTime(),
- opTime,
- _currentConfig.getConfigVersion(),
- OID(),
- primaryIndex,
- syncSourceIndex);
- }
-
HeartbeatResponseAction receiveUpHeartbeat(const HostAndPort& member,
const std::string& setName,
MemberState memberState,
@@ -664,9 +649,9 @@ TEST_F(TopoCoordTest, ChooseRequestedSyncSourceOnlyTheFirstTimeAfterTheSyncSourc
// force should cause shouldChangeSyncSource() to return true
// even if the currentSource is the force target
ASSERT_TRUE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("h2"), OpTime(), makeMetadata(oldOpTime), now()));
+ HostAndPort("h2"), OpTime(), oldOpTime, false, now()));
ASSERT_TRUE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("h3"), OpTime(), makeMetadata(newOpTime), now()));
+ HostAndPort("h3"), OpTime(), newOpTime, false, now()));
getTopoCoord().chooseNewSyncSource(now()++, Timestamp());
ASSERT_EQUALS(HostAndPort("h2"), getTopoCoord().getSyncSourceAddress());
@@ -3093,7 +3078,7 @@ TEST_F(HeartbeatResponseTestV1,
// set up complete, time for actual check
startCapturingLogMessages();
ASSERT_TRUE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(lastOpTimeApplied), now()));
+ HostAndPort("host2"), OpTime(), lastOpTimeApplied, false, now()));
stopCapturingLogMessages();
ASSERT_EQUALS(1, countLogLinesContaining("re-evaluating sync source"));
}
@@ -3135,7 +3120,7 @@ TEST_F(HeartbeatResponseTestV1,
ASSERT_NO_ACTION(nextAction.getAction());
// Show we like host2 while it is primary.
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), lastOpTimeApplied, makeMetadata(lastOpTimeApplied, 1), now()));
+ HostAndPort("host2"), lastOpTimeApplied, lastOpTimeApplied, false, now()));
// Show that we also like host2 while it has a sync source.
nextAction = receiveUpHeartbeat(HostAndPort("host2"),
@@ -3146,7 +3131,7 @@ TEST_F(HeartbeatResponseTestV1,
lastOpTimeApplied);
ASSERT_NO_ACTION(nextAction.getAction());
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), lastOpTimeApplied, makeMetadata(lastOpTimeApplied, 2, 2), now()));
+ HostAndPort("host2"), lastOpTimeApplied, lastOpTimeApplied, true, now()));
// Show that we do not like it when it is not PRIMARY and lacks a sync source and lacks progress
// beyond our own.
@@ -3158,16 +3143,9 @@ TEST_F(HeartbeatResponseTestV1,
lastOpTimeApplied);
ASSERT_NO_ACTION(nextAction.getAction());
ASSERT(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), lastOpTimeApplied, makeMetadata(lastOpTimeApplied), now()));
-
- // Sometimes the heartbeat is stale and the metadata says it's the primary. Trust the metadata.
- ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"),
- lastOpTimeApplied,
- makeMetadata(lastOpTimeApplied, 1 /* host2 is primary */, -1 /* no sync source */),
- now()));
+ HostAndPort("host2"), lastOpTimeApplied, lastOpTimeApplied, false, now()));
- // But if it is secondary and has some progress beyond our own, we still like it.
+ // But if it has some progress beyond our own, we still like it.
OpTime newerThanLastOpTimeApplied = OpTime(Timestamp(500, 0), 0);
nextAction = receiveUpHeartbeat(HostAndPort("host2"),
"rs0",
@@ -3177,7 +3155,7 @@ TEST_F(HeartbeatResponseTestV1,
newerThanLastOpTimeApplied);
ASSERT_NO_ACTION(nextAction.getAction());
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), lastOpTimeApplied, makeMetadata(newerThanLastOpTimeApplied), now()));
+ HostAndPort("host2"), lastOpTimeApplied, newerThanLastOpTimeApplied, false, now()));
}
TEST_F(HeartbeatResponseTestV1, ShouldNotChangeSyncSourceWhenFresherMemberIsDown) {
@@ -3209,7 +3187,7 @@ TEST_F(HeartbeatResponseTestV1, ShouldNotChangeSyncSourceWhenFresherMemberIsDown
nextAction = receiveDownHeartbeat(HostAndPort("host3"), "rs0", lastOpTimeApplied);
ASSERT_NO_ACTION(nextAction.getAction());
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(lastOpTimeApplied), now()));
+ HostAndPort("host2"), OpTime(), lastOpTimeApplied, false, now()));
}
TEST_F(HeartbeatResponseTestV1, ShouldNotChangeSyncSourceWhileFresherMemberIsBlackListed) {
@@ -3241,18 +3219,18 @@ TEST_F(HeartbeatResponseTestV1, ShouldNotChangeSyncSourceWhileFresherMemberIsBla
// set up complete, time for actual check
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(lastOpTimeApplied), now()));
+ HostAndPort("host2"), OpTime(), lastOpTimeApplied, false, now()));
// unblacklist with too early a time (node should remained blacklisted)
getTopoCoord().unblacklistSyncSource(HostAndPort("host3"), now() + Milliseconds(90));
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(lastOpTimeApplied), now()));
+ HostAndPort("host2"), OpTime(), lastOpTimeApplied, false, now()));
// unblacklist and it should succeed
getTopoCoord().unblacklistSyncSource(HostAndPort("host3"), now() + Milliseconds(100));
startCapturingLogMessages();
ASSERT_TRUE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(lastOpTimeApplied), now()));
+ HostAndPort("host2"), OpTime(), lastOpTimeApplied, false, now()));
stopCapturingLogMessages();
ASSERT_EQUALS(1, countLogLinesContaining("re-evaluating sync source"));
}
@@ -3285,7 +3263,7 @@ TEST_F(HeartbeatResponseTestV1, ShouldNotChangeSyncSourceIfNodeIsFreshByHeartbea
// set up complete, time for actual check
startCapturingLogMessages();
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(lastOpTimeApplied), now()));
+ HostAndPort("host2"), OpTime(), lastOpTimeApplied, false, now()));
stopCapturingLogMessages();
ASSERT_EQUALS(0, countLogLinesContaining("re-evaluating sync source"));
}
@@ -3318,7 +3296,7 @@ TEST_F(HeartbeatResponseTestV1, ShouldNotChangeSyncSourceIfNodeIsStaleByHeartbea
// set up complete, time for actual check
startCapturingLogMessages();
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(fresherLastOpTimeApplied), now()));
+ HostAndPort("host2"), OpTime(), fresherLastOpTimeApplied, false, now()));
stopCapturingLogMessages();
ASSERT_EQUALS(0, countLogLinesContaining("re-evaluating sync source"));
}
@@ -3350,7 +3328,7 @@ TEST_F(HeartbeatResponseTestV1, ShouldChangeSyncSourceWhenFresherMemberExists) {
// set up complete, time for actual check
startCapturingLogMessages();
ASSERT_TRUE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(lastOpTimeApplied), now()));
+ HostAndPort("host2"), OpTime(), lastOpTimeApplied, false, now()));
stopCapturingLogMessages();
ASSERT_EQUALS(1, countLogLinesContaining("re-evaluating sync source"));
}
@@ -3359,15 +3337,14 @@ TEST_F(HeartbeatResponseTestV1, ShouldNotChangeSyncSourceWhenMemberHasYetToHeart
// In this test, the TopologyCoordinator should not tell us to change sync sources away from
// "host2" since we do not use the member's heartbeatdata in pv1.
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(), now()));
+ HostAndPort("host2"), OpTime(), OpTime(), true, now()));
}
TEST_F(HeartbeatResponseTestV1, ShouldNotChangeSyncSourceWhenMemberNotInConfig) {
// In this test, the TopologyCoordinator should tell us to change sync sources away from
- // "host4" since "host4" is absent from the config of version 10.
- ReplSetMetadata metadata(0, OpTime(), OpTime(), 10, OID(), -1, -1);
- ASSERT_TRUE(
- getTopoCoord().shouldChangeSyncSource(HostAndPort("host4"), OpTime(), metadata, now()));
+ // "host4" since "host4" is absent from the config
+ ASSERT_TRUE(getTopoCoord().shouldChangeSyncSource(
+ HostAndPort("host4"), OpTime(), OpTime(), true, now()));
}
// TODO(dannenberg) figure out what this is trying to test..
@@ -4297,7 +4274,7 @@ TEST_F(HeartbeatResponseTestV1, ShouldNotChangeSyncSourceWhenFresherMemberDoesNo
// set up complete, time for actual check
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(lastOpTimeApplied), now()));
+ HostAndPort("host2"), OpTime(), lastOpTimeApplied, true, now()));
}
TEST_F(HeartbeatResponseTestV1, ShouldNotChangeSyncSourceWhenFresherMemberIsNotReadable) {
@@ -4327,7 +4304,7 @@ TEST_F(HeartbeatResponseTestV1, ShouldNotChangeSyncSourceWhenFresherMemberIsNotR
// set up complete, time for actual check
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(lastOpTimeApplied), now()));
+ HostAndPort("host2"), OpTime(), lastOpTimeApplied, true, now()));
}
class HeartbeatResponseTestOneRetryV1 : public HeartbeatResponseTestV1 {