File tree Expand file tree Collapse file tree 7 files changed +18
-12
lines changed Expand file tree Collapse file tree 7 files changed +18
-12
lines changed Original file line number Diff line number Diff line change 4343
4444namespace mongo {
4545
46+ const ConnectionString ShardLocal::kLocalConnectionString = ConnectionString::forLocal();
47+
4648ShardLocal::ShardLocal (const ShardId& id) : Shard(id) {
4749 // Currently ShardLocal only works for config servers. If we ever start using ShardLocal on
4850 // shards we'll need to consider how to handle shards.
4951 invariant (serverGlobalParams.clusterRole .has (ClusterRole::ConfigServer));
5052}
5153
52- ConnectionString ShardLocal::getConnString () const {
53- return repl::ReplicationCoordinator::get (getGlobalServiceContext ())
54- ->getConfigConnectionString ();
54+ const ConnectionString& ShardLocal::getConnString () const {
55+ return kLocalConnectionString ;
5556}
5657
5758std::shared_ptr<RemoteCommandTargeter> ShardLocal::getTargeter () const {
Original file line number Diff line number Diff line change @@ -61,6 +61,10 @@ class ShardLocal : public Shard {
6161 ShardLocal& operator =(const ShardLocal&) = delete ;
6262
6363public:
64+ // ShardLocal doesn't have a "real" connection string since it's always a connection to the
65+ // local process, so it uses the hardcoded local connection string. Only used in tests.
66+ static const ConnectionString kLocalConnectionString ;
67+
6468 explicit ShardLocal (const ShardId& id);
6569
6670 ~ShardLocal () = default ;
@@ -69,7 +73,7 @@ class ShardLocal : public Shard {
6973 * These functions are implemented for the Shard interface's sake. They should not be called on
7074 * ShardLocal because doing so triggers invariants.
7175 */
72- ConnectionString getConnString () const override ;
76+ const ConnectionString& getConnString () const override ;
7377 std::shared_ptr<RemoteCommandTargeter> getTargeter () const override ;
7478 void updateReplSetMonitor (const HostAndPort& remoteHost,
7579 const Status& remoteCommandStatus) override ;
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ ConfigShardWrapper::ConfigShardWrapper(std::shared_ptr<Shard> configShard)
4444 invariant (_configShard->isConfig ());
4545}
4646
47- ConnectionString ConfigShardWrapper::getConnString () const {
47+ const ConnectionString& ConfigShardWrapper::getConnString () const {
4848 return _configShard->getConnString ();
4949}
5050
Original file line number Diff line number Diff line change @@ -72,7 +72,7 @@ class ConfigShardWrapper : public Shard {
7272
7373 ~ConfigShardWrapper () = default ;
7474
75- ConnectionString getConnString () const override ;
75+ const ConnectionString& getConnString () const override ;
7676
7777 std::shared_ptr<RemoteCommandTargeter> getTargeter () const override ;
7878
Original file line number Diff line number Diff line change 5353namespace mongo {
5454namespace {
5555
56+ const HostAndPort kConfigHost {" configHost1" };
57+ ConnectionString kConfigCS {ConnectionString::forReplicaSet (" configReplSet" , {kConfigHost })};
58+
5659class MockShard : public Shard {
5760 MockShard (const MockShard&) = delete ;
5861 MockShard& operator =(const MockShard&) = delete ;
@@ -61,10 +64,8 @@ class MockShard : public Shard {
6164 explicit MockShard (const ShardId& id) : Shard(id) {}
6265 ~MockShard () = default ;
6366
64- ConnectionString getConnString () const override {
65- const HostAndPort configHost{" configHost1" };
66- ConnectionString configCS{ConnectionString::forReplicaSet (" configReplSet" , {configHost})};
67- return configCS;
67+ const ConnectionString& getConnString () const override {
68+ return kConfigCS ;
6869 }
6970
7071 std::shared_ptr<RemoteCommandTargeter> getTargeter () const override {
Original file line number Diff line number Diff line change @@ -128,7 +128,7 @@ class Shard {
128128 /* *
129129 * Returns the current connection string for the shard.
130130 */
131- virtual ConnectionString getConnString () const = 0;
131+ virtual const ConnectionString& getConnString () const = 0;
132132
133133 /* *
134134 * Returns the RemoteCommandTargeter for the hosts in this shard.
Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ class ShardRemote : public Shard {
7474
7575 ~ShardRemote ();
7676
77- ConnectionString getConnString () const override {
77+ const ConnectionString& getConnString () const override {
7878 return _connString;
7979 }
8080
You can’t perform that action at this time.
0 commit comments