summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2015-06-27 07:55:04 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2015-06-27 07:55:33 -0400
commit38f937036b5033bd50a9fd740e897415bd9f21db (patch)
tree22b14a4fd9106520911aa2236bd5e6af0a677f0e
parent8910277205b7b1cc52e4650c38172f801c522597 (diff)
downloadmongo-38f937036b5033bd50a9fd740e897415bd9f21db.tar.gz
SERVER-19004 Get rid of Shard::runCommand
-rw-r--r--src/mongo/client/SConscript10
-rw-r--r--src/mongo/client/remote_command_runner_mock.cpp70
-rw-r--r--src/mongo/client/remote_command_runner_mock.h80
-rw-r--r--src/mongo/db/auth/authz_manager_external_state_s.cpp15
-rw-r--r--src/mongo/db/auth/user_cache_invalidator_job.cpp2
-rw-r--r--src/mongo/executor/network_test_env.h1
-rw-r--r--src/mongo/s/balance.cpp24
-rw-r--r--src/mongo/s/catalog/SConscript1
-rw-r--r--src/mongo/s/catalog/catalog_manager.h12
-rw-r--r--src/mongo/s/catalog/catalog_manager_mock.cpp6
-rw-r--r--src/mongo/s/catalog/catalog_manager_mock.h6
-rw-r--r--src/mongo/s/catalog/dist_lock_catalog_impl.h1
-rw-r--r--src/mongo/s/catalog/dist_lock_catalog_impl_test.cpp2
-rw-r--r--src/mongo/s/catalog/legacy/catalog_manager_legacy.cpp6
-rw-r--r--src/mongo/s/catalog/legacy/catalog_manager_legacy.h6
-rw-r--r--src/mongo/s/catalog/replset/SConscript1
-rw-r--r--src/mongo/s/catalog/replset/catalog_manager_replica_set.cpp6
-rw-r--r--src/mongo/s/catalog/replset/catalog_manager_replica_set.h6
-rw-r--r--src/mongo/s/catalog/replset/catalog_manager_replica_set_test.cpp9
-rw-r--r--src/mongo/s/catalog/replset/catalog_manager_replica_set_test_fixture.cpp6
-rw-r--r--src/mongo/s/catalog/replset/catalog_manager_replica_set_test_fixture.h3
-rw-r--r--src/mongo/s/client/shard.cpp60
-rw-r--r--src/mongo/s/client/shard.h6
-rw-r--r--src/mongo/s/client/shard_registry.cpp3
-rw-r--r--src/mongo/s/client/shard_registry.h9
-rw-r--r--src/mongo/s/commands/cluster_fsync_cmd.cpp11
-rw-r--r--src/mongo/s/commands/cluster_list_databases_cmd.cpp51
-rw-r--r--src/mongo/s/commands/cluster_user_management_commands.cpp4
-rw-r--r--src/mongo/s/d_state.cpp2
-rw-r--r--src/mongo/s/server.cpp2
30 files changed, 101 insertions, 320 deletions
diff --git a/src/mongo/client/SConscript b/src/mongo/client/SConscript
index d71678fe1f1..0b2d9cf7805 100644
--- a/src/mongo/client/SConscript
+++ b/src/mongo/client/SConscript
@@ -122,16 +122,6 @@ env.Library(
)
env.Library(
- target='remote_command_runner_mock',
- source=[
- 'remote_command_runner_mock.cpp',
- ],
- LIBDEPS=[
- 'remote_command_runner',
- ]
-)
-
-env.Library(
target='remote_command_targeter',
source=[
'remote_command_targeter_factory_impl.cpp',
diff --git a/src/mongo/client/remote_command_runner_mock.cpp b/src/mongo/client/remote_command_runner_mock.cpp
deleted file mode 100644
index c9df7c52bca..00000000000
--- a/src/mongo/client/remote_command_runner_mock.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- * Copyright (C) 2015 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/client/remote_command_runner_mock.h"
-
-#include "mongo/unittest/unittest.h"
-#include "mongo/util/mongoutils/str.h"
-
-namespace mongo {
-
-namespace {
-void noCheckerSet(const RemoteCommandRequest& request) {
- FAIL(str::stream() << "runCommand not expected to be called. request: " << request.toString());
-}
-}
-
-RemoteCommandRunnerMock::RemoteCommandRunnerMock()
- : _runCommandChecker(noCheckerSet),
- _response(Status(ErrorCodes::InternalError, "response not set")) {}
-
-RemoteCommandRunnerMock::~RemoteCommandRunnerMock() = default;
-
-RemoteCommandRunnerMock* RemoteCommandRunnerMock::get(RemoteCommandRunner* runner) {
- auto mock = dynamic_cast<RemoteCommandRunnerMock*>(runner);
- invariant(mock);
-
- return mock;
-}
-
-StatusWith<RemoteCommandResponse> RemoteCommandRunnerMock::runCommand(
- const RemoteCommandRequest& request) {
- _runCommandChecker(request);
- _runCommandChecker = noCheckerSet;
- return _response;
-}
-
-void RemoteCommandRunnerMock::setNextExpectedCommand(
- stdx::function<void(const RemoteCommandRequest& request)> checkerFunc,
- StatusWith<RemoteCommandResponse> returnThis) {
- _runCommandChecker = checkerFunc;
- _response = std::move(returnThis);
-}
-}
diff --git a/src/mongo/client/remote_command_runner_mock.h b/src/mongo/client/remote_command_runner_mock.h
deleted file mode 100644
index fb3b6bc26dd..00000000000
--- a/src/mongo/client/remote_command_runner_mock.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/**
- * Copyright (C) 2015 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 "mongo/client/remote_command_runner.h"
-#include "mongo/stdx/functional.h"
-
-namespace mongo {
-
-/**
- * Note: This is NOT thread-safe.
- *
- * Example usage:
- *
- * RemoteCommandRunnerMock executor;
- * executor.setNextExpectedCommand([](const RemoteCommandRequest& request) {
- * ASSERT_EQUALS("config", request.dbname);
- * },
- * RemoteCommandResponse(BSON("ok" << 1), Milliseconds(0)));
- *
- * auto response = executor.runCommand(RemoteCommandRequest()); // Assertion error!
- */
-class RemoteCommandRunnerMock final : public RemoteCommandRunner {
-public:
- RemoteCommandRunnerMock();
- virtual ~RemoteCommandRunnerMock();
-
- /**
- * Shortcut for unit-tests.
- */
- static RemoteCommandRunnerMock* get(RemoteCommandRunner* runner);
-
- /**
- * Runs the function set by the last call to setNextExpectedCommand. Calling this more
- * than once after a single call to setNextExpectedCommand will result in an assertion
- * failure.
- *
- * Returns the value set on a previous call to setNextExpectedCommand.
- */
- StatusWith<RemoteCommandResponse> runCommand(const RemoteCommandRequest& request) override;
-
- /**
- * Sets the checker method to use and it's return value the next time runCommand is
- * called.
- */
- void setNextExpectedCommand(
- stdx::function<void(const RemoteCommandRequest& request)> checkerFunc,
- StatusWith<RemoteCommandResponse> returnThis);
-
-private:
- stdx::function<void(const RemoteCommandRequest& request)> _runCommandChecker;
- StatusWith<RemoteCommandResponse> _response;
-};
-}
diff --git a/src/mongo/db/auth/authz_manager_external_state_s.cpp b/src/mongo/db/auth/authz_manager_external_state_s.cpp
index 91ca85ee3ef..6d6ae04db01 100644
--- a/src/mongo/db/auth/authz_manager_external_state_s.cpp
+++ b/src/mongo/db/auth/authz_manager_external_state_s.cpp
@@ -70,8 +70,7 @@ Status AuthzManagerExternalStateMongos::getStoredAuthorizationVersion(OperationC
// that runs this command
BSONObj getParameterCmd = BSON("getParameter" << 1 << authSchemaVersionServerParameter << 1);
BSONObjBuilder builder;
- const bool ok =
- grid.catalogManager()->runUserManagementReadCommand("admin", getParameterCmd, &builder);
+ const bool ok = grid.catalogManager()->runReadCommand("admin", getParameterCmd, &builder);
BSONObj cmdResult = builder.obj();
if (!ok) {
return Command::getStatusFromCommandResult(cmdResult);
@@ -96,8 +95,7 @@ Status AuthzManagerExternalStateMongos::getUserDescription(OperationContext* txn
<< userName.getDB())) << "showPrivileges" << true
<< "showCredentials" << true);
BSONObjBuilder builder;
- const bool ok =
- grid.catalogManager()->runUserManagementReadCommand("admin", usersInfoCmd, &builder);
+ const bool ok = grid.catalogManager()->runReadCommand("admin", usersInfoCmd, &builder);
BSONObj cmdResult = builder.obj();
if (!ok) {
return Command::getStatusFromCommandResult(cmdResult);
@@ -126,8 +124,7 @@ Status AuthzManagerExternalStateMongos::getRoleDescription(const RoleName& roleN
<< roleName.getRole() << AuthorizationManager::ROLE_DB_FIELD_NAME
<< roleName.getDB())) << "showPrivileges" << showPrivileges);
BSONObjBuilder builder;
- const bool ok =
- grid.catalogManager()->runUserManagementReadCommand("admin", rolesInfoCmd, &builder);
+ const bool ok = grid.catalogManager()->runReadCommand("admin", rolesInfoCmd, &builder);
BSONObj cmdResult = builder.obj();
if (!ok) {
return Command::getStatusFromCommandResult(cmdResult);
@@ -154,8 +151,7 @@ Status AuthzManagerExternalStateMongos::getRoleDescriptionsForDB(const std::stri
BSONObj rolesInfoCmd = BSON("rolesInfo" << 1 << "showPrivileges" << showPrivileges
<< "showBuiltinRoles" << showBuiltinRoles);
BSONObjBuilder builder;
- const bool ok =
- grid.catalogManager()->runUserManagementReadCommand(dbname, rolesInfoCmd, &builder);
+ const bool ok = grid.catalogManager()->runReadCommand(dbname, rolesInfoCmd, &builder);
BSONObj cmdResult = builder.obj();
if (!ok) {
return Command::getStatusFromCommandResult(cmdResult);
@@ -169,8 +165,7 @@ Status AuthzManagerExternalStateMongos::getRoleDescriptionsForDB(const std::stri
bool AuthzManagerExternalStateMongos::hasAnyPrivilegeDocuments(OperationContext* txn) {
BSONObj usersInfoCmd = BSON("usersInfo" << 1);
BSONObjBuilder builder;
- const bool ok =
- grid.catalogManager()->runUserManagementReadCommand("admin", usersInfoCmd, &builder);
+ const bool ok = grid.catalogManager()->runReadCommand("admin", usersInfoCmd, &builder);
if (!ok) {
// If we were unable to complete the query,
// it's best to assume that there _are_ privilege documents. This might happen
diff --git a/src/mongo/db/auth/user_cache_invalidator_job.cpp b/src/mongo/db/auth/user_cache_invalidator_job.cpp
index dd44b200f60..2e44a9ff65a 100644
--- a/src/mongo/db/auth/user_cache_invalidator_job.cpp
+++ b/src/mongo/db/auth/user_cache_invalidator_job.cpp
@@ -91,7 +91,7 @@ public:
StatusWith<OID> getCurrentCacheGeneration() {
try {
BSONObjBuilder result;
- const bool ok = grid.catalogManager()->runUserManagementReadCommand(
+ const bool ok = grid.catalogManager()->runReadCommand(
"admin", BSON("_getUserCacheGeneration" << 1), &result);
if (!ok) {
return Command::getStatusFromCommandResult(result.obj());
diff --git a/src/mongo/executor/network_test_env.h b/src/mongo/executor/network_test_env.h
index d5ec03b1226..5606d71d504 100644
--- a/src/mongo/executor/network_test_env.h
+++ b/src/mongo/executor/network_test_env.h
@@ -42,7 +42,6 @@ class BSONObj;
class CatalogManagerReplicaSet;
class DistLockManagerMock;
struct RemoteCommandRequest;
-class RemoteCommandRunnerMock;
class ShardRegistry;
template <typename T>
class StatusWith;
diff --git a/src/mongo/s/balance.cpp b/src/mongo/s/balance.cpp
index 29444e27953..7b836bb26d8 100644
--- a/src/mongo/s/balance.cpp
+++ b/src/mongo/s/balance.cpp
@@ -35,6 +35,7 @@
#include <algorithm>
#include "mongo/client/dbclientcursor.h"
+#include "mongo/client/remote_command_targeter.h"
#include "mongo/db/client.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/namespace_string.h"
@@ -243,6 +244,7 @@ static BSONObj _buildDetails(bool didError,
builder.append("candidateChunks", candidateChunks);
builder.append("chunksMoved", chunksMoved);
}
+
return builder.obj();
}
@@ -259,7 +261,11 @@ bool Balancer::_checkOIDs() {
continue;
}
- BSONObj f = s->runCommand("admin", "features");
+ const auto shardHost = uassertStatusOK(
+ s->getTargeter()->findHost({ReadPreference::PrimaryOnly, TagSet::primaryOnly()}));
+
+ BSONObj f = uassertStatusOK(
+ grid.shardRegistry()->runCommand(shardHost, "admin", BSON("features" << 1)));
if (f["oidMachine"].isNumber()) {
int x = f["oidMachine"].numberInt();
if (oids.count(x) == 0) {
@@ -267,18 +273,26 @@ bool Balancer::_checkOIDs() {
} else {
log() << "error: 2 machines have " << x << " as oid machine piece: " << shardId
<< " and " << oids[x];
- s->runCommand("admin", BSON("features" << 1 << "oidReset" << 1));
+
+ uassertStatusOK(grid.shardRegistry()->runCommand(
+ shardHost, "admin", BSON("features" << 1 << "oidReset" << 1)));
const auto otherShard = grid.shardRegistry()->getShard(oids[x]);
if (otherShard) {
- otherShard->runCommand("admin", BSON("features" << 1 << "oidReset" << 1));
+ const auto otherShardHost = uassertStatusOK(otherShard->getTargeter()->findHost(
+ {ReadPreference::PrimaryOnly, TagSet::primaryOnly()}));
+
+ uassertStatusOK(grid.shardRegistry()->runCommand(
+ otherShardHost, "admin", BSON("features" << 1 << "oidReset" << 1)));
}
+
return false;
}
} else {
log() << "warning: oidMachine not set on: " << s->toString();
}
}
+
return true;
}
@@ -488,8 +502,8 @@ bool Balancer::_init() {
void Balancer::run() {
Client::initThread("Balancer");
- // This is the body of a BackgroundJob so if we throw here we're basically ending the
- // balancer thread prematurely.
+ // This is the body of a BackgroundJob so if we throw here we're basically ending the balancer
+ // thread prematurely.
while (!inShutdown()) {
if (!_init()) {
log() << "will retry to initialize balancer in one minute";
diff --git a/src/mongo/s/catalog/SConscript b/src/mongo/s/catalog/SConscript
index f7a6265f5da..78bad9a62a9 100644
--- a/src/mongo/s/catalog/SConscript
+++ b/src/mongo/s/catalog/SConscript
@@ -128,7 +128,6 @@ env.CppUnitTest(
LIBDEPS=[
'catalog_manager_mock',
'dist_lock_catalog_impl',
- '$BUILD_DIR/mongo/client/remote_command_runner_mock',
'$BUILD_DIR/mongo/client/remote_command_targeter_mock',
'$BUILD_DIR/mongo/db/auth/authorization_manager_mock_init',
'$BUILD_DIR/mongo/executor/network_test_env',
diff --git a/src/mongo/s/catalog/catalog_manager.h b/src/mongo/s/catalog/catalog_manager.h
index 04cc05c7d9a..e9f6ecac43f 100644
--- a/src/mongo/s/catalog/catalog_manager.h
+++ b/src/mongo/s/catalog/catalog_manager.h
@@ -276,7 +276,9 @@ public:
virtual bool isShardHost(const ConnectionString& shardConnectionString) = 0;
/**
- * Runs a user management command on the config servers.
+ * Runs a user management command on the config servers, potentially synchronizing through
+ * a distributed lock. Do not use for general write command execution.
+ *
* @param commandName: name of command
* @param dbname: database for which the user management command is invoked
* @param cmdObj: command obj
@@ -289,11 +291,11 @@ public:
BSONObjBuilder* result) = 0;
/**
- * Runs a read-only user management command on a single config server.
+ * Runs a read-only command on a single config server.
*/
- virtual bool runUserManagementReadCommand(const std::string& dbname,
- const BSONObj& cmdObj,
- BSONObjBuilder* result) = 0;
+ virtual bool runReadCommand(const std::string& dbname,
+ const BSONObj& cmdObj,
+ BSONObjBuilder* result) = 0;
/**
* Applies oplog entries to the config servers.
diff --git a/src/mongo/s/catalog/catalog_manager_mock.cpp b/src/mongo/s/catalog/catalog_manager_mock.cpp
index bbeab57f372..478f30c7141 100644
--- a/src/mongo/s/catalog/catalog_manager_mock.cpp
+++ b/src/mongo/s/catalog/catalog_manager_mock.cpp
@@ -148,9 +148,9 @@ bool CatalogManagerMock::runUserManagementWriteCommand(const string& commandName
return true;
}
-bool CatalogManagerMock::runUserManagementReadCommand(const string& dbname,
- const BSONObj& cmdObj,
- BSONObjBuilder* result) {
+bool CatalogManagerMock::runReadCommand(const string& dbname,
+ const BSONObj& cmdObj,
+ BSONObjBuilder* result) {
return true;
}
diff --git a/src/mongo/s/catalog/catalog_manager_mock.h b/src/mongo/s/catalog/catalog_manager_mock.h
index d208af32b79..eff3d2e10a0 100644
--- a/src/mongo/s/catalog/catalog_manager_mock.h
+++ b/src/mongo/s/catalog/catalog_manager_mock.h
@@ -106,9 +106,9 @@ public:
const BSONObj& cmdObj,
BSONObjBuilder* result) override;
- bool runUserManagementReadCommand(const std::string& dbname,
- const BSONObj& cmdObj,
- BSONObjBuilder* result) override;
+ bool runReadCommand(const std::string& dbname,
+ const BSONObj& cmdObj,
+ BSONObjBuilder* result) override;
Status applyChunkOpsDeprecated(const BSONArray& updateOps,
const BSONArray& preCondition) override;
diff --git a/src/mongo/s/catalog/dist_lock_catalog_impl.h b/src/mongo/s/catalog/dist_lock_catalog_impl.h
index b496936d63c..e91217a6f91 100644
--- a/src/mongo/s/catalog/dist_lock_catalog_impl.h
+++ b/src/mongo/s/catalog/dist_lock_catalog_impl.h
@@ -37,7 +37,6 @@
namespace mongo {
-class RemoteCommandRunner;
class RemoteCommandTargeter;
class ShardRegistry;
diff --git a/src/mongo/s/catalog/dist_lock_catalog_impl_test.cpp b/src/mongo/s/catalog/dist_lock_catalog_impl_test.cpp
index 8f6026d6651..26979ed061e 100644
--- a/src/mongo/s/catalog/dist_lock_catalog_impl_test.cpp
+++ b/src/mongo/s/catalog/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_runner_mock.h"
#include "mongo/client/remote_command_targeter_factory_mock.h"
#include "mongo/client/remote_command_targeter_mock.h"
#include "mongo/db/commands.h"
@@ -107,7 +106,6 @@ private:
_shardRegistry =
stdx::make_unique<ShardRegistry>(stdx::make_unique<RemoteCommandTargeterFactoryMock>(),
- stdx::make_unique<RemoteCommandRunnerMock>(),
std::move(executor),
network,
&_catalogMgr);
diff --git a/src/mongo/s/catalog/legacy/catalog_manager_legacy.cpp b/src/mongo/s/catalog/legacy/catalog_manager_legacy.cpp
index ecdd5775bf5..c364fa08045 100644
--- a/src/mongo/s/catalog/legacy/catalog_manager_legacy.cpp
+++ b/src/mongo/s/catalog/legacy/catalog_manager_legacy.cpp
@@ -1348,9 +1348,9 @@ bool CatalogManagerLegacy::runUserManagementWriteCommand(const string& commandNa
return Command::appendCommandStatus(*result, status);
}
-bool CatalogManagerLegacy::runUserManagementReadCommand(const string& dbname,
- const BSONObj& cmdObj,
- BSONObjBuilder* result) {
+bool CatalogManagerLegacy::runReadCommand(const string& dbname,
+ const BSONObj& cmdObj,
+ BSONObjBuilder* result) {
try {
// let SyncClusterConnection handle connecting to the first config server
// that is reachable and returns data
diff --git a/src/mongo/s/catalog/legacy/catalog_manager_legacy.h b/src/mongo/s/catalog/legacy/catalog_manager_legacy.h
index 1067b98600d..2c625d9c76c 100644
--- a/src/mongo/s/catalog/legacy/catalog_manager_legacy.h
+++ b/src/mongo/s/catalog/legacy/catalog_manager_legacy.h
@@ -113,9 +113,9 @@ public:
const BSONObj& cmdObj,
BSONObjBuilder* result) override;
- bool runUserManagementReadCommand(const std::string& dbname,
- const BSONObj& cmdObj,
- BSONObjBuilder* result) override;
+ bool runReadCommand(const std::string& dbname,
+ const BSONObj& cmdObj,
+ BSONObjBuilder* result) override;
Status applyChunkOpsDeprecated(const BSONArray& updateOps,
const BSONArray& preCondition) override;
diff --git a/src/mongo/s/catalog/replset/SConscript b/src/mongo/s/catalog/replset/SConscript
index c889cb36bcb..8324a7eaaf3 100644
--- a/src/mongo/s/catalog/replset/SConscript
+++ b/src/mongo/s/catalog/replset/SConscript
@@ -49,7 +49,6 @@ env.CppUnitTest(
],
LIBDEPS=[
'catalog_manager_replica_set',
- '$BUILD_DIR/mongo/client/remote_command_runner_mock',
'$BUILD_DIR/mongo/client/remote_command_targeter_mock',
'$BUILD_DIR/mongo/db/auth/authorization_manager_mock_init',
'$BUILD_DIR/mongo/executor/network_test_env',
diff --git a/src/mongo/s/catalog/replset/catalog_manager_replica_set.cpp b/src/mongo/s/catalog/replset/catalog_manager_replica_set.cpp
index c77532b89a4..795b822e0a2 100644
--- a/src/mongo/s/catalog/replset/catalog_manager_replica_set.cpp
+++ b/src/mongo/s/catalog/replset/catalog_manager_replica_set.cpp
@@ -568,9 +568,9 @@ bool CatalogManagerReplicaSet::runUserManagementWriteCommand(const std::string&
return Command::getStatusFromCommandResult(response.getValue()).isOK();
}
-bool CatalogManagerReplicaSet::runUserManagementReadCommand(const std::string& dbname,
- const BSONObj& cmdObj,
- BSONObjBuilder* result) {
+bool CatalogManagerReplicaSet::runReadCommand(const std::string& dbname,
+ const BSONObj& cmdObj,
+ BSONObjBuilder* result) {
auto targeter = grid.shardRegistry()->getShard("config")->getTargeter();
auto target = targeter->findHost(kConfigReadSelector);
if (!target.isOK()) {
diff --git a/src/mongo/s/catalog/replset/catalog_manager_replica_set.h b/src/mongo/s/catalog/replset/catalog_manager_replica_set.h
index 5756fbcf853..b66432fdd0f 100644
--- a/src/mongo/s/catalog/replset/catalog_manager_replica_set.h
+++ b/src/mongo/s/catalog/replset/catalog_manager_replica_set.h
@@ -113,9 +113,9 @@ public:
const BSONObj& cmdObj,
BSONObjBuilder* result) override;
- bool runUserManagementReadCommand(const std::string& dbname,
- const BSONObj& cmdObj,
- BSONObjBuilder* result) override;
+ bool runReadCommand(const std::string& dbname,
+ const BSONObj& cmdObj,
+ BSONObjBuilder* result) override;
Status applyChunkOpsDeprecated(const BSONArray& updateOps,
const BSONArray& preCondition) override;
diff --git a/src/mongo/s/catalog/replset/catalog_manager_replica_set_test.cpp b/src/mongo/s/catalog/replset/catalog_manager_replica_set_test.cpp
index 6267fef1c8a..07da0c6d6a0 100644
--- a/src/mongo/s/catalog/replset/catalog_manager_replica_set_test.cpp
+++ b/src/mongo/s/catalog/replset/catalog_manager_replica_set_test.cpp
@@ -549,8 +549,8 @@ TEST_F(CatalogManagerReplSetTestFixture, RunUserManagementReadCommand) {
auto future = launchAsync([this] {
BSONObjBuilder responseBuilder;
- bool ok = catalogManager()->runUserManagementReadCommand(
- "test", BSON("usersInfo" << 1), &responseBuilder);
+ bool ok =
+ catalogManager()->runReadCommand("test", BSON("usersInfo" << 1), &responseBuilder);
ASSERT_TRUE(ok);
BSONObj response = responseBuilder.obj();
@@ -566,7 +566,7 @@ TEST_F(CatalogManagerReplSetTestFixture, RunUserManagementReadCommand) {
return BSON("ok" << 1 << "users" << BSONArrayBuilder().arr());
});
- // Now wait for the runUserManagementReadCommand call to return
+ // Now wait for the runReadCommand call to return
future.wait_for(kFutureTimeout);
}
@@ -577,8 +577,7 @@ TEST_F(CatalogManagerReplSetTestFixture, RunUserManagementReadCommandUnsatisfied
Status(ErrorCodes::FailedToSatisfyReadPreference, "no nodes up"));
BSONObjBuilder responseBuilder;
- bool ok = catalogManager()->runUserManagementReadCommand(
- "test", BSON("usersInfo" << 1), &responseBuilder);
+ bool ok = catalogManager()->runReadCommand("test", BSON("usersInfo" << 1), &responseBuilder);
ASSERT_FALSE(ok);
Status commandStatus = Command::getStatusFromCommandResult(responseBuilder.obj());
diff --git a/src/mongo/s/catalog/replset/catalog_manager_replica_set_test_fixture.cpp b/src/mongo/s/catalog/replset/catalog_manager_replica_set_test_fixture.cpp
index 8896b56327e..1fd46d42bde 100644
--- a/src/mongo/s/catalog/replset/catalog_manager_replica_set_test_fixture.cpp
+++ b/src/mongo/s/catalog/replset/catalog_manager_replica_set_test_fixture.cpp
@@ -33,7 +33,6 @@
#include <vector>
#include "mongo/base/status_with.h"
-#include "mongo/client/remote_command_runner_mock.h"
#include "mongo/client/remote_command_targeter_factory_mock.h"
#include "mongo/db/repl/replication_executor.h"
#include "mongo/executor/network_interface_mock.h"
@@ -73,7 +72,6 @@ void CatalogManagerReplSetTestFixture::setUp() {
auto shardRegistry(
stdx::make_unique<ShardRegistry>(stdx::make_unique<RemoteCommandTargeterFactoryMock>(),
- stdx::make_unique<RemoteCommandRunnerMock>(),
std::move(executor),
_mockNetwork,
cm.get()));
@@ -101,10 +99,6 @@ ShardRegistry* CatalogManagerReplSetTestFixture::shardRegistry() const {
return grid.shardRegistry();
}
-RemoteCommandRunnerMock* CatalogManagerReplSetTestFixture::commandRunner() const {
- return RemoteCommandRunnerMock::get(shardRegistry()->getCommandRunner());
-}
-
executor::NetworkInterfaceMock* CatalogManagerReplSetTestFixture::network() const {
return _mockNetwork;
}
diff --git a/src/mongo/s/catalog/replset/catalog_manager_replica_set_test_fixture.h b/src/mongo/s/catalog/replset/catalog_manager_replica_set_test_fixture.h
index a5b22289e97..e95b9717c43 100644
--- a/src/mongo/s/catalog/replset/catalog_manager_replica_set_test_fixture.h
+++ b/src/mongo/s/catalog/replset/catalog_manager_replica_set_test_fixture.h
@@ -39,7 +39,6 @@ class BSONObj;
class CatalogManagerReplicaSet;
class DistLockManagerMock;
struct RemoteCommandRequest;
-class RemoteCommandRunnerMock;
class ShardRegistry;
template <typename T>
class StatusWith;
@@ -67,8 +66,6 @@ protected:
ShardRegistry* shardRegistry() const;
- RemoteCommandRunnerMock* commandRunner() const;
-
executor::NetworkInterfaceMock* network() const;
DistLockManagerMock* distLock() const;
diff --git a/src/mongo/s/client/shard.cpp b/src/mongo/s/client/shard.cpp
index 65aac08384f..5280a4107c5 100644
--- a/src/mongo/s/client/shard.cpp
+++ b/src/mongo/s/client/shard.cpp
@@ -36,10 +36,8 @@
#include "mongo/client/replica_set_monitor.h"
#include "mongo/client/read_preference.h"
-#include "mongo/client/remote_command_runner.h"
#include "mongo/client/remote_command_targeter.h"
#include "mongo/db/jsobj.h"
-#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/grid.h"
#include "mongo/util/log.h"
@@ -61,61 +59,19 @@ ShardPtr Shard::lookupRSName(const string& name) {
return grid.shardRegistry()->lookupRSName(name);
}
-BSONObj Shard::runCommand(const std::string& db, const std::string& simple) const {
- return runCommand(db, BSON(simple << 1));
-}
-
-BSONObj Shard::runCommand(const string& db, const BSONObj& cmd) const {
- BSONObj res;
- bool ok = runCommand(db, cmd, res);
- if (!ok) {
- stringstream ss;
- ss << "runCommand (" << cmd << ") on shard (" << _id << ") failed : " << res;
- throw UserException(13136, ss.str());
- }
- res = res.getOwned();
- return res;
-}
-
-bool Shard::runCommand(const std::string& db, const std::string& simple, BSONObj& res) const {
- return runCommand(db, BSON(simple << 1), res);
-}
-
-bool Shard::runCommand(const string& db, const BSONObj& cmd, BSONObj& res) const {
- const ReadPreferenceSetting readPref(ReadPreference::PrimaryOnly, TagSet::primaryOnly());
- auto selectedHost = getTargeter()->findHost(readPref);
- if (!selectedHost.isOK()) {
- return false;
- }
-
- const RemoteCommandRequest request(selectedHost.getValue(), db, cmd);
-
- auto statusCommand = grid.shardRegistry()->getCommandRunner()->runCommand(request);
- if (!statusCommand.isOK()) {
- return false;
- }
-
- res = statusCommand.getValue().data.getOwned();
-
- return getStatusFromCommandResult(res).isOK();
-}
-
ShardStatus Shard::getStatus() const {
- BSONObj listDatabases;
- uassert(28589,
- str::stream() << "call to listDatabases on " << getConnString().toString()
- << " failed: " << listDatabases,
- runCommand("admin", BSON("listDatabases" << 1), listDatabases));
+ const ReadPreferenceSetting readPref(ReadPreference::PrimaryOnly, TagSet::primaryOnly());
+ auto shardHost = uassertStatusOK(getTargeter()->findHost(readPref));
+ // List databases command
+ BSONObj listDatabases = uassertStatusOK(
+ grid.shardRegistry()->runCommand(shardHost, "admin", BSON("listDatabases" << 1)));
BSONElement totalSizeElem = listDatabases["totalSize"];
uassert(28590, "totalSize field not found in listDatabases", totalSizeElem.isNumber());
- BSONObj serverStatus;
- uassert(28591,
- str::stream() << "call to serverStatus on " << getConnString().toString()
- << " failed: " << serverStatus,
- runCommand("admin", BSON("serverStatus" << 1), serverStatus));
-
+ // Server status command
+ BSONObj serverStatus = uassertStatusOK(
+ grid.shardRegistry()->runCommand(shardHost, "admin", BSON("serverStatus" << 1)));
BSONElement versionElement = serverStatus["version"];
uassert(28599, "version field not found in serverStatus", versionElement.type() == String);
diff --git a/src/mongo/s/client/shard.h b/src/mongo/s/client/shard.h
index 077cd784000..d22e4d3fa83 100644
--- a/src/mongo/s/client/shard.h
+++ b/src/mongo/s/client/shard.h
@@ -95,12 +95,6 @@ public:
return _targeter.get();
}
- BSONObj runCommand(const std::string& db, const std::string& simple) const;
- BSONObj runCommand(const std::string& db, const BSONObj& cmd) const;
-
- bool runCommand(const std::string& db, const std::string& simple, BSONObj& res) const;
- bool runCommand(const std::string& db, const BSONObj& cmd, BSONObj& res) const;
-
/**
* Returns metadata and stats for this shard.
*/
diff --git a/src/mongo/s/client/shard_registry.cpp b/src/mongo/s/client/shard_registry.cpp
index 73db753262a..158fd48013b 100644
--- a/src/mongo/s/client/shard_registry.cpp
+++ b/src/mongo/s/client/shard_registry.cpp
@@ -34,7 +34,6 @@
#include "mongo/client/connection_string.h"
#include "mongo/client/query_fetcher.h"
-#include "mongo/client/remote_command_runner_impl.h"
#include "mongo/client/remote_command_targeter.h"
#include "mongo/client/remote_command_targeter_factory.h"
#include "mongo/executor/task_executor.h"
@@ -61,12 +60,10 @@ const Seconds kConfigCommandTimeout{30};
} // unnamed namespace
ShardRegistry::ShardRegistry(std::unique_ptr<RemoteCommandTargeterFactory> targeterFactory,
- std::unique_ptr<RemoteCommandRunner> commandRunner,
std::unique_ptr<executor::TaskExecutor> executor,
executor::NetworkInterface* network,
CatalogManager* catalogManager)
: _targeterFactory(std::move(targeterFactory)),
- _commandRunner(std::move(commandRunner)),
_executor(std::move(executor)),
_network(network),
_catalogManager(catalogManager) {
diff --git a/src/mongo/s/client/shard_registry.h b/src/mongo/s/client/shard_registry.h
index 7251745d374..5bd91b42098 100644
--- a/src/mongo/s/client/shard_registry.h
+++ b/src/mongo/s/client/shard_registry.h
@@ -43,7 +43,6 @@ class BSONObjBuilder;
class CatalogManager;
struct HostAndPort;
class NamespaceString;
-class RemoteCommandRunner;
class RemoteCommandTargeterFactory;
class Shard;
class ShardType;
@@ -76,7 +75,6 @@ public:
* @param catalogManager Used to retrieve the list of registered shard. TODO: remove.
*/
ShardRegistry(std::unique_ptr<RemoteCommandTargeterFactory> targeterFactory,
- std::unique_ptr<RemoteCommandRunner> commandRunner,
std::unique_ptr<executor::TaskExecutor> executor,
executor::NetworkInterface* network,
CatalogManager* catalogManager);
@@ -94,10 +92,6 @@ public:
*/
void shutdown();
- RemoteCommandRunner* getCommandRunner() const {
- return _commandRunner.get();
- }
-
executor::TaskExecutor* getExecutor() const {
return _executor.get();
}
@@ -165,9 +159,6 @@ private:
// Factory to obtain remote command targeters for shards
const std::unique_ptr<RemoteCommandTargeterFactory> _targeterFactory;
- // API to run remote commands to shards in a synchronous manner
- const std::unique_ptr<RemoteCommandRunner> _commandRunner;
-
// Executor for scheduling work and remote commands to shards that run in an asynchronous
// manner.
const std::unique_ptr<executor::TaskExecutor> _executor;
diff --git a/src/mongo/s/commands/cluster_fsync_cmd.cpp b/src/mongo/s/commands/cluster_fsync_cmd.cpp
index f9dc78ee9d7..90735a25784 100644
--- a/src/mongo/s/commands/cluster_fsync_cmd.cpp
+++ b/src/mongo/s/commands/cluster_fsync_cmd.cpp
@@ -28,6 +28,8 @@
#include "mongo/platform/basic.h"
+#include "mongo/client/read_preference.h"
+#include "mongo/client/remote_command_targeter.h"
#include "mongo/db/commands.h"
#include "mongo/s/client/shard.h"
#include "mongo/s/client/shard_registry.h"
@@ -89,7 +91,12 @@ public:
continue;
}
- BSONObj x = s->runCommand("admin", "fsync");
+ const auto shardHost = uassertStatusOK(
+ s->getTargeter()->findHost({ReadPreference::PrimaryOnly, TagSet::primaryOnly()}));
+
+ BSONObj x = uassertStatusOK(
+ grid.shardRegistry()->runCommand(shardHost, "admin", BSON("fsync" << 1)));
+
sub.append(s->getId(), x);
if (!x["ok"].trueValue()) {
@@ -105,7 +112,7 @@ public:
return ok;
}
-} fsyncCmd;
+} clusterFsyncCmd;
} // namespace
} // namespace mongo
diff --git a/src/mongo/s/commands/cluster_list_databases_cmd.cpp b/src/mongo/s/commands/cluster_list_databases_cmd.cpp
index 248fb79f488..0e50c845df5 100644
--- a/src/mongo/s/commands/cluster_list_databases_cmd.cpp
+++ b/src/mongo/s/commands/cluster_list_databases_cmd.cpp
@@ -28,13 +28,14 @@
#include "mongo/platform/basic.h"
-
#include <map>
#include <string>
#include <vector>
#include "mongo/client/connpool.h"
+#include "mongo/client/remote_command_targeter.h"
#include "mongo/db/commands.h"
+#include "mongo/s/catalog/catalog_manager.h"
#include "mongo/s/client/shard.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/grid.h"
@@ -98,7 +99,11 @@ public:
continue;
}
- BSONObj x = s->runCommand("admin", "listDatabases");
+ const auto shardHost = uassertStatusOK(
+ s->getTargeter()->findHost({ReadPreference::PrimaryOnly, TagSet::primaryOnly()}));
+
+ BSONObj x = uassertStatusOK(
+ grid.shardRegistry()->runCommand(shardHost, "admin", BSON("listDatabases" << 1)));
BSONObjIterator j(x["databases"].Obj());
while (j.more()) {
@@ -153,45 +158,45 @@ public:
bb.append(temp.obj());
}
- // Obtain the cached config shard
- const auto configShard = grid.shardRegistry()->getShard("config");
-
{
- // get config db from the config servers (first one)
- BSONObj x;
- if (configShard->runCommand("config", "dbstats", x)) {
+ // get config db from the config servers
+ BSONObjBuilder builder;
+
+ if (!grid.catalogManager()->runReadCommand("config", BSON("dbstats" << 1), &builder)) {
+ bb.append(BSON("name"
+ << "config"));
+ } else {
+ BSONObj x = builder.obj();
BSONObjBuilder b;
b.append("name", "config");
b.appendBool("empty", false);
- if (x["fileSize"].type())
+ if (x["fileSize"].type()) {
b.appendAs(x["fileSize"], "sizeOnDisk");
- else
+ } else {
b.append("sizeOnDisk", 1);
+ }
bb.append(b.obj());
- } else {
- bb.append(BSON("name"
- << "config"));
}
}
{
- // get admin db from the config servers (first one)
- BSONObj x;
- if (configShard->runCommand("admin", "dbstats", x)) {
+ // get admin db from the config servers
+ BSONObjBuilder builder;
+
+ if (!grid.catalogManager()->runReadCommand("admin", BSON("dbstats" << 1), &builder)) {
+ bb.append(BSON("name"
+ << "admin"));
+ } else {
+ BSONObj x = builder.obj();
BSONObjBuilder b;
b.append("name", "admin");
b.appendBool("empty", false);
-
if (x["fileSize"].type()) {
b.appendAs(x["fileSize"], "sizeOnDisk");
} else {
b.append("sizeOnDisk", 1);
}
-
bb.append(b.obj());
- } else {
- bb.append(BSON("name"
- << "admin"));
}
}
@@ -200,10 +205,10 @@ public:
result.appendNumber("totalSize", totalSize);
result.appendNumber("totalSizeMb", totalSize / (1024 * 1024));
- return 1;
+ return true;
}
-} cmdListDatabases;
+} clusterCmdListDatabases;
} // namespace
} // namespace mongo
diff --git a/src/mongo/s/commands/cluster_user_management_commands.cpp b/src/mongo/s/commands/cluster_user_management_commands.cpp
index d2a6ab667d4..0bb67e31c2a 100644
--- a/src/mongo/s/commands/cluster_user_management_commands.cpp
+++ b/src/mongo/s/commands/cluster_user_management_commands.cpp
@@ -352,7 +352,7 @@ public:
int options,
string& errmsg,
BSONObjBuilder& result) {
- return grid.catalogManager()->runUserManagementReadCommand(dbname, cmdObj, &result);
+ return grid.catalogManager()->runReadCommand(dbname, cmdObj, &result);
}
} cmdUsersInfo;
@@ -710,7 +710,7 @@ public:
int options,
string& errmsg,
BSONObjBuilder& result) {
- return grid.catalogManager()->runUserManagementReadCommand(dbname, cmdObj, &result);
+ return grid.catalogManager()->runReadCommand(dbname, cmdObj, &result);
}
} cmdRolesInfo;
diff --git a/src/mongo/s/d_state.cpp b/src/mongo/s/d_state.cpp
index aa5fcf51e5f..2cc3c99da8b 100644
--- a/src/mongo/s/d_state.cpp
+++ b/src/mongo/s/d_state.cpp
@@ -40,7 +40,6 @@
#include "mongo/client/connpool.h"
#include "mongo/client/global_conn_pool.h"
-#include "mongo/client/remote_command_runner_impl.h"
#include "mongo/client/remote_command_targeter_factory_impl.h"
#include "mongo/db/auth/action_set.h"
#include "mongo/db/auth/action_type.h"
@@ -482,7 +481,6 @@ void ShardingState::_initialize(const string& server) {
auto shardRegistry(
stdx::make_unique<ShardRegistry>(stdx::make_unique<RemoteCommandTargeterFactoryImpl>(),
- stdx::make_unique<RemoteCommandRunnerImpl>(0),
stdx::make_unique<repl::ReplicationExecutor>(
new executor::NetworkInterfaceImpl(), nullptr, 0),
nullptr,
diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp
index be3f6001398..2a03d2123b9 100644
--- a/src/mongo/s/server.cpp
+++ b/src/mongo/s/server.cpp
@@ -38,7 +38,6 @@
#include "mongo/client/connpool.h"
#include "mongo/client/dbclient_rs.h"
#include "mongo/client/global_conn_pool.h"
-#include "mongo/client/remote_command_runner_impl.h"
#include "mongo/client/remote_command_targeter_factory_impl.h"
#include "mongo/client/replica_set_monitor.h"
#include "mongo/config.h"
@@ -230,7 +229,6 @@ static ExitCode runMongosServer(bool doUpgrade) {
auto shardRegistry(
stdx::make_unique<ShardRegistry>(stdx::make_unique<RemoteCommandTargeterFactoryImpl>(),
- stdx::make_unique<RemoteCommandRunnerImpl>(0),
stdx::make_unique<repl::ReplicationExecutor>(
new executor::NetworkInterfaceImpl(), nullptr, 0),
nullptr,