diff options
36 files changed, 428 insertions, 406 deletions
diff --git a/src/mongo/client/replica_set_monitor_manager.cpp b/src/mongo/client/replica_set_monitor_manager.cpp index bbf2a95ad9d..484302b00d9 100644 --- a/src/mongo/client/replica_set_monitor_manager.cpp +++ b/src/mongo/client/replica_set_monitor_manager.cpp @@ -88,12 +88,11 @@ Status ReplicaSetMonitorManagerNetworkConnectionHook::validateHost( if (publisher) { try { if (isMasterReply.status.isOK()) { - publisher->onServerHandshakeCompleteEvent(isMasterReply.elapsedMillis.get(), - remoteHost.toString(), - isMasterReply.data); + publisher->onServerHandshakeCompleteEvent( + isMasterReply.elapsedMillis.get(), remoteHost, isMasterReply.data); } else { publisher->onServerHandshakeFailedEvent( - remoteHost.toString(), isMasterReply.status, isMasterReply.data); + remoteHost, isMasterReply.status, isMasterReply.data); } } catch (const DBException& exception) { LOGV2_ERROR(4712101, diff --git a/src/mongo/client/sdam/sdam_configuration.cpp b/src/mongo/client/sdam/sdam_configuration.cpp index d9852ddae94..9dc8c48abce 100644 --- a/src/mongo/client/sdam/sdam_configuration.cpp +++ b/src/mongo/client/sdam/sdam_configuration.cpp @@ -29,7 +29,7 @@ #include "sdam_configuration.h" namespace mongo::sdam { -SdamConfiguration::SdamConfiguration(boost::optional<std::vector<ServerAddress>> seedList, +SdamConfiguration::SdamConfiguration(boost::optional<std::vector<HostAndPort>> seedList, TopologyType initialType, mongo::Milliseconds heartBeatFrequencyMs, boost::optional<std::string> setName) @@ -61,7 +61,7 @@ SdamConfiguration::SdamConfiguration(boost::optional<std::vector<ServerAddress>> _heartBeatFrequencyMs >= kMinHeartbeatFrequencyMS); } -const boost::optional<std::vector<ServerAddress>>& SdamConfiguration::getSeedList() const { +const boost::optional<std::vector<HostAndPort>>& SdamConfiguration::getSeedList() const { return _seedList; } diff --git a/src/mongo/client/sdam/sdam_configuration.h b/src/mongo/client/sdam/sdam_configuration.h index fad9796cd9e..29cb89f8793 100644 --- a/src/mongo/client/sdam/sdam_configuration.h +++ b/src/mongo/client/sdam/sdam_configuration.h @@ -54,12 +54,12 @@ public: * If setName is not null, only TopologyType ReplicaSetNoPrimary and Single, are * allowed. */ - explicit SdamConfiguration(boost::optional<std::vector<ServerAddress>> seedList, + explicit SdamConfiguration(boost::optional<std::vector<HostAndPort>> seedList, TopologyType initialType = TopologyType::kUnknown, Milliseconds heartBeatFrequencyMs = kDefaultHeartbeatFrequencyMs, boost::optional<std::string> setName = boost::none); - const boost::optional<std::vector<ServerAddress>>& getSeedList() const; + const boost::optional<std::vector<HostAndPort>>& getSeedList() const; TopologyType getInitialType() const; Milliseconds getHeartBeatFrequency() const; const boost::optional<std::string>& getSetName() const; @@ -69,7 +69,7 @@ public: static constexpr Milliseconds kDefaultConnectTimeoutMS = Milliseconds(10000); private: - boost::optional<std::vector<ServerAddress>> _seedList; + boost::optional<std::vector<HostAndPort>> _seedList; TopologyType _initialType; Milliseconds _heartBeatFrequencyMs; boost::optional<std::string> _setName; diff --git a/src/mongo/client/sdam/sdam_datatypes.cpp b/src/mongo/client/sdam/sdam_datatypes.cpp index b8b9926077d..82d03851409 100644 --- a/src/mongo/client/sdam/sdam_datatypes.cpp +++ b/src/mongo/client/sdam/sdam_datatypes.cpp @@ -145,7 +145,7 @@ const std::vector<TopologyType> allTopologyTypes() { return result; } -const ServerAddress& IsMasterOutcome::getServer() const { +const HostAndPort& IsMasterOutcome::getServer() const { return _server; } bool IsMasterOutcome::isSuccess() const { @@ -166,7 +166,7 @@ const std::string& IsMasterOutcome::getErrorMsg() const { BSONObj IsMasterOutcome::toBSON() const { BSONObjBuilder builder; - builder.append("host", _server); + builder.append("host", _server.toString()); builder.append("success", _success); if (_errorMsg != "") diff --git a/src/mongo/client/sdam/sdam_datatypes.h b/src/mongo/client/sdam/sdam_datatypes.h index 71fdd1e10ed..4e59dd5a6b7 100644 --- a/src/mongo/client/sdam/sdam_datatypes.h +++ b/src/mongo/client/sdam/sdam_datatypes.h @@ -36,6 +36,7 @@ #include "mongo/bson/bsonobj.h" #include "mongo/rpc/topology_version_gen.h" #include "mongo/util/duration.h" +#include "mongo/util/net/hostandport.h" /** @@ -72,7 +73,6 @@ std::string toString(const ServerType serverType); StatusWith<ServerType> parseServerType(StringData strServerType); std::ostream& operator<<(std::ostream& os, const ServerType serverType); -using ServerAddress = std::string; using IsMasterRTT = mongo::Nanoseconds; // The result of an attempt to call the "ismaster" command on a server. @@ -81,7 +81,7 @@ class IsMasterOutcome { public: // Success constructor. - IsMasterOutcome(ServerAddress server, + IsMasterOutcome(HostAndPort server, BSONObj response, boost::optional<IsMasterRTT> rtt = boost::none) : _server(std::move(server)), _success(true), _response(response), _rtt(rtt) { @@ -93,7 +93,7 @@ public: } // Failure constructor. - IsMasterOutcome(ServerAddress server, BSONObj response, std::string errorMsg) + IsMasterOutcome(HostAndPort server, BSONObj response, std::string errorMsg) : _server(std::move(server)), _success(false), _errorMsg(errorMsg) { const auto topologyVersionField = response.getField("topologyVersion"); if (topologyVersionField) { @@ -102,7 +102,7 @@ public: } } - const ServerAddress& getServer() const; + const HostAndPort& getServer() const; bool isSuccess() const; const boost::optional<BSONObj>& getResponse() const; const boost::optional<IsMasterRTT>& getRtt() const; @@ -111,7 +111,7 @@ public: BSONObj toBSON() const; private: - ServerAddress _server; + HostAndPort _server; // Indicates the success or failure of the attempt. bool _success; // An error message in case of failure. diff --git a/src/mongo/client/sdam/sdam_json_test_runner.cpp b/src/mongo/client/sdam/sdam_json_test_runner.cpp index d557384a3e0..115c97c745d 100644 --- a/src/mongo/client/sdam/sdam_json_test_runner.cpp +++ b/src/mongo/client/sdam/sdam_json_test_runner.cpp @@ -88,7 +88,7 @@ public: auto bsonResponses = phase.getField("responses").Array(); for (auto& response : bsonResponses) { const auto pair = response.Array(); - const auto address = pair[0].String(); + const auto address = HostAndPort(pair[0].String()); const auto bsonIsMaster = pair[1].Obj(); if (bsonIsMaster.nFields() == 0) { @@ -297,7 +297,7 @@ private: } for (const BSONElement& bsonExpectedServer : bsonServers) { - const auto& serverAddress = bsonExpectedServer.fieldName(); + const auto& serverAddress = HostAndPort(bsonExpectedServer.fieldName()); const auto& expectedServerDescriptionFields = bsonExpectedServer.Obj(); const auto& serverDescription = topologyDescription->findServerByAddress(serverAddress); @@ -525,10 +525,10 @@ private: } } - std::vector<ServerAddress> getSeedList() { - std::vector<ServerAddress> result; + std::vector<HostAndPort> getSeedList() { + std::vector<HostAndPort> result; for (const auto& hostAndPort : _testUri.getServers()) { - result.push_back(hostAndPort.toString()); + result.push_back(hostAndPort); } return result; } diff --git a/src/mongo/client/sdam/server_description.cpp b/src/mongo/client/sdam/server_description.cpp index 70686b3d660..81ea0f7e3ed 100644 --- a/src/mongo/client/sdam/server_description.cpp +++ b/src/mongo/client/sdam/server_description.cpp @@ -92,7 +92,7 @@ ServerDescription::ServerDescription(ClockSource* clockSource, auto primaryField = response.getField("primary"); if (primaryField.type() == BSONType::String) { - _primary = response.getStringField("primary"); + _primary = HostAndPort(response.getStringField("primary")); } if (poolResetCounter) { @@ -109,20 +109,20 @@ ServerDescription::ServerDescription(ClockSource* clockSource, void ServerDescription::storeHostListIfPresent(const std::string key, const BSONObj response, - std::set<ServerAddress>& destination) { + std::set<HostAndPort>& destination) { if (response.hasField(key)) { auto hostsBsonArray = response[key].Array(); std::transform(hostsBsonArray.begin(), hostsBsonArray.end(), std::inserter(destination, destination.begin()), - [](const BSONElement e) { return e.String(); }); + [](const BSONElement e) { return HostAndPort(e.String()); }); } } void ServerDescription::saveHosts(const BSONObj response) { if (response.hasField("me")) { auto me = response.getField("me"); - _me = me.str(); + _me = HostAndPort(me.str()); } storeHostListIfPresent("hosts", response, _hosts); @@ -238,7 +238,7 @@ void ServerDescription::parseTypeFromIsMaster(const BSONObj isMaster) { _type = t; } -const ServerAddress& ServerDescription::getAddress() const { +const HostAndPort& ServerDescription::getAddress() const { return _address; } @@ -262,19 +262,19 @@ ServerType ServerDescription::getType() const { return _type; } -const boost::optional<ServerAddress>& ServerDescription::getMe() const { +const boost::optional<HostAndPort>& ServerDescription::getMe() const { return _me; } -const std::set<ServerAddress>& ServerDescription::getHosts() const { +const std::set<HostAndPort>& ServerDescription::getHosts() const { return _hosts; } -const std::set<ServerAddress>& ServerDescription::getPassives() const { +const std::set<HostAndPort>& ServerDescription::getPassives() const { return _passives; } -const std::set<ServerAddress>& ServerDescription::getArbiters() const { +const std::set<HostAndPort>& ServerDescription::getArbiters() const { return _arbiters; } @@ -294,7 +294,7 @@ const boost::optional<mongo::OID>& ServerDescription::getElectionId() const { return _electionId; } -const boost::optional<ServerAddress>& ServerDescription::getPrimary() const { +const boost::optional<HostAndPort>& ServerDescription::getPrimary() const { return _primary; } @@ -368,7 +368,7 @@ bool ServerDescription::isDataBearingServer() const { // output server description to bson. This is primarily used for debugging. BSONObj ServerDescription::toBson() const { BSONObjBuilder bson; - bson.append("address", _address); + bson.append("address", _address.toString()); if (_topologyVersion) { bson.append("topologyVersion", _topologyVersion->toBSON()); @@ -398,7 +398,7 @@ BSONObj ServerDescription::toBson() const { if (_me) { - bson.append("me", *_me); + bson.append("me", (*_me).toString()); } if (_setName) { bson.append("setName", *_setName); @@ -410,7 +410,7 @@ BSONObj ServerDescription::toBson() const { bson.append("electionId", *_electionId); } if (_primary) { - bson.append("primary", *_primary); + bson.append("primary", (*_primary).toString()); } if (_lastUpdateTime) { bson.append("lastUpdateTime", *_lastUpdateTime); @@ -419,9 +419,23 @@ BSONObj ServerDescription::toBson() const { bson.append("logicalSessionTimeoutMinutes", *_logicalSessionTimeoutMinutes); } - bson.append("hosts", _hosts); - bson.append("arbiters", _arbiters); - bson.append("passives", _passives); + BSONArrayBuilder hostsBuilder; + for (const auto& host : _hosts) { + hostsBuilder.append(host.toString()); + } + bson.append("hosts", hostsBuilder.obj()); + + BSONArrayBuilder arbitersBuilder; + for (const auto& arbiter : _arbiters) { + hostsBuilder.append(arbiter.toString()); + } + bson.append("arbiters", arbitersBuilder.obj()); + + BSONArrayBuilder passivesBuilder; + for (const auto& passive : _passives) { + hostsBuilder.append(passive.toString()); + } + bson.append("passives", passivesBuilder.obj()); if (getTags().size()) { BSONObjBuilder tagsBuilder(bson.subobjStart("tags")); diff --git a/src/mongo/client/sdam/server_description.h b/src/mongo/client/sdam/server_description.h index 159d7948738..8ae5d88933e 100644 --- a/src/mongo/client/sdam/server_description.h +++ b/src/mongo/client/sdam/server_description.h @@ -50,7 +50,7 @@ public: /** * Construct an unknown ServerDescription with default values except the server's address. */ - ServerDescription(ServerAddress address) + ServerDescription(HostAndPort address) : _address(std::move(address)), _type(ServerType::kUnknown) {} /** @@ -71,9 +71,9 @@ public: bool isEquivalent(const ServerDescription& other) const; // server identity - const ServerAddress& getAddress() const; + const HostAndPort& getAddress() const; ServerType getType() const; - const boost::optional<ServerAddress>& getMe() const; + const boost::optional<HostAndPort>& getMe() const; const boost::optional<std::string>& getSetName() const; const std::map<std::string, std::string>& getTags() const; void appendBsonTags(BSONObjBuilder& builder) const; @@ -96,10 +96,10 @@ public: const boost::optional<repl::OpTime>& getOpTime() const; // topology membership - const boost::optional<ServerAddress>& getPrimary() const; - const std::set<ServerAddress>& getHosts() const; - const std::set<ServerAddress>& getPassives() const; - const std::set<ServerAddress>& getArbiters() const; + const boost::optional<HostAndPort>& getPrimary() const; + const std::set<HostAndPort>& getHosts() const; + const std::set<HostAndPort>& getPassives() const; + const std::set<HostAndPort>& getArbiters() const; const boost::optional<int>& getSetVersion() const; const boost::optional<OID>& getElectionId() const; const boost::optional<TopologyVersion>& getTopologyVersion() const; @@ -123,7 +123,7 @@ private: void storeHostListIfPresent(const std::string key, const BSONObj response, - std::set<ServerAddress>& destination); + std::set<HostAndPort>& destination); void saveHosts(const BSONObj response); void saveTags(BSONObj tagsObj); void saveElectionId(BSONElement electionId); @@ -136,7 +136,7 @@ private: // address: the hostname or IP, and the port number, that the client connects to. Note that this // is not the server's ismaster.me field, in the case that the server reports an address // different from the address the client uses. - ServerAddress _address; + HostAndPort _address; // topologyVersion: the server's topology version. Updated upon a significant topology change. boost::optional<TopologyVersion> _topologyVersion; @@ -166,14 +166,14 @@ private: // (=) me: The hostname or IP, and the port number, that this server was configured with in the // replica set. Default null. - boost::optional<ServerAddress> _me; + boost::optional<HostAndPort> _me; // (=) hosts, passives, arbiters: Sets of addresses. This server's opinion of the replica set's // members, if any. These hostnames are normalized to lower-case. Default empty. The client // monitors all three types of servers in a replica set. - std::set<ServerAddress> _hosts; - std::set<ServerAddress> _passives; - std::set<ServerAddress> _arbiters; + std::set<HostAndPort> _hosts; + std::set<HostAndPort> _passives; + std::set<HostAndPort> _arbiters; // (=) tags: map from string to string. Default empty. std::map<std::string, std::string> _tags; @@ -189,7 +189,7 @@ private: boost::optional<OID> _electionId; // (=) primary: an address. This server's opinion of who the primary is. Default null. - boost::optional<ServerAddress> _primary; + boost::optional<HostAndPort> _primary; // lastUpdateTime: when this server was last checked. Default "infinity ago". boost::optional<Date_t> _lastUpdateTime = Date_t::min(); diff --git a/src/mongo/client/sdam/server_description_builder.cpp b/src/mongo/client/sdam/server_description_builder.cpp index 534a3ea8454..cc5312ed911 100644 --- a/src/mongo/client/sdam/server_description_builder.cpp +++ b/src/mongo/client/sdam/server_description_builder.cpp @@ -33,7 +33,7 @@ ServerDescriptionPtr ServerDescriptionBuilder::instance() const { return _instance; } -ServerDescriptionBuilder& ServerDescriptionBuilder::withAddress(const ServerAddress& address) { +ServerDescriptionBuilder& ServerDescriptionBuilder::withAddress(const HostAndPort& address) { _instance->_address = address; return *this; } @@ -72,23 +72,23 @@ ServerDescriptionBuilder& ServerDescriptionBuilder::withMaxWireVersion(int maxVe return *this; } -ServerDescriptionBuilder& ServerDescriptionBuilder::withMe(const ServerAddress& me) { - _instance->_me = std::string(me); +ServerDescriptionBuilder& ServerDescriptionBuilder::withMe(const HostAndPort& me) { + _instance->_me = me; return *this; } -ServerDescriptionBuilder& ServerDescriptionBuilder::withHost(const ServerAddress& host) { - _instance->_hosts.emplace(boost::to_lower_copy(host)); +ServerDescriptionBuilder& ServerDescriptionBuilder::withHost(const HostAndPort& host) { + _instance->_hosts.emplace(host); return *this; } -ServerDescriptionBuilder& ServerDescriptionBuilder::withPassive(const ServerAddress& passive) { - _instance->_passives.emplace(boost::to_lower_copy(passive)); +ServerDescriptionBuilder& ServerDescriptionBuilder::withPassive(const HostAndPort& passive) { + _instance->_passives.emplace(passive); return *this; } -ServerDescriptionBuilder& ServerDescriptionBuilder::withArbiter(const ServerAddress& arbiter) { - _instance->_arbiters.emplace(boost::to_lower_copy(arbiter)); +ServerDescriptionBuilder& ServerDescriptionBuilder::withArbiter(const HostAndPort& arbiter) { + _instance->_arbiters.emplace(arbiter); return *this; } @@ -113,7 +113,7 @@ ServerDescriptionBuilder& ServerDescriptionBuilder::withElectionId(const OID& el return *this; } -ServerDescriptionBuilder& ServerDescriptionBuilder::withPrimary(const ServerAddress& primary) { +ServerDescriptionBuilder& ServerDescriptionBuilder::withPrimary(const HostAndPort& primary) { _instance->_primary = primary; return *this; } diff --git a/src/mongo/client/sdam/server_description_builder.h b/src/mongo/client/sdam/server_description_builder.h index 85078f1b287..d59be152b45 100644 --- a/src/mongo/client/sdam/server_description_builder.h +++ b/src/mongo/client/sdam/server_description_builder.h @@ -45,9 +45,9 @@ public: ServerDescriptionPtr instance() const; // server identity - ServerDescriptionBuilder& withAddress(const ServerAddress& address); + ServerDescriptionBuilder& withAddress(const HostAndPort& address); ServerDescriptionBuilder& withType(const ServerType type); - ServerDescriptionBuilder& withMe(const ServerAddress& me); + ServerDescriptionBuilder& withMe(const HostAndPort& me); ServerDescriptionBuilder& withTag(const std::string key, const std::string value); ServerDescriptionBuilder& withSetName(const std::string setName); @@ -69,17 +69,17 @@ public: ServerDescriptionBuilder& withLastUpdateTime(const Date_t& lastUpdateTime); // topology membership - ServerDescriptionBuilder& withPrimary(const ServerAddress& primary); - ServerDescriptionBuilder& withHost(const ServerAddress& host); - ServerDescriptionBuilder& withPassive(const ServerAddress& passive); - ServerDescriptionBuilder& withArbiter(const ServerAddress& arbiter); + ServerDescriptionBuilder& withPrimary(const HostAndPort& primary); + ServerDescriptionBuilder& withHost(const HostAndPort& host); + ServerDescriptionBuilder& withPassive(const HostAndPort& passive); + ServerDescriptionBuilder& withArbiter(const HostAndPort& arbiter); ServerDescriptionBuilder& withSetVersion(const int setVersion); ServerDescriptionBuilder& withElectionId(const OID& electionId); ServerDescriptionBuilder& withTopologyVersion(TopologyVersion topologyVersion); private: - constexpr static auto kServerAddressNotSet = "address.not.set:1234"; + constexpr static auto kHostAndPortNotSet = "address.not.set:1234"; ServerDescriptionPtr _instance = - std::shared_ptr<ServerDescription>(new ServerDescription(kServerAddressNotSet)); + std::shared_ptr<ServerDescription>(new ServerDescription(HostAndPort(kHostAndPortNotSet))); }; } // namespace mongo::sdam diff --git a/src/mongo/client/sdam/server_description_test.cpp b/src/mongo/client/sdam/server_description_test.cpp index 8ed40911927..2f42d8e97b3 100644 --- a/src/mongo/client/sdam/server_description_test.cpp +++ b/src/mongo/client/sdam/server_description_test.cpp @@ -49,8 +49,8 @@ namespace mongo::sdam { //} TEST(ServerDescriptionEqualityTest, ShouldCompareDefaultValuesAsEqual) { - auto a = ServerDescription("foo:1234"); - auto b = ServerDescription("foo:1234"); + auto a = ServerDescription(HostAndPort("foo:1234")); + auto b = ServerDescription(HostAndPort("foo:1234")); ASSERT_EQUALS(a, b); } @@ -59,11 +59,11 @@ TEST(ServerDescriptionEqualityTest, ShouldCompareDifferentAddressButSameServerTy // different addresses for equality. We choose that two descriptions are considered equal if // their addresses are different. auto a = *ServerDescriptionBuilder() - .withAddress("foo:1234") + .withAddress(HostAndPort("foo:1234")) .withType(ServerType::kStandalone) .instance(); auto b = *ServerDescriptionBuilder() - .withAddress("bar:1234") + .withAddress(HostAndPort("bar:1234")) .withType(ServerType::kStandalone) .instance(); ASSERT_EQUALS(a, b); @@ -91,48 +91,66 @@ TEST(ServerDescriptionEqualityTest, ShouldCompareMaxWireVersion) { } TEST(ServerDescriptionEqualityTest, ShouldCompareMeValues) { - auto a = *ServerDescriptionBuilder().withMe("foo").instance(); - auto b = *ServerDescriptionBuilder().withMe("bar").instance(); + auto a = *ServerDescriptionBuilder().withMe(HostAndPort("foo")).instance(); + auto b = *ServerDescriptionBuilder().withMe(HostAndPort("bar")).instance(); ASSERT_NOT_EQUALS(a, b); ASSERT_EQUALS(a, a); } TEST(ServerDescriptionEqualityTest, ShouldCompareHosts) { - auto a = *ServerDescriptionBuilder().withHost("foo").instance(); - auto b = *ServerDescriptionBuilder().withHost("bar").instance(); + auto a = *ServerDescriptionBuilder().withHost(HostAndPort("foo")).instance(); + auto b = *ServerDescriptionBuilder().withHost(HostAndPort("bar")).instance(); ASSERT_NOT_EQUALS(a, b); ASSERT_EQUALS(a, a); } TEST(ServerDescriptionEqualityTest, ShouldComparePassives) { - auto a = *ServerDescriptionBuilder().withPassive("foo").instance(); - auto b = *ServerDescriptionBuilder().withPassive("bar").instance(); + auto a = *ServerDescriptionBuilder().withPassive(HostAndPort("foo")).instance(); + auto b = *ServerDescriptionBuilder().withPassive(HostAndPort("bar")).instance(); ASSERT_NOT_EQUALS(a, b); ASSERT_EQUALS(a, a); } TEST(ServerDescriptionEqualityTest, ShouldCompareArbiters) { - auto a = *ServerDescriptionBuilder().withArbiter("foo").instance(); - auto b = *ServerDescriptionBuilder().withArbiter("bar").instance(); + auto a = *ServerDescriptionBuilder().withArbiter(HostAndPort("foo")).instance(); + auto b = *ServerDescriptionBuilder().withArbiter(HostAndPort("bar")).instance(); ASSERT_NOT_EQUALS(a, b); ASSERT_EQUALS(a, a); } TEST(ServerDescriptionEqualityTest, ShouldCompareMultipleHostsOrderDoesntMatter) { - auto a = *ServerDescriptionBuilder().withHost("foo").withHost("bar").instance(); - auto b = *ServerDescriptionBuilder().withHost("bar").withHost("foo").instance(); + auto a = *ServerDescriptionBuilder() + .withHost(HostAndPort("foo")) + .withHost(HostAndPort("bar")) + .instance(); + auto b = *ServerDescriptionBuilder() + .withHost(HostAndPort("bar")) + .withHost(HostAndPort("foo")) + .instance(); ASSERT_EQUALS(a, b); } TEST(ServerDescriptionEqualityTest, ShouldCompareMultiplePassivesOrderDoesntMatter) { - auto a = *ServerDescriptionBuilder().withPassive("foo").withPassive("bar").instance(); - auto b = *ServerDescriptionBuilder().withPassive("bar").withPassive("foo").instance(); + auto a = *ServerDescriptionBuilder() + .withPassive(HostAndPort("foo")) + .withPassive(HostAndPort("bar")) + .instance(); + auto b = *ServerDescriptionBuilder() + .withPassive(HostAndPort("bar")) + .withPassive(HostAndPort("foo")) + .instance(); ASSERT_EQUALS(a, b); } TEST(ServerDescriptionEqualityTest, ShouldCompareMultipleArbitersOrderDoesntMatter) { - auto a = *ServerDescriptionBuilder().withArbiter("foo").withArbiter("bar").instance(); - auto b = *ServerDescriptionBuilder().withArbiter("bar").withArbiter("foo").instance(); + auto a = *ServerDescriptionBuilder() + .withArbiter(HostAndPort("foo")) + .withArbiter(HostAndPort("bar")) + .instance(); + auto b = *ServerDescriptionBuilder() + .withArbiter(HostAndPort("bar")) + .withArbiter(HostAndPort("foo")) + .instance(); ASSERT_EQUALS(a, b); } @@ -165,8 +183,8 @@ TEST(ServerDescriptionEqualityTest, ShouldCompareElectionId) { } TEST(ServerDescriptionEqualityTest, ShouldComparePrimary) { - auto a = *ServerDescriptionBuilder().withPrimary("foo:1234").instance(); - auto b = *ServerDescriptionBuilder().withPrimary("bar:1234").instance(); + auto a = *ServerDescriptionBuilder().withPrimary(HostAndPort("foo:1234")).instance(); + auto b = *ServerDescriptionBuilder().withPrimary(HostAndPort("bar:1234")).instance(); ASSERT_NOT_EQUALS(a, b); ASSERT_EQUALS(a, a); } @@ -284,81 +302,81 @@ protected: }; TEST_F(ServerDescriptionTestFixture, ShouldParseTypeAsUnknownForIsMasterError) { - auto response = IsMasterOutcome("foo:1234", kTopologyVersion, "an error occurred"); + auto response = IsMasterOutcome(HostAndPort("foo:1234"), kTopologyVersion, "an error occurred"); auto description = ServerDescription(clockSource, response); ASSERT_EQUALS(ServerType::kUnknown, description.getType()); } TEST_F(ServerDescriptionTestFixture, ShouldParseTypeAsUnknownIfOkMissing) { - auto response = IsMasterOutcome("foo:1234", kBsonMissingOk, IsMasterRTT::min()); + auto response = IsMasterOutcome(HostAndPort("foo:1234"), kBsonMissingOk, IsMasterRTT::min()); auto description = ServerDescription(clockSource, response); ASSERT_EQUALS(ServerType::kUnknown, description.getType()); } TEST_F(ServerDescriptionTestFixture, ShouldParseTypeAsStandalone) { // No "msg: isdbgrid", no setName, and no "isreplicaset: true". - auto response = IsMasterOutcome("foo:1234", kBsonOk, IsMasterRTT::min()); + auto response = IsMasterOutcome(HostAndPort("foo:1234"), kBsonOk, IsMasterRTT::min()); auto description = ServerDescription(clockSource, response); ASSERT_EQUALS(ServerType::kStandalone, description.getType()); } TEST_F(ServerDescriptionTestFixture, ShouldParseTypeAsMongos) { // contains "msg: isdbgrid" - auto response = IsMasterOutcome("foo:1234", kBsonMongos, IsMasterRTT::min()); + auto response = IsMasterOutcome(HostAndPort("foo:1234"), kBsonMongos, IsMasterRTT::min()); auto description = ServerDescription(clockSource, response); ASSERT_EQUALS(ServerType::kMongos, description.getType()); } TEST_F(ServerDescriptionTestFixture, ShouldParseTypeAsRSPrimary) { // "ismaster: true", "setName" in response - auto response = IsMasterOutcome("foo:1234", kBsonRsPrimary, IsMasterRTT::min()); + auto response = IsMasterOutcome(HostAndPort("foo:1234"), kBsonRsPrimary, IsMasterRTT::min()); auto description = ServerDescription(clockSource, response); ASSERT_EQUALS(ServerType::kRSPrimary, description.getType()); } TEST_F(ServerDescriptionTestFixture, ShouldParseTypeAsRSSecondary) { // "secondary: true", "setName" in response - auto response = IsMasterOutcome("foo:1234", kBsonRsSecondary, IsMasterRTT::min()); + auto response = IsMasterOutcome(HostAndPort("foo:1234"), kBsonRsSecondary, IsMasterRTT::min()); auto description = ServerDescription(clockSource, response); ASSERT_EQUALS(ServerType::kRSSecondary, description.getType()); } TEST_F(ServerDescriptionTestFixture, ShouldParseTypeAsArbiter) { // "arbiterOnly: true", "setName" in response. - auto response = IsMasterOutcome("foo:1234", kBsonRsArbiter, IsMasterRTT::min()); + auto response = IsMasterOutcome(HostAndPort("foo:1234"), kBsonRsArbiter, IsMasterRTT::min()); auto description = ServerDescription(clockSource, response); ASSERT_EQUALS(ServerType::kRSArbiter, description.getType()); } TEST_F(ServerDescriptionTestFixture, ShouldParseTypeAsOther) { // "hidden: true", "setName" in response, or not primary, secondary, nor arbiter - auto response = IsMasterOutcome("foo:1234", kBsonRsOther, IsMasterRTT::min()); + auto response = IsMasterOutcome(HostAndPort("foo:1234"), kBsonRsOther, IsMasterRTT::min()); auto description = ServerDescription(clockSource, response); ASSERT_EQUALS(ServerType::kRSOther, description.getType()); } TEST_F(ServerDescriptionTestFixture, ShouldParseTypeAsGhost) { // "isreplicaset: true" in response. - auto response = IsMasterOutcome("foo:1234", kBsonRsGhost, IsMasterRTT::min()); + auto response = IsMasterOutcome(HostAndPort("foo:1234"), kBsonRsGhost, IsMasterRTT::min()); auto description = ServerDescription(clockSource, response); ASSERT_EQUALS(ServerType::kRSGhost, description.getType()); } TEST_F(ServerDescriptionTestFixture, ShouldStoreErrorDescription) { auto errorMsg = "an error occurred"; - auto response = IsMasterOutcome("foo:1234", kTopologyVersion, errorMsg); + auto response = IsMasterOutcome(HostAndPort("foo:1234"), kTopologyVersion, errorMsg); auto description = ServerDescription(clockSource, response); ASSERT_EQUALS(errorMsg, *description.getError()); } TEST_F(ServerDescriptionTestFixture, ShouldStoreRTTWithNoPreviousLatency) { - auto response = IsMasterOutcome("foo:1234", kBsonRsPrimary, IsMasterRTT::max()); + auto response = IsMasterOutcome(HostAndPort("foo:1234"), kBsonRsPrimary, IsMasterRTT::max()); auto description = ServerDescription(clockSource, response); ASSERT_EQUALS(IsMasterRTT::max(), *description.getRtt()); } TEST_F(ServerDescriptionTestFixture, ShouldStoreRTTNullWhenServerTypeIsUnknown) { - auto response = IsMasterOutcome("foo:1234", kBsonMissingOk, IsMasterRTT::max()); + auto response = IsMasterOutcome(HostAndPort("foo:1234"), kBsonMissingOk, IsMasterRTT::max()); auto description = ServerDescription(clockSource, response, boost::none); ASSERT_EQUALS(boost::none, description.getRtt()); } @@ -366,7 +384,7 @@ TEST_F(ServerDescriptionTestFixture, ShouldStoreRTTNullWhenServerTypeIsUnknown) TEST_F(ServerDescriptionTestFixture, ShouldStoreConstantRTTWhenChangingFromOneKnownServerTypeToAnother) { // Simulate a non-ping monitoring response. - auto response = IsMasterOutcome("foo:1234", kBsonRsPrimary); + auto response = IsMasterOutcome(HostAndPort("foo:1234"), kBsonRsPrimary); auto lastServerDescription = ServerDescriptionBuilder() .withType(ServerType::kRSSecondary) .withRtt(mongo::Milliseconds(20)) @@ -376,29 +394,32 @@ TEST_F(ServerDescriptionTestFixture, auto description = ServerDescription(clockSource, response, lastServerDescription->getRtt()); ASSERT_EQUALS(20, durationCount<mongo::Milliseconds>(*description.getRtt())); - auto response2 = IsMasterOutcome("foo:1234", kBsonRsPrimary); + auto response2 = IsMasterOutcome(HostAndPort("foo:1234"), kBsonRsPrimary); auto description2 = ServerDescription(clockSource, response2, description.getRtt()); ASSERT_EQUALS(20, durationCount<mongo::Milliseconds>(*description2.getRtt())); } TEST_F(ServerDescriptionTestFixture, ShouldStoreLastWriteDate) { - auto response = IsMasterOutcome( - "foo:1234", kBsonLastWrite, duration_cast<IsMasterRTT>(mongo::Milliseconds(40))); + auto response = IsMasterOutcome(HostAndPort("foo:1234"), + kBsonLastWrite, + duration_cast<IsMasterRTT>(mongo::Milliseconds(40))); auto description = ServerDescription(clockSource, response); ASSERT_EQUALS(kLastWriteDate, description.getLastWriteDate()); } TEST_F(ServerDescriptionTestFixture, ShouldStoreOpTime) { - auto response = IsMasterOutcome( - "foo:1234", kBsonLastWrite, duration_cast<IsMasterRTT>(mongo::Milliseconds(40))); + auto response = IsMasterOutcome(HostAndPort("foo:1234"), + kBsonLastWrite, + duration_cast<IsMasterRTT>(mongo::Milliseconds(40))); auto description = ServerDescription(clockSource, response); ASSERT_EQUALS(kOpTime, description.getOpTime()); } TEST_F(ServerDescriptionTestFixture, ShouldStoreLastUpdateTime) { auto testStart = clockSource->now(); - auto response = IsMasterOutcome( - "foo:1234", kBsonRsPrimary, duration_cast<IsMasterRTT>(mongo::Milliseconds(40))); + auto response = IsMasterOutcome(HostAndPort("foo:1234"), + kBsonRsPrimary, + duration_cast<IsMasterRTT>(mongo::Milliseconds(40))); auto description = ServerDescription(clockSource, response); ASSERT_GREATER_THAN_OR_EQUALS(description.getLastUpdateTime(), testStart); } @@ -406,7 +427,7 @@ TEST_F(ServerDescriptionTestFixture, ShouldStoreLastUpdateTime) { // Disabling these tests since this causes jstest failures when // running on a host with a mixed case hostname. // TEST_F(ServerDescriptionTestFixture, ShouldStoreHostNamesAsLowercase) { -// auto response = IsMasterOutcome("FOO:1234", kBsonHostNames, +// auto response = IsMasterOutcome(HostAndPort("FOO:1234"), kBsonHostNames, // duration_cast<IsMasterRTT>(mongo::Milliseconds(40))); // auto description = ServerDescription(clockSource, response); // @@ -426,23 +447,25 @@ TEST_F(ServerDescriptionTestFixture, ShouldStoreLastUpdateTime) { //} TEST_F(ServerDescriptionTestFixture, ShouldStoreMinMaxWireVersion) { - auto response = IsMasterOutcome( - "foo:1234", kBsonWireVersion, duration_cast<IsMasterRTT>(mongo::Milliseconds(40))); + auto response = IsMasterOutcome(HostAndPort("foo:1234"), + kBsonWireVersion, + duration_cast<IsMasterRTT>(mongo::Milliseconds(40))); auto description = ServerDescription(clockSource, response); ASSERT_EQUALS(kBsonWireVersion["minWireVersion"].Int(), description.getMinWireVersion()); ASSERT_EQUALS(kBsonWireVersion["maxWireVersion"].Int(), description.getMaxWireVersion()); } TEST_F(ServerDescriptionTestFixture, ShouldStoreTags) { - auto response = - IsMasterOutcome("foo:1234", kBsonTags, duration_cast<IsMasterRTT>(mongo::Milliseconds(40))); + auto response = IsMasterOutcome( + HostAndPort("foo:1234"), kBsonTags, duration_cast<IsMasterRTT>(mongo::Milliseconds(40))); auto description = ServerDescription(clockSource, response); ASSERT_EQUALS(toStringMap(kBsonTags["tags"].Obj()), description.getTags()); } TEST_F(ServerDescriptionTestFixture, ShouldStoreSetVersionAndName) { - auto response = IsMasterOutcome( - "foo:1234", kBsonSetVersionName, duration_cast<IsMasterRTT>(mongo::Milliseconds(40))); + auto response = IsMasterOutcome(HostAndPort("foo:1234"), + kBsonSetVersionName, + duration_cast<IsMasterRTT>(mongo::Milliseconds(40))); auto description = ServerDescription(clockSource, response); ASSERT_EQUALS(kBsonSetVersionName.getIntField("setVersion"), description.getSetVersion()); ASSERT_EQUALS(std::string(kBsonSetVersionName.getStringField("setName")), @@ -450,21 +473,23 @@ TEST_F(ServerDescriptionTestFixture, ShouldStoreSetVersionAndName) { } TEST_F(ServerDescriptionTestFixture, ShouldStoreElectionId) { - auto response = IsMasterOutcome( - "foo:1234", kBsonElectionId, duration_cast<IsMasterRTT>(mongo::Milliseconds(40))); + auto response = IsMasterOutcome(HostAndPort("foo:1234"), + kBsonElectionId, + duration_cast<IsMasterRTT>(mongo::Milliseconds(40))); auto description = ServerDescription(clockSource, response); ASSERT_EQUALS(kBsonElectionId.getField("electionId").OID(), description.getElectionId()); } TEST_F(ServerDescriptionTestFixture, ShouldStorePrimary) { auto response = IsMasterOutcome( - "foo:1234", kBsonPrimary, duration_cast<IsMasterRTT>(mongo::Milliseconds(40))); + HostAndPort("foo:1234"), kBsonPrimary, duration_cast<IsMasterRTT>(mongo::Milliseconds(40))); auto description = ServerDescription(clockSource, response); - ASSERT_EQUALS(std::string(kBsonPrimary.getStringField("primary")), description.getPrimary()); + ASSERT_EQUALS(std::string(kBsonPrimary.getStringField("primary")), + description.getPrimary()->toString()); } TEST_F(ServerDescriptionTestFixture, ShouldStoreLogicalSessionTimeout) { - auto response = IsMasterOutcome("foo:1234", + auto response = IsMasterOutcome(HostAndPort("foo:1234"), kBsonLogicalSessionTimeout, duration_cast<IsMasterRTT>(mongo::Milliseconds(40))); auto description = ServerDescription(clockSource, response); @@ -473,8 +498,9 @@ TEST_F(ServerDescriptionTestFixture, ShouldStoreLogicalSessionTimeout) { } TEST_F(ServerDescriptionTestFixture, ShouldStoreTopologyVersion) { - auto response = IsMasterOutcome( - "foo:1234", kTopologyVersion, duration_cast<IsMasterRTT>(mongo::Milliseconds(40))); + auto response = IsMasterOutcome(HostAndPort("foo:1234"), + kTopologyVersion, + duration_cast<IsMasterRTT>(mongo::Milliseconds(40))); auto topologyVersion = TopologyVersion::parse(IDLParserErrorContext("TopologyVersion"), kTopologyVersion.getObjectField("topologyVersion")); @@ -490,14 +516,14 @@ TEST_F(ServerDescriptionTestFixture, ShouldStoreTopologyVersion) { TEST_F(ServerDescriptionTestFixture, ShouldStoreStreamable) { auto response = IsMasterOutcome( - "foo:1234", kStreamable, duration_cast<IsMasterRTT>(mongo::Milliseconds(40))); + HostAndPort("foo:1234"), kStreamable, duration_cast<IsMasterRTT>(mongo::Milliseconds(40))); auto description = ServerDescription(clockSource, response); ASSERT_EQUALS(true, description.isStreamable()); } TEST_F(ServerDescriptionTestFixture, ShouldStorePoolResetCounter) { auto response = IsMasterOutcome( - "foo:1234", kStreamable, duration_cast<IsMasterRTT>(mongo::Milliseconds(40))); + HostAndPort("foo:1234"), kStreamable, duration_cast<IsMasterRTT>(mongo::Milliseconds(40))); auto description = ServerDescription( clockSource, response, boost::none /*lastRtt*/, boost::none /*topologyVersion*/, 1); ASSERT_EQUALS(1, description.getPoolResetCounter()); @@ -505,14 +531,14 @@ TEST_F(ServerDescriptionTestFixture, ShouldStorePoolResetCounter) { TEST_F(ServerDescriptionTestFixture, ShouldStoreServerAddressOnError) { - auto response = IsMasterOutcome("foo:1234", kTopologyVersion, "an error occurred"); + auto response = IsMasterOutcome(HostAndPort("foo:1234"), kTopologyVersion, "an error occurred"); auto description = ServerDescription(clockSource, response); - ASSERT_EQUALS(std::string("foo:1234"), description.getAddress()); + ASSERT_EQUALS(std::string("foo:1234"), description.getAddress().toString()); } TEST_F(ServerDescriptionTestFixture, ShouldStoreCorrectDefaultValuesOnSuccess) { - auto response = - IsMasterOutcome("foo:1234", kBsonOk, duration_cast<IsMasterRTT>(mongo::Milliseconds(40))); + auto response = IsMasterOutcome( + HostAndPort("foo:1234"), kBsonOk, duration_cast<IsMasterRTT>(mongo::Milliseconds(40))); auto description = ServerDescription(clockSource, response); ASSERT_EQUALS(boost::none, description.getError()); ASSERT_EQUALS(boost::none, description.getLastWriteDate()); @@ -534,7 +560,7 @@ TEST_F(ServerDescriptionTestFixture, ShouldStoreCorrectDefaultValuesOnSuccess) { TEST_F(ServerDescriptionTestFixture, ShouldStoreCorrectDefaultValuesOnFailure) { - auto response = IsMasterOutcome("foo:1234", kTopologyVersion, "an error occurred"); + auto response = IsMasterOutcome(HostAndPort("foo:1234"), kTopologyVersion, "an error occurred"); auto description = ServerDescription(clockSource, response); ASSERT_EQUALS(boost::none, description.getLastWriteDate()); ASSERT_EQUALS(ServerType::kUnknown, description.getType()); diff --git a/src/mongo/client/sdam/server_selection_json_test_runner.cpp b/src/mongo/client/sdam/server_selection_json_test_runner.cpp index 7dfa93ea0a2..b2ce37d45a5 100644 --- a/src/mongo/client/sdam/server_selection_json_test_runner.cpp +++ b/src/mongo/client/sdam/server_selection_json_test_runner.cpp @@ -80,9 +80,9 @@ std::string emphasize(const std::string text) { return output.str(); } -std::ostream& operator<<(std::ostream& os, const std::vector<std::string>& input) { +std::ostream& operator<<(std::ostream& os, const std::vector<HostAndPort>& input) { for (auto const& i : input) { - os << i << " "; + os << i.toString() << " "; } return os; } @@ -130,7 +130,7 @@ public: auto clockSource = std::make_unique<ClockSourceMock>(); updatedServerDescription = std::make_shared<ServerDescription>( ServerDescription(clockSource.get(), - IsMasterOutcome(ServerAddress("dummy"), + IsMasterOutcome(HostAndPort("dummy"), BSON("ok" << 1 << "setname" << "replSet" << "ismaster" << true), @@ -171,7 +171,7 @@ private: std::string origRttAsString = _jsonTest.getStringField("avg_rtt_ms"); if (origRttAsString.compare("NULL") != 0) { auto serverDescription = ServerDescriptionBuilder() - .withAddress("dummy") + .withAddress(HostAndPort("dummy")) .withType(ServerType::kRSPrimary) .instance(); auto origAvgRtt = Milliseconds(_jsonTest["avg_rtt_ms"].numberInt()); @@ -272,14 +272,14 @@ private: auto topologyDescriptionObj = _jsonTest.getObjectField("topology_description"); std::vector<ServerDescriptionPtr> serverDescriptions; - std::vector<ServerAddress> serverAddresses; + std::vector<HostAndPort> serverAddresses; const std::vector<BSONElement>& bsonServers = topologyDescriptionObj["servers"].Array(); for (auto bsonServer : bsonServers) { auto server = bsonServer.Obj(); auto serverType = uassertStatusOK(parseServerType(server.getStringField("type"))); auto serverDescription = ServerDescriptionBuilder() - .withAddress(server.getStringField("address")) + .withAddress(HostAndPort(server.getStringField("address"))) .withType(serverType) .withRtt(Milliseconds(server["avg_rtt_ms"].numberInt())) .withMinWireVersion(8) @@ -292,7 +292,7 @@ private: } serverDescriptions.push_back(serverDescription.instance()); - serverAddresses.push_back(server.getStringField("address")); + serverAddresses.push_back(HostAndPort(server.getStringField("address"))); } TopologyType initType = @@ -301,7 +301,7 @@ private: if (initType == TopologyType::kReplicaSetNoPrimary || initType == TopologyType::kSingle) setName = "replset"; - boost::optional<std::vector<ServerAddress>> seedList = boost::none; + boost::optional<std::vector<HostAndPort>> seedList = boost::none; if (serverAddresses.size() > 0) seedList = serverAddresses; @@ -316,7 +316,7 @@ private: for (auto bsonServer : bsonLatencyWindow) { auto server = bsonServer.Obj(); if (serverDescription->getAddress() == - ServerAddress(server.getStringField("address"))) { + HostAndPort(server.getStringField("address"))) { _inLatencyWindow.push_back(serverDescription); } } @@ -343,27 +343,27 @@ private: // _inLatencyWindow vectors. We do not need to compare the entire server description // because we only need to make sure that the correct server was chosen and are not // manipulating the ServerDescriptions at all. - std::vector<std::string> selectedServerAddresses; - std::vector<std::string> expectedServerAddresses; + std::vector<HostAndPort> selectedHostAndPortes; + std::vector<HostAndPort> expectedHostAndPortes; auto selectedServersIt = selectedServers->begin(); for (auto expectedServersIt = _inLatencyWindow.begin(); expectedServersIt != _inLatencyWindow.end(); ++expectedServersIt) { - selectedServerAddresses.push_back((*selectedServersIt)->getAddress()); - expectedServerAddresses.push_back((*expectedServersIt)->getAddress()); + selectedHostAndPortes.push_back((*selectedServersIt)->getAddress()); + expectedHostAndPortes.push_back((*expectedServersIt)->getAddress()); selectedServersIt++; } - std::sort(selectedServerAddresses.begin(), selectedServerAddresses.end()); - std::sort(expectedServerAddresses.begin(), expectedServerAddresses.end()); - if (!std::equal(selectedServerAddresses.begin(), - selectedServerAddresses.end(), - expectedServerAddresses.begin())) { + std::sort(selectedHostAndPortes.begin(), selectedHostAndPortes.end()); + std::sort(expectedHostAndPortes.begin(), expectedHostAndPortes.end()); + if (!std::equal(selectedHostAndPortes.begin(), + selectedHostAndPortes.end(), + expectedHostAndPortes.begin())) { std::stringstream errorMessage; - errorMessage << "selected servers with addresses '" << selectedServerAddresses - << "' server(s), but expected '" << expectedServerAddresses + errorMessage << "selected servers with addresses '" << selectedHostAndPortes + << "' server(s), but expected '" << expectedHostAndPortes << "' to be selected."; auto errorDescription = std::make_pair("servers in latency window", errorMessage.str()); diff --git a/src/mongo/client/sdam/server_selector_test.cpp b/src/mongo/client/sdam/server_selector_test.cpp index 568645df9a6..77e5c90e7dd 100644 --- a/src/mongo/client/sdam/server_selector_test.cpp +++ b/src/mongo/client/sdam/server_selector_test.cpp @@ -42,7 +42,7 @@ namespace mongo::sdam { class ServerSelectorTestFixture : public SdamTestFixture { public: static inline const auto clockSource = SystemClockSource::get(); - static inline const auto sdamConfiguration = SdamConfiguration({{"s0"}}); + static inline const auto sdamConfiguration = SdamConfiguration({{HostAndPort("s0")}}); static inline const auto selectionConfig = ServerSelectionConfiguration(Milliseconds(10), Milliseconds(10)); @@ -94,7 +94,7 @@ public: }; static ServerDescriptionPtr make_with_latency(IsMasterRTT latency, - ServerAddress address, + HostAndPort address, ServerType serverType = ServerType::kRSPrimary, std::map<std::string, std::string> tags = {}) { auto builder = ServerDescriptionBuilder() @@ -117,23 +117,23 @@ public: static auto makeServerDescriptionList() { return std::vector<ServerDescriptionPtr>{ make_with_latency(Milliseconds(1), - "s1", + HostAndPort("s1"), ServerType::kRSSecondary, {{"dc", "east"}, {"usage", "production"}}), make_with_latency(Milliseconds(1), - "s1-test", + HostAndPort("s1-test"), ServerType::kRSSecondary, {{"dc", "east"}, {"usage", "test"}}), make_with_latency(Milliseconds(1), - "s2", + HostAndPort("s2"), ServerType::kRSSecondary, {{"dc", "west"}, {"usage", "production"}}), make_with_latency(Milliseconds(1), - "s2-test", + HostAndPort("s2-test"), ServerType::kRSSecondary, {{"dc", "west"}, {"usage", "test"}}), make_with_latency(Milliseconds(1), - "s3", + HostAndPort("s3"), ServerType::kRSSecondary, {{"dc", "north"}, {"usage", "production"}})}; }; @@ -149,18 +149,18 @@ TEST_F(ServerSelectorTestFixture, ShouldFilterCorrectlyByLatencyWindow) { auto window = LatencyWindow(lowerBound, windowWidth); std::vector<ServerDescriptionPtr> servers = { - make_with_latency(window.lower - delta, "less"), - make_with_latency(window.lower, "boundary-lower"), - make_with_latency(window.lower + delta, "within"), - make_with_latency(window.upper, "boundary-upper"), - make_with_latency(window.upper + delta, "greater")}; + make_with_latency(window.lower - delta, HostAndPort("less")), + make_with_latency(window.lower, HostAndPort("boundary-lower")), + make_with_latency(window.lower + delta, HostAndPort("within")), + make_with_latency(window.upper, HostAndPort("boundary-upper")), + make_with_latency(window.upper + delta, HostAndPort("greater"))}; window.filterServers(&servers); ASSERT_EQ(3, servers.size()); - ASSERT_EQ("boundary-lower", servers[0]->getAddress()); - ASSERT_EQ("within", servers[1]->getAddress()); - ASSERT_EQ("boundary-upper", servers[2]->getAddress()); + ASSERT_EQ(HostAndPort("boundary-lower"), servers[0]->getAddress()); + ASSERT_EQ(HostAndPort("within"), servers[1]->getAddress()); + ASSERT_EQ(HostAndPort("boundary-upper"), servers[2]->getAddress()); } TEST_F(ServerSelectorTestFixture, ShouldThrowOnWireError) { @@ -191,37 +191,42 @@ TEST_F(ServerSelectorTestFixture, ShouldSelectRandomlyWhenMultipleOptionsAreAvai const auto s0Latency = Milliseconds(1); auto primary = ServerDescriptionBuilder() - .withAddress("s0") + .withAddress(HostAndPort("s0")) .withType(ServerType::kRSPrimary) .withLastUpdateTime(Date_t::now()) .withLastWriteDate(Date_t::now()) .withRtt(s0Latency) .withSetName("set") - .withHost("s0") - .withHost("s1") - .withHost("s2") - .withHost("s3") + .withHost(HostAndPort("s0")) + .withHost(HostAndPort("s1")) + .withHost(HostAndPort("s2")) + .withHost(HostAndPort("s3")) .withMinWireVersion(WireVersion::SUPPORTS_OP_MSG) .withMaxWireVersion(WireVersion::LATEST_WIRE_VERSION) .instance(); stateMachine.onServerDescription(*topologyDescription, primary); const auto s1Latency = Milliseconds((s0Latency + selectionConfig.getLocalThresholdMs()) / 2); - auto secondaryInLatencyWindow = make_with_latency(s1Latency, "s1", ServerType::kRSSecondary); + auto secondaryInLatencyWindow = + make_with_latency(s1Latency, HostAndPort("s1"), ServerType::kRSSecondary); stateMachine.onServerDescription(*topologyDescription, secondaryInLatencyWindow); // s2 is on the boundary of the latency window const auto s2Latency = s0Latency + selectionConfig.getLocalThresholdMs(); auto secondaryOnBoundaryOfLatencyWindow = - make_with_latency(s2Latency, "s2", ServerType::kRSSecondary); + make_with_latency(s2Latency, HostAndPort("s2"), ServerType::kRSSecondary); stateMachine.onServerDescription(*topologyDescription, secondaryOnBoundaryOfLatencyWindow); // s3 should not be selected const auto s3Latency = s2Latency + Milliseconds(10); - auto secondaryTooFar = make_with_latency(s3Latency, "s3", ServerType::kRSSecondary); + auto secondaryTooFar = + make_with_latency(s3Latency, HostAndPort("s3"), ServerType::kRSSecondary); stateMachine.onServerDescription(*topologyDescription, secondaryTooFar); - std::map<ServerAddress, int> frequencyInfo{{"s0", 0}, {"s1", 0}, {"s2", 0}, {"s3", 0}}; + std::map<HostAndPort, int> frequencyInfo{{HostAndPort("s0"), 0}, + {HostAndPort("s1"), 0}, + {HostAndPort("s2"), 0}, + {HostAndPort("s3"), 0}}; for (int i = 0; i < NUM_ITERATIONS; i++) { auto server = selector.selectServer(topologyDescription, ReadPreferenceSetting(ReadPreference::Nearest)); @@ -230,10 +235,10 @@ TEST_F(ServerSelectorTestFixture, ShouldSelectRandomlyWhenMultipleOptionsAreAvai } } - ASSERT(frequencyInfo["s0"]); - ASSERT(frequencyInfo["s1"]); - ASSERT(frequencyInfo["s2"]); - ASSERT_FALSE(frequencyInfo["s3"]); + ASSERT(frequencyInfo[HostAndPort("s0")]); + ASSERT(frequencyInfo[HostAndPort("s1")]); + ASSERT(frequencyInfo[HostAndPort("s2")]); + ASSERT_FALSE(frequencyInfo[HostAndPort("s3")]); } TEST_F(ServerSelectorTestFixture, ShouldFilterByLastWriteTime) { @@ -247,13 +252,13 @@ TEST_F(ServerSelectorTestFixture, ShouldFilterByLastWriteTime) { const auto d0 = now - Milliseconds(1000); const auto s0 = ServerDescriptionBuilder() - .withAddress("s0") + .withAddress(HostAndPort("s0")) .withType(ServerType::kRSPrimary) .withRtt(selectionConfig.getLocalThresholdMs()) .withSetName("set") - .withHost("s0") - .withHost("s1") - .withHost("s2") + .withHost(HostAndPort("s0")) + .withHost(HostAndPort("s1")) + .withHost(HostAndPort("s2")) .withMinWireVersion(WireVersion::SUPPORTS_OP_MSG) .withMaxWireVersion(WireVersion::LATEST_WIRE_VERSION) .withLastUpdateTime(now) @@ -263,7 +268,7 @@ TEST_F(ServerSelectorTestFixture, ShouldFilterByLastWriteTime) { const auto d1 = now - Milliseconds(1000 * 5); const auto s1 = ServerDescriptionBuilder() - .withAddress("s1") + .withAddress(HostAndPort("s1")) .withType(ServerType::kRSSecondary) .withRtt(selectionConfig.getLocalThresholdMs()) .withSetName("set") @@ -277,7 +282,7 @@ TEST_F(ServerSelectorTestFixture, ShouldFilterByLastWriteTime) { // d2 is stale, so s2 should not be selected. const auto d2 = now - ninetySeconds - ninetySeconds; const auto s2 = ServerDescriptionBuilder() - .withAddress("s2") + .withAddress(HostAndPort("s2")) .withType(ServerType::kRSSecondary) .withRtt(selectionConfig.getLocalThresholdMs()) .withSetName("set") @@ -291,7 +296,8 @@ TEST_F(ServerSelectorTestFixture, ShouldFilterByLastWriteTime) { const auto readPref = ReadPreferenceSetting(ReadPreference::Nearest, TagSets::emptySet, ninetySeconds); - std::map<ServerAddress, int> frequencyInfo{{"s0", 0}, {"s1", 0}, {"s2", 0}}; + std::map<HostAndPort, int> frequencyInfo{ + {HostAndPort("s0"), 0}, {HostAndPort("s1"), 0}, {HostAndPort("s2"), 0}}; for (int i = 0; i < NUM_ITERATIONS; i++) { auto server = selector.selectServer(topologyDescription, readPref); @@ -300,9 +306,9 @@ TEST_F(ServerSelectorTestFixture, ShouldFilterByLastWriteTime) { } } - ASSERT(frequencyInfo["s0"]); - ASSERT(frequencyInfo["s1"]); - ASSERT_FALSE(frequencyInfo["s2"]); + ASSERT(frequencyInfo[HostAndPort("s0")]); + ASSERT(frequencyInfo[HostAndPort("s1")]); + ASSERT_FALSE(frequencyInfo[HostAndPort("s2")]); } TEST_F(ServerSelectorTestFixture, ShouldSelectPreferredIfAvailable) { @@ -314,12 +320,12 @@ TEST_F(ServerSelectorTestFixture, ShouldSelectPreferredIfAvailable) { const auto d0 = now - Milliseconds(1000); const auto s0 = ServerDescriptionBuilder() - .withAddress("s0") + .withAddress(HostAndPort("s0")) .withType(ServerType::kRSPrimary) .withRtt(selectionConfig.getLocalThresholdMs()) .withSetName("set") - .withHost("s0") - .withHost("s1") + .withHost(HostAndPort("s0")) + .withHost(HostAndPort("s1")) .withMinWireVersion(WireVersion::SUPPORTS_OP_MSG) .withMaxWireVersion(WireVersion::LATEST_WIRE_VERSION) .withLastWriteDate(d0) @@ -328,12 +334,12 @@ TEST_F(ServerSelectorTestFixture, ShouldSelectPreferredIfAvailable) { stateMachine.onServerDescription(*topologyDescription, s0); const auto s1 = ServerDescriptionBuilder() - .withAddress("s1") + .withAddress(HostAndPort("s1")) .withType(ServerType::kRSSecondary) .withRtt(selectionConfig.getLocalThresholdMs()) .withSetName("set") - .withHost("s0") - .withHost("s1") + .withHost(HostAndPort("s0")) + .withHost(HostAndPort("s1")) .withMinWireVersion(WireVersion::SUPPORTS_OP_MSG) .withMaxWireVersion(WireVersion::LATEST_WIRE_VERSION) .withLastWriteDate(d0) @@ -345,18 +351,18 @@ TEST_F(ServerSelectorTestFixture, ShouldSelectPreferredIfAvailable) { ReadPreferenceSetting(ReadPreference::PrimaryPreferred, TagSets::secondarySet); auto result1 = selector.selectServer(topologyDescription, primaryPreferredTagSecondary); ASSERT(result1 != boost::none); - ASSERT_EQ("s0", (*result1)->getAddress()); + ASSERT_EQ(HostAndPort("s0"), (*result1)->getAddress()); const auto secondaryPreferredWithTag = ReadPreferenceSetting(ReadPreference::SecondaryPreferred, TagSets::secondarySet); auto result2 = selector.selectServer(topologyDescription, secondaryPreferredWithTag); ASSERT(result2 != boost::none); - ASSERT_EQ("s1", (*result2)->getAddress()); + ASSERT_EQ(HostAndPort("s1"), (*result2)->getAddress()); const auto secondaryPreferredNoTag = ReadPreferenceSetting(ReadPreference::SecondaryPreferred); auto result3 = selector.selectServer(topologyDescription, secondaryPreferredNoTag); ASSERT(result3 != boost::none); - ASSERT_EQ("s1", (*result2)->getAddress()); + ASSERT_EQ(HostAndPort("s1"), (*result2)->getAddress()); } TEST_F(ServerSelectorTestFixture, ShouldSelectTaggedSecondaryIfPreferredPrimaryNotAvailable) { @@ -368,13 +374,13 @@ TEST_F(ServerSelectorTestFixture, ShouldSelectTaggedSecondaryIfPreferredPrimaryN const auto d0 = now - Milliseconds(1000); const auto s0 = ServerDescriptionBuilder() - .withAddress("s0") + .withAddress(HostAndPort("s0")) .withType(ServerType::kRSPrimary) .withRtt(selectionConfig.getLocalThresholdMs()) .withSetName("set") - .withHost("s0") - .withHost("s1") - .withHost("s2") + .withHost(HostAndPort("s0")) + .withHost(HostAndPort("s1")) + .withHost(HostAndPort("s2")) .withMinWireVersion(WireVersion::SUPPORTS_OP_MSG) .withMaxWireVersion(WireVersion::LATEST_WIRE_VERSION) .withLastWriteDate(d0) @@ -384,20 +390,20 @@ TEST_F(ServerSelectorTestFixture, ShouldSelectTaggedSecondaryIfPreferredPrimaryN // old primary unavailable const auto s0_failed = ServerDescriptionBuilder() - .withAddress("s0") + .withAddress(HostAndPort("s0")) .withType(ServerType::kUnknown) .withSetName("set") .instance(); stateMachine.onServerDescription(*topologyDescription, s0_failed); const auto s1 = ServerDescriptionBuilder() - .withAddress("s1") + .withAddress(HostAndPort("s1")) .withType(ServerType::kRSSecondary) .withRtt(selectionConfig.getLocalThresholdMs()) .withSetName("set") - .withHost("s0") - .withHost("s1") - .withHost("s2") + .withHost(HostAndPort("s0")) + .withHost(HostAndPort("s1")) + .withHost(HostAndPort("s2")) .withMinWireVersion(WireVersion::SUPPORTS_OP_MSG) .withMaxWireVersion(WireVersion::LATEST_WIRE_VERSION) .withLastWriteDate(d0) @@ -406,13 +412,13 @@ TEST_F(ServerSelectorTestFixture, ShouldSelectTaggedSecondaryIfPreferredPrimaryN stateMachine.onServerDescription(*topologyDescription, s1); const auto s2 = ServerDescriptionBuilder() - .withAddress("s2") + .withAddress(HostAndPort("s2")) .withType(ServerType::kRSSecondary) .withRtt(selectionConfig.getLocalThresholdMs()) .withSetName("set") - .withHost("s0") - .withHost("s1") - .withHost("s2") + .withHost(HostAndPort("s0")) + .withHost(HostAndPort("s1")) + .withHost(HostAndPort("s2")) .withMinWireVersion(WireVersion::SUPPORTS_OP_MSG) .withMaxWireVersion(WireVersion::LATEST_WIRE_VERSION) .withLastWriteDate(d0) @@ -423,7 +429,7 @@ TEST_F(ServerSelectorTestFixture, ShouldSelectTaggedSecondaryIfPreferredPrimaryN ReadPreferenceSetting(ReadPreference::PrimaryPreferred, TagSets::secondarySet); auto result1 = selector.selectServer(topologyDescription, primaryPreferredTagSecondary); ASSERT(result1 != boost::none); - ASSERT_EQ("s1", (*result1)->getAddress()); + ASSERT_EQ(HostAndPort("s1"), (*result1)->getAddress()); } TEST_F(ServerSelectorTestFixture, ShouldFilterByTags) { diff --git a/src/mongo/client/sdam/topology_description.cpp b/src/mongo/client/sdam/topology_description.cpp index 8f44c653237..fdd8f36191d 100644 --- a/src/mongo/client/sdam/topology_description.cpp +++ b/src/mongo/client/sdam/topology_description.cpp @@ -90,7 +90,7 @@ void TopologyDescription::setType(TopologyType type) { _type = type; } -bool TopologyDescription::containsServerAddress(const ServerAddress& address) const { +bool TopologyDescription::containsServerAddress(const HostAndPort& address) const { return findServerByAddress(address) != boost::none; } @@ -102,7 +102,7 @@ std::vector<ServerDescriptionPtr> TopologyDescription::findServers( } const boost::optional<ServerDescriptionPtr> TopologyDescription::findServerByAddress( - ServerAddress address) const { + HostAndPort address) const { auto results = findServers([address](const ServerDescriptionPtr& serverDescription) { return serverDescription->getAddress() == address; }); @@ -146,10 +146,10 @@ boost::optional<ServerDescriptionPtr> TopologyDescription::installServerDescript return previousDescription; } -void TopologyDescription::removeServerDescription(const ServerAddress& serverAddress) { +void TopologyDescription::removeServerDescription(const HostAndPort& HostAndPort) { auto it = std::find_if( - _servers.begin(), _servers.end(), [serverAddress](const ServerDescriptionPtr& description) { - return description->getAddress() == serverAddress; + _servers.begin(), _servers.end(), [HostAndPort](const ServerDescriptionPtr& description) { + return description->getAddress() == HostAndPort; }); if (it != _servers.end()) { _servers.erase(it); @@ -245,7 +245,7 @@ BSONObj TopologyDescription::toBSON() { BSONObjBuilder bsonServers; for (auto server : this->getServers()) { - bsonServers << server->getAddress() << server->toBson(); + bsonServers << server->getAddress().toString() << server->toBson(); } bson.append("servers", bsonServers.obj()); diff --git a/src/mongo/client/sdam/topology_description.h b/src/mongo/client/sdam/topology_description.h index a0469eb118b..b17e99e0bd8 100644 --- a/src/mongo/client/sdam/topology_description.h +++ b/src/mongo/client/sdam/topology_description.h @@ -67,20 +67,20 @@ public: const boost::optional<int>& getLogicalSessionTimeoutMinutes() const; const Milliseconds& getHeartBeatFrequency() const; - const boost::optional<ServerDescriptionPtr> findServerByAddress(ServerAddress address) const; - bool containsServerAddress(const ServerAddress& address) const; + const boost::optional<ServerDescriptionPtr> findServerByAddress(HostAndPort address) const; + bool containsServerAddress(const HostAndPort& address) const; std::vector<ServerDescriptionPtr> findServers( std::function<bool(const ServerDescriptionPtr&)> predicate) const; boost::optional<ServerDescriptionPtr> getPrimary(); /** * Adds the given ServerDescription or swaps it with an existing one - * using the description's ServerAddress as the lookup key. If present, the previous server + * using the description's HostAndPort as the lookup key. If present, the previous server * description is returned. */ boost::optional<ServerDescriptionPtr> installServerDescription( const ServerDescriptionPtr& newServerDescription); - void removeServerDescription(const ServerAddress& serverAddress); + void removeServerDescription(const HostAndPort& HostAndPort); void setType(TopologyType type); @@ -153,7 +153,7 @@ private: // servers: a set of ServerDescription instances. Default contains one server: // "localhost:27017", ServerType Unknown. std::vector<ServerDescriptionPtr> _servers{ - std::make_shared<ServerDescription>("localhost:27017")}; + std::make_shared<ServerDescription>(HostAndPort("localhost:27017"))}; // compatible: a boolean. False if any server's wire protocol version range is incompatible with // the client's. Default true. diff --git a/src/mongo/client/sdam/topology_description_test.cpp b/src/mongo/client/sdam/topology_description_test.cpp index dc00fec7422..ebb78472115 100644 --- a/src/mongo/client/sdam/topology_description_test.cpp +++ b/src/mongo/client/sdam/topology_description_test.cpp @@ -41,8 +41,7 @@ #include "mongo/unittest/death_test.h" namespace mongo { -template std::ostream& operator<<(std::ostream& os, - const std::vector<mongo::sdam::ServerAddress>& s); +template std::ostream& operator<<(std::ostream& os, const std::vector<HostAndPort>& s); bool operator==(const TopologyVersion& a, const TopologyVersion& b) { return a.getProcessId() == b.getProcessId() && a.getCounter() == b.getCounter(); @@ -58,11 +57,13 @@ protected: static inline const auto kSetName = std::string("mySetName"); - static inline const std::vector<ServerAddress> kOneServer{"foo:1234"}; - static inline const std::vector<ServerAddress> kTwoServersVaryCase{"FoO:1234", "BaR:1234"}; - static inline const std::vector<ServerAddress> kTwoServersNormalCase{"foo:1234", "bar:1234"}; - static inline const std::vector<ServerAddress> kThreeServers{ - "foo:1234", "bar:1234", "baz:1234"}; + static inline const std::vector<HostAndPort> kOneServer{HostAndPort("foo:1234")}; + static inline const std::vector<HostAndPort> kTwoServersVaryCase{HostAndPort("FoO:1234"), + HostAndPort("BaR:1234")}; + static inline const std::vector<HostAndPort> kTwoServersNormalCase{HostAndPort("foo:1234"), + HostAndPort("bar:1234")}; + static inline const std::vector<HostAndPort> kThreeServers{ + HostAndPort("foo:1234"), HostAndPort("bar:1234"), HostAndPort("baz:1234")}; static inline const auto kDefaultConfig = SdamConfiguration(); static inline const auto kSingleSeedConfig = @@ -74,7 +75,7 @@ void TopologyDescriptionTestFixture::assertDefaultConfig( ASSERT_EQUALS(boost::none, topologyDescription.getSetName()); ASSERT_EQUALS(boost::none, topologyDescription.getMaxElectionId()); - auto expectedDefaultServer = ServerDescription("localhost:27017"); + auto expectedDefaultServer = ServerDescription(HostAndPort("localhost:27017")); ASSERT_EQUALS(expectedDefaultServer, *topologyDescription.getServers().front()); ASSERT_EQUALS(static_cast<std::size_t>(1), topologyDescription.getServers().size()); @@ -96,7 +97,7 @@ TEST_F(TopologyDescriptionTestFixture, ShouldHaveCorrectDefaultValues) { // // auto expectedAddresses = kTwoServersNormalCase; // -// auto serverAddresses = map<ServerDescriptionPtr, ServerAddress>( +// auto serverAddresses = map<ServerDescriptionPtr, HostAndPort>( // topologyDescription.getServers(), // [](const ServerDescriptionPtr& description) { return description->getAddress(); }); // @@ -108,7 +109,7 @@ TEST_F(TopologyDescriptionTestFixture, ShouldAllowTypeSingleWithASingleSeed) { ASSERT(TopologyType::kSingle == topologyDescription.getType()); - auto servers = map<ServerDescriptionPtr, ServerAddress>( + auto servers = map<ServerDescriptionPtr, HostAndPort>( topologyDescription.getServers(), [](const ServerDescriptionPtr& desc) { return desc->getAddress(); }); ASSERT_EQUALS(kOneServer, servers); diff --git a/src/mongo/client/sdam/topology_listener.cpp b/src/mongo/client/sdam/topology_listener.cpp index f56ea9181b3..b4d6be361e8 100644 --- a/src/mongo/client/sdam/topology_listener.cpp +++ b/src/mongo/client/sdam/topology_listener.cpp @@ -60,7 +60,7 @@ void TopologyEventsPublisher::onTopologyDescriptionChangedEvent( } void TopologyEventsPublisher::onServerHandshakeCompleteEvent(IsMasterRTT durationMs, - const sdam::ServerAddress& address, + const HostAndPort& address, const BSONObj reply) { { stdx::lock_guard<Mutex> lock(_eventQueueMutex); @@ -74,7 +74,7 @@ void TopologyEventsPublisher::onServerHandshakeCompleteEvent(IsMasterRTT duratio _scheduleNextDelivery(); } -void TopologyEventsPublisher::onServerHandshakeFailedEvent(const sdam::ServerAddress& address, +void TopologyEventsPublisher::onServerHandshakeFailedEvent(const HostAndPort& address, const Status& status, const BSONObj reply) { { @@ -89,7 +89,7 @@ void TopologyEventsPublisher::onServerHandshakeFailedEvent(const sdam::ServerAdd _scheduleNextDelivery(); } -void TopologyEventsPublisher::onServerHeartbeatSucceededEvent(const ServerAddress& hostAndPort, +void TopologyEventsPublisher::onServerHeartbeatSucceededEvent(const HostAndPort& hostAndPort, const BSONObj reply) { { stdx::lock_guard lock(_eventQueueMutex); @@ -103,7 +103,7 @@ void TopologyEventsPublisher::onServerHeartbeatSucceededEvent(const ServerAddres } void TopologyEventsPublisher::onServerHeartbeatFailureEvent(Status errorStatus, - const ServerAddress& hostAndPort, + const HostAndPort& hostAndPort, const BSONObj reply) { { stdx::lock_guard lock(_eventQueueMutex); @@ -123,7 +123,7 @@ void TopologyEventsPublisher::_scheduleNextDelivery() { [self = shared_from_this()](const Status& status) { self->_nextDelivery(); }); } -void TopologyEventsPublisher::onServerPingFailedEvent(const ServerAddress& hostAndPort, +void TopologyEventsPublisher::onServerPingFailedEvent(const HostAndPort& hostAndPort, const Status& status) { { stdx::lock_guard lock(_eventQueueMutex); @@ -137,7 +137,7 @@ void TopologyEventsPublisher::onServerPingFailedEvent(const ServerAddress& hostA } void TopologyEventsPublisher::onServerPingSucceededEvent(IsMasterRTT durationMS, - const ServerAddress& hostAndPort) { + const HostAndPort& hostAndPort) { { stdx::lock_guard lock(_eventQueueMutex); EventPtr event = std::make_unique<Event>(); diff --git a/src/mongo/client/sdam/topology_listener.h b/src/mongo/client/sdam/topology_listener.h index bbb2a5b21b6..a503193ff5c 100644 --- a/src/mongo/client/sdam/topology_listener.h +++ b/src/mongo/client/sdam/topology_listener.h @@ -51,17 +51,17 @@ public: TopologyDescriptionPtr newDescription){}; virtual void onServerHeartbeatFailureEvent(Status errorStatus, - const ServerAddress& hostAndPort, + const HostAndPort& hostAndPort, const BSONObj reply){}; /** * Called when a ServerHandshakeCompleteEvent is published - The initial handshake to the server * at hostAndPort was successful. durationMS is the measured RTT (Round Trip Time). */ virtual void onServerHandshakeCompleteEvent(IsMasterRTT durationMs, - const sdam::ServerAddress& address, + const HostAndPort& address, const BSONObj reply = BSONObj()){}; - virtual void onServerHandshakeFailedEvent(const sdam::ServerAddress& address, + virtual void onServerHandshakeFailedEvent(const HostAndPort& address, const Status& status, const BSONObj reply){}; @@ -70,21 +70,21 @@ public: * hostAndPort succeeded. durationMS is the execution time of the event, including the time it * took to send the message and recieve the reply from the server. */ - virtual void onServerHeartbeatSucceededEvent(const ServerAddress& hostAndPort, + virtual void onServerHeartbeatSucceededEvent(const HostAndPort& hostAndPort, const BSONObj reply){}; /* * Called when a ServerPingFailedEvent is published - A monitoring ping to the server at * hostAndPort was not successful. */ - virtual void onServerPingFailedEvent(const ServerAddress& hostAndPort, const Status& status){}; + virtual void onServerPingFailedEvent(const HostAndPort& hostAndPort, const Status& status){}; /** * Called when a ServerPingSucceededEvent is published - A monitoring ping to the server at * hostAndPort was successful. durationMS is the measured RTT (Round Trip Time). */ virtual void onServerPingSucceededEvent(IsMasterRTT durationMS, - const ServerAddress& hostAndPort){}; + const HostAndPort& hostAndPort){}; }; /** @@ -105,21 +105,21 @@ public: void onTopologyDescriptionChangedEvent(TopologyDescriptionPtr previousDescription, TopologyDescriptionPtr newDescription) override; virtual void onServerHandshakeCompleteEvent(IsMasterRTT durationMs, - const sdam::ServerAddress& address, + const HostAndPort& address, const BSONObj reply = BSONObj()) override; - void onServerHandshakeFailedEvent(const sdam::ServerAddress& address, + void onServerHandshakeFailedEvent(const HostAndPort& address, const Status& status, const BSONObj reply); - void onServerHeartbeatSucceededEvent(const ServerAddress& hostAndPort, + void onServerHeartbeatSucceededEvent(const HostAndPort& hostAndPort, const BSONObj reply) override; void onServerHeartbeatFailureEvent(Status errorStatus, - const ServerAddress& hostAndPort, + const HostAndPort& hostAndPort, const BSONObj reply) override; - void onServerPingFailedEvent(const ServerAddress& hostAndPort, const Status& status) override; + void onServerPingFailedEvent(const HostAndPort& hostAndPort, const Status& status) override; void onServerPingSucceededEvent(IsMasterRTT durationMS, - const ServerAddress& hostAndPort) override; + const HostAndPort& hostAndPort) override; private: enum class EventType { @@ -134,7 +134,7 @@ private: struct Event { EventType type; - ServerAddress hostAndPort; + HostAndPort hostAndPort; IsMasterRTT duration; BSONObj reply; TopologyDescriptionPtr previousDescription; diff --git a/src/mongo/client/sdam/topology_listener_mock.cpp b/src/mongo/client/sdam/topology_listener_mock.cpp index b737402d181..22aebbd2c2e 100644 --- a/src/mongo/client/sdam/topology_listener_mock.cpp +++ b/src/mongo/client/sdam/topology_listener_mock.cpp @@ -34,7 +34,7 @@ namespace mongo::sdam { -void TopologyListenerMock::onServerHeartbeatSucceededEvent(const ServerAddress& hostAndPort, +void TopologyListenerMock::onServerHeartbeatSucceededEvent(const HostAndPort& hostAndPort, const BSONObj reply) { stdx::lock_guard lk(_mutex); auto it = _serverIsMasterReplies.find(hostAndPort); @@ -46,7 +46,7 @@ void TopologyListenerMock::onServerHeartbeatSucceededEvent(const ServerAddress& } void TopologyListenerMock::onServerHeartbeatFailureEvent(Status errorStatus, - const ServerAddress& hostAndPort, + const HostAndPort& hostAndPort, const BSONObj reply) { stdx::lock_guard lk(_mutex); // If the map already contains an element for hostAndPort, append to its already existing @@ -59,16 +59,16 @@ void TopologyListenerMock::onServerHeartbeatFailureEvent(Status errorStatus, } } -bool TopologyListenerMock::hasIsMasterResponse(const ServerAddress& hostAndPort) { +bool TopologyListenerMock::hasIsMasterResponse(const HostAndPort& hostAndPort) { stdx::lock_guard lock(_mutex); return _hasIsMasterResponse(lock, hostAndPort); } -bool TopologyListenerMock::_hasIsMasterResponse(WithLock, const ServerAddress& hostAndPort) { +bool TopologyListenerMock::_hasIsMasterResponse(WithLock, const HostAndPort& hostAndPort) { return _serverIsMasterReplies.find(hostAndPort) != _serverIsMasterReplies.end(); } -std::vector<Status> TopologyListenerMock::getIsMasterResponse(const ServerAddress& hostAndPort) { +std::vector<Status> TopologyListenerMock::getIsMasterResponse(const HostAndPort& hostAndPort) { stdx::lock_guard lock(_mutex); invariant(_hasIsMasterResponse(lock, hostAndPort)); auto it = _serverIsMasterReplies.find(hostAndPort); @@ -78,7 +78,7 @@ std::vector<Status> TopologyListenerMock::getIsMasterResponse(const ServerAddres } void TopologyListenerMock::onServerPingSucceededEvent(IsMasterRTT latency, - const ServerAddress& hostAndPort) { + const HostAndPort& hostAndPort) { stdx::lock_guard lk(_mutex); auto it = _serverPingRTTs.find(hostAndPort); if (it != _serverPingRTTs.end()) { @@ -88,7 +88,7 @@ void TopologyListenerMock::onServerPingSucceededEvent(IsMasterRTT latency, } } -void TopologyListenerMock::onServerPingFailedEvent(const ServerAddress& hostAndPort, +void TopologyListenerMock::onServerPingFailedEvent(const HostAndPort& hostAndPort, const Status& errorStatus) { stdx::lock_guard lk(_mutex); // If the map already contains an element for hostAndPort, append to its already existing @@ -101,17 +101,17 @@ void TopologyListenerMock::onServerPingFailedEvent(const ServerAddress& hostAndP } } -bool TopologyListenerMock::hasPingResponse(const ServerAddress& hostAndPort) { +bool TopologyListenerMock::hasPingResponse(const HostAndPort& hostAndPort) { stdx::lock_guard lock(_mutex); return _hasPingResponse(lock, hostAndPort); } -bool TopologyListenerMock::_hasPingResponse(WithLock, const ServerAddress& hostAndPort) { +bool TopologyListenerMock::_hasPingResponse(WithLock, const HostAndPort& hostAndPort) { return _serverPingRTTs.find(hostAndPort) != _serverPingRTTs.end(); } std::vector<StatusWith<IsMasterRTT>> TopologyListenerMock::getPingResponse( - const ServerAddress& hostAndPort) { + const HostAndPort& hostAndPort) { stdx::lock_guard lock(_mutex); invariant(_hasPingResponse(lock, hostAndPort)); auto it = _serverPingRTTs.find(hostAndPort); diff --git a/src/mongo/client/sdam/topology_listener_mock.h b/src/mongo/client/sdam/topology_listener_mock.h index 836354e52c2..0c5007c2457 100644 --- a/src/mongo/client/sdam/topology_listener_mock.h +++ b/src/mongo/client/sdam/topology_listener_mock.h @@ -40,43 +40,43 @@ public: TopologyListenerMock() = default; virtual ~TopologyListenerMock() = default; - void onServerHeartbeatSucceededEvent(const ServerAddress& hostAndPort, + void onServerHeartbeatSucceededEvent(const HostAndPort& hostAndPort, const BSONObj reply) override; void onServerHeartbeatFailureEvent(Status errorStatus, - const ServerAddress& hostAndPort, + const HostAndPort& hostAndPort, const BSONObj reply) override; /** * Returns true if _serverIsMasterReplies contains an element corresponding to hostAndPort. */ - bool hasIsMasterResponse(const ServerAddress& hostAndPort); - bool _hasIsMasterResponse(WithLock, const ServerAddress& hostAndPort); + bool hasIsMasterResponse(const HostAndPort& hostAndPort); + bool _hasIsMasterResponse(WithLock, const HostAndPort& hostAndPort); /** * Returns the responses for the most recent onServerHeartbeat events. */ - std::vector<Status> getIsMasterResponse(const ServerAddress& hostAndPort); + std::vector<Status> getIsMasterResponse(const HostAndPort& hostAndPort); - void onServerPingSucceededEvent(IsMasterRTT latency, const ServerAddress& hostAndPort) override; + void onServerPingSucceededEvent(IsMasterRTT latency, const HostAndPort& hostAndPort) override; - void onServerPingFailedEvent(const ServerAddress& hostAndPort, const Status& status) override; + void onServerPingFailedEvent(const HostAndPort& hostAndPort, const Status& status) override; /** * Returns true if _serverPingRTTs contains an element corresponding to hostAndPort. */ - bool hasPingResponse(const ServerAddress& hostAndPort); - bool _hasPingResponse(WithLock, const ServerAddress& hostAndPort); + bool hasPingResponse(const HostAndPort& hostAndPort); + bool _hasPingResponse(WithLock, const HostAndPort& hostAndPort); /** * Returns the responses for the most recent onServerPing events. */ - std::vector<StatusWith<IsMasterRTT>> getPingResponse(const ServerAddress& hostAndPort); + std::vector<StatusWith<IsMasterRTT>> getPingResponse(const HostAndPort& hostAndPort); private: Mutex _mutex; - stdx::unordered_map<ServerAddress, std::vector<Status>> _serverIsMasterReplies; - stdx::unordered_map<ServerAddress, std::vector<StatusWith<IsMasterRTT>>> _serverPingRTTs; + stdx::unordered_map<HostAndPort, std::vector<Status>> _serverIsMasterReplies; + stdx::unordered_map<HostAndPort, std::vector<StatusWith<IsMasterRTT>>> _serverPingRTTs; }; } // namespace mongo::sdam diff --git a/src/mongo/client/sdam/topology_manager.cpp b/src/mongo/client/sdam/topology_manager.cpp index ae39a253b4d..28070ef17e5 100644 --- a/src/mongo/client/sdam/topology_manager.cpp +++ b/src/mongo/client/sdam/topology_manager.cpp @@ -128,7 +128,7 @@ const std::shared_ptr<TopologyDescription> TopologyManager::getTopologyDescripti return _topologyDescription; } -void TopologyManager::onServerRTTUpdated(ServerAddress hostAndPort, IsMasterRTT rtt) { +void TopologyManager::onServerRTTUpdated(HostAndPort hostAndPort, IsMasterRTT rtt) { { stdx::lock_guard<mongo::Mutex> lock(_mutex); diff --git a/src/mongo/client/sdam/topology_manager.h b/src/mongo/client/sdam/topology_manager.h index 5ae64d94644..0ea306ce1a3 100644 --- a/src/mongo/client/sdam/topology_manager.h +++ b/src/mongo/client/sdam/topology_manager.h @@ -72,7 +72,7 @@ public: * 3. Installs the cloned ServerDescription into the TopologyDescription from step 1 * 4. Installs the cloned TopologyDescription as the current one. */ - void onServerRTTUpdated(ServerAddress hostAndPort, IsMasterRTT rtt); + void onServerRTTUpdated(HostAndPort hostAndPort, IsMasterRTT rtt); /** * Get the current TopologyDescription. This is safe to call from multiple threads. diff --git a/src/mongo/client/sdam/topology_manager_test.cpp b/src/mongo/client/sdam/topology_manager_test.cpp index 765d784e04f..33145151178 100644 --- a/src/mongo/client/sdam/topology_manager_test.cpp +++ b/src/mongo/client/sdam/topology_manager_test.cpp @@ -37,8 +37,7 @@ #include "mongo/util/system_clock_source.h" namespace mongo { -template std::ostream& operator<<(std::ostream& os, - const std::vector<mongo::sdam::ServerAddress>& s); +template std::ostream& operator<<(std::ostream& os, const std::vector<HostAndPort>& s); namespace sdam { using mongo::operator<<; @@ -49,7 +48,7 @@ protected: static inline const auto kSetName = std::string("mySetName"); - static inline const std::vector<ServerAddress> kOneServer{"foo:1234"}; + static inline const std::vector<HostAndPort> kOneServer{HostAndPort("foo:1234")}; static BSONObjBuilder okBuilder() { return std::move(BSONObjBuilder().append("ok", 1)); diff --git a/src/mongo/client/sdam/topology_state_machine.cpp b/src/mongo/client/sdam/topology_state_machine.cpp index 966ffb4f79d..faa3cea1368 100644 --- a/src/mongo/client/sdam/topology_state_machine.cpp +++ b/src/mongo/client/sdam/topology_state_machine.cpp @@ -200,9 +200,9 @@ void TopologyStateMachine::updateRSWithoutPrimary(TopologyDescription& topologyD void TopologyStateMachine::addUnknownServers(TopologyDescription& topologyDescription, const ServerDescriptionPtr& serverDescription) { - const std::set<ServerAddress>* addressSets[3]{&serverDescription->getHosts(), - &serverDescription->getPassives(), - &serverDescription->getArbiters()}; + const std::set<HostAndPort>* addressSets[3]{&serverDescription->getHosts(), + &serverDescription->getPassives(), + &serverDescription->getArbiters()}; for (const auto addresses : addressSets) { for (const auto& addressFromSet : *addresses) { if (!topologyDescription.containsServerAddress(addressFromSet)) { @@ -294,7 +294,7 @@ void TopologyStateMachine::updateRSFromPrimary(TopologyDescription& topologyDesc addUnknownServers(topologyDescription, serverDescription); - std::vector<ServerAddress> toRemove; + std::vector<HostAndPort> toRemove; for (const auto& currentServerDescription : topologyDescription.getServers()) { const auto currentServerAddress = currentServerDescription->getAddress(); auto hosts = serverDescription->getHosts().find(currentServerAddress); @@ -363,7 +363,7 @@ void TopologyStateMachine::setTopologyTypeAndUpdateRSWithoutPrimary( } void TopologyStateMachine::removeServerDescription(TopologyDescription& topologyDescription, - const ServerAddress serverAddress) { + const HostAndPort serverAddress) { topologyDescription.removeServerDescription(serverAddress); LOGV2(20220, "{kLogPrefix}server '{serverAddress}' was removed from the topology.", diff --git a/src/mongo/client/sdam/topology_state_machine.h b/src/mongo/client/sdam/topology_state_machine.h index 9c8d1718eb3..e0505806e1f 100644 --- a/src/mongo/client/sdam/topology_state_machine.h +++ b/src/mongo/client/sdam/topology_state_machine.h @@ -89,7 +89,7 @@ private: ServerDescriptionPtr newServerDescription, bool newServer); void removeServerDescription(TopologyDescription& topologyDescription, - const ServerAddress serverAddress); + const HostAndPort serverAddress); void modifyTopologyType(TopologyDescription& topologyDescription, TopologyType topologyType); void modifySetName(TopologyDescription& topologyDescription, diff --git a/src/mongo/client/sdam/topology_state_machine_test.cpp b/src/mongo/client/sdam/topology_state_machine_test.cpp index d01f48e6c34..bc3e8efba25 100644 --- a/src/mongo/client/sdam/topology_state_machine_test.cpp +++ b/src/mongo/client/sdam/topology_state_machine_test.cpp @@ -39,20 +39,20 @@ namespace mongo::sdam { class TopologyStateMachineTestFixture : public SdamTestFixture { protected: static inline const auto kReplicaSetName = "replica_set"; - static inline const auto kLocalServer = "localhost:123"; - static inline const auto kLocalServer2 = "localhost:456"; + static inline const auto kLocalServer = HostAndPort("localhost:123"); + static inline const auto kLocalServer2 = HostAndPort("localhost:456"); static inline const auto kTwoSeedConfig = - SdamConfiguration(std::vector<ServerAddress>{kLocalServer, kLocalServer2}, + SdamConfiguration(std::vector<HostAndPort>{kLocalServer, kLocalServer2}, TopologyType::kUnknown, mongo::Milliseconds(500)); static inline const auto kTwoSeedReplicaSetNoPrimaryConfig = - SdamConfiguration(std::vector<ServerAddress>{kLocalServer, kLocalServer2}, + SdamConfiguration(std::vector<HostAndPort>{kLocalServer, kLocalServer2}, TopologyType::kReplicaSetNoPrimary, mongo::Milliseconds(500), std::string("setName")); static inline const auto kSingleConfig = - SdamConfiguration(std::vector<ServerAddress>{kLocalServer}, TopologyType::kSingle); + SdamConfiguration(std::vector<HostAndPort>{kLocalServer}, TopologyType::kSingle); // Given we in 'starting' state with initial config 'initialConfig'. We receive a // ServerDescription with type 'incoming', and expected the ending topology state to be @@ -126,7 +126,7 @@ TEST_F(TopologyStateMachineTestFixture, ShouldInstallServerDescriptionInSingleTo TopologyStateMachine stateMachine(kSingleConfig); auto topologyDescription = std::make_shared<TopologyDescription>(kSingleConfig); - auto updatedMeAddress = "foo:1234"; + auto updatedMeAddress = HostAndPort("foo:1234"); auto serverDescription = ServerDescriptionBuilder() .withAddress(kLocalServer) .withMe(updatedMeAddress) @@ -177,13 +177,13 @@ TEST_F(TopologyStateMachineTestFixture, .instance(); ASSERT_EQUALS(static_cast<size_t>(2), topologyDescription->getServers().size()); - auto serversBefore = map<ServerDescriptionPtr, ServerAddress>(topologyDescription->getServers(), - getServerDescriptionAddress); + auto serversBefore = map<ServerDescriptionPtr, HostAndPort>(topologyDescription->getServers(), + getServerDescriptionAddress); stateMachine.onServerDescription(*topologyDescription, serverDescription); - auto serversAfter = map<ServerDescriptionPtr, ServerAddress>(topologyDescription->getServers(), - getServerDescriptionAddress); + auto serversAfter = map<ServerDescriptionPtr, HostAndPort>(topologyDescription->getServers(), + getServerDescriptionAddress); ASSERT_EQUALS(serversBefore, serversAfter); } @@ -216,23 +216,23 @@ TEST_F(TopologyStateMachineTestFixture, ASSERT_EQUALS(topologyDescription->getType(), TopologyType::kReplicaSetWithPrimary); ASSERT_EQUALS(static_cast<size_t>(2), topologyDescription->getServers().size()); - auto serversBefore = map<ServerDescriptionPtr, ServerAddress>(topologyDescription->getServers(), - getServerDescriptionAddress); + auto serversBefore = map<ServerDescriptionPtr, HostAndPort>(topologyDescription->getServers(), + getServerDescriptionAddress); stateMachine.onServerDescription(*topologyDescription, serverDescription); ASSERT_EQUALS(topologyDescription->getType(), TopologyType::kReplicaSetWithPrimary); - auto serversAfter = map<ServerDescriptionPtr, ServerAddress>(topologyDescription->getServers(), - getServerDescriptionAddress); + auto serversAfter = map<ServerDescriptionPtr, HostAndPort>(topologyDescription->getServers(), + getServerDescriptionAddress); ASSERT_EQUALS(serversBefore, serversAfter); } TEST_F(TopologyStateMachineTestFixture, ShouldRemoveNonPrimaryServerWhenTopologyIsReplicaSetNoPrimaryAndMeDoesntMatchAddress) { const auto serverAddress = (*kTwoSeedReplicaSetNoPrimaryConfig.getSeedList()).front(); - const auto expectedRemainingServerAddress = + const auto expectedRemainingHostAndPort = (*kTwoSeedReplicaSetNoPrimaryConfig.getSeedList()).back(); - const auto me = std::string("foo") + serverAddress; + const auto me = HostAndPort(std::string("foo") + serverAddress.toString()); TopologyStateMachine stateMachine(kTwoSeedReplicaSetNoPrimaryConfig); auto topologyDescription = @@ -247,7 +247,7 @@ TEST_F(TopologyStateMachineTestFixture, ASSERT_EQUALS(static_cast<size_t>(2), topologyDescription->getServers().size()); stateMachine.onServerDescription(*topologyDescription, serverDescription); ASSERT_EQUALS(static_cast<size_t>(1), topologyDescription->getServers().size()); - ASSERT_EQUALS(expectedRemainingServerAddress, + ASSERT_EQUALS(expectedRemainingHostAndPort, topologyDescription->getServers().front()->getAddress()); } @@ -255,7 +255,7 @@ TEST_F(TopologyStateMachineTestFixture, ShouldAddServerDescriptionIfInHostsListButNotInTopologyDescription) { const auto primary = (*kTwoSeedConfig.getSeedList()).front(); const auto secondary = (*kTwoSeedConfig.getSeedList()).back(); - const auto newHost = ServerAddress("newhost:123"); + const auto newHost = HostAndPort("newhost:123"); TopologyStateMachine stateMachine(kTwoSeedConfig); auto topologyDescription = std::make_shared<TopologyDescription>(kTwoSeedConfig); diff --git a/src/mongo/client/server_is_master_monitor.cpp b/src/mongo/client/server_is_master_monitor.cpp index 8371f74d315..03ed68f05af 100644 --- a/src/mongo/client/server_is_master_monitor.cpp +++ b/src/mongo/client/server_is_master_monitor.cpp @@ -63,7 +63,7 @@ bool exhaustEnabled(boost::optional<TopologyVersion> topologyVersion) { SingleServerIsMasterMonitor::SingleServerIsMasterMonitor( const MongoURI& setUri, - const sdam::ServerAddress& host, + const HostAndPort& host, boost::optional<TopologyVersion> topologyVersion, Milliseconds heartbeatFrequencyMS, sdam::TopologyEventsPublisherPtr eventListener, diff --git a/src/mongo/client/server_is_master_monitor.h b/src/mongo/client/server_is_master_monitor.h index ac77a0cd0b5..5745e4fef37 100644 --- a/src/mongo/client/server_is_master_monitor.h +++ b/src/mongo/client/server_is_master_monitor.h @@ -39,7 +39,7 @@ class SingleServerIsMasterMonitor : public std::enable_shared_from_this<SingleServerIsMasterMonitor> { public: explicit SingleServerIsMasterMonitor(const MongoURI& setUri, - const ServerAddress& host, + const HostAndPort& host, boost::optional<TopologyVersion> topologyVersion, Milliseconds heartbeatFrequencyMS, TopologyEventsPublisherPtr eventListener, @@ -96,7 +96,7 @@ private: Mutex _mutex = MONGO_MAKE_LATCH(HierarchicalAcquisitionLevel(4), "SingleServerIsMasterMonitor::mutex"); - ServerAddress _host; + HostAndPort _host; boost::optional<TopologyVersion> _topologyVersion; TopologyEventsPublisherPtr _eventListener; std::shared_ptr<executor::TaskExecutor> _executor; @@ -155,7 +155,7 @@ private: SdamConfiguration _sdamConfiguration; TopologyEventsPublisherPtr _eventPublisher; std::shared_ptr<executor::TaskExecutor> _executor; - stdx::unordered_map<ServerAddress, SingleServerIsMasterMonitorPtr> _singleMonitors; + stdx::unordered_map<HostAndPort, SingleServerIsMasterMonitorPtr> _singleMonitors; bool _isShutdown; MongoURI _setUri; }; diff --git a/src/mongo/client/server_is_master_monitor_test.cpp b/src/mongo/client/server_is_master_monitor_test.cpp index 8ba84d768d4..b1a33fd350d 100644 --- a/src/mongo/client/server_is_master_monitor_test.cpp +++ b/src/mongo/client/server_is_master_monitor_test.cpp @@ -130,7 +130,7 @@ protected: * Sets up a SingleServerIsMasterMonitor that starts sending isMasters to the server. */ std::shared_ptr<SingleServerIsMasterMonitor> initSingleServerIsMasterMonitor( - const sdam::ServerAddress& hostAndPort, MockReplicaSet* replSet) { + const HostAndPort& hostAndPort, MockReplicaSet* replSet) { auto ssIsMasterMonitor = std::make_shared<SingleServerIsMasterMonitor>(replSet->getURI(), hostAndPort, boost::none, @@ -163,7 +163,7 @@ protected: * assertHostCheck is true, asserts that the isMaster was sent to the server at hostAndPort. */ void processIsMasterRequest(MockReplicaSet* replSet, - boost::optional<sdam::ServerAddress> hostAndPort = boost::none) { + boost::optional<HostAndPort> hostAndPort = boost::none) { ASSERT(hasReadyRequests()); InNetworkGuard guard(_net); _net->runReadyNetworkOperations(); @@ -173,7 +173,7 @@ protected: executor::TaskExecutorTest::assertRemoteCommandNameEquals("isMaster", request); auto requestHost = request.target.toString(); if (hostAndPort) { - ASSERT_EQ(request.target.toString(), hostAndPort); + ASSERT_EQ(request.target, hostAndPort); } LOGV2(457991, @@ -209,7 +209,7 @@ protected: * heartbeatFrequency. */ void checkSingleIsMaster(Milliseconds heartbeatFrequency, - const sdam::ServerAddress& hostAndPort, + const HostAndPort& hostAndPort, MockReplicaSet* replSet) { auto deadline = elapsed() + heartbeatFrequency; processIsMasterRequest(replSet, hostAndPort); @@ -221,7 +221,7 @@ protected: checkNoActivityBefore(deadline, hostAndPort); } - void validateIsMasterResponse(const sdam::ServerAddress& hostAndPort, Milliseconds deadline) { + void validateIsMasterResponse(const HostAndPort& hostAndPort, Milliseconds deadline) { ASSERT_TRUE(_topologyListener->hasIsMasterResponse(hostAndPort)); ASSERT_LT(elapsed(), deadline); auto isMasterResponse = _topologyListener->getIsMasterResponse(hostAndPort); @@ -236,7 +236,7 @@ protected: * isMaster responses are received between elapsed() and deadline when hostAndPort is specified. */ void checkNoActivityBefore(Milliseconds deadline, - boost::optional<sdam::ServerAddress> hostAndPort = boost::none) { + boost::optional<HostAndPort> hostAndPort = boost::none) { while (elapsed() < deadline) { if (hasReadyRequests()) { { @@ -296,7 +296,7 @@ private: TEST_F(ServerIsMasterMonitorTestFixture, heartbeatFrequencyCheck) { auto replSet = std::make_unique<MockReplicaSet>( "test", 1, /* hasPrimary = */ false, /* dollarPrefixHosts = */ false); - auto hostAndPort = HostAndPort(replSet->getSecondaries()[0]).toString(); + auto hostAndPort = HostAndPort(replSet->getSecondaries()[0]); auto ssIsMasterMonitor = initSingleServerIsMasterMonitor(hostAndPort, replSet.get()); ssIsMasterMonitor->disableExpeditedChecking(); @@ -327,10 +327,10 @@ TEST_F(ServerIsMasterMonitorTestFixture, singleServerIsMasterMonitorReportsFailu "test", 1, /* hasPrimary = */ false, /* dollarPrefixHosts = */ false); // Kill the server before starting up the SingleServerIsMasterMonitor. - auto hostAndPort = HostAndPort(replSet->getSecondaries()[0]).toString(); + auto hostAndPort = HostAndPort(replSet->getSecondaries()[0]); { NetworkInterfaceMock::InNetworkGuard ing(getNet()); - replSet->kill(hostAndPort); + replSet->kill(hostAndPort.toString()); } auto ssIsMasterMonitor = initSingleServerIsMasterMonitor(hostAndPort, replSet.get()); @@ -354,8 +354,8 @@ TEST_F(ServerIsMasterMonitorTestFixture, serverIsMasterMonitorOnTopologyDescript "test", 2, /* hasPrimary = */ false, /* dollarPrefixHosts = */ false); auto hostAndPortList = replSet->getHosts(); - auto host0 = hostAndPortList[0].toString(); - std::vector<sdam::ServerAddress> host0Vec{host0}; + auto host0 = hostAndPortList[0]; + std::vector<HostAndPort> host0Vec{host0}; // Start up the ServerIsMasterMonitor to monitor host0 only. auto sdamConfig0 = sdam::SdamConfiguration(host0Vec); @@ -369,8 +369,8 @@ TEST_F(ServerIsMasterMonitorTestFixture, serverIsMasterMonitorOnTopologyDescript ASSERT_FALSE(hasReadyRequests()); // Start monitoring host1. - auto host1 = hostAndPortList[1].toString(); - std::vector<sdam::ServerAddress> allHostsVec{host0, host1}; + auto host1 = hostAndPortList[1]; + std::vector<HostAndPort> allHostsVec{host0, host1}; auto sdamConfigAllHosts = sdam::SdamConfiguration(allHostsVec); auto topologyDescriptionAllHosts = std::make_shared<sdam::TopologyDescription>(sdamConfigAllHosts); @@ -393,9 +393,9 @@ TEST_F(ServerIsMasterMonitorTestFixture, "test", 2, /* hasPrimary = */ false, /* dollarPrefixHosts = */ false); auto hostAndPortList = replSet->getHosts(); - auto host0 = hostAndPortList[0].toString(); - auto host1 = hostAndPortList[1].toString(); - std::vector<sdam::ServerAddress> allHostsVec{host0, host1}; + auto host0 = hostAndPortList[0]; + auto host1 = hostAndPortList[1]; + std::vector<HostAndPort> allHostsVec{host0, host1}; // Start up the ServerIsMasterMonitor to monitor both hosts. auto sdamConfigAllHosts = sdam::SdamConfiguration(allHostsVec); @@ -424,7 +424,7 @@ TEST_F(ServerIsMasterMonitorTestFixture, validateIsMasterResponse(host1, deadline); // Remove host1 from the TopologyDescription to stop monitoring it. - std::vector<sdam::ServerAddress> host0Vec{host0}; + std::vector<HostAndPort> host0Vec{host0}; auto sdamConfig0 = sdam::SdamConfiguration(host0Vec); auto topologyDescription0 = std::make_shared<sdam::TopologyDescription>(sdamConfig0); isMasterMonitor->onTopologyDescriptionChangedEvent(topologyDescriptionAllHosts, @@ -444,7 +444,7 @@ TEST_F(ServerIsMasterMonitorTestFixture, serverIsMasterMonitorShutdownStopsIsMas auto replSet = std::make_unique<MockReplicaSet>( "test", 1, /* hasPrimary = */ false, /* dollarPrefixHosts = */ false); - std::vector<sdam::ServerAddress> hostVec{replSet->getHosts()[0].toString()}; + std::vector<HostAndPort> hostVec{replSet->getHosts()[0]}; auto sdamConfig = sdam::SdamConfiguration(hostVec); auto topologyDescription = std::make_shared<sdam::TopologyDescription>(sdamConfig); auto uri = replSet->getURI(); @@ -488,7 +488,7 @@ TEST_F(ServerIsMasterMonitorTestFixture, auto replSet = std::make_unique<MockReplicaSet>( "test", 1, /* hasPrimary = */ false, /* dollarPrefixHosts = */ false); - std::vector<sdam::ServerAddress> hostVec{replSet->getHosts()[0].toString()}; + std::vector<HostAndPort> hostVec{replSet->getHosts()[0]}; // Start up the ServerIsMasterMonitor to monitor host0 only. auto sdamConfig0 = sdam::SdamConfiguration(hostVec); @@ -532,7 +532,7 @@ TEST_F(ServerIsMasterMonitorTestFixture, serverIsMasterMonitorRequestImmediateCh auto replSet = std::make_unique<MockReplicaSet>( "test", 1, /* hasPrimary = */ false, /* dollarPrefixHosts = */ false); - std::vector<sdam::ServerAddress> hostVec{replSet->getHosts()[0].toString()}; + std::vector<HostAndPort> hostVec{replSet->getHosts()[0]}; // Start up the ServerIsMasterMonitor to monitor host0 only. auto sdamConfig0 = sdam::SdamConfiguration(hostVec); diff --git a/src/mongo/client/server_ping_monitor.cpp b/src/mongo/client/server_ping_monitor.cpp index 6ce8682fd7c..568a1381c62 100644 --- a/src/mongo/client/server_ping_monitor.cpp +++ b/src/mongo/client/server_ping_monitor.cpp @@ -53,7 +53,7 @@ using CallbackArgs = TaskExecutor::CallbackArgs; using CallbackHandle = TaskExecutor::CallbackHandle; SingleServerPingMonitor::SingleServerPingMonitor(const MongoURI& setUri, - const sdam::ServerAddress& hostAndPort, + const HostAndPort& hostAndPort, sdam::TopologyListener* rttListener, Milliseconds pingFrequency, std::shared_ptr<TaskExecutor> executor) @@ -151,7 +151,8 @@ void SingleServerPingMonitor::_doServerPing() { if (MONGO_unlikely(serverPingMonitorFailWithHostUnreachable.shouldFail( [&](const BSONObj& data) { - return anchor->_hostAndPort == data.getStringField("hostAndPort"); + return anchor->_hostAndPort.toString() == + data.getStringField("hostAndPort"); }))) { const std::string reason = str::stream() << "Failing the ping command to " << (anchor->_hostAndPort); @@ -223,7 +224,7 @@ void ServerPingMonitor::shutdown() { } void ServerPingMonitor::onServerHandshakeCompleteEvent(sdam::IsMasterRTT durationMs, - const sdam::ServerAddress& address, + const HostAndPort& address, const BSONObj reply) { stdx::lock_guard lk(_mutex); if (_isShutdown) { diff --git a/src/mongo/client/server_ping_monitor.h b/src/mongo/client/server_ping_monitor.h index 6523ad39a30..13f6fc250e5 100644 --- a/src/mongo/client/server_ping_monitor.h +++ b/src/mongo/client/server_ping_monitor.h @@ -44,7 +44,7 @@ namespace mongo { class SingleServerPingMonitor : public std::enable_shared_from_this<SingleServerPingMonitor> { public: explicit SingleServerPingMonitor(const MongoURI& setUri, - const sdam::ServerAddress& hostAndPort, + const HostAndPort& hostAndPort, sdam::TopologyListener* rttListener, Milliseconds pingFrequency, std::shared_ptr<executor::TaskExecutor> executor); @@ -91,7 +91,7 @@ private: MongoURI _setUri; - sdam::ServerAddress _hostAndPort; + HostAndPort _hostAndPort; /** * Listens for when new RTT (Round Trip Time) values are published. @@ -154,7 +154,7 @@ public: * SingleServerPingMonitor to monitor the new replica set member. */ void onServerHandshakeCompleteEvent(sdam::IsMasterRTT durationMs, - const sdam::ServerAddress& address, + const HostAndPort& address, const BSONObj reply = BSONObj()); /** @@ -191,7 +191,7 @@ private: * Note: SingleServerPingMonitor's drop() should always be called before removing it from the * _serverPingMonitorMap. */ - stdx::unordered_map<sdam::ServerAddress, std::shared_ptr<SingleServerPingMonitor>> + stdx::unordered_map<HostAndPort, std::shared_ptr<SingleServerPingMonitor>> _serverPingMonitorMap; bool _isShutdown{false}; diff --git a/src/mongo/client/server_ping_monitor_test.cpp b/src/mongo/client/server_ping_monitor_test.cpp index 98d77a67949..f665e61e9f1 100644 --- a/src/mongo/client/server_ping_monitor_test.cpp +++ b/src/mongo/client/server_ping_monitor_test.cpp @@ -103,7 +103,7 @@ protected: /** * Checks that a ping has been made to the server at hostAndPort and schedules a response. */ - void processPingRequest(const sdam::ServerAddress& hostAndPort, MockReplicaSet* replSet) { + void processPingRequest(const HostAndPort& hostAndPort, MockReplicaSet* replSet) { ASSERT(hasReadyRequests()); InNetworkGuard guard(_net); @@ -113,13 +113,13 @@ protected: // Check that it is a ping request from the expected hostAndPort. executor::TaskExecutorTest::assertRemoteCommandNameEquals("ping", request); - ASSERT_EQ(request.target.toString(), hostAndPort); + ASSERT_EQ(request.target, hostAndPort); LOGV2(23925, "at {elapsed} got mock network operation {request}", "elapsed"_attr = elapsed(), "request"_attr = request.toString()); - const auto node = replSet->getNode(hostAndPort); + const auto node = replSet->getNode(hostAndPort.toString()); node->setCommandReply("ping", BSON("ok" << 1)); if (node->isRunning()) { @@ -150,7 +150,7 @@ protected: * no additional pings are issued for at least pingFrequency. */ void checkSinglePing(Milliseconds pingFrequency, - const sdam::ServerAddress& hostAndPort, + const HostAndPort& hostAndPort, MockReplicaSet* replSet) { processPingRequest(hostAndPort, replSet); @@ -172,7 +172,7 @@ protected: * Confirms no more ping requests are sent between elapsed() and deadline. Confirms no more ping * responses are received between elapsed() and deadline. */ - void checkNoActivityBefore(Milliseconds deadline, const sdam::ServerAddress& hostAndPort) { + void checkNoActivityBefore(Milliseconds deadline, const HostAndPort& hostAndPort) { while (elapsed() < deadline) { ASSERT_FALSE(hasReadyRequests()); ASSERT_FALSE(_topologyListener->hasPingResponse(hostAndPort)); @@ -185,20 +185,13 @@ protected: * prompt the event with a new TopologyDescription that does not include hostToDrop. */ void closeMonitor(MockReplicaSet* replSet, - sdam::ServerAddress hostToDrop, + HostAndPort hostToDrop, ServerPingMonitor* pingMonitor) { - auto hostAndPorts = replSet->getHosts(); - std::vector<sdam::ServerAddress> hosts; - std::transform(hostAndPorts.begin(), - hostAndPorts.end(), - std::back_inserter(hosts), - [](const auto& hostAndPort) { return hostAndPort.toString(); }); - + auto hosts = replSet->getHosts(); auto sdamConfigOld = sdam::SdamConfiguration(hosts); auto topologyDescriptionOld = std::make_shared<sdam::TopologyDescription>(sdamConfigOld); - - std::vector<sdam::ServerAddress> hostsNew(hosts.begin(), hosts.end()); + std::vector<HostAndPort> hostsNew(hosts.begin(), hosts.end()); hostsNew.erase(std::remove_if(hostsNew.begin(), hostsNew.end(), [&](auto host) { return host == hostToDrop; }), @@ -206,7 +199,7 @@ protected: // Since the seedlist cannot be empty, the new TopologyDescription contains an empty // HostAndPort. if (hostsNew.size() == 0) { - hostsNew.emplace_back(HostAndPort().toString()); + hostsNew.emplace_back(HostAndPort()); } auto sdamConfigNew = sdam::SdamConfiguration(hostsNew); auto topologyDescriptionNew = std::make_shared<sdam::TopologyDescription>(sdamConfigNew); @@ -227,7 +220,7 @@ protected: ServerPingMonitorTestFixture::setUp(); _replSet.reset(new MockReplicaSet( "test", 1, /* hasPrimary = */ false, /* dollarPrefixHosts = */ false)); - _hostAndPort = HostAndPort(_replSet->getSecondaries()[0]).toString(); + _hostAndPort = HostAndPort(_replSet->getSecondaries()[0]); } void tearDown() { @@ -239,7 +232,7 @@ protected: return _replSet.get(); } - sdam::ServerAddress getHostAndPort() { + HostAndPort getHostAndPort() { return _hostAndPort; } @@ -276,9 +269,9 @@ private: std::unique_ptr<MockReplicaSet> _replSet; /** - * Stores the ServerAddress of the node ping requests are sent to. + * Stores the HostAndPort of the node ping requests are sent to. */ - sdam::ServerAddress _hostAndPort; + HostAndPort _hostAndPort; }; TEST_F(SingleServerPingMonitorTest, pingFrequencyCheck) { @@ -300,7 +293,7 @@ TEST_F(SingleServerPingMonitorTest, pingDeadServer) { auto hostAndPort = getHostAndPort(); { NetworkInterfaceMock::InNetworkGuard ing(getNet()); - getReplSet()->kill(hostAndPort); + getReplSet()->kill(hostAndPort.toString()); } auto pingFrequency = Seconds(10); @@ -326,7 +319,7 @@ TEST_F(SingleServerPingMonitorTest, pingDeadServer) { { NetworkInterfaceMock::InNetworkGuard ing(getNet()); - getReplSet()->restore(hostAndPort); + getReplSet()->restore(hostAndPort.toString()); } checkSinglePing(pingFrequency); checkSinglePing(pingFrequency); @@ -364,8 +357,7 @@ TEST_F(ServerPingMonitorTest, singleNodeServerPingMonitorCycle) { auto replSet = std::make_unique<MockReplicaSet>( "test", 1, /* hasPrimary = */ false, /* dollarPrefixHosts = */ false); auto serverPingMonitor = makeServerPingMonitor(replSet->getURI(), pingFrequency); - - auto hostAndPort = HostAndPort(replSet->getSecondaries()[0]).toString(); + auto hostAndPort = HostAndPort(replSet->getSecondaries()[0]); // Add a SingleServerPingMonitor to the ServerPingMonitor. Confirm pings are sent to the server // at pingFrequency. @@ -390,8 +382,8 @@ TEST_F(ServerPingMonitorTest, twoNodeServerPingMonitorOneClosed) { auto serverPingMonitor = makeServerPingMonitor(replSet->getURI(), pingFrequency); auto hosts = replSet->getHosts(); - auto host0 = hosts[0].toString(); - auto host1 = hosts[1].toString(); + auto host0 = hosts[0]; + auto host1 = hosts[1]; // Add SingleServerPingMonitors for host0 and host1 where host1 is added host1Delay seconds // after host0. @@ -421,8 +413,8 @@ TEST_F(ServerPingMonitorTest, twoNodeServerPingMonitorMutlipleShutdown) { auto serverPingMonitor = makeServerPingMonitor(replSet->getURI(), pingFrequency); auto hosts = replSet->getHosts(); - auto host0 = hosts[0].toString(); - auto host1 = hosts[1].toString(); + auto host0 = hosts[0]; + auto host1 = hosts[1]; // Add SingleServerPingMonitors for host0 and host1 where host1 is added host1Delay seconds // after host0. diff --git a/src/mongo/client/streamable_replica_set_monitor.cpp b/src/mongo/client/streamable_replica_set_monitor.cpp index 7cd41ae1ce9..76bfdc58269 100644 --- a/src/mongo/client/streamable_replica_set_monitor.cpp +++ b/src/mongo/client/streamable_replica_set_monitor.cpp @@ -154,10 +154,9 @@ StreamableReplicaSetMonitor::StreamableReplicaSetMonitor( _executor(executor), _random(PseudoRandom(SecureRandom().nextInt64())) { - // TODO SERVER-45395: sdam should use the HostAndPort type for ServerAddress - std::vector<ServerAddress> seeds; + std::vector<HostAndPort> seeds; for (const auto& seed : uri.getServers()) { - seeds.push_back(seed.toString()); + seeds.push_back(seed); } _sdamConfig = SdamConfiguration(seeds); @@ -409,12 +408,12 @@ boost::optional<ServerDescriptionPtr> StreamableReplicaSetMonitor::_currentPrima bool StreamableReplicaSetMonitor::isPrimary(const HostAndPort& host) const { const auto currentPrimary = _currentPrimary(); - return (currentPrimary ? (*currentPrimary)->getAddress() == host.toString() : false); + return (currentPrimary ? (*currentPrimary)->getAddress() == host : false); } bool StreamableReplicaSetMonitor::isHostUp(const HostAndPort& host) const { auto currentTopology = _currentTopology(); - const auto& serverDescription = currentTopology->findServerByAddress(host.toString()); + const auto& serverDescription = currentTopology->findServerByAddress(host); return serverDescription && (*serverDescription)->getType() != ServerType::kUnknown; } @@ -468,7 +467,7 @@ const MongoURI& StreamableReplicaSetMonitor::getOriginalUri() const { } bool StreamableReplicaSetMonitor::contains(const HostAndPort& host) const { - return static_cast<bool>(_currentTopology()->findServerByAddress(host.toString())); + return static_cast<bool>(_currentTopology()->findServerByAddress(host)); } void StreamableReplicaSetMonitor::appendInfo(BSONObjBuilder& bsonObjBuilder, bool forFTDC) const { @@ -477,7 +476,7 @@ void StreamableReplicaSetMonitor::appendInfo(BSONObjBuilder& bsonObjBuilder, boo BSONObjBuilder monitorInfo(bsonObjBuilder.subobjStart(getName())); if (forFTDC) { for (auto serverDescription : topologyDescription->getServers()) { - monitorInfo.appendNumber(serverDescription->getAddress(), + monitorInfo.appendNumber(serverDescription->getAddress().toString(), pingTimeMillis(serverDescription)); } return; @@ -517,7 +516,7 @@ void StreamableReplicaSetMonitor::appendInfo(BSONObjBuilder& bsonObjBuilder, boo } BSONObjBuilder builder(hosts.subobjStart()); - builder.append("addr", serverDescription->getAddress()); + builder.append("addr", serverDescription->getAddress().toString()); builder.append("ok", isUp); builder.append("ismaster", isMaster); // intentionally not camelCase builder.append("hidden", isHidden); @@ -543,29 +542,15 @@ void StreamableReplicaSetMonitor::_setConfirmedNotifierState( WithLock, const ServerDescriptionPtr& primaryDescription) { invariant(primaryDescription && primaryDescription->getType() == sdam::ServerType::kRSPrimary); - const auto& hosts = primaryDescription->getHosts(); - const auto& passives = primaryDescription->getPassives(); + auto hosts = primaryDescription->getHosts(); + auto passives = primaryDescription->getPassives(); + hosts.insert(passives.begin(), passives.end()); - // TODO SERVER-45395: remove need for HostAndPort conversion - std::set<HostAndPort> confirmedHosts; - std::transform(hosts.begin(), - hosts.end(), - std::inserter(confirmedHosts, confirmedHosts.end()), - [](const ServerAddress& addr) -> HostAndPort { return HostAndPort(addr); }); - - std::set<HostAndPort> confirmedPassives; - std::transform(passives.begin(), - passives.end(), - std::inserter(confirmedPassives, confirmedPassives.end()), - [](const ServerAddress& addr) -> HostAndPort { return HostAndPort(addr); }); - - confirmedHosts.insert(confirmedPassives.begin(), confirmedPassives.end()); - - _confirmedNotifierState = ChangeNotifierState{ - HostAndPort(primaryDescription->getAddress()), - confirmedPassives, - ConnectionString::forReplicaSet( - getName(), std::vector<HostAndPort>(confirmedHosts.begin(), confirmedHosts.end()))}; + _confirmedNotifierState = + ChangeNotifierState{primaryDescription->getAddress(), + passives, + ConnectionString::forReplicaSet( + getName(), std::vector<HostAndPort>(hosts.begin(), hosts.end()))}; } void StreamableReplicaSetMonitor::onTopologyDescriptionChangedEvent( @@ -614,7 +599,7 @@ void StreamableReplicaSetMonitor::onTopologyDescriptionChangedEvent( } } -void StreamableReplicaSetMonitor::onServerHeartbeatSucceededEvent(const ServerAddress& hostAndPort, +void StreamableReplicaSetMonitor::onServerHeartbeatSucceededEvent(const HostAndPort& hostAndPort, const BSONObj reply) { // After the inital handshake, isMasterResponses should not update the RTT with durationMs. IsMasterOutcome outcome(hostAndPort, reply, boost::none); @@ -622,25 +607,25 @@ void StreamableReplicaSetMonitor::onServerHeartbeatSucceededEvent(const ServerAd } void StreamableReplicaSetMonitor::onServerHeartbeatFailureEvent(Status errorStatus, - const ServerAddress& hostAndPort, + const HostAndPort& hostAndPort, const BSONObj reply) { _failedHost( HostAndPort(hostAndPort), errorStatus, reply, HandshakeStage::kPostHandshake, false); } -void StreamableReplicaSetMonitor::onServerPingFailedEvent(const ServerAddress& hostAndPort, +void StreamableReplicaSetMonitor::onServerPingFailedEvent(const HostAndPort& hostAndPort, const Status& status) { _failedHost(HostAndPort(hostAndPort), status, BSONObj(), HandshakeStage::kPostHandshake, false); } -void StreamableReplicaSetMonitor::onServerHandshakeFailedEvent(const sdam::ServerAddress& address, +void StreamableReplicaSetMonitor::onServerHandshakeFailedEvent(const HostAndPort& address, const Status& status, const BSONObj reply) { _failedHost(HostAndPort(address), status, reply, HandshakeStage::kPreHandshake, false); }; void StreamableReplicaSetMonitor::onServerPingSucceededEvent(sdam::IsMasterRTT durationMS, - const ServerAddress& hostAndPort) { + const HostAndPort& hostAndPort) { LOGV2_DEBUG(4668132, kLowerLogLevel, "ReplicaSetMonitor ping success", @@ -651,7 +636,7 @@ void StreamableReplicaSetMonitor::onServerPingSucceededEvent(sdam::IsMasterRTT d } void StreamableReplicaSetMonitor::onServerHandshakeCompleteEvent(sdam::IsMasterRTT durationMs, - const ServerAddress& hostAndPort, + const HostAndPort& hostAndPort, const BSONObj reply) { IsMasterOutcome outcome(hostAndPort, reply, durationMs); _topologyManager->onServerDescription(outcome); diff --git a/src/mongo/client/streamable_replica_set_monitor.h b/src/mongo/client/streamable_replica_set_monitor.h index 127a746cd7f..8df300b7f91 100644 --- a/src/mongo/client/streamable_replica_set_monitor.h +++ b/src/mongo/client/streamable_replica_set_monitor.h @@ -165,25 +165,24 @@ private: void onTopologyDescriptionChangedEvent(sdam::TopologyDescriptionPtr previousDescription, sdam::TopologyDescriptionPtr newDescription) override; - void onServerHeartbeatSucceededEvent(const sdam::ServerAddress& hostAndPort, + void onServerHeartbeatSucceededEvent(const HostAndPort& hostAndPort, const BSONObj reply) override; - void onServerHandshakeFailedEvent(const sdam::ServerAddress& address, + void onServerHandshakeFailedEvent(const HostAndPort& address, const Status& status, const BSONObj reply) override; void onServerHeartbeatFailureEvent(Status errorStatus, - const ServerAddress& hostAndPort, + const HostAndPort& hostAndPort, const BSONObj reply) override; - void onServerPingFailedEvent(const sdam::ServerAddress& hostAndPort, - const Status& status) override; + void onServerPingFailedEvent(const HostAndPort& hostAndPort, const Status& status) override; void onServerPingSucceededEvent(sdam::IsMasterRTT durationMS, - const sdam::ServerAddress& hostAndPort) override; + const HostAndPort& hostAndPort) override; void onServerHandshakeCompleteEvent(sdam::IsMasterRTT durationMs, - const ServerAddress& hostAndPort, + const HostAndPort& hostAndPort, const BSONObj reply) override; // Get a pointer to the current primary's ServerDescription diff --git a/src/mongo/client/streamable_replica_set_monitor_error_handler.h b/src/mongo/client/streamable_replica_set_monitor_error_handler.h index 86e9db135e7..989990d4847 100644 --- a/src/mongo/client/streamable_replica_set_monitor_error_handler.h +++ b/src/mongo/client/streamable_replica_set_monitor_error_handler.h @@ -61,7 +61,7 @@ protected: sdam::IsMasterOutcome _createErrorIsMasterOutcome(const HostAndPort& host, boost::optional<BSONObj> bson, const Status& status) const { - return sdam::IsMasterOutcome(host.toString(), bson ? *bson : BSONObj(), status.toString()); + return sdam::IsMasterOutcome(host, bson ? *bson : BSONObj(), status.toString()); } }; diff --git a/src/mongo/client/streamable_replica_set_monitor_error_handler_test.cpp b/src/mongo/client/streamable_replica_set_monitor_error_handler_test.cpp index 3e86d826e31..b0084985223 100644 --- a/src/mongo/client/streamable_replica_set_monitor_error_handler_test.cpp +++ b/src/mongo/client/streamable_replica_set_monitor_error_handler_test.cpp @@ -119,7 +119,7 @@ public: inline static const std::string kErrorMessage = "an error message"; inline static const BSONObj kErrorBson = BSONObjBuilder().append("ok", 0).obj(); inline static const sdam::IsMasterOutcome kErrorIsMasterOutcome = - sdam::IsMasterOutcome(kHost.toString(), kErrorBson, kErrorMessage); + sdam::IsMasterOutcome(kHost, kErrorBson, kErrorMessage); static constexpr bool kApplicationOperation = true; static constexpr bool kMonitoringOperation = false; |