summaryrefslogtreecommitdiff
path: root/src/mongo/db
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/db
parent9fe5c85db8a6aa1432807d8c473360a81a9a2eaf (diff)
downloadmongo-fe488bc9f33d81fbc77f179b4e77effc4f0844fc.tar.gz
SERVER-62261: Implement getClusterParameter command on mongod and mongos
Diffstat (limited to 'src/mongo/db')
-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
10 files changed, 185 insertions, 11 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.
*/