summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorMarcos José Grillo Ramirez <marcos.grillo@mongodb.com>2022-02-22 14:54:31 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-02-22 16:01:22 +0000
commit6ca25c9e65eeb1420a4dce3cba9ae4991d6106e7 (patch)
tree0388089b10059788e677b0e4e115f1ba5a3ee82a /src/mongo/db
parent379733ee85d84235e768621c1365f58532712d94 (diff)
downloadmongo-6ca25c9e65eeb1420a4dce3cba9ae4991d6106e7.tar.gz
SERVER-63431 Add SetClusterParameter coordinator
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/s/SConscript2
-rw-r--r--src/mongo/db/s/config/set_cluster_parameter_coordinator.cpp93
-rw-r--r--src/mongo/db/s/config/set_cluster_parameter_coordinator.h80
-rw-r--r--src/mongo/db/s/config/set_cluster_parameter_coordinator_document.idl57
4 files changed, 232 insertions, 0 deletions
diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript
index cc2b45f727f..db55136a9a3 100644
--- a/src/mongo/db/s/SConscript
+++ b/src/mongo/db/s/SConscript
@@ -286,6 +286,8 @@ env.Library(
'clone_collection_options_from_primary_shard_cmd.cpp',
'collmod_coordinator.cpp',
'collmod_coordinator_document.idl',
+ 'config/set_cluster_parameter_coordinator.cpp',
+ 'config/set_cluster_parameter_coordinator_document.idl',
'config/set_user_write_block_mode_coordinator.cpp',
'config/set_user_write_block_mode_coordinator_document.idl',
'config/configsvr_abort_reshard_collection_command.cpp',
diff --git a/src/mongo/db/s/config/set_cluster_parameter_coordinator.cpp b/src/mongo/db/s/config/set_cluster_parameter_coordinator.cpp
new file mode 100644
index 00000000000..3dc3d24746f
--- /dev/null
+++ b/src/mongo/db/s/config/set_cluster_parameter_coordinator.cpp
@@ -0,0 +1,93 @@
+/**
+ * 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/s/config/set_cluster_parameter_coordinator.h"
+
+#include "mongo/logv2/log.h"
+#include "mongo/s/request_types/sharded_ddl_commands_gen.h"
+
+namespace mongo {
+
+bool SetClusterParameterCoordinator::hasSameOptions(const BSONObj&) {
+ // TODO SERVER-63870: add command parameters to comparison.
+ return true;
+}
+
+boost::optional<BSONObj> SetClusterParameterCoordinator::reportForCurrentOp(
+ MongoProcessInterface::CurrentOpConnectionsMode connMode,
+ MongoProcessInterface::CurrentOpSessionsMode sessionMode) noexcept {
+
+ BSONObjBuilder bob;
+ bob.append("type", "op");
+ bob.append("desc", "SetClusterParameterCoordinator");
+ bob.append("op", "command");
+ bob.append("currentPhase", _doc.getPhase());
+ bob.append("active", true);
+ return bob.obj();
+}
+
+void SetClusterParameterCoordinator::_enterPhase(Phase newPhase) {
+ StateDoc newDoc(_doc);
+ newDoc.setPhase(newPhase);
+
+ LOGV2_DEBUG(6343101,
+ 2,
+ "SetClusterParameterCoordinator phase transition",
+ "newPhase"_attr = SetClusterParameterCoordinatorPhase_serializer(newDoc.getPhase()),
+ "oldPhase"_attr = SetClusterParameterCoordinatorPhase_serializer(_doc.getPhase()));
+
+ auto opCtx = cc().makeOperationContext();
+ PersistentTaskStore<StateDoc> store(NamespaceString::kConfigsvrCoordinatorsNamespace);
+
+ if (_doc.getPhase() == Phase::kUnset) {
+ store.add(opCtx.get(), newDoc, WriteConcerns::kMajorityWriteConcernShardingTimeout);
+ } else {
+ store.update(opCtx.get(),
+ BSON(StateDoc::kIdFieldName << _coordId.toBSON()),
+ newDoc.toBSON(),
+ WriteConcerns::kMajorityWriteConcernNoTimeout);
+ }
+
+ _doc = std::move(newDoc);
+}
+
+ExecutorFuture<void> SetClusterParameterCoordinator::_runImpl(
+ std::shared_ptr<executor::ScopedTaskExecutor> executor,
+ const CancellationToken& token) noexcept {
+ return ExecutorFuture<void>(**executor)
+ .then(_executePhase(Phase::kSetClusterParameter, [this, anchor = shared_from_this()] {
+ // TODO Implement
+ }));
+}
+
+} // namespace mongo
diff --git a/src/mongo/db/s/config/set_cluster_parameter_coordinator.h b/src/mongo/db/s/config/set_cluster_parameter_coordinator.h
new file mode 100644
index 00000000000..6331dc1419d
--- /dev/null
+++ b/src/mongo/db/s/config/set_cluster_parameter_coordinator.h
@@ -0,0 +1,80 @@
+/**
+ * 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.
+ */
+
+#pragma once
+
+#include "mongo/db/internal_session_pool.h"
+#include "mongo/db/s/config/configsvr_coordinator.h"
+#include "mongo/db/s/config/set_cluster_parameter_coordinator_document_gen.h"
+
+namespace mongo {
+
+class SetClusterParameterCoordinator : public ConfigsvrCoordinator {
+public:
+ using StateDoc = SetClusterParameterCoordinatorDocument;
+ using Phase = SetClusterParameterCoordinatorPhaseEnum;
+
+ explicit SetClusterParameterCoordinator(const BSONObj& stateDoc)
+ : ConfigsvrCoordinator(stateDoc),
+ _doc(StateDoc::parse(IDLParserErrorContext("SetClusterParameterCoordinatorDocument"),
+ stateDoc)) {}
+
+ bool hasSameOptions(const BSONObj& participantDoc);
+
+ boost::optional<BSONObj> reportForCurrentOp(
+ MongoProcessInterface::CurrentOpConnectionsMode connMode,
+ MongoProcessInterface::CurrentOpSessionsMode sessionMode) noexcept override;
+
+private:
+ StateDoc _doc;
+
+ ExecutorFuture<void> _runImpl(std::shared_ptr<executor::ScopedTaskExecutor> executor,
+ const CancellationToken& token) noexcept override;
+
+ template <typename Func>
+ auto _executePhase(const Phase& newPhase, Func&& func) {
+ return [=] {
+ const auto& currPhase = _doc.getPhase();
+
+ if (currPhase > newPhase) {
+ // Do not execute this phase if we already reached a subsequent one.
+ return;
+ }
+ if (currPhase < newPhase) {
+ // Persist the new phase if this is the first time we are executing it.
+ _enterPhase(newPhase);
+ }
+ return func();
+ };
+ }
+
+ void _enterPhase(Phase newPhase);
+};
+
+} // namespace mongo
diff --git a/src/mongo/db/s/config/set_cluster_parameter_coordinator_document.idl b/src/mongo/db/s/config/set_cluster_parameter_coordinator_document.idl
new file mode 100644
index 00000000000..a7ed879bd32
--- /dev/null
+++ b/src/mongo/db/s/config/set_cluster_parameter_coordinator_document.idl
@@ -0,0 +1,57 @@
+# 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.
+#
+
+
+global:
+ cpp_namespace: "mongo"
+
+imports:
+ - "mongo/db/s/config/configsvr_coordinator.idl"
+ - "mongo/idl/basic_types.idl"
+ - "mongo/s/request_types/sharded_ddl_commands.idl"
+
+enums:
+ SetClusterParameterCoordinatorPhase:
+ description: "Current set cluster parameter state."
+ type: string
+ values:
+ kUnset: "unset"
+ kSetClusterParameter: "setClusterParameter"
+
+structs:
+ SetClusterParameterCoordinatorDocument:
+ description: "Document to store the POS state"
+ generate_comparison_operators: false
+ strict: false
+ chained_structs:
+ ConfigsvrCoordinatorMetadata: ConfigsvrCoordinatorMetadata
+ fields:
+ phase:
+ type: SetClusterParameterCoordinatorPhase
+ description: "Coordinator phase."
+ default: kUnset