summaryrefslogtreecommitdiff
path: root/src/mongo/s
diff options
context:
space:
mode:
authorMisha Tyulenev <misha@mongodb.com>2016-04-14 10:21:09 -0400
committerMisha Tyulenev <misha@mongodb.com>2016-04-14 10:21:51 -0400
commit0d30a89c8ce925b4176389ecc2bb59e09afb24f4 (patch)
tree271357f952f4aa20deebd6bdf9b006e146c372f8 /src/mongo/s
parentd0717b4c75cd931abdf7d09d1cab3c8dc554bdaf (diff)
downloadmongo-0d30a89c8ce925b4176389ecc2bb59e09afb24f4.tar.gz
SERVER-23498 Add ShardFactory
Diffstat (limited to 'src/mongo/s')
-rw-r--r--src/mongo/s/SConscript2
-rw-r--r--src/mongo/s/catalog/replset/SConscript2
-rw-r--r--src/mongo/s/catalog/replset/catalog_manager_replica_set_add_shard_test.cpp38
-rw-r--r--src/mongo/s/catalog/replset/catalog_manager_replica_set_shard_collection_test.cpp12
-rw-r--r--src/mongo/s/catalog/replset/dist_lock_catalog_impl_test.cpp13
-rw-r--r--src/mongo/s/chunk_manager_tests.cpp1
-rw-r--r--src/mongo/s/client/SConscript1
-rw-r--r--src/mongo/s/client/shard.cpp27
-rw-r--r--src/mongo/s/client/shard.h28
-rw-r--r--src/mongo/s/client/shard_factory.h75
-rw-r--r--src/mongo/s/client/shard_factory_impl.cpp55
-rw-r--r--src/mongo/s/client/shard_factory_impl.h58
-rw-r--r--src/mongo/s/client/shard_factory_mock.cpp58
-rw-r--r--src/mongo/s/client/shard_factory_mock.h62
-rw-r--r--src/mongo/s/client/shard_registry.cpp67
-rw-r--r--src/mongo/s/client/shard_registry.h14
-rw-r--r--src/mongo/s/query/async_results_merger.cpp4
-rw-r--r--src/mongo/s/query/async_results_merger_test.cpp6
-rw-r--r--src/mongo/s/sharding_initialization.cpp4
-rw-r--r--src/mongo/s/sharding_test_fixture.cpp16
-rw-r--r--src/mongo/s/sharding_test_fixture.h6
21 files changed, 435 insertions, 114 deletions
diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript
index 26bca7b0761..c858e9fe136 100644
--- a/src/mongo/s/SConscript
+++ b/src/mongo/s/SConscript
@@ -60,7 +60,6 @@ env.Library(
'sharding_test_fixture.cpp',
],
LIBDEPS=[
- '$BUILD_DIR/mongo/client/remote_command_targeter_mock',
'$BUILD_DIR/mongo/db/auth/authorization_manager_mock_init',
'$BUILD_DIR/mongo/executor/network_test_env',
'$BUILD_DIR/mongo/executor/task_executor_pool',
@@ -69,6 +68,7 @@ env.Library(
'$BUILD_DIR/mongo/s/catalog/dist_lock_manager_mock',
'$BUILD_DIR/mongo/s/catalog/catalog_manager_impl',
'$BUILD_DIR/mongo/s/catalog/replset/catalog_manager_replica_set',
+ '$BUILD_DIR/mongo/client/remote_command_targeter_mock',
'$BUILD_DIR/mongo/s/coreshard',
'$BUILD_DIR/mongo/s/mongoscore',
'$BUILD_DIR/mongo/util/clock_source_mock',
diff --git a/src/mongo/s/catalog/replset/SConscript b/src/mongo/s/catalog/replset/SConscript
index 45d6d7fbe1d..6dddc65fca8 100644
--- a/src/mongo/s/catalog/replset/SConscript
+++ b/src/mongo/s/catalog/replset/SConscript
@@ -45,7 +45,6 @@ env.CppUnitTest(
'replset_dist_lock_manager_test.cpp',
],
LIBDEPS=[
- '$BUILD_DIR/mongo/client/remote_command_targeter_mock',
'$BUILD_DIR/mongo/db/auth/authorization_manager_mock_init',
'$BUILD_DIR/mongo/executor/network_test_env',
'$BUILD_DIR/mongo/executor/thread_pool_task_executor_test_fixture',
@@ -53,6 +52,7 @@ env.CppUnitTest(
'$BUILD_DIR/mongo/s/catalog/dist_lock_catalog_mock',
'$BUILD_DIR/mongo/s/coreshard',
'$BUILD_DIR/mongo/s/mongoscore',
+ '$BUILD_DIR/mongo/s/sharding_test_fixture',
'$BUILD_DIR/mongo/util/tick_source_mock',
'dist_lock_catalog_impl',
]
diff --git a/src/mongo/s/catalog/replset/catalog_manager_replica_set_add_shard_test.cpp b/src/mongo/s/catalog/replset/catalog_manager_replica_set_add_shard_test.cpp
index 86887c4826e..a14e1cc1bfb 100644
--- a/src/mongo/s/catalog/replset/catalog_manager_replica_set_add_shard_test.cpp
+++ b/src/mongo/s/catalog/replset/catalog_manager_replica_set_add_shard_test.cpp
@@ -33,7 +33,6 @@
#include <vector>
#include "mongo/client/remote_command_targeter_mock.h"
-#include "mongo/client/remote_command_targeter_factory_mock.h"
#include "mongo/db/commands.h"
#include "mongo/db/query/lite_parsed_query.h"
#include "mongo/rpc/metadata/repl_set_metadata.h"
@@ -43,6 +42,7 @@
#include "mongo/s/catalog/type_changelog.h"
#include "mongo/s/catalog/type_database.h"
#include "mongo/s/catalog/type_shard.h"
+#include "mongo/s/client/shard_factory_mock.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/write_ops/batched_command_response.h"
#include "mongo/s/write_ops/batched_insert_request.h"
@@ -268,7 +268,7 @@ TEST_F(AddShardTest, Standalone) {
targeter->setConnectionStringReturnValue(ConnectionString(shardTarget));
targeter->setFindHostReturnValue(shardTarget);
- targeterFactory()->addTargeterToReturn(ConnectionString(shardTarget), std::move(targeter));
+ shardFactory()->addTargeterToReturn(ConnectionString(shardTarget), std::move(targeter));
std::string expectedShardName = "StandaloneShard";
auto future = launchAsync([this, expectedShardName] {
@@ -343,7 +343,7 @@ TEST_F(AddShardTest, StandaloneGenerateName) {
targeter->setConnectionStringReturnValue(ConnectionString(shardTarget));
targeter->setFindHostReturnValue(shardTarget);
- targeterFactory()->addTargeterToReturn(ConnectionString(shardTarget), std::move(targeter));
+ shardFactory()->addTargeterToReturn(ConnectionString(shardTarget), std::move(targeter));
std::string expectedShardName = "shard0006";
auto future = launchAsync([this, expectedShardName, shardTarget] {
@@ -471,8 +471,8 @@ TEST_F(AddShardTest, UnreachableHost) {
targeter->setConnectionStringReturnValue(ConnectionString(HostAndPort("StandaloneHost:12345")));
targeter->setFindHostReturnValue(HostAndPort("StandaloneHost:12345"));
- targeterFactory()->addTargeterToReturn(ConnectionString(HostAndPort("StandaloneHost:12345")),
- std::move(targeter));
+ shardFactory()->addTargeterToReturn(ConnectionString(HostAndPort("StandaloneHost:12345")),
+ std::move(targeter));
std::string expectedShardName = "StandaloneShard";
auto future = launchAsync([this, expectedShardName] {
@@ -501,8 +501,8 @@ TEST_F(AddShardTest, AddMongosAsShard) {
targeter->setConnectionStringReturnValue(ConnectionString(HostAndPort("StandaloneHost:12345")));
targeter->setFindHostReturnValue(HostAndPort("StandaloneHost:12345"));
- targeterFactory()->addTargeterToReturn(ConnectionString(HostAndPort("StandaloneHost:12345")),
- std::move(targeter));
+ shardFactory()->addTargeterToReturn(ConnectionString(HostAndPort("StandaloneHost:12345")),
+ std::move(targeter));
std::string expectedShardName = "StandaloneShard";
auto future = launchAsync([this, expectedShardName] {
@@ -534,7 +534,7 @@ TEST_F(AddShardTest, AddReplicaSetShardAsStandalone) {
targeter->setConnectionStringReturnValue(ConnectionString(shardTarget));
targeter->setFindHostReturnValue(shardTarget);
- targeterFactory()->addTargeterToReturn(ConnectionString(shardTarget), std::move(targeter));
+ shardFactory()->addTargeterToReturn(ConnectionString(shardTarget), std::move(targeter));
std::string expectedShardName = "StandaloneShard";
auto future = launchAsync([this, expectedShardName, shardTarget] {
@@ -563,7 +563,7 @@ TEST_F(AddShardTest, AndStandaloneHostShardAsReplicaSet) {
targeter->setConnectionStringReturnValue(connString);
targeter->setFindHostReturnValue(shardTarget);
- targeterFactory()->addTargeterToReturn(connString, std::move(targeter));
+ shardFactory()->addTargeterToReturn(connString, std::move(targeter));
std::string expectedShardName = "StandaloneShard";
auto future = launchAsync([this, expectedShardName, connString] {
@@ -597,7 +597,7 @@ TEST_F(AddShardTest, ReplicaSetMistmatchedSetName) {
HostAndPort shardTarget = connString.getServers().front();
targeter->setFindHostReturnValue(shardTarget);
- targeterFactory()->addTargeterToReturn(connString, std::move(targeter));
+ shardFactory()->addTargeterToReturn(connString, std::move(targeter));
std::string expectedShardName = "StandaloneShard";
auto future = launchAsync([this, expectedShardName, connString] {
@@ -632,7 +632,7 @@ TEST_F(AddShardTest, ShardIsCSRSConfigServer) {
HostAndPort shardTarget = connString.getServers().front();
targeter->setFindHostReturnValue(shardTarget);
- targeterFactory()->addTargeterToReturn(connString, std::move(targeter));
+ shardFactory()->addTargeterToReturn(connString, std::move(targeter));
std::string expectedShardName = "StandaloneShard";
auto future = launchAsync([this, expectedShardName, connString] {
@@ -668,7 +668,7 @@ TEST_F(AddShardTest, ShardIsSCCConfigServer) {
HostAndPort shardTarget = connString.getServers().front();
targeter->setFindHostReturnValue(shardTarget);
- targeterFactory()->addTargeterToReturn(connString, std::move(targeter));
+ shardFactory()->addTargeterToReturn(connString, std::move(targeter));
std::string expectedShardName = "StandaloneShard";
auto future = launchAsync([this, expectedShardName, connString] {
@@ -706,7 +706,7 @@ TEST_F(AddShardTest, ReplicaSetMissingHostsProvidedInSeedList) {
HostAndPort shardTarget = connString.getServers().front();
targeter->setFindHostReturnValue(shardTarget);
- targeterFactory()->addTargeterToReturn(connString, std::move(targeter));
+ shardFactory()->addTargeterToReturn(connString, std::move(targeter));
std::string expectedShardName = "StandaloneShard";
auto future = launchAsync([this, expectedShardName, connString] {
@@ -735,7 +735,7 @@ TEST_F(AddShardTest, ReplicaSetNameIsConfig) {
HostAndPort shardTarget = connString.getServers().front();
targeter->setFindHostReturnValue(shardTarget);
- targeterFactory()->addTargeterToReturn(connString, std::move(targeter));
+ shardFactory()->addTargeterToReturn(connString, std::move(targeter));
std::string expectedShardName = "config";
auto future = launchAsync([this, expectedShardName, connString] {
@@ -764,7 +764,7 @@ TEST_F(AddShardTest, ShardContainsExistingDatabase) {
HostAndPort shardTarget = connString.getServers().front();
targeter->setFindHostReturnValue(shardTarget);
- targeterFactory()->addTargeterToReturn(connString, std::move(targeter));
+ shardFactory()->addTargeterToReturn(connString, std::move(targeter));
std::string expectedShardName = "mySet";
auto future = launchAsync([this, expectedShardName, connString] {
@@ -803,7 +803,7 @@ TEST_F(AddShardTest, ExistingShardName) {
HostAndPort shardTarget = connString.getServers().front();
targeter->setFindHostReturnValue(shardTarget);
- targeterFactory()->addTargeterToReturn(connString, std::move(targeter));
+ shardFactory()->addTargeterToReturn(connString, std::move(targeter));
std::string expectedShardName = "mySet";
auto future = launchAsync([this, expectedShardName, connString] {
@@ -865,7 +865,7 @@ TEST_F(AddShardTest, ReplicaSet) {
HostAndPort shardTarget = connString.getServers().front();
targeter->setFindHostReturnValue(shardTarget);
- targeterFactory()->addTargeterToReturn(connString, std::move(targeter));
+ shardFactory()->addTargeterToReturn(connString, std::move(targeter));
std::string expectedShardName = "mySet";
auto future = launchAsync([this, expectedShardName, connString] {
@@ -919,7 +919,7 @@ TEST_F(AddShardTest, AddShardSucceedsEvenIfAddingDBsFromNewShardFails) {
HostAndPort shardTarget = connString.getServers().front();
targeter->setFindHostReturnValue(shardTarget);
- targeterFactory()->addTargeterToReturn(connString, std::move(targeter));
+ shardFactory()->addTargeterToReturn(connString, std::move(targeter));
std::string expectedShardName = "mySet";
auto future = launchAsync([this, expectedShardName, connString] {
@@ -997,7 +997,7 @@ TEST_F(AddShardTest, ReplicaSetExtraHostsDiscovered) {
HostAndPort shardTarget = seedString.getServers().front();
targeter->setFindHostReturnValue(shardTarget);
- targeterFactory()->addTargeterToReturn(seedString, std::move(targeter));
+ shardFactory()->addTargeterToReturn(seedString, std::move(targeter));
std::string expectedShardName = "mySet";
auto future = launchAsync([this, expectedShardName, seedString] {
diff --git a/src/mongo/s/catalog/replset/catalog_manager_replica_set_shard_collection_test.cpp b/src/mongo/s/catalog/replset/catalog_manager_replica_set_shard_collection_test.cpp
index 2873b1f2a35..d3e85b9d5c2 100644
--- a/src/mongo/s/catalog/replset/catalog_manager_replica_set_shard_collection_test.cpp
+++ b/src/mongo/s/catalog/replset/catalog_manager_replica_set_shard_collection_test.cpp
@@ -35,7 +35,6 @@
#include <vector>
#include "mongo/client/remote_command_targeter_mock.h"
-#include "mongo/client/remote_command_targeter_factory_mock.h"
#include "mongo/db/client.h"
#include "mongo/db/commands.h"
#include "mongo/executor/network_interface_mock.h"
@@ -50,6 +49,7 @@
#include "mongo/s/catalog/type_collection.h"
#include "mongo/s/catalog/type_database.h"
#include "mongo/s/catalog/type_shard.h"
+#include "mongo/s/client/shard_factory_mock.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/chunk.h"
#include "mongo/s/grid.h"
@@ -293,7 +293,7 @@ TEST_F(ShardCollectionTest, noInitialChunksOrData) {
stdx::make_unique<RemoteCommandTargeterMock>());
targeter->setConnectionStringReturnValue(ConnectionString(shardHost));
targeter->setFindHostReturnValue(shardHost);
- targeterFactory()->addTargeterToReturn(ConnectionString(shardHost), std::move(targeter));
+ shardFactory()->addTargeterToReturn(ConnectionString(shardHost), std::move(targeter));
setupShards(vector<ShardType>{shard});
@@ -411,13 +411,13 @@ TEST_F(ShardCollectionTest, withInitialChunks) {
stdx::make_unique<RemoteCommandTargeterMock>());
targeter0->setConnectionStringReturnValue(ConnectionString(shard0Host));
targeter0->setFindHostReturnValue(shard0Host);
- targeterFactory()->addTargeterToReturn(ConnectionString(shard0Host), std::move(targeter0));
+ shardFactory()->addTargeterToReturn(ConnectionString(shard0Host), std::move(targeter0));
targeter1->setConnectionStringReturnValue(ConnectionString(shard1Host));
targeter1->setFindHostReturnValue(shard1Host);
- targeterFactory()->addTargeterToReturn(ConnectionString(shard1Host), std::move(targeter1));
+ shardFactory()->addTargeterToReturn(ConnectionString(shard1Host), std::move(targeter1));
targeter2->setConnectionStringReturnValue(ConnectionString(shard2Host));
targeter2->setFindHostReturnValue(shard2Host);
- targeterFactory()->addTargeterToReturn(ConnectionString(shard2Host), std::move(targeter2));
+ shardFactory()->addTargeterToReturn(ConnectionString(shard2Host), std::move(targeter2));
setupShards(vector<ShardType>{shard0, shard1, shard2});
@@ -572,7 +572,7 @@ TEST_F(ShardCollectionTest, withInitialData) {
stdx::make_unique<RemoteCommandTargeterMock>());
targeter->setConnectionStringReturnValue(ConnectionString(shardHost));
targeter->setFindHostReturnValue(shardHost);
- targeterFactory()->addTargeterToReturn(ConnectionString(shardHost), std::move(targeter));
+ shardFactory()->addTargeterToReturn(ConnectionString(shardHost), std::move(targeter));
setupShards(vector<ShardType>{shard});
diff --git a/src/mongo/s/catalog/replset/dist_lock_catalog_impl_test.cpp b/src/mongo/s/catalog/replset/dist_lock_catalog_impl_test.cpp
index cf8ee77acd4..bcbc0cd16a6 100644
--- a/src/mongo/s/catalog/replset/dist_lock_catalog_impl_test.cpp
+++ b/src/mongo/s/catalog/replset/dist_lock_catalog_impl_test.cpp
@@ -33,7 +33,6 @@
#include "mongo/base/status.h"
#include "mongo/base/status_with.h"
#include "mongo/bson/json.h"
-#include "mongo/client/remote_command_targeter_factory_mock.h"
#include "mongo/client/remote_command_targeter_mock.h"
#include "mongo/db/commands.h"
#include "mongo/db/jsobj.h"
@@ -47,6 +46,7 @@
#include "mongo/s/catalog/replset/dist_lock_catalog_impl.h"
#include "mongo/s/catalog/type_lockpings.h"
#include "mongo/s/catalog/type_locks.h"
+#include "mongo/s/client/shard_factory_mock.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/write_ops/batched_update_request.h"
#include "mongo/stdx/future.h"
@@ -126,12 +126,11 @@ private:
stdx::make_unique<executor::NetworkInterfaceMock>());
ConnectionString configCS(HostAndPort("dummy:1234"));
- _shardRegistry =
- stdx::make_unique<ShardRegistry>(stdx::make_unique<RemoteCommandTargeterFactoryMock>(),
- std::move(executorPool),
- network,
- std::move(addShardExecutor),
- configCS);
+ _shardRegistry = stdx::make_unique<ShardRegistry>(stdx::make_unique<ShardFactoryMock>(),
+ std::move(executorPool),
+ network,
+ std::move(addShardExecutor),
+ configCS);
_shardRegistry->startup();
_distLockCatalog = stdx::make_unique<DistLockCatalogImpl>(_shardRegistry.get());
diff --git a/src/mongo/s/chunk_manager_tests.cpp b/src/mongo/s/chunk_manager_tests.cpp
index de46653617a..0e683b83fdc 100644
--- a/src/mongo/s/chunk_manager_tests.cpp
+++ b/src/mongo/s/chunk_manager_tests.cpp
@@ -29,7 +29,6 @@
#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
#include "mongo/client/remote_command_targeter_mock.h"
-#include "mongo/client/remote_command_targeter_factory_mock.h"
#include "mongo/platform/basic.h"
#include "mongo/s/catalog/replset/catalog_manager_replica_set_test_fixture.h"
#include "mongo/s/catalog/type_chunk.h"
diff --git a/src/mongo/s/client/SConscript b/src/mongo/s/client/SConscript
index 1565c96edc0..cf44ddfc879 100644
--- a/src/mongo/s/client/SConscript
+++ b/src/mongo/s/client/SConscript
@@ -10,6 +10,7 @@ env.Library(
'shard_connection.cpp',
'shard_registry.cpp',
'version_manager.cpp',
+ 'shard_factory_impl.cpp',
],
LIBDEPS=[
'$BUILD_DIR/mongo/client/clientdriver',
diff --git a/src/mongo/s/client/shard.cpp b/src/mongo/s/client/shard.cpp
index 0c31ca8fa88..6985ce27a28 100644
--- a/src/mongo/s/client/shard.cpp
+++ b/src/mongo/s/client/shard.cpp
@@ -48,9 +48,9 @@ using std::string;
using std::stringstream;
Shard::Shard(const ShardId& id,
- const ConnectionString& connStr,
+ const ConnectionString& originalConnString,
std::unique_ptr<RemoteCommandTargeter> targeter)
- : _id(id), _cs(connStr), _targeter(targeter.release()) {}
+ : _id(id), _originalConnString(originalConnString), _targeter(targeter.release()) {}
Shard::~Shard() = default;
@@ -59,7 +59,28 @@ bool Shard::isConfig() const {
}
std::string Shard::toString() const {
- return _id + ":" + _cs.toString();
+ return _id + ":" + _originalConnString.toString();
}
+void Shard::updateReplSetMonitor(const HostAndPort& remoteHost, const Status& remoteCommandStatus) {
+ if (remoteCommandStatus.isOK())
+ return;
+
+ if (ErrorCodes::isNotMasterError(remoteCommandStatus.code()) ||
+ (remoteCommandStatus == ErrorCodes::InterruptedDueToReplStateChange)) {
+ _targeter->markHostNotMaster(remoteHost);
+ } else if (ErrorCodes::isNetworkError(remoteCommandStatus.code())) {
+ _targeter->markHostUnreachable(remoteHost);
+ } else if (remoteCommandStatus == ErrorCodes::NotMasterOrSecondary) {
+ _targeter->markHostUnreachable(remoteHost);
+ } else if (remoteCommandStatus == ErrorCodes::ExceededTimeLimit) {
+ _targeter->markHostUnreachable(remoteHost);
+ }
+}
+
+const ConnectionString Shard::getConnString() const {
+ return _targeter->connectionString();
+}
+
+
} // namespace mongo
diff --git a/src/mongo/s/client/shard.h b/src/mongo/s/client/shard.h
index 5eca311eac2..9d273d6904a 100644
--- a/src/mongo/s/client/shard.h
+++ b/src/mongo/s/client/shard.h
@@ -55,7 +55,7 @@ public:
* Instantiates a new shard connection management object for the specified shard.
*/
Shard(const ShardId& id,
- const ConnectionString& connStr,
+ const ConnectionString& originalConnString,
std::unique_ptr<RemoteCommandTargeter> targeter);
~Shard();
@@ -69,8 +69,18 @@ public:
*/
bool isConfig() const;
- const ConnectionString getConnString() const {
- return _cs;
+
+ /**
+ * Returns the current config string.
+ */
+ const ConnectionString getConnString() const;
+
+ /**
+ * Returns the config string that was used on the shard creation. The RS config string may be
+ * different.
+ */
+ const ConnectionString originalConnString() const {
+ return _originalConnString;
}
std::shared_ptr<RemoteCommandTargeter> getTargeter() const {
@@ -82,6 +92,14 @@ public:
*/
std::string toString() const;
+
+ /**
+ * Notifies the RemoteCommandTargeter owned by the shard of a particular mode of failure for the
+ * specified host.
+ */
+ void updateReplSetMonitor(const HostAndPort& remoteHost, const Status& remoteCommandStatus);
+
+
private:
/**
* Identifier of the shard as obtained from the configuration data (i.e. shard0000).
@@ -89,9 +107,9 @@ private:
const ShardId _id;
/**
- * Connection string for the shard.
+ * Connection string for the shard at the creation time.
*/
- const ConnectionString _cs;
+ const ConnectionString _originalConnString;
/**
* Targeter for obtaining hosts from which to read or to which to write.
diff --git a/src/mongo/s/client/shard_factory.h b/src/mongo/s/client/shard_factory.h
new file mode 100644
index 00000000000..b643c15f4c9
--- /dev/null
+++ b/src/mongo/s/client/shard_factory.h
@@ -0,0 +1,75 @@
+/**
+ * Copyright (C) 2016 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#pragma once
+
+#include <memory>
+#include <string>
+
+#include "mongo/base/disallow_copying.h"
+
+namespace mongo {
+
+class Shard;
+class ConnectionString;
+
+/**
+ * An interface to Shard instantiating factory.
+ */
+class ShardFactory {
+ MONGO_DISALLOW_COPYING(ShardFactory);
+
+public:
+ virtual ~ShardFactory() = default;
+
+ /**
+ * Creates a unique_ptr with a new instance of a Shard with the provided shardId
+ * and connection string. This method is currently only used when shard does not exists yet.
+ * Consider using createShard instead.
+ * TODO: currently isLocal argument is ignored until the Shard will provide local and remote
+ * implementations.
+ */
+ virtual std::unique_ptr<Shard> createUniqueShard(const std::string& shardId,
+ const ConnectionString& connStr,
+ bool isLocal) = 0;
+
+ /**
+ * Creates a shared_ptr with a new instance of a Shard with the provided shardId
+ * and connection string.
+ * TODO: currently isLocal argument is ignored until the Shard will provide local and remote
+ * implementations.
+ */
+ virtual std::shared_ptr<Shard> createShard(const std::string& shardId,
+ const ConnectionString& connStr,
+ bool isLocal) = 0;
+
+protected:
+ ShardFactory() = default;
+};
+
+} // namespace mongo
diff --git a/src/mongo/s/client/shard_factory_impl.cpp b/src/mongo/s/client/shard_factory_impl.cpp
new file mode 100644
index 00000000000..a770796a565
--- /dev/null
+++ b/src/mongo/s/client/shard_factory_impl.cpp
@@ -0,0 +1,55 @@
+/**
+ * Copyright (C) 2016 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/base/status_with.h"
+#include "mongo/client/remote_command_targeter.h"
+#include "mongo/client/remote_command_targeter_factory_impl.h"
+#include "mongo/client/connection_string.h"
+#include "mongo/s/client/shard.h"
+#include "mongo/s/client/shard_factory_impl.h"
+#include "mongo/stdx/memory.h"
+#include "mongo/util/assert_util.h"
+
+namespace mongo {
+
+std::unique_ptr<Shard> ShardFactoryImpl::createUniqueShard(const ShardId& shardId,
+ const ConnectionString& connStr,
+ bool isLocal) {
+ return stdx::make_unique<Shard>(shardId, connStr, std::move(_targeterFactory.create(connStr)));
+}
+
+std::shared_ptr<Shard> ShardFactoryImpl::createShard(const ShardId& shardId,
+ const ConnectionString& connStr,
+ bool isLocal) {
+ return std::make_shared<Shard>(shardId, connStr, std::move(_targeterFactory.create(connStr)));
+}
+
+} // namespace mongo
diff --git a/src/mongo/s/client/shard_factory_impl.h b/src/mongo/s/client/shard_factory_impl.h
new file mode 100644
index 00000000000..616113a64f0
--- /dev/null
+++ b/src/mongo/s/client/shard_factory_impl.h
@@ -0,0 +1,58 @@
+/**
+ * Copyright (C) 2016 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#pragma once
+
+#include <memory>
+
+#include "mongo/s/client/shard_factory.h"
+#include "mongo/client/remote_command_targeter_factory_impl.h"
+
+namespace mongo {
+
+
+/**
+ * ShardFactory implementation.
+ */
+class ShardFactoryImpl final : public ShardFactory {
+public:
+ ShardFactoryImpl() = default;
+
+ virtual std::unique_ptr<Shard> createUniqueShard(const std::string& shardId,
+ const ConnectionString& connStr,
+ bool isLocal);
+
+ virtual std::shared_ptr<Shard> createShard(const std::string& shardId,
+ const ConnectionString& connStr,
+ bool isLocal);
+
+private:
+ RemoteCommandTargeterFactoryImpl _targeterFactory;
+};
+
+} // namespace mongo
diff --git a/src/mongo/s/client/shard_factory_mock.cpp b/src/mongo/s/client/shard_factory_mock.cpp
new file mode 100644
index 00000000000..8f667a88f16
--- /dev/null
+++ b/src/mongo/s/client/shard_factory_mock.cpp
@@ -0,0 +1,58 @@
+/**
+ * Copyright (C) 2016 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/s/client/shard_factory_mock.h"
+#include "mongo/client/remote_command_targeter_mock.h"
+#include "mongo/client/connection_string.h"
+#include "mongo/s/client/shard.h"
+#include "mongo/stdx/memory.h"
+#include "mongo/util/assert_util.h"
+
+namespace mongo {
+
+std::unique_ptr<Shard> ShardFactoryMock::createUniqueShard(const ShardId& shardId,
+ const ConnectionString& connStr,
+ bool isLocal) {
+ return stdx::make_unique<Shard>(shardId, connStr, _targeterFactory.create(connStr));
+}
+
+std::shared_ptr<Shard> ShardFactoryMock::createShard(const ShardId& shardId,
+ const ConnectionString& connStr,
+ bool isLocal) {
+ return std::make_shared<Shard>(shardId, connStr, std::move(_targeterFactory.create(connStr)));
+}
+
+void ShardFactoryMock::addTargeterToReturn(
+ const ConnectionString& connStr, std::unique_ptr<RemoteCommandTargeterMock> mockTargeter) {
+ _targeterFactory.addTargeterToReturn(connStr, std::move(mockTargeter));
+}
+
+} // namespace mongo
diff --git a/src/mongo/s/client/shard_factory_mock.h b/src/mongo/s/client/shard_factory_mock.h
new file mode 100644
index 00000000000..eb83b04bf9d
--- /dev/null
+++ b/src/mongo/s/client/shard_factory_mock.h
@@ -0,0 +1,62 @@
+/**
+ * Copyright (C) 2016 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#pragma once
+
+#include <memory>
+
+#include "mongo/s/client/shard_factory.h"
+#include "mongo/client/remote_command_targeter_factory_mock.h"
+
+namespace mongo {
+
+class RemoteCommandTargeterMock;
+
+/**
+ * ShardFactory subclass for testing.
+ */
+class ShardFactoryMock final : public ShardFactory {
+public:
+ ShardFactoryMock() = default;
+
+ virtual std::unique_ptr<Shard> createUniqueShard(const std::string& shardId,
+ const ConnectionString& connStr,
+ bool isLocal);
+
+ virtual std::shared_ptr<Shard> createShard(const std::string& shardId,
+ const ConnectionString& connStr,
+ bool isLocal);
+
+ void addTargeterToReturn(const ConnectionString& connStr,
+ std::unique_ptr<RemoteCommandTargeterMock> mockTargeter);
+
+private:
+ RemoteCommandTargeterFactoryMock _targeterFactory;
+};
+
+} // namespace mongo
diff --git a/src/mongo/s/client/shard_registry.cpp b/src/mongo/s/client/shard_registry.cpp
index 2735e9b59c4..b418cc7e59b 100644
--- a/src/mongo/s/client/shard_registry.cpp
+++ b/src/mongo/s/client/shard_registry.cpp
@@ -39,7 +39,6 @@
#include "mongo/client/connection_string.h"
#include "mongo/client/query_fetcher.h"
#include "mongo/client/remote_command_targeter.h"
-#include "mongo/client/remote_command_targeter_factory.h"
#include "mongo/client/replica_set_monitor.h"
#include "mongo/db/client.h"
#include "mongo/db/query/lite_parsed_query.h"
@@ -54,6 +53,7 @@
#include "mongo/s/client/shard.h"
#include "mongo/s/client/shard_connection.h"
#include "mongo/s/grid.h"
+#include "mongo/s/client/shard_factory.h"
#include "mongo/s/write_ops/wc_error_detail.h"
#include "mongo/stdx/memory.h"
#include "mongo/stdx/mutex.h"
@@ -169,12 +169,12 @@ const ShardRegistry::ErrorCodesSet ShardRegistry::kWriteConcernErrors{
ErrorCodes::UnknownReplWriteConcern,
ErrorCodes::CannotSatisfyWriteConcern};
-ShardRegistry::ShardRegistry(std::unique_ptr<RemoteCommandTargeterFactory> targeterFactory,
+ShardRegistry::ShardRegistry(std::unique_ptr<ShardFactory> shardFactory,
std::unique_ptr<executor::TaskExecutorPool> executorPool,
executor::NetworkInterface* network,
std::unique_ptr<executor::TaskExecutor> addShardExecutor,
ConnectionString configServerCS)
- : _targeterFactory(std::move(targeterFactory)),
+ : _shardFactory(std::move(shardFactory)),
_executorPool(std::move(executorPool)),
_network(network),
_executorForAddShard(std::move(addShardExecutor)) {
@@ -260,8 +260,7 @@ bool ShardRegistry::reload(OperationContext* txn) {
// Ensure targeter exists for all shards and take shard connection string from the targeter.
// Do this before re-taking the mutex to avoid deadlock with the ReplicaSetMonitor updating
// hosts for a given shard.
- std::vector<std::tuple<std::string, ConnectionString, std::unique_ptr<RemoteCommandTargeter>>>
- shardsInfo;
+ std::vector<std::tuple<std::string, ConnectionString>> shardsInfo;
for (const auto& shardType : shards) {
// This validation should ideally go inside the ShardType::validate call. However, doing
// it there would prevent us from loading previously faulty shard hosts, which might have
@@ -272,10 +271,7 @@ bool ShardRegistry::reload(OperationContext* txn) {
continue;
}
- auto targeter = _targeterFactory->create(shardHostStatus.getValue());
-
- shardsInfo.push_back(std::make_tuple(
- shardType.getName(), targeter->connectionString(), std::move(targeter)));
+ shardsInfo.push_back(std::make_tuple(shardType.getName(), shardHostStatus.getValue()));
}
lk.lock();
@@ -293,9 +289,7 @@ bool ShardRegistry::reload(OperationContext* txn) {
continue;
}
- _addShard_inlock(std::move(std::get<0>(shardInfo)),
- std::move(std::get<1>(shardInfo)),
- std::move(std::get<2>(shardInfo)));
+ _addShard_inlock(std::move(std::get<0>(shardInfo)), std::move(std::get<1>(shardInfo)));
}
nextReloadState = ReloadState::Idle;
@@ -342,7 +336,7 @@ shared_ptr<Shard> ShardRegistry::getConfigShard() {
}
unique_ptr<Shard> ShardRegistry::createConnection(const ConnectionString& connStr) const {
- return stdx::make_unique<Shard>("<unnamed>", connStr, _targeterFactory->create(connStr));
+ return _shardFactory->createUniqueShard("<unnamed>", connStr, false);
}
shared_ptr<Shard> ShardRegistry::lookupRSName(const string& name) const {
@@ -429,7 +423,7 @@ void ShardRegistry::appendConnectionStats(executor::ConnectionPoolStats* stats)
}
void ShardRegistry::_addConfigShard_inlock() {
- _addShard_inlock("config", _configServerCS, _targeterFactory->create(_configServerCS));
+ _addShard_inlock("config", _configServerCS);
}
void ShardRegistry::updateReplSetHosts(const ConnectionString& newConnString) {
@@ -444,19 +438,17 @@ void ShardRegistry::updateReplSetHosts(const ConnectionString& newConnString) {
if (shard->isConfig()) {
_updateConfigServerConnectionString_inlock(newConnString);
} else {
- _addShard_inlock(shard->getId(), newConnString, _targeterFactory->create(newConnString));
+ _addShard_inlock(shard->getId(), newConnString);
}
}
-void ShardRegistry::_addShard_inlock(const ShardId& shardId,
- const ConnectionString& connString,
- std::unique_ptr<RemoteCommandTargeter> targeter) {
- auto originalShard = _findUsingLookUp_inlock(shardId);
- if (originalShard) {
- auto oldConnString = originalShard->getConnString();
+void ShardRegistry::_addShard_inlock(const ShardId& shardId, const ConnectionString& connString) {
+ auto currentShard = _findUsingLookUp_inlock(shardId);
+ if (currentShard) {
+ auto oldConnString = currentShard->originalConnString();
if (oldConnString.toString() != connString.toString()) {
- log() << "Updating ShardRegistry connection string for shard " << originalShard->getId()
+ log() << "Updating ShardRegistry connection string for shard " << currentShard->getId()
<< " from: " << oldConnString.toString() << " to: " << connString.toString();
}
@@ -466,7 +458,9 @@ void ShardRegistry::_addShard_inlock(const ShardId& shardId,
}
}
- shared_ptr<Shard> shard = std::make_shared<Shard>(shardId, connString, std::move(targeter));
+ // TODO: the third argument should pass the bool that will instruct factory to create either
+ // local or remote shard.
+ auto shard = _shardFactory->createShard(shardId, connString, false);
_lookup[shard->getId()] = shard;
@@ -513,7 +507,8 @@ StatusWith<ShardRegistry::QueryResponse> ShardRegistry::_exhaustiveFindOnConfig(
const BSONObj& query,
const BSONObj& sort,
boost::optional<long long> limit) {
- const auto targeter = getConfigShard()->getTargeter();
+ const auto configShard = getConfigShard();
+ const auto targeter = configShard->getTargeter();
const auto host =
targeter->findHost(readPref, RemoteCommandTargeter::selectFindHostMaxWaitTime(txn));
if (!host.isOK()) {
@@ -606,7 +601,7 @@ StatusWith<ShardRegistry::QueryResponse> ShardRegistry::_exhaustiveFindOnConfig(
fetcher.wait();
- updateReplSetMonitor(targeter, host.getValue(), status);
+ configShard->updateReplSetMonitor(host.getValue(), status);
if (!status.isOK()) {
if (status.compareCode(ErrorCodes::ExceededTimeLimit)) {
@@ -809,7 +804,7 @@ StatusWith<ShardRegistry::CommandResponse> ShardRegistry::_runCommandWithMetadat
executor->wait(callStatus.getValue());
if (!responseStatus.isOK()) {
- updateReplSetMonitor(targeter, host.getValue(), responseStatus.getStatus());
+ shard->updateReplSetMonitor(host.getValue(), responseStatus.getStatus());
if (responseStatus.getStatus().compareCode(ErrorCodes::ExceededTimeLimit)) {
LOG(0) << "Operation timed out with status " << responseStatus.getStatus();
}
@@ -819,7 +814,7 @@ StatusWith<ShardRegistry::CommandResponse> ShardRegistry::_runCommandWithMetadat
auto response = std::move(responseStatus.getValue());
Status commandSpecificStatus = getStatusFromCommandResult(response.data);
- updateReplSetMonitor(targeter, host.getValue(), commandSpecificStatus);
+ shard->updateReplSetMonitor(host.getValue(), commandSpecificStatus);
CommandResponse cmdResponse;
cmdResponse.response = response.data.getOwned();
@@ -837,22 +832,4 @@ StatusWith<ShardRegistry::CommandResponse> ShardRegistry::_runCommandWithMetadat
return StatusWith<CommandResponse>(std::move(cmdResponse));
}
-void ShardRegistry::updateReplSetMonitor(const std::shared_ptr<RemoteCommandTargeter>& targeter,
- const HostAndPort& remoteHost,
- const Status& remoteCommandStatus) {
- if (remoteCommandStatus.isOK())
- return;
-
- if (ErrorCodes::isNotMasterError(remoteCommandStatus.code()) ||
- (remoteCommandStatus == ErrorCodes::InterruptedDueToReplStateChange)) {
- targeter->markHostNotMaster(remoteHost);
- } else if (ErrorCodes::isNetworkError(remoteCommandStatus.code())) {
- targeter->markHostUnreachable(remoteHost);
- } else if (remoteCommandStatus == ErrorCodes::NotMasterOrSecondary) {
- targeter->markHostUnreachable(remoteHost);
- } else if (remoteCommandStatus == ErrorCodes::ExceededTimeLimit) {
- targeter->markHostUnreachable(remoteHost);
- }
-}
-
} // namespace mongo
diff --git a/src/mongo/s/client/shard_registry.h b/src/mongo/s/client/shard_registry.h
index c057d7c7910..e5e0ea380ca 100644
--- a/src/mongo/s/client/shard_registry.h
+++ b/src/mongo/s/client/shard_registry.h
@@ -51,7 +51,7 @@ class CatalogManager;
struct HostAndPort;
class NamespaceString;
class OperationContext;
-class RemoteCommandTargeterFactory;
+class ShardFactory;
class Shard;
class ShardType;
struct ReadPreferenceSetting;
@@ -85,7 +85,7 @@ public:
/**
* Instantiates a new shard registry.
*
- * @param targeterFactory Produces targeters for each shard's individual connection string
+ * @param shardFactory Makes shards
* @param commandRunner Command runner for executing commands against hosts
* @param executor Asynchronous task executor to use for making calls to shards and
* config servers.
@@ -94,7 +94,7 @@ public:
* are not yet in the ShardRegistry
* @param configServerCS ConnectionString used for communicating with the config servers
*/
- ShardRegistry(std::unique_ptr<RemoteCommandTargeterFactory> targeterFactory,
+ ShardRegistry(std::unique_ptr<ShardFactory> shardFactory,
std::unique_ptr<executor::TaskExecutorPool> executorPool,
executor::NetworkInterface* network,
std::unique_ptr<executor::TaskExecutor> addShardExecutor,
@@ -332,9 +332,7 @@ private:
/**
* Creates a shard based on the specified information and puts it into the lookup maps.
*/
- void _addShard_inlock(const ShardId& shardId,
- const ConnectionString& connString,
- std::unique_ptr<RemoteCommandTargeter> targeter);
+ void _addShard_inlock(const ShardId& shardId, const ConnectionString& connString);
/**
* Adds the "config" shard (representing the config server) to the shard registry.
@@ -381,9 +379,9 @@ private:
const BSONObj& metadata,
const ErrorCodesSet& errorsToCheck);
- // Factory to obtain remote command targeters for shards. Never changed after startup so safe
+ // Factory to create shards. Never changed after startup so safe
// to access outside of _mutex.
- const std::unique_ptr<RemoteCommandTargeterFactory> _targeterFactory;
+ const std::unique_ptr<ShardFactory> _shardFactory;
// Executor pool for scheduling work and remote commands to shards and config servers. Each
// contained executor has a connection hook set on it for initialization sharding data on shards
diff --git a/src/mongo/s/query/async_results_merger.cpp b/src/mongo/s/query/async_results_merger.cpp
index c82de6a3bbe..0167ac5683d 100644
--- a/src/mongo/s/query/async_results_merger.cpp
+++ b/src/mongo/s/query/async_results_merger.cpp
@@ -436,8 +436,8 @@ void AsyncResultsMerger::handleBatchResponse(
<< " containing host "
<< remote.getTargetHost().toString());
} else {
- ShardRegistry::updateReplSetMonitor(
- shard->getTargeter(), remote.getTargetHost(), cursorResponseStatus.getStatus());
+ shard->updateReplSetMonitor(remote.getTargetHost(),
+ cursorResponseStatus.getStatus());
}
}
diff --git a/src/mongo/s/query/async_results_merger_test.cpp b/src/mongo/s/query/async_results_merger_test.cpp
index 8f9e04664b1..17826b9a0da 100644
--- a/src/mongo/s/query/async_results_merger_test.cpp
+++ b/src/mongo/s/query/async_results_merger_test.cpp
@@ -31,7 +31,6 @@
#include "mongo/s/query/async_results_merger.h"
#include "mongo/client/remote_command_targeter_mock.h"
-#include "mongo/client/remote_command_targeter_factory_mock.h"
#include "mongo/db/json.h"
#include "mongo/db/query/cursor_response.h"
#include "mongo/db/query/getmore_request.h"
@@ -41,6 +40,7 @@
#include "mongo/executor/thread_pool_task_executor_test_fixture.h"
#include "mongo/rpc/metadata/server_selection_metadata.h"
#include "mongo/s/catalog/type_shard.h"
+#include "mongo/s/client/shard_factory_mock.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/sharding_test_fixture.h"
#include "mongo/stdx/memory.h"
@@ -86,8 +86,8 @@ public:
targeter->setConnectionStringReturnValue(ConnectionString(kTestShardHosts[i]));
targeter->setFindHostReturnValue(kTestShardHosts[i]);
- targeterFactory()->addTargeterToReturn(ConnectionString(kTestShardHosts[i]),
- std::move(targeter));
+ shardFactory()->addTargeterToReturn(ConnectionString(kTestShardHosts[i]),
+ std::move(targeter));
}
setupShards(shards);
diff --git a/src/mongo/s/sharding_initialization.cpp b/src/mongo/s/sharding_initialization.cpp
index 00e62802cb9..77778b8a7d1 100644
--- a/src/mongo/s/sharding_initialization.cpp
+++ b/src/mongo/s/sharding_initialization.cpp
@@ -36,7 +36,7 @@
#include <string>
#include "mongo/base/status.h"
-#include "mongo/client/remote_command_targeter_factory_impl.h"
+#include "mongo/s/client/shard_factory_impl.h"
#include "mongo/db/audit.h"
#include "mongo/db/server_options.h"
#include "mongo/db/service_context.h"
@@ -149,7 +149,7 @@ Status initializeGlobalShardingState(OperationContext* txn,
std::move(metadataHook));
auto networkPtr = network.get();
auto shardRegistry(
- stdx::make_unique<ShardRegistry>(stdx::make_unique<RemoteCommandTargeterFactoryImpl>(),
+ stdx::make_unique<ShardRegistry>(stdx::make_unique<ShardFactoryImpl>(),
makeTaskExecutorPool(std::move(network), isMongos),
networkPtr,
makeTaskExecutor(executor::makeNetworkInterface(
diff --git a/src/mongo/s/sharding_test_fixture.cpp b/src/mongo/s/sharding_test_fixture.cpp
index f8e86017e7c..3b0228c6cce 100644
--- a/src/mongo/s/sharding_test_fixture.cpp
+++ b/src/mongo/s/sharding_test_fixture.cpp
@@ -34,7 +34,6 @@
#include <vector>
#include "mongo/base/status_with.h"
-#include "mongo/client/remote_command_targeter_factory_mock.h"
#include "mongo/client/remote_command_targeter_mock.h"
#include "mongo/db/client.h"
#include "mongo/db/commands.h"
@@ -52,6 +51,7 @@
#include "mongo/s/catalog/type_changelog.h"
#include "mongo/s/catalog/type_collection.h"
#include "mongo/s/catalog/type_shard.h"
+#include "mongo/s/client/shard_factory_mock.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/grid.h"
#include "mongo/s/query/cluster_cursor_manager.h"
@@ -88,8 +88,8 @@ void ShardingTestFixture::setUp() {
_client = _service->makeClient("ShardingTestFixture", _messagePort.get());
_opCtx = _client->makeOperationContext();
- auto targeterFactory(stdx::make_unique<RemoteCommandTargeterFactoryMock>());
- _targeterFactory = targeterFactory.get();
+ auto shardFactory(stdx::make_unique<ShardFactoryMock>());
+ _shardFactory = shardFactory.get();
// Set up executor pool used for most operations.
auto fixedNet = stdx::make_unique<executor::NetworkInterfaceMock>();
@@ -126,9 +126,9 @@ void ShardingTestFixture::setUp() {
auto configTargeter(stdx::make_unique<RemoteCommandTargeterMock>());
_configTargeter = configTargeter.get();
- _targeterFactory->addTargeterToReturn(configCS, std::move(configTargeter));
+ _shardFactory->addTargeterToReturn(configCS, std::move(configTargeter));
- auto shardRegistry(stdx::make_unique<ShardRegistry>(std::move(targeterFactory),
+ auto shardRegistry(stdx::make_unique<ShardRegistry>(std::move(shardFactory),
std::move(executorPool),
_mockNetwork,
std::move(specialExec),
@@ -173,10 +173,10 @@ ShardRegistry* ShardingTestFixture::shardRegistry() const {
return grid.shardRegistry();
}
-RemoteCommandTargeterFactoryMock* ShardingTestFixture::targeterFactory() const {
- invariant(_targeterFactory);
+ShardFactoryMock* ShardingTestFixture::shardFactory() const {
+ invariant(_shardFactory);
- return _targeterFactory;
+ return _shardFactory;
}
RemoteCommandTargeterMock* ShardingTestFixture::configTargeter() const {
diff --git a/src/mongo/s/sharding_test_fixture.h b/src/mongo/s/sharding_test_fixture.h
index ecfa1a9e3b3..6019bfe928d 100644
--- a/src/mongo/s/sharding_test_fixture.h
+++ b/src/mongo/s/sharding_test_fixture.h
@@ -45,7 +45,7 @@ struct ChunkVersion;
class CollectionType;
class DistLockManagerMock;
class NamespaceString;
-class RemoteCommandTargeterFactoryMock;
+class ShardFactoryMock;
class RemoteCommandTargeterMock;
class ShardRegistry;
class ShardType;
@@ -83,7 +83,7 @@ protected:
ShardRegistry* shardRegistry() const;
- RemoteCommandTargeterFactoryMock* targeterFactory() const;
+ ShardFactoryMock* shardFactory() const;
RemoteCommandTargeterMock* configTargeter() const;
@@ -201,7 +201,7 @@ private:
ServiceContext::UniqueOperationContext _opCtx;
std::unique_ptr<MessagingPortMock> _messagePort;
- RemoteCommandTargeterFactoryMock* _targeterFactory;
+ ShardFactoryMock* _shardFactory;
RemoteCommandTargeterMock* _configTargeter;
executor::NetworkInterfaceMock* _mockNetwork;