summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorVarun Ravichandran <varun.ravichandran@mongodb.com>2022-03-17 23:50:53 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-04-01 19:24:56 +0000
commitfe488bc9f33d81fbc77f179b4e77effc4f0844fc (patch)
tree8c81733111eb1d6266be62a734238462717255e8 /src/mongo
parent9fe5c85db8a6aa1432807d8c473360a81a9a2eaf (diff)
downloadmongo-fe488bc9f33d81fbc77f179b4e77effc4f0844fc.tar.gz
SERVER-62261: Implement getClusterParameter command on mongod and mongos
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/auth/action_type.idl1
-rw-r--r--src/mongo/db/auth/builtin_roles.cpp3
-rw-r--r--src/mongo/db/commands/SConscript9
-rw-r--r--src/mongo/db/commands/cluster_server_parameter_cmds.idl (renamed from src/mongo/db/commands/set_cluster_parameter.idl)21
-rw-r--r--src/mongo/db/commands/get_cluster_parameter_command.cpp142
-rw-r--r--src/mongo/db/commands/set_cluster_parameter_command.cpp6
-rw-r--r--src/mongo/db/commands/set_cluster_parameter_invocation.cpp4
-rw-r--r--src/mongo/db/commands/set_cluster_parameter_invocation.h4
-rw-r--r--src/mongo/db/namespace_string.cpp3
-rw-r--r--src/mongo/db/namespace_string.h3
-rw-r--r--src/mongo/idl/SConscript1
-rw-r--r--src/mongo/idl/cluster_server_parameter.idl38
-rw-r--r--src/mongo/s/SConscript2
-rw-r--r--src/mongo/s/commands/SConscript3
-rw-r--r--src/mongo/s/commands/cluster_get_cluster_parameter_cmd.cpp188
-rw-r--r--src/mongo/s/commands/cluster_set_cluster_parameter_cmd.cpp2
16 files changed, 415 insertions, 15 deletions
diff --git a/src/mongo/db/auth/action_type.idl b/src/mongo/db/auth/action_type.idl
index dc11b26fb4a..6cfbd32d0a9 100644
--- a/src/mongo/db/auth/action_type.idl
+++ b/src/mongo/db/auth/action_type.idl
@@ -97,6 +97,7 @@ enums:
forceUUID : "forceUUID"
fsync : "fsync"
getChangeStreamOptions: "getChangeStreamOptions"
+ getClusterParameter: "getClusterParameter"
getDatabaseVersion : "getDatabaseVersion"
getDefaultRWConcern : "getDefaultRWConcern"
getCmdLineOpts : "getCmdLineOpts"
diff --git a/src/mongo/db/auth/builtin_roles.cpp b/src/mongo/db/auth/builtin_roles.cpp
index cbad7142669..70331b72391 100644
--- a/src/mongo/db/auth/builtin_roles.cpp
+++ b/src/mongo/db/auth/builtin_roles.cpp
@@ -255,7 +255,8 @@ MONGO_INITIALIZER(AuthorizationBuiltinRoles)(InitializerContext* context) {
<< ActionType::setFreeMonitoring
<< ActionType::setChangeStreamOptions
<< ActionType::getChangeStreamOptions
- << ActionType::setClusterParameter;
+ << ActionType::setClusterParameter
+ << ActionType::getClusterParameter;
clusterManagerRoleDatabaseActions
<< ActionType::clearJumboFlag
diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript
index d28bd5d286b..cd2f7b33a87 100644
--- a/src/mongo/db/commands/SConscript
+++ b/src/mongo/db/commands/SConscript
@@ -322,9 +322,9 @@ env.Library(
)
env.Library(
- target='set_cluster_parameter_idl',
+ target='cluster_server_parameter_cmds_idl',
source=[
- 'set_cluster_parameter.idl',
+ 'cluster_server_parameter_cmds.idl',
],
LIBDEPS=[
'$BUILD_DIR/mongo/base',
@@ -535,6 +535,7 @@ env.Library(
"dbcommands_d.cpp",
"dbhash.cpp",
"driverHelpers.cpp",
+ 'get_cluster_parameter_command.cpp',
"internal_rename_if_options_and_indexes_match_cmd.cpp",
"fle2_compact_cmd.cpp",
"map_reduce_command.cpp",
@@ -638,7 +639,7 @@ env.Library(
LIBDEPS=[
'$BUILD_DIR/mongo/base',
'$BUILD_DIR/mongo/s/write_ops/cluster_write_ops',
- 'set_cluster_parameter_idl'
+ 'cluster_server_parameter_cmds_idl'
],
)
@@ -849,4 +850,4 @@ env.CppUnitTest(
"set_cluster_parameter_invocation",
"standalone",
],
-) \ No newline at end of file
+)
diff --git a/src/mongo/db/commands/set_cluster_parameter.idl b/src/mongo/db/commands/cluster_server_parameter_cmds.idl
index b20af08dc8e..9c768f43f23 100644
--- a/src/mongo/db/commands/set_cluster_parameter.idl
+++ b/src/mongo/db/commands/cluster_server_parameter_cmds.idl
@@ -27,17 +27,34 @@
#
global:
- cpp_namespace: "mongo"
+ cpp_namespace: "mongo"
imports:
- "mongo/idl/basic_types.idl"
+structs:
+ GetClusterParameterReply:
+ description: "Reply to getClusterParameter command"
+ fields:
+ clusterParameters: array<object>
+
commands:
setClusterParameter:
- description: Command to set a ClusterServerParameter
+ description: "Command to set a ClusterServerParameter"
command_name: setClusterParameter
cpp_name: SetClusterParameter
api_version: ""
namespace: type
type: object
strict: true
+
+ getClusterParameter:
+ description: "Retrieves the in-memory value of the specified cluster server parameter(s)"
+ command_name: getClusterParameter
+ cpp_name: GetClusterParameter
+ api_version: ""
+ namespace: type
+ type:
+ variant: [string, array<string>]
+ reply_type: GetClusterParameterReply
+ strict: false
diff --git a/src/mongo/db/commands/get_cluster_parameter_command.cpp b/src/mongo/db/commands/get_cluster_parameter_command.cpp
new file mode 100644
index 00000000000..76f6f91c590
--- /dev/null
+++ b/src/mongo/db/commands/get_cluster_parameter_command.cpp
@@ -0,0 +1,142 @@
+/**
+ * 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.
+ */
+
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kCommand
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/db/auth/authorization_session.h"
+#include "mongo/db/commands.h"
+#include "mongo/db/commands/cluster_server_parameter_cmds_gen.h"
+#include "mongo/idl/cluster_server_parameter_gen.h"
+#include "mongo/logv2/log.h"
+
+namespace mongo {
+
+namespace {
+
+class GetClusterParameterCommand final : public TypedCommand<GetClusterParameterCommand> {
+public:
+ using Request = GetClusterParameter;
+ using Reply = GetClusterParameter::Reply;
+ using Map = ServerParameterSet::Map;
+
+ AllowedOnSecondary secondaryAllowed(ServiceContext*) const override {
+ return AllowedOnSecondary::kAlways;
+ }
+
+ bool adminOnly() const override {
+ return true;
+ }
+
+ std::string help() const override {
+ return "Get in-memory cluster parameter value(s) from this node";
+ }
+
+ class Invocation final : public InvocationBase {
+ public:
+ using InvocationBase::InvocationBase;
+
+ Reply typedRun(OperationContext* opCtx) {
+ uassert(
+ ErrorCodes::IllegalOperation,
+ "featureFlagClusterWideConfig not enabled",
+ gFeatureFlagClusterWideConfig.isEnabled(serverGlobalParams.featureCompatibility));
+
+ const stdx::variant<std::string, std::vector<std::string>>& cmdBody =
+ request().getCommandParameter();
+ ServerParameterSet* clusterParameters = ServerParameterSet::getClusterParameterSet();
+ std::vector<BSONObj> parameterValues;
+ std::vector<std::string> parameterNames;
+
+ // For each parameter, generate a BSON representation of it and retrieve its name.
+ auto makeBSON = [&](ServerParameter* requestedParameter) {
+ BSONObjBuilder bob;
+ bob.append("_id"_sd, requestedParameter->name());
+ requestedParameter->append(opCtx, bob, requestedParameter->name());
+ parameterValues.push_back(bob.obj());
+ parameterNames.push_back(requestedParameter->name());
+ };
+
+ stdx::visit(
+ visit_helper::Overloaded{
+ [&](const std::string& strParameterName) {
+ if (strParameterName == "*"_sd) {
+ // Retrieve all cluster parameter values.
+ Map clusterParameterMap = clusterParameters->getMap();
+ parameterValues.reserve(clusterParameterMap.size());
+ parameterNames.reserve(clusterParameterMap.size());
+ for (const auto& param : clusterParameterMap) {
+ makeBSON(param.second);
+ }
+ } else {
+ // Any other string must correspond to a single parameter name.
+ ServerParameter* sp = clusterParameters->get(strParameterName);
+ makeBSON(sp);
+ }
+ },
+ [&](const std::vector<std::string>& listParameterNames) {
+ parameterValues.reserve(listParameterNames.size());
+ parameterNames.reserve(listParameterNames.size());
+ for (const auto& requestedParameterName : listParameterNames) {
+ ServerParameter* sp = clusterParameters->get(requestedParameterName);
+ makeBSON(sp);
+ }
+ }},
+ cmdBody);
+
+ LOGV2_DEBUG(6226100,
+ 2,
+ "Retrieved parameter values for cluster server parameters",
+ "parameterNames"_attr = parameterNames);
+
+ return Reply(parameterValues);
+ }
+
+ private:
+ bool supportsWriteConcern() const override {
+ return false;
+ }
+
+ void doCheckAuthorization(OperationContext* opCtx) const override {
+ auto* authzSession = AuthorizationSession::get(opCtx->getClient());
+ uassert(ErrorCodes::Unauthorized,
+ "Not authorized to retrieve cluster server parameters",
+ authzSession->isAuthorizedForPrivilege(Privilege{
+ ResourcePattern::forClusterResource(), ActionType::getClusterParameter}));
+ }
+
+ NamespaceString ns() const override {
+ return NamespaceString(request().getDbName(), "");
+ }
+ };
+} getClusterParameterCommand;
+
+} // namespace
+} // namespace mongo
diff --git a/src/mongo/db/commands/set_cluster_parameter_command.cpp b/src/mongo/db/commands/set_cluster_parameter_command.cpp
index b5285dbeae3..9d4074ac0bc 100644
--- a/src/mongo/db/commands/set_cluster_parameter_command.cpp
+++ b/src/mongo/db/commands/set_cluster_parameter_command.cpp
@@ -27,13 +27,16 @@
* it in the license file.
*/
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kCommand
+
#include "mongo/platform/basic.h"
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/commands.h"
-#include "mongo/db/commands/set_cluster_parameter_gen.h"
+#include "mongo/db/commands/cluster_server_parameter_cmds_gen.h"
#include "mongo/db/commands/set_cluster_parameter_invocation.h"
#include "mongo/idl/cluster_server_parameter_gen.h"
+#include "mongo/logv2/log.h"
namespace mongo {
@@ -94,5 +97,6 @@ public:
}
};
} setClusterParameterCommand;
+
} // namespace
} // namespace mongo
diff --git a/src/mongo/db/commands/set_cluster_parameter_invocation.cpp b/src/mongo/db/commands/set_cluster_parameter_invocation.cpp
index 4cb1087996a..513ae376564 100644
--- a/src/mongo/db/commands/set_cluster_parameter_invocation.cpp
+++ b/src/mongo/db/commands/set_cluster_parameter_invocation.cpp
@@ -31,10 +31,10 @@
#include "mongo/platform/basic.h"
+#include "mongo/db/commands/set_cluster_parameter_invocation.h"
+
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/commands.h"
-#include "mongo/db/commands/set_cluster_parameter_gen.h"
-#include "mongo/db/commands/set_cluster_parameter_invocation.h"
#include "mongo/db/vector_clock.h"
#include "mongo/idl/cluster_server_parameter_gen.h"
#include "mongo/logv2/log.h"
diff --git a/src/mongo/db/commands/set_cluster_parameter_invocation.h b/src/mongo/db/commands/set_cluster_parameter_invocation.h
index 6077ccac5d9..35b74530a95 100644
--- a/src/mongo/db/commands/set_cluster_parameter_invocation.h
+++ b/src/mongo/db/commands/set_cluster_parameter_invocation.h
@@ -27,7 +27,9 @@
* it in the license file.
*/
-#include "mongo/db/commands/set_cluster_parameter_gen.h"
+#pragma once
+
+#include "mongo/db/commands/cluster_server_parameter_cmds_gen.h"
#include "mongo/db/dbdirectclient.h"
#include "mongo/db/dbhelpers.h"
diff --git a/src/mongo/db/namespace_string.cpp b/src/mongo/db/namespace_string.cpp
index 2eab32c841f..649423f106b 100644
--- a/src/mongo/db/namespace_string.cpp
+++ b/src/mongo/db/namespace_string.cpp
@@ -162,6 +162,9 @@ const NamespaceString NamespaceString::kUserWritesCriticalSectionsNamespace(
const NamespaceString NamespaceString::kCompactStructuredEncryptionCoordinatorNamespace(
NamespaceString::kConfigDb, "compact_structured_encryption_coordinator");
+const NamespaceString NamespaceString::kClusterParametersNamespace(NamespaceString::kConfigDb,
+ "clusterParameters");
+
bool NamespaceString::isListCollectionsCursorNS() const {
return coll() == listCollectionsCursorCol;
}
diff --git a/src/mongo/db/namespace_string.h b/src/mongo/db/namespace_string.h
index 599f5aac11f..4d1dba82f83 100644
--- a/src/mongo/db/namespace_string.h
+++ b/src/mongo/db/namespace_string.h
@@ -216,6 +216,9 @@ public:
// Namespace used for CompactParticipantCoordinator service.
static const NamespaceString kCompactStructuredEncryptionCoordinatorNamespace;
+ // Namespace used for storing cluster wide parameters.
+ static const NamespaceString kClusterParametersNamespace;
+
/**
* Constructs an empty NamespaceString.
*/
diff --git a/src/mongo/idl/SConscript b/src/mongo/idl/SConscript
index 17520eafd06..a63af90f83a 100644
--- a/src/mongo/idl/SConscript
+++ b/src/mongo/idl/SConscript
@@ -61,7 +61,6 @@ env.Library(
LIBDEPS_PRIVATE=[
'feature_flag',
'idl_parser',
- 'server_parameter',
],
)
diff --git a/src/mongo/idl/cluster_server_parameter.idl b/src/mongo/idl/cluster_server_parameter.idl
index 762f33006ee..dc1b53ee0e6 100644
--- a/src/mongo/idl/cluster_server_parameter.idl
+++ b/src/mongo/idl/cluster_server_parameter.idl
@@ -51,9 +51,47 @@ structs:
In normal operation, the clusterParameterTime will increase as the CSP is updated via
setClusterParameter, but may decrease to a previously-seen value on rollback.
type: logicalTime
+ default: LogicalTime::kUninitialized
+
+ TestIntClusterParameterStorage:
+ description: "Storage used for testIntClusterParameter"
+ inline_chained_structs: true
+ chained_structs:
+ ClusterServerParameter: ClusterServerParameter
+ fields:
+ intData:
+ description: "Some int parameter"
+ type: safeInt64
+ default: 16
+
+ TestStrClusterParameterStorage:
+ description: "Storage used for testStrClusterParameter"
+ inline_chained_structs: true
+ chained_structs:
+ ClusterServerParameter: ClusterServerParameter
+ fields:
+ strData:
+ description: "Some string parameter"
+ type: string
+ default: "\"off\""
feature_flags:
featureFlagClusterWideConfig:
description: Mechanism for cluster-wide configuration options
cpp_varname: gFeatureFlagClusterWideConfig
default: false
+
+server_parameters:
+ testIntClusterParameter:
+ set_at: cluster
+ description: "Test cluster parameter that is only usable if enableTestCommands=true"
+ cpp_vartype: TestIntClusterParameterStorage
+ cpp_varname: intStorage
+ test_only: true
+
+ testStrClusterParameter:
+ set_at: cluster
+ description: "Test cluster parameter that is only usable if enableTestCommands=true"
+ cpp_vartype: TestStrClusterParameterStorage
+ cpp_varname: strStorage
+ test_only: true
diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript
index 187e802d613..bfc36af2a0f 100644
--- a/src/mongo/s/SConscript
+++ b/src/mongo/s/SConscript
@@ -234,7 +234,7 @@ env.Library(
LIBDEPS=[
'$BUILD_DIR/mongo/client/connection_string',
'$BUILD_DIR/mongo/db/coll_mod_command_idl',
- '$BUILD_DIR/mongo/db/commands/set_cluster_parameter_idl',
+ '$BUILD_DIR/mongo/db/commands/cluster_server_parameter_cmds_idl',
'$BUILD_DIR/mongo/db/commands/set_user_write_block_mode_idl',
'$BUILD_DIR/mongo/db/common',
'$BUILD_DIR/mongo/db/namespace_string',
diff --git a/src/mongo/s/commands/SConscript b/src/mongo/s/commands/SConscript
index 385824d19f6..d80e09c82d3 100644
--- a/src/mongo/s/commands/SConscript
+++ b/src/mongo/s/commands/SConscript
@@ -60,6 +60,7 @@ env.Library(
'cluster_fle2_compact_cmd.cpp',
'cluster_fsync_cmd.cpp',
'cluster_ftdc_commands.cpp',
+ 'cluster_get_cluster_parameter_cmd.cpp',
'cluster_get_last_error_cmd.cpp',
'cluster_get_shard_version_cmd.cpp',
'cluster_getmore_cmd_s.cpp',
@@ -106,6 +107,7 @@ env.Library(
'$BUILD_DIR/mongo/db/api_parameters',
'$BUILD_DIR/mongo/db/auth/auth_checks',
'$BUILD_DIR/mongo/db/commands/change_stream_options',
+ '$BUILD_DIR/mongo/db/commands/cluster_server_parameter_cmds_idl',
'$BUILD_DIR/mongo/db/commands/core',
'$BUILD_DIR/mongo/db/commands/create_command',
'$BUILD_DIR/mongo/db/commands/current_op_common',
@@ -118,7 +120,6 @@ env.Library(
'$BUILD_DIR/mongo/db/commands/rwc_defaults_commands',
'$BUILD_DIR/mongo/db/commands/server_status',
'$BUILD_DIR/mongo/db/commands/servers',
- '$BUILD_DIR/mongo/db/commands/set_cluster_parameter_idl',
'$BUILD_DIR/mongo/db/commands/set_feature_compatibility_version_idl',
'$BUILD_DIR/mongo/db/commands/set_index_commit_quorum_idl',
'$BUILD_DIR/mongo/db/commands/set_user_write_block_mode_idl',
diff --git a/src/mongo/s/commands/cluster_get_cluster_parameter_cmd.cpp b/src/mongo/s/commands/cluster_get_cluster_parameter_cmd.cpp
new file mode 100644
index 00000000000..7f5022ab989
--- /dev/null
+++ b/src/mongo/s/commands/cluster_get_cluster_parameter_cmd.cpp
@@ -0,0 +1,188 @@
+/**
+ * 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.
+ */
+
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/db/auth/authorization_session.h"
+#include "mongo/db/commands.h"
+#include "mongo/db/commands/cluster_server_parameter_cmds_gen.h"
+#include "mongo/idl/cluster_server_parameter_gen.h"
+#include "mongo/logv2/log.h"
+#include "mongo/s/cluster_commands_helpers.h"
+#include "mongo/s/grid.h"
+#include "mongo/s/request_types/sharded_ddl_commands_gen.h"
+
+namespace mongo {
+namespace {
+
+class GetClusterParameterCmd final : public TypedCommand<GetClusterParameterCmd> {
+public:
+ using Request = GetClusterParameter;
+ using Reply = GetClusterParameter::Reply;
+ using Map = ServerParameterSet::Map;
+
+ AllowedOnSecondary secondaryAllowed(ServiceContext*) const override {
+ return AllowedOnSecondary::kAlways;
+ }
+
+ bool adminOnly() const override {
+ return true;
+ }
+
+ std::string help() const override {
+ return "Get majority-written cluster parameter value(s) from the config servers";
+ }
+
+ class Invocation final : public InvocationBase {
+ public:
+ using InvocationBase::InvocationBase;
+
+ Reply typedRun(OperationContext* opCtx) {
+ uassert(
+ ErrorCodes::IllegalOperation,
+ "featureFlagClusterWideConfig not enabled",
+ gFeatureFlagClusterWideConfig.isEnabled(serverGlobalParams.featureCompatibility));
+
+ // For now, the mongos implementation retrieves the names of the requested cluster
+ // server parameters and queries them from the config.clusterParameters namespace on
+ // the config servers. This may change after SERVER-62264, when cluster server
+ // parameters will be cached on mongoses as well.
+ auto configServers = Grid::get(opCtx)->shardRegistry()->getConfigShard();
+
+ // Create the query document such that all documents in config.clusterParmeters with _id
+ // in the requested list of ServerParameters are returned.
+ const stdx::variant<std::string, std::vector<std::string>>& cmdBody =
+ request().getCommandParameter();
+ ServerParameterSet* clusterParameters = ServerParameterSet::getClusterParameterSet();
+
+ std::vector<std::string> requestedParameterNames;
+ BSONObjBuilder queryDocBuilder;
+ BSONObjBuilder inObjBuilder = queryDocBuilder.subobjStart("_id"_sd);
+ BSONArrayBuilder parameterNameBuilder = inObjBuilder.subarrayStart("$in"_sd);
+
+ stdx::visit(
+ visit_helper::Overloaded{
+ [&](const std::string& strParameterName) {
+ if (strParameterName == "*"_sd) {
+ // Append all cluster parameter names.
+ Map clusterParameterMap = clusterParameters->getMap();
+ requestedParameterNames.reserve(clusterParameterMap.size());
+ for (const auto& param : clusterParameterMap) {
+ parameterNameBuilder.append(param.first);
+ requestedParameterNames.push_back(param.first);
+ }
+ } else {
+ parameterNameBuilder.append(strParameterName);
+ requestedParameterNames.push_back(strParameterName);
+ }
+ },
+ [&](const std::vector<std::string>& listParameterNames) {
+ requestedParameterNames.reserve(listParameterNames.size());
+ for (const auto& requestedParameterName : listParameterNames) {
+ parameterNameBuilder.append(requestedParameterName);
+ requestedParameterNames.push_back(requestedParameterName);
+ }
+ }},
+ cmdBody);
+
+ parameterNameBuilder.doneFast();
+ inObjBuilder.doneFast();
+
+ // Perform the majority read on the config server primary.
+ BSONObj query = queryDocBuilder.obj();
+ LOGV2(6226101, "Querying config servers for cluster parameters", "query"_attr = query);
+ auto findResponse = uassertStatusOK(configServers->exhaustiveFindOnConfig(
+ opCtx,
+ ReadPreferenceSetting{ReadPreference::PrimaryOnly},
+ repl::ReadConcernLevel::kMajorityReadConcern,
+ NamespaceString::kClusterParametersNamespace,
+ query,
+ BSONObj(),
+ boost::none));
+
+ // Any parameters that are not included in the response don't have a cluster parameter
+ // document yet, which means they still are using the default value.
+ std::vector<BSONObj> retrievedParameters = std::move(findResponse.docs);
+ if (retrievedParameters.size() < requestedParameterNames.size()) {
+ std::vector<std::string> onDiskParameterNames;
+ onDiskParameterNames.reserve(retrievedParameters.size());
+ std::transform(retrievedParameters.begin(),
+ retrievedParameters.end(),
+ std::back_inserter(onDiskParameterNames),
+ [&](const auto& onDiskParameter) {
+ return onDiskParameter["_id"_sd].String();
+ });
+
+ // Sort and find the set difference of the requested parameters and the parameters
+ // returned.
+ std::vector<std::string> defaultParameterNames;
+ defaultParameterNames.reserve(requestedParameterNames.size() -
+ onDiskParameterNames.size());
+ std::sort(onDiskParameterNames.begin(), onDiskParameterNames.end());
+ std::set_difference(requestedParameterNames.begin(),
+ requestedParameterNames.end(),
+ onDiskParameterNames.begin(),
+ onDiskParameterNames.end(),
+ std::back_inserter(defaultParameterNames));
+
+ for (const auto& defaultParameterName : defaultParameterNames) {
+ auto defaultParameter = clusterParameters->get(defaultParameterName);
+ BSONObjBuilder bob;
+ bob.append("_id"_sd, defaultParameterName);
+ defaultParameter->append(opCtx, bob, defaultParameterName);
+ retrievedParameters.push_back(bob.obj());
+ }
+ }
+
+ return Reply(retrievedParameters);
+ }
+
+ private:
+ bool supportsWriteConcern() const override {
+ return false;
+ }
+
+ void doCheckAuthorization(OperationContext* opCtx) const final {
+ auto* authzSession = AuthorizationSession::get(opCtx->getClient());
+ uassert(ErrorCodes::Unauthorized,
+ "Not authorized to retrieve cluster parameters",
+ authzSession->isAuthorizedForPrivilege(Privilege{
+ ResourcePattern::forClusterResource(), ActionType::getClusterParameter}));
+ }
+
+ NamespaceString ns() const override {
+ return NamespaceString(request().getDbName(), "");
+ }
+ };
+} getClusterParameterCmd;
+
+} // namespace
+} // namespace mongo
diff --git a/src/mongo/s/commands/cluster_set_cluster_parameter_cmd.cpp b/src/mongo/s/commands/cluster_set_cluster_parameter_cmd.cpp
index 6b5d4ce6e9e..32b304b903a 100644
--- a/src/mongo/s/commands/cluster_set_cluster_parameter_cmd.cpp
+++ b/src/mongo/s/commands/cluster_set_cluster_parameter_cmd.cpp
@@ -33,7 +33,7 @@
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/commands.h"
-#include "mongo/db/commands/set_cluster_parameter_gen.h"
+#include "mongo/db/commands/cluster_server_parameter_cmds_gen.h"
#include "mongo/s/cluster_commands_helpers.h"
#include "mongo/s/grid.h"
#include "mongo/s/request_types/sharded_ddl_commands_gen.h"