diff options
author | Cheahuychou Mao <mao.cheahuychou@gmail.com> | 2022-09-15 19:54:35 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-09-15 22:34:59 +0000 |
commit | 6d10aea7079ac0f73c443346f929c2989c97532a (patch) | |
tree | 6de108b18c63b6fe3226f5af0ffdda3756f3327d /src/mongo/db | |
parent | 7fca187deec6b2b28339bbb8613a9f8809ab07c8 (diff) | |
download | mongo-6d10aea7079ac0f73c443346f929c2989c97532a.tar.gz |
SERVER-69528 Link cluster count command into mongod
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/s/SConscript | 2 | ||||
-rw-r--r-- | src/mongo/db/s/cluster_count_cmd_d.cpp | 66 |
2 files changed, 68 insertions, 0 deletions
diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript index a437bc2579c..da2bc3faf03 100644 --- a/src/mongo/db/s/SConscript +++ b/src/mongo/db/s/SConscript @@ -360,6 +360,7 @@ env.Library( 'clone_catalog_data_command.cpp', 'cluster_abort_transaction_cmd_d.cpp', 'cluster_commit_transaction_cmd_d.cpp', + 'cluster_count_cmd_d.cpp', 'cluster_find_cmd_d.cpp', 'cluster_getmore_cmd_d.cpp', 'cluster_pipeline_cmd_d.cpp', @@ -517,6 +518,7 @@ env.Library( '$BUILD_DIR/mongo/s/commands/sharded_cluster_sharding_commands', '$BUILD_DIR/mongo/s/sharding_initialization', '$BUILD_DIR/mongo/s/sharding_router_api', + '$BUILD_DIR/mongo/s/startup_initialization', 'forwardable_operation_metadata', 'sharding_logging', 'sharding_runtime_d', diff --git a/src/mongo/db/s/cluster_count_cmd_d.cpp b/src/mongo/db/s/cluster_count_cmd_d.cpp new file mode 100644 index 00000000000..e291ec2ee29 --- /dev/null +++ b/src/mongo/db/s/cluster_count_cmd_d.cpp @@ -0,0 +1,66 @@ +/** + * Copyright (C) 2022-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * 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 + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * <http://www.mongodb.com/licensing/server-side-public-license>. + * + * 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 Server Side 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/db/s/sharding_state.h" +#include "mongo/s/commands/cluster_count_cmd.h" +#include "mongo/s/grid.h" + +namespace mongo { +namespace { + +/** + * Implements the cluster count command on mongod. + */ +struct ClusterCountCmdD { + static constexpr StringData kName = "clusterCount"_sd; + + static const std::set<std::string>& getApiVersions() { + return kNoApiVersions; + } + + static void addRequiredPrivileges(const std::string& dbname, + const BSONObj& cmdObj, + std::vector<Privilege>* out) { + ActionSet actions; + actions.addAction(ActionType::internal); + out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); + } + + static void checkCanRunHere(OperationContext* opCtx) { + Grid::get(opCtx)->assertShardingIsInitialized(); + + // A cluster command on the config server may attempt to use a ShardLocal to target itself, + // which triggers an invariant, so only shard servers can run this. + uassertStatusOK(ShardingState::get(opCtx)->canAcceptShardedCommands()); + } +}; +ClusterCountCmdBase<ClusterCountCmdD> clusterCountCmdD; + +} // namespace +} // namespace mongo |