diff options
author | Andrew Shuvalov <andrew.shuvalov@mongodb.com> | 2021-08-19 19:39:32 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-08-19 19:54:11 +0000 |
commit | 0c6300fedd5fa9c074fa4c97f5e4193cd7645593 (patch) | |
tree | d4d345e8eaae98e464b9d884b9b3f064db6fd5fd | |
parent | c18a5f208e91dedcdf2bbfefc8a770b45f082750 (diff) | |
download | mongo-0c6300fedd5fa9c074fa4c97f5e4193cd7645593.tar.gz |
SERVER-59330: bugfix: StreamableReplicaSetMonitor constructor should bootstrap SdamConfiguration with RS name
-rw-r--r-- | src/mongo/client/sdam/sdam_configuration.h | 10 | ||||
-rw-r--r-- | src/mongo/client/sdam/topology_state_machine_test.cpp | 32 | ||||
-rw-r--r-- | src/mongo/client/streamable_replica_set_monitor.cpp | 6 |
3 files changed, 46 insertions, 2 deletions
diff --git a/src/mongo/client/sdam/sdam_configuration.h b/src/mongo/client/sdam/sdam_configuration.h index 71606e1234b..c274da69f8c 100644 --- a/src/mongo/client/sdam/sdam_configuration.h +++ b/src/mongo/client/sdam/sdam_configuration.h @@ -63,6 +63,16 @@ public: Milliseconds localThreshholdMs = Milliseconds(sdamLocalThreshholdMs), boost::optional<std::string> setName = boost::none); + SdamConfiguration(boost::optional<std::vector<HostAndPort>> seedList, + TopologyType initialType, + boost::optional<std::string> setName) + : SdamConfiguration(seedList, + initialType, + Milliseconds(sdamHeartBeatFrequencyMs), + Milliseconds(sdamConnectTimeoutMs), + Milliseconds(sdamLocalThreshholdMs), + setName) {} + /** * The initial set of servers to monitor in the replica set. */ diff --git a/src/mongo/client/sdam/topology_state_machine_test.cpp b/src/mongo/client/sdam/topology_state_machine_test.cpp index 821d476aade..a1fcb416110 100644 --- a/src/mongo/client/sdam/topology_state_machine_test.cpp +++ b/src/mongo/client/sdam/topology_state_machine_test.cpp @@ -168,7 +168,6 @@ TEST_F(TopologyStateMachineTestFixture, ShouldRemoveServerDescriptionIfNotInHost ASSERT_EQUALS(serverDescription, topologyDescription->getServers().front()); } - TEST_F(TopologyStateMachineTestFixture, ShouldNotRemoveReplicaSetMemberServerWhenTopologyIsReplicaSetNoPrimaryAndMeIsNotPresent) { const auto serverAddress = (*kTwoSeedReplicaSetNoPrimaryConfig.getSeedList()).front(); @@ -194,6 +193,37 @@ TEST_F(TopologyStateMachineTestFixture, ASSERT_EQUALS(serversBefore, serversAfter); } +TEST_F(TopologyStateMachineTestFixture, ShouldRemoveServerDescriptionIfShardDoesntMatch) { + const auto expectedRemovedServer = (*kTwoSeedReplicaSetNoPrimaryConfig.getSeedList()).front(); + const auto expectedRemainingServer = (*kTwoSeedReplicaSetNoPrimaryConfig.getSeedList()).back(); + + TopologyStateMachine stateMachine(kTwoSeedReplicaSetNoPrimaryConfig); + auto topologyDescription = + std::make_shared<TopologyDescription>(kTwoSeedReplicaSetNoPrimaryConfig); + + auto serverDescription = ServerDescriptionBuilder() + .withAddress(expectedRemovedServer) + .withType(ServerType::kRSSecondary) + .withSetName(*topologyDescription->getSetName()) + .instance(); + auto serverDescriptionWithBadSetName = ServerDescriptionBuilder() + .withAddress(expectedRemovedServer) + .withType(ServerType::kRSSecondary) + .withSetName("wrong_name_should_not_match") + .instance(); + + ASSERT_EQUALS(static_cast<size_t>(2), topologyDescription->getServers().size()); + + // First tests that description is not removed if set name is correct. + stateMachine.onServerDescription(*topologyDescription, serverDescription); + ASSERT_EQUALS(static_cast<size_t>(2), topologyDescription->getServers().size()); + + // Tests that description is removed if the set name does not match. + stateMachine.onServerDescription(*topologyDescription, serverDescriptionWithBadSetName); + ASSERT_EQUALS(static_cast<size_t>(1), topologyDescription->getServers().size()); + ASSERT_EQUALS(expectedRemainingServer, topologyDescription->getServers().front()->getAddress()); +} + TEST_F(TopologyStateMachineTestFixture, ShouldChangeStandaloneServerToUnknownAndPreserveTopologyType) { const auto primary = (*kTwoSeedConfig.getSeedList()).front(); diff --git a/src/mongo/client/streamable_replica_set_monitor.cpp b/src/mongo/client/streamable_replica_set_monitor.cpp index 53d8e3f629e..2c3b621cf68 100644 --- a/src/mongo/client/streamable_replica_set_monitor.cpp +++ b/src/mongo/client/streamable_replica_set_monitor.cpp @@ -166,7 +166,11 @@ StreamableReplicaSetMonitor::StreamableReplicaSetMonitor( } } - _sdamConfig = SdamConfiguration(seedsNoDups); + // StreamableReplicaSetMonitor cannot be used with kSingle type, thus we know that the type is + // kReplicaSetNoPrimary. We need to save the expected set name to avoid the case when the + // provided seed address contains a ReplicaSet with different name (deployment mistake). + _sdamConfig = + SdamConfiguration(seedsNoDups, TopologyType::kReplicaSetNoPrimary, _uri.getSetName()); _serverSelector = std::make_unique<SdamServerSelector>(_sdamConfig); } |