summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierlauro Sciarelli <pierlauro.sciarelli@mongodb.com>2021-01-07 11:27:03 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-09-30 16:57:54 +0000
commit58ee9a806ec4ebb0cca181294688911997d714c4 (patch)
tree75c1bf3ee56d330c71dea71010f6c65ab37a786f
parent0ec341883d37f4fe44ccf75db7c443d76e62ae52 (diff)
downloadmongo-58ee9a806ec4ebb0cca181294688911997d714c4.tar.gz
SERVER-53332 Change ShardRegistry::_connStringLookup to store connection strings as std::strings
-rw-r--r--src/mongo/s/client/shard_registry.cpp18
-rw-r--r--src/mongo/s/client/shard_registry.h5
2 files changed, 11 insertions, 12 deletions
diff --git a/src/mongo/s/client/shard_registry.cpp b/src/mongo/s/client/shard_registry.cpp
index 41f4677094e..5d18387f63f 100644
--- a/src/mongo/s/client/shard_registry.cpp
+++ b/src/mongo/s/client/shard_registry.cpp
@@ -532,8 +532,8 @@ shared_ptr<Shard> ShardRegistryData::findByShardId(const ShardId& shardId) const
return _findByShardId(lk, shardId);
}
-shared_ptr<Shard> ShardRegistryData::_findByConnectionString(
- WithLock, const ConnectionString& connectionString) const {
+std::shared_ptr<Shard> ShardRegistryData::_findByConnectionString(
+ WithLock, const std::string& connectionString) const {
auto i = _connStringLookup.find(connectionString);
return (i != _connStringLookup.end()) ? i->second : nullptr;
}
@@ -559,12 +559,9 @@ shared_ptr<Shard> ShardRegistryData::_findShard(WithLock lk, ShardId const& shar
return shard;
}
- StatusWith<ConnectionString> swConnString = ConnectionString::parse(shardId.toString());
- if (swConnString.isOK()) {
- shard = _findByConnectionString(lk, swConnString.getValue());
- if (shard) {
- return shard;
- }
+ shard = _findByConnectionString(lk, shardId.toString());
+ if (shard) {
+ return shard;
}
StatusWith<HostAndPort> swHostAndPort = HostAndPort::parse(shardId.toString());
@@ -671,7 +668,8 @@ void ShardRegistryData::_addShard(WithLock lk,
for (const auto& host : oldConnString.getServers()) {
_hostLookup.erase(host);
}
- _connStringLookup.erase(oldConnString);
+
+ _connStringLookup.erase(connString.toString());
}
_shardIdLookup[shard->getId()] = shard;
@@ -693,7 +691,7 @@ void ShardRegistryData::_addShard(WithLock lk,
_hostLookup[HostAndPort("localhost")] = shard;
}
- _connStringLookup[connString] = shard;
+ _connStringLookup[connString.toString()] = shard;
for (const HostAndPort& hostAndPort : connString.getServers()) {
_hostLookup[hostAndPort] = shard;
diff --git a/src/mongo/s/client/shard_registry.h b/src/mongo/s/client/shard_registry.h
index 166f316e860..5ed94c5d143 100644
--- a/src/mongo/s/client/shard_registry.h
+++ b/src/mongo/s/client/shard_registry.h
@@ -116,6 +116,7 @@ public:
*/
void shardIdSetDifference(std::set<ShardId>& diff) const;
void toBSON(BSONObjBuilder* result) const;
+
/**
* If the shard with same replica set name as in the newConnString already exists then replace
* it with the shard built for the newConnString.
@@ -133,7 +134,7 @@ private:
auto _findByShardId(WithLock, ShardId const&) const -> std::shared_ptr<Shard>;
auto _findByHostAndPort(WithLock, const HostAndPort& hostAndPort) const
-> std::shared_ptr<Shard>;
- auto _findByConnectionString(WithLock, const ConnectionString& connectionString) const
+ auto _findByConnectionString(WithLock, const std::string& connectionString) const
-> std::shared_ptr<Shard>;
auto _findShard(WithLock lk, ShardId const& shardId) const -> std::shared_ptr<Shard>;
void _rebuildShard(WithLock, ConnectionString const& newConnString, ShardFactory* factory);
@@ -153,7 +154,7 @@ private:
stdx::unordered_map<HostAndPort, std::shared_ptr<Shard>> _hostLookup;
// Map of connection string to Shard
- std::map<ConnectionString, std::shared_ptr<Shard>> _connStringLookup;
+ std::map<std::string, std::shared_ptr<Shard>> _connStringLookup;
// store configShard separately to always have a reference
std::shared_ptr<Shard> _configShard;