summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mongo/SConscript12
-rw-r--r--src/mongo/db/fts/SConscript5
-rw-r--r--src/mongo/db/sorter/sorter.cpp2
-rw-r--r--src/mongo/s/SConscript41
-rw-r--r--src/mongo/s/catalog/SConscript4
-rw-r--r--src/mongo/s/client/SConscript3
-rw-r--r--src/mongo/s/client/version_manager.cpp2
-rw-r--r--src/mongo/s/cluster_cursor_stats.cpp1
-rw-r--r--src/mongo/s/cluster_last_error_info.cpp1
-rw-r--r--src/mongo/s/cluster_last_error_info.h1
-rw-r--r--src/mongo/s/commands/SConscript5
-rw-r--r--src/mongo/s/commands/cluster_find_and_modify_cmd.cpp1
-rw-r--r--src/mongo/s/commands/cluster_get_last_error_cmd.cpp3
-rw-r--r--src/mongo/s/commands/cluster_write.cpp2
-rw-r--r--src/mongo/s/commands/cluster_write_cmd.cpp2
-rw-r--r--src/mongo/s/commands/dbclient_multi_command.cpp (renamed from src/mongo/s/client/dbclient_multi_command.cpp)2
-rw-r--r--src/mongo/s/commands/dbclient_multi_command.h (renamed from src/mongo/s/client/dbclient_multi_command.h)0
-rw-r--r--src/mongo/s/commands/strategy.cpp125
-rw-r--r--src/mongo/s/query/SConscript3
-rw-r--r--src/mongo/s/s_only.cpp179
-rw-r--r--src/mongo/s/s_sharding_server_status.cpp43
21 files changed, 177 insertions, 260 deletions
diff --git a/src/mongo/SConscript b/src/mongo/SConscript
index 1f02fb78741..daa019af2bb 100644
--- a/src/mongo/SConscript
+++ b/src/mongo/SConscript
@@ -342,19 +342,27 @@ env.Install(
env.Program(
target='mongos',
source=[
+ 's/cluster_cursor_stats.cpp',
+ 's/mongos_options.cpp',
's/mongos_options_init.cpp',
+ 's/s_sharding_server_status.cpp',
's/server.cpp',
's/service_entry_point_mongos.cpp',
+ 's/sharding_uptime_reporter.cpp',
+ 's/version_mongos.cpp',
] + env.WindowsResourceFile("s/server.rc"),
LIBDEPS=[
- 'db/conn_pool_options',
'db/commands/core',
+ 'db/conn_pool_options',
'db/mongodandmongos',
+ 'db/server_options',
+ 'db/stats/counters',
's/client/sharding_connection_hook',
's/commands/cluster_commands',
's/commands/shared_cluster_commands',
's/coreshard',
- 's/mongoscore',
+ 's/is_mongos',
+ 's/sharding_egress_metadata_hook_for_mongos',
's/sharding_initialization',
'transport/service_entry_point_utils',
'transport/transport_layer_legacy',
diff --git a/src/mongo/db/fts/SConscript b/src/mongo/db/fts/SConscript
index 4118f0f738f..a0e16484d17 100644
--- a/src/mongo/db/fts/SConscript
+++ b/src/mongo/db/fts/SConscript
@@ -77,11 +77,6 @@ env.Library(
env.Library('ftsmongod', [
], LIBDEPS=["base","$BUILD_DIR/mongo/base"])
-
-env.Library('ftsmongos', [
- ], LIBDEPS=["$BUILD_DIR/mongo/base"])
-
-
env.CppUnitTest( "fts_basic_phrase_matcher_test", "fts_basic_phrase_matcher_test.cpp",
LIBDEPS=["base"] )
diff --git a/src/mongo/db/sorter/sorter.cpp b/src/mongo/db/sorter/sorter.cpp
index 1a34322a95e..eef0c51038c 100644
--- a/src/mongo/db/sorter/sorter.cpp
+++ b/src/mongo/db/sorter/sorter.cpp
@@ -58,7 +58,7 @@
#include "mongo/db/storage/storage_options.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_customization_hooks.h"
#include "mongo/platform/atomic_word.h"
-#include "mongo/s/mongos_options.h"
+#include "mongo/s/is_mongos.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/bufreader.h"
#include "mongo/util/destructor_guard.h"
diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript
index ff072e796ea..3ee3d34939f 100644
--- a/src/mongo/s/SConscript
+++ b/src/mongo/s/SConscript
@@ -112,16 +112,6 @@ env.Library(
)
env.Library(
- target='config_server_test_fixture',
- source=[
- 'config_server_test_fixture.cpp',
- ],
- LIBDEPS=[
- 'sharding_mongod_test_fixture',
- ],
-)
-
-env.Library(
target='shard_server_test_fixture',
source=[
'shard_server_test_fixture.cpp',
@@ -156,6 +146,16 @@ env.Library(
],
)
+env.Library(
+ target='config_server_test_fixture',
+ source=[
+ 'config_server_test_fixture.cpp',
+ ],
+ LIBDEPS=[
+ 'sharding_mongod_test_fixture',
+ ],
+)
+
env.CppUnitTest(
target='shard_id_test',
source=[
@@ -291,27 +291,6 @@ env.Library(
LIBDEPS=[],
)
-env.Library(
- target='mongoscore',
- source=[
- 'cluster_cursor_stats.cpp',
- 'mongos_options.cpp',
- 's_only.cpp',
- 's_sharding_server_status.cpp',
- 'sharding_uptime_reporter.cpp',
- 'version_mongos.cpp',
- ],
- LIBDEPS=[
- '$BUILD_DIR/mongo/db/auth/authmongos',
- '$BUILD_DIR/mongo/db/fts/ftsmongos',
- '$BUILD_DIR/mongo/db/stats/counters',
- '$BUILD_DIR/mongo/s/query/cluster_query',
- '$BUILD_DIR/mongo/util/concurrency/task',
- 'sharding_egress_metadata_hook_for_mongos',
- 'is_mongos',
- ],
-)
-
env.CppUnitTest(
target='balancer_configuration_test',
source=[
diff --git a/src/mongo/s/catalog/SConscript b/src/mongo/s/catalog/SConscript
index e06a518b2dc..68d99fcf1ff 100644
--- a/src/mongo/s/catalog/SConscript
+++ b/src/mongo/s/catalog/SConscript
@@ -111,11 +111,11 @@ env.CppUnitTest(
'replset_dist_lock_manager_test.cpp',
],
LIBDEPS=[
- 'dist_lock_catalog_impl',
- 'replset_dist_lock_manager',
'$BUILD_DIR/mongo/s/catalog/dist_lock_catalog_mock',
'$BUILD_DIR/mongo/s/catalog/sharding_catalog_mock',
'$BUILD_DIR/mongo/s/sharding_mongod_test_fixture',
+ 'dist_lock_catalog_impl',
+ 'replset_dist_lock_manager',
]
)
diff --git a/src/mongo/s/client/SConscript b/src/mongo/s/client/SConscript
index 0f2ef4ec20f..158afab4e44 100644
--- a/src/mongo/s/client/SConscript
+++ b/src/mongo/s/client/SConscript
@@ -7,7 +7,6 @@ env = env.Clone()
env.Library(
target='sharding_client',
source=[
- 'dbclient_multi_command.cpp',
'shard_connection.cpp',
'shard_factory.cpp',
'shard_registry.cpp',
@@ -74,7 +73,6 @@ env.CppUnitTest(
'$BUILD_DIR/mongo/db/service_context_noop_init',
'$BUILD_DIR/mongo/dbtests/mocklib',
'$BUILD_DIR/mongo/s/coreshard',
- '$BUILD_DIR/mongo/s/mongoscore',
'$BUILD_DIR/mongo/util/net/network',
]
)
@@ -86,7 +84,6 @@ env.CppUnitTest(
],
LIBDEPS=[
'$BUILD_DIR/mongo/s/coreshard',
- '$BUILD_DIR/mongo/s/mongoscore',
'$BUILD_DIR/mongo/s/sharding_test_fixture',
]
)
diff --git a/src/mongo/s/client/version_manager.cpp b/src/mongo/s/client/version_manager.cpp
index 2e6a35f5e09..107579eeaab 100644
--- a/src/mongo/s/client/version_manager.cpp
+++ b/src/mongo/s/client/version_manager.cpp
@@ -40,7 +40,7 @@
#include "mongo/s/client/shard_connection.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/grid.h"
-#include "mongo/s/mongos_options.h"
+#include "mongo/s/is_mongos.h"
#include "mongo/s/set_shard_version_request.h"
#include "mongo/s/sharding_raii.h"
#include "mongo/s/stale_exception.h"
diff --git a/src/mongo/s/cluster_cursor_stats.cpp b/src/mongo/s/cluster_cursor_stats.cpp
index db72b245795..d0620705052 100644
--- a/src/mongo/s/cluster_cursor_stats.cpp
+++ b/src/mongo/s/cluster_cursor_stats.cpp
@@ -59,6 +59,7 @@ public:
}
cursorBob.done();
}
+
} clusterCursorStats;
} // namespace
diff --git a/src/mongo/s/cluster_last_error_info.cpp b/src/mongo/s/cluster_last_error_info.cpp
index b474574f35b..e860d760183 100644
--- a/src/mongo/s/cluster_last_error_info.cpp
+++ b/src/mongo/s/cluster_last_error_info.cpp
@@ -30,6 +30,7 @@
#include "mongo/s/cluster_last_error_info.h"
+#include "mongo/client/connection_string.h"
#include "mongo/db/lasterror.h"
namespace mongo {
diff --git a/src/mongo/s/cluster_last_error_info.h b/src/mongo/s/cluster_last_error_info.h
index 3755bfe90ae..66377eceeb8 100644
--- a/src/mongo/s/cluster_last_error_info.h
+++ b/src/mongo/s/cluster_last_error_info.h
@@ -28,6 +28,7 @@
#pragma once
#include <set>
+#include <string>
#include "mongo/db/client.h"
#include "mongo/s/write_ops/batch_write_exec.h"
diff --git a/src/mongo/s/commands/SConscript b/src/mongo/s/commands/SConscript
index 3efb17e3320..7cb7a7147e3 100644
--- a/src/mongo/s/commands/SConscript
+++ b/src/mongo/s/commands/SConscript
@@ -76,19 +76,22 @@ env.Library(
'cluster_write.cpp',
'cluster_write_cmd.cpp',
'commands_public.cpp',
+ 'dbclient_multi_command.cpp',
'run_on_all_shards_cmd.cpp',
'sharded_command_processing.cpp',
'strategy.cpp',
],
LIBDEPS=[
+ '$BUILD_DIR/mongo/db/auth/authmongos',
'$BUILD_DIR/mongo/db/commands/apply_ops_cmd_common',
+ '$BUILD_DIR/mongo/db/commands/core',
'$BUILD_DIR/mongo/db/commands/killcursors_common',
'$BUILD_DIR/mongo/db/pipeline/aggregation',
'$BUILD_DIR/mongo/db/views/views',
'$BUILD_DIR/mongo/rpc/client_metadata',
'$BUILD_DIR/mongo/s/client/parallel',
'$BUILD_DIR/mongo/s/coreshard',
- '$BUILD_DIR/mongo/s/mongoscore',
+ '$BUILD_DIR/mongo/s/query/cluster_query',
'$BUILD_DIR/mongo/s/write_ops/cluster_write_op',
'$BUILD_DIR/mongo/s/write_ops/cluster_write_op_conversion',
'$BUILD_DIR/mongo/transport/transport_layer_common',
diff --git a/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp b/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp
index eabb8661051..d41fa0a5707 100644
--- a/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp
+++ b/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp
@@ -48,7 +48,6 @@
#include "mongo/s/commands/sharded_command_processing.h"
#include "mongo/s/commands/strategy.h"
#include "mongo/s/grid.h"
-#include "mongo/s/mongos_options.h"
#include "mongo/s/sharding_raii.h"
#include "mongo/s/stale_exception.h"
#include "mongo/util/timer.h"
diff --git a/src/mongo/s/commands/cluster_get_last_error_cmd.cpp b/src/mongo/s/commands/cluster_get_last_error_cmd.cpp
index dbeb35a673e..d1f01d4ebc0 100644
--- a/src/mongo/s/commands/cluster_get_last_error_cmd.cpp
+++ b/src/mongo/s/commands/cluster_get_last_error_cmd.cpp
@@ -34,9 +34,9 @@
#include "mongo/db/client.h"
#include "mongo/db/commands.h"
#include "mongo/db/lasterror.h"
-#include "mongo/s/client/dbclient_multi_command.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/cluster_last_error_info.h"
+#include "mongo/s/commands/dbclient_multi_command.h"
#include "mongo/s/grid.h"
#include "mongo/s/write_ops/batch_downconvert.h"
@@ -47,7 +47,6 @@ class GetLastErrorCmd : public Command {
public:
GetLastErrorCmd() : Command("getLastError", false, "getlasterror") {}
-
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
}
diff --git a/src/mongo/s/commands/cluster_write.cpp b/src/mongo/s/commands/cluster_write.cpp
index e235c3fa673..3468ca6dcf4 100644
--- a/src/mongo/s/commands/cluster_write.cpp
+++ b/src/mongo/s/commands/cluster_write.cpp
@@ -40,9 +40,9 @@
#include "mongo/s/catalog/sharding_catalog_client.h"
#include "mongo/s/catalog/type_collection.h"
#include "mongo/s/chunk.h"
-#include "mongo/s/client/dbclient_multi_command.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/commands/chunk_manager_targeter.h"
+#include "mongo/s/commands/dbclient_multi_command.h"
#include "mongo/s/config_server_client.h"
#include "mongo/s/grid.h"
#include "mongo/s/shard_util.h"
diff --git a/src/mongo/s/commands/cluster_write_cmd.cpp b/src/mongo/s/commands/cluster_write_cmd.cpp
index fd664878473..c25c15b5545 100644
--- a/src/mongo/s/commands/cluster_write_cmd.cpp
+++ b/src/mongo/s/commands/cluster_write_cmd.cpp
@@ -38,12 +38,12 @@
#include "mongo/db/lasterror.h"
#include "mongo/db/stats/counters.h"
#include "mongo/db/stats/counters.h"
-#include "mongo/s/client/dbclient_multi_command.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/cluster_last_error_info.h"
#include "mongo/s/commands/chunk_manager_targeter.h"
#include "mongo/s/commands/cluster_explain.h"
#include "mongo/s/commands/cluster_write.h"
+#include "mongo/s/commands/dbclient_multi_command.h"
#include "mongo/s/grid.h"
#include "mongo/s/write_ops/batch_upconvert.h"
#include "mongo/s/write_ops/batched_command_request.h"
diff --git a/src/mongo/s/client/dbclient_multi_command.cpp b/src/mongo/s/commands/dbclient_multi_command.cpp
index 9b086c15aa3..2bceb5a4993 100644
--- a/src/mongo/s/client/dbclient_multi_command.cpp
+++ b/src/mongo/s/commands/dbclient_multi_command.cpp
@@ -28,7 +28,7 @@
#include "mongo/platform/basic.h"
-#include "mongo/s/client/dbclient_multi_command.h"
+#include "mongo/s/commands/dbclient_multi_command.h"
#include "mongo/db/audit.h"
#include "mongo/db/client.h"
diff --git a/src/mongo/s/client/dbclient_multi_command.h b/src/mongo/s/commands/dbclient_multi_command.h
index c277a756cfd..c277a756cfd 100644
--- a/src/mongo/s/client/dbclient_multi_command.h
+++ b/src/mongo/s/commands/dbclient_multi_command.h
diff --git a/src/mongo/s/commands/strategy.cpp b/src/mongo/s/commands/strategy.cpp
index 6d6b9a74f9f..148dcd66e05 100644
--- a/src/mongo/s/commands/strategy.cpp
+++ b/src/mongo/s/commands/strategy.cpp
@@ -33,6 +33,7 @@
#include "mongo/s/commands/strategy.h"
#include "mongo/base/data_cursor.h"
+#include "mongo/base/init.h"
#include "mongo/base/owned_pointer_vector.h"
#include "mongo/base/status.h"
#include "mongo/bson/util/bson_extract.h"
@@ -51,6 +52,7 @@
#include "mongo/db/views/resolved_view.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/rpc/metadata/server_selection_metadata.h"
+#include "mongo/rpc/metadata/tracking_metadata.h"
#include "mongo/s/catalog_cache.h"
#include "mongo/s/chunk_manager.h"
#include "mongo/s/chunk_version.h"
@@ -67,6 +69,7 @@
#include "mongo/s/write_ops/batched_command_response.h"
#include "mongo/util/log.h"
#include "mongo/util/mongoutils/str.h"
+#include "mongo/util/scopeguard.h"
#include "mongo/util/timer.h"
namespace mongo {
@@ -104,6 +107,40 @@ void runAgainstRegistered(OperationContext* txn,
execCommandClient(txn, c, queryOptions, ns, jsobj, anObjBuilder);
}
+/**
+ * Called into by the web server. For now we just translate the parameters to their old style
+ * equivalents.
+ */
+void execCommandHandler(OperationContext* txn,
+ Command* command,
+ const rpc::RequestInterface& request,
+ rpc::ReplyBuilderInterface* replyBuilder) {
+ int queryFlags = 0;
+ BSONObj cmdObj;
+
+ std::tie(cmdObj, queryFlags) = uassertStatusOK(
+ rpc::downconvertRequestMetadata(request.getCommandArgs(), request.getMetadata()));
+
+ std::string db = request.getDatabase().rawData();
+ BSONObjBuilder result;
+
+ execCommandClient(txn, command, queryFlags, request.getDatabase().rawData(), cmdObj, result);
+
+ replyBuilder->setCommandReply(result.done()).setMetadata(rpc::makeEmptyMetadata());
+}
+
+MONGO_INITIALIZER(InitializeCommandExecCommandHandler)(InitializerContext* const) {
+ Command::registerExecCommand(execCommandHandler);
+ return Status::OK();
+}
+
+void registerErrorImpl(OperationContext* txn, const DBException& exception) {}
+
+MONGO_INITIALIZER(InitializeRegisterErrorHandler)(InitializerContext* const) {
+ Command::registerRegisterError(registerErrorImpl);
+ return Status::OK();
+}
+
} // namespace
void Strategy::queryOp(OperationContext* txn, const NamespaceString& nss, DbMessage* dbm) {
@@ -567,4 +604,92 @@ Status Strategy::explainFind(OperationContext* txn,
txn, shardResults, mongosStageName, millisElapsed, out);
}
+/**
+ * Called into by the commands infrastructure.
+ */
+void execCommandClient(OperationContext* txn,
+ Command* c,
+ int queryOptions,
+ const char* ns,
+ BSONObj& cmdObj,
+ BSONObjBuilder& result) {
+ const std::string dbname = nsToDatabase(ns);
+
+ if (cmdObj.getBoolField("help")) {
+ std::stringstream help;
+ help << "help for: " << c->getName() << " ";
+ c->help(help);
+ result.append("help", help.str());
+ Command::appendCommandStatus(result, true, "");
+ return;
+ }
+
+ Status status = Command::checkAuthorization(c, txn, dbname, cmdObj);
+ if (!status.isOK()) {
+ Command::appendCommandStatus(result, status);
+ return;
+ }
+
+ c->_commandsExecuted.increment();
+
+ if (c->shouldAffectCommandCounter()) {
+ globalOpCounters.gotCommand();
+ }
+
+ StatusWith<WriteConcernOptions> wcResult =
+ WriteConcernOptions::extractWCFromCommand(cmdObj, dbname);
+ if (!wcResult.isOK()) {
+ Command::appendCommandStatus(result, wcResult.getStatus());
+ return;
+ }
+
+ bool supportsWriteConcern = c->supportsWriteConcern(cmdObj);
+ if (!supportsWriteConcern && !wcResult.getValue().usedDefault) {
+ // This command doesn't do writes so it should not be passed a writeConcern.
+ // If we did not use the default writeConcern, one was provided when it shouldn't have
+ // been by the user.
+ Command::appendCommandStatus(
+ result, Status(ErrorCodes::InvalidOptions, "Command does not support writeConcern"));
+ return;
+ }
+
+
+ // attach tracking
+ rpc::TrackingMetadata trackingMetadata;
+ trackingMetadata.initWithOperName(c->getName());
+ rpc::TrackingMetadata::get(txn) = trackingMetadata;
+
+ std::string errmsg;
+ bool ok = false;
+ try {
+ if (!supportsWriteConcern) {
+ ok = c->run(txn, dbname, cmdObj, queryOptions, errmsg, result);
+ } else {
+ // Change the write concern while running the command.
+ const auto oldWC = txn->getWriteConcern();
+ ON_BLOCK_EXIT([&] { txn->setWriteConcern(oldWC); });
+ txn->setWriteConcern(wcResult.getValue());
+
+ ok = c->run(txn, dbname, cmdObj, queryOptions, errmsg, result);
+ }
+ } catch (const DBException& e) {
+ result.resetToEmpty();
+ const int code = e.getCode();
+
+ // Codes for StaleConfigException
+ if (code == ErrorCodes::RecvStaleConfig || code == ErrorCodes::SendStaleConfig) {
+ throw;
+ }
+
+ errmsg = e.what();
+ result.append("code", code);
+ }
+
+ if (!ok) {
+ c->_commandsFailed.increment();
+ }
+
+ Command::appendCommandStatus(result, ok, errmsg);
+}
+
} // namespace mongo
diff --git a/src/mongo/s/query/SConscript b/src/mongo/s/query/SConscript
index b560529ae3c..51b60590239 100644
--- a/src/mongo/s/query/SConscript
+++ b/src/mongo/s/query/SConscript
@@ -54,7 +54,6 @@ env.CppUnitTest(
'router_exec_stage',
'$BUILD_DIR/mongo/db/auth/authorization_manager_mock_init',
'$BUILD_DIR/mongo/db/service_context_noop_init',
- '$BUILD_DIR/mongo/s/mongoscore',
],
)
@@ -119,7 +118,6 @@ env.CppUnitTest(
'store_possible_cursor',
'$BUILD_DIR/mongo/db/auth/authorization_manager_mock_init',
'$BUILD_DIR/mongo/db/service_context_noop_init',
- '$BUILD_DIR/mongo/s/mongoscore',
'$BUILD_DIR/mongo/util/clock_source_mock',
],
)
@@ -166,6 +164,5 @@ env.CppUnitTest(
'cluster_client_cursor',
'$BUILD_DIR/mongo/db/auth/authorization_manager_mock_init',
'$BUILD_DIR/mongo/db/service_context_noop_init',
- '$BUILD_DIR/mongo/s/mongoscore',
],
)
diff --git a/src/mongo/s/s_only.cpp b/src/mongo/s/s_only.cpp
deleted file mode 100644
index 609a01910a8..00000000000
--- a/src/mongo/s/s_only.cpp
+++ /dev/null
@@ -1,179 +0,0 @@
-/**
- * Copyright (C) 2009-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.
- */
-
-#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kSharding
-
-#include "mongo/platform/basic.h"
-
-#include <tuple>
-
-#include "mongo/base/init.h"
-#include "mongo/db/auth/authorization_manager.h"
-#include "mongo/db/auth/authorization_manager_global.h"
-#include "mongo/db/auth/authorization_session.h"
-#include "mongo/db/client.h"
-#include "mongo/db/commands.h"
-#include "mongo/db/operation_context.h"
-#include "mongo/db/service_context.h"
-#include "mongo/db/stats/counters.h"
-#include "mongo/db/write_concern_options.h"
-#include "mongo/rpc/metadata.h"
-#include "mongo/rpc/metadata/tracking_metadata.h"
-#include "mongo/rpc/reply_builder_interface.h"
-#include "mongo/rpc/request_interface.h"
-#include "mongo/util/assert_util.h"
-#include "mongo/util/concurrency/thread_name.h"
-#include "mongo/util/log.h"
-#include "mongo/util/scopeguard.h"
-
-void mongo::execCommandClient(OperationContext* txn,
- Command* c,
- int queryOptions,
- const char* ns,
- BSONObj& cmdObj,
- BSONObjBuilder& result) {
- std::string dbname = nsToDatabase(ns);
-
- if (cmdObj.getBoolField("help")) {
- std::stringstream help;
- help << "help for: " << c->getName() << " ";
- c->help(help);
- result.append("help", help.str());
- Command::appendCommandStatus(result, true, "");
- return;
- }
-
- Status status = Command::checkAuthorization(c, txn, dbname, cmdObj);
- if (!status.isOK()) {
- Command::appendCommandStatus(result, status);
- return;
- }
-
- c->_commandsExecuted.increment();
-
- if (c->shouldAffectCommandCounter()) {
- globalOpCounters.gotCommand();
- }
-
- StatusWith<WriteConcernOptions> wcResult =
- WriteConcernOptions::extractWCFromCommand(cmdObj, dbname);
- if (!wcResult.isOK()) {
- Command::appendCommandStatus(result, wcResult.getStatus());
- return;
- }
-
- bool supportsWriteConcern = c->supportsWriteConcern(cmdObj);
- if (!supportsWriteConcern && !wcResult.getValue().usedDefault) {
- // This command doesn't do writes so it should not be passed a writeConcern.
- // If we did not use the default writeConcern, one was provided when it shouldn't have
- // been by the user.
- Command::appendCommandStatus(
- result, Status(ErrorCodes::InvalidOptions, "Command does not support writeConcern"));
- return;
- }
-
-
- // attach tracking
- rpc::TrackingMetadata trackingMetadata;
- trackingMetadata.initWithOperName(c->getName());
- rpc::TrackingMetadata::get(txn) = trackingMetadata;
-
- std::string errmsg;
- bool ok = false;
- try {
- if (!supportsWriteConcern) {
- ok = c->run(txn, dbname, cmdObj, queryOptions, errmsg, result);
- } else {
- // Change the write concern while running the command.
- const auto oldWC = txn->getWriteConcern();
- ON_BLOCK_EXIT([&] { txn->setWriteConcern(oldWC); });
- txn->setWriteConcern(wcResult.getValue());
-
- ok = c->run(txn, dbname, cmdObj, queryOptions, errmsg, result);
- }
- } catch (const DBException& e) {
- result.resetToEmpty();
- const int code = e.getCode();
-
- // Codes for StaleConfigException
- if (code == ErrorCodes::RecvStaleConfig || code == ErrorCodes::SendStaleConfig) {
- throw;
- }
-
- errmsg = e.what();
- result.append("code", code);
- }
-
- if (!ok) {
- c->_commandsFailed.increment();
- }
-
- Command::appendCommandStatus(result, ok, errmsg);
-}
-
-namespace mongo {
-
-using std::string;
-using std::stringstream;
-
-namespace {
-// called into by the web server. For now we just translate the parameters
-// to their old style equivalents.
-void execCommandHandler(OperationContext* txn,
- Command* command,
- const rpc::RequestInterface& request,
- rpc::ReplyBuilderInterface* replyBuilder) {
- int queryFlags = 0;
- BSONObj cmdObj;
-
- std::tie(cmdObj, queryFlags) = uassertStatusOK(
- rpc::downconvertRequestMetadata(request.getCommandArgs(), request.getMetadata()));
-
- std::string db = request.getDatabase().rawData();
- BSONObjBuilder result;
-
- execCommandClient(txn, command, queryFlags, request.getDatabase().rawData(), cmdObj, result);
-
- replyBuilder->setCommandReply(result.done()).setMetadata(rpc::makeEmptyMetadata());
-}
-MONGO_INITIALIZER(InitializeCommandExecCommandHandler)(InitializerContext* const) {
- Command::registerExecCommand(execCommandHandler);
- return Status::OK();
-}
-} // namespace
-
-namespace {
-void registerErrorImpl(OperationContext* txn, const DBException& exception) {}
-
-MONGO_INITIALIZER(InitializeRegisterErrorHandler)(InitializerContext* const) {
- Command::registerRegisterError(registerErrorImpl);
- return Status::OK();
-}
-} // namespace
-
-} // namespace mongo
diff --git a/src/mongo/s/s_sharding_server_status.cpp b/src/mongo/s/s_sharding_server_status.cpp
index 1d37f83c9c4..7fa52987aaf 100644
--- a/src/mongo/s/s_sharding_server_status.cpp
+++ b/src/mongo/s/s_sharding_server_status.cpp
@@ -34,40 +34,31 @@
#include "mongo/s/grid.h"
namespace mongo {
-
namespace {
-class ShardingServerStatus : public ServerStatusSection {
+class ShardingServerStatus final : public ServerStatusSection {
public:
- ShardingServerStatus();
-
- bool includeByDefault() const final;
+ ShardingServerStatus() : ServerStatusSection("sharding") {}
- BSONObj generateSection(OperationContext* txn, const BSONElement& configElement) const final;
-};
-
-} // namespace
+ bool includeByDefault() const override {
+ return true;
+ }
-ShardingServerStatus shardingServerStatus;
+ BSONObj generateSection(OperationContext* txn,
+ const BSONElement& configElement) const override {
+ auto shardRegistry = Grid::get(txn)->shardRegistry();
+ invariant(shardRegistry);
-ShardingServerStatus::ShardingServerStatus() : ServerStatusSection("sharding") {}
+ BSONObjBuilder result;
+ result.append("configsvrConnectionString",
+ shardRegistry->getConfigServerConnectionString().toString());
-bool ShardingServerStatus::includeByDefault() const {
- return true;
-}
+ Grid::get(txn)->configOpTime().append(&result, "lastSeenConfigServerOpTime");
-// This implementation runs on mongoS.
-BSONObj ShardingServerStatus::generateSection(OperationContext* txn,
- const BSONElement& configElement) const {
- invariant(grid.shardRegistry());
+ return result.obj();
+ }
- BSONObjBuilder result;
- result.append("configsvrConnectionString",
- grid.shardRegistry()->getConfigServerConnectionString().toString());
-
- grid.configOpTime().append(&result, "lastSeenConfigServerOpTime");
-
- return result.obj();
-}
+} shardingServerStatus;
+} // namespace
} // namespace mongo