summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatt Kneiser <matt.kneiser@mongodb.com>2022-03-29 03:43:37 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-03-29 04:10:07 +0000
commitbfb041da4093fc8d8645aa20fc45b55723e2e789 (patch)
tree57bfbd20de6bc756bae8f3ddd8628ccae2138eb8 /src
parent0c289c9f9ea159650a9598eaeffa178c2a310544 (diff)
downloadmongo-bfb041da4093fc8d8645aa20fc45b55723e2e789.tar.gz
SERVER-64603 Creates Skeleton for Renaming Database for Restore
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/commands/SConscript12
-rw-r--r--src/mongo/db/commands/rename_database_for_restore_command.cpp114
-rw-r--r--src/mongo/db/commands/rename_database_for_restore_command.idl49
-rw-r--r--src/mongo/embedded/mongo_embedded/mongo_embedded_test.cpp1
4 files changed, 176 insertions, 0 deletions
diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript
index ed43ec2a953..29e58008a5b 100644
--- a/src/mongo/db/commands/SConscript
+++ b/src/mongo/db/commands/SConscript
@@ -372,6 +372,7 @@ env.Library(
"plan_cache_clear_command.cpp",
"plan_cache_commands.cpp",
"rename_collection_cmd.cpp",
+ "rename_database_for_restore_command.cpp",
"run_aggregate.cpp",
"sleep_command.cpp",
"validate.cpp",
@@ -440,6 +441,7 @@ env.Library(
'list_collections_filter',
'list_databases_command',
'rename_collection_idl',
+ 'rename_database_for_restore_command_idl',
'test_commands_enabled',
'validate_db_metadata_command',
],
@@ -465,6 +467,16 @@ env.Library(
)
env.Library(
+ target='rename_database_for_restore_command_idl',
+ source=[
+ 'rename_database_for_restore_command.idl',
+ ],
+ LIBDEPS_PRIVATE=[
+ '$BUILD_DIR/mongo/idl/idl_parser',
+ ],
+)
+
+env.Library(
target='set_index_commit_quorum_idl',
source=[
'set_index_commit_quorum.idl',
diff --git a/src/mongo/db/commands/rename_database_for_restore_command.cpp b/src/mongo/db/commands/rename_database_for_restore_command.cpp
new file mode 100644
index 00000000000..91de5aa1b27
--- /dev/null
+++ b/src/mongo/db/commands/rename_database_for_restore_command.cpp
@@ -0,0 +1,114 @@
+/**
+ * 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 <string>
+
+#include "mongo/bson/bsonobj.h"
+#include "mongo/db/auth/authorization_session.h"
+#include "mongo/db/catalog/catalog_control.h"
+#include "mongo/db/commands.h"
+#include "mongo/db/commands/rename_database_for_restore_command_gen.h"
+#include "mongo/db/repl/replication_coordinator.h"
+#include "mongo/db/storage/storage_parameters_gen.h"
+#include "mongo/logv2/log.h"
+
+namespace mongo {
+namespace {
+
+class RenameDatabaseForRestoreCmd
+ : public BasicCommandWithRequestParser<RenameDatabaseForRestoreCmd> {
+public:
+ using Request = RenameDatabaseForRestoreCommand;
+
+ bool skipApiVersionCheck() const override {
+ // Internal command used by the restore procedure.
+ return true;
+ }
+
+ AllowedOnSecondary secondaryAllowed(ServiceContext*) const override {
+ return AllowedOnSecondary::kNever;
+ }
+
+ bool adminOnly() const {
+ return true;
+ }
+
+ bool supportsWriteConcern(const BSONObj& cmd) const override {
+ return false;
+ }
+
+ Status checkAuthForCommand(Client* client,
+ const std::string& dbname,
+ const BSONObj& cmdObj) const override {
+ if (!AuthorizationSession::get(client)->isAuthorizedForActionsOnResource(
+ ResourcePattern::forClusterResource(), ActionType::internal)) {
+ return Status(ErrorCodes::Unauthorized, "Unauthorized");
+ }
+
+ return Status::OK();
+ }
+
+ bool runWithRequestParser(OperationContext* opCtx,
+ const std::string& db,
+ const BSONObj& cmdObj,
+ const RequestParser& requestParser,
+ BSONObjBuilder& result) final {
+ uassert(ErrorCodes::CommandFailed,
+ "Cannot run the 'renameDatabaseForRestore' command when the "
+ "'featureFlagDatabaseRenameDuringRestore' is disabled.",
+ feature_flags::gDatabaseRenameDuringRestore.isEnabled(
+ serverGlobalParams.featureCompatibility));
+
+ uassert(ErrorCodes::CommandFailed,
+ "This command can only be used in standalone mode",
+ !repl::ReplicationCoordinator::get(opCtx)->getSettings().usingReplSets());
+
+ uassert(ErrorCodes::CommandFailed,
+ "This command can only be run during a restore procedure",
+ storageGlobalParams.restore);
+
+ const auto* cmd = &requestParser.request();
+ auto from = cmd->getFrom();
+ auto to = cmd->getTo();
+
+ LOGV2(6460300, "CMD: renameDatabaseForRestore", "from"_attr = from, "to"_attr = to);
+
+ return true;
+ }
+
+ void validateResult(const BSONObj& resultObj) final {
+ return;
+ }
+
+} renameDatabaseForRestoreCmd;
+
+} // namespace
+} // namespace mongo
diff --git a/src/mongo/db/commands/rename_database_for_restore_command.idl b/src/mongo/db/commands/rename_database_for_restore_command.idl
new file mode 100644
index 00000000000..01af27396ee
--- /dev/null
+++ b/src/mongo/db/commands/rename_database_for_restore_command.idl
@@ -0,0 +1,49 @@
+# 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/idl/basic_types.idl"
+
+commands:
+ renameDatabaseForRestore:
+ command_name: "renameDatabaseForRestore"
+ description: "Rename Database during Restore"
+ cpp_name: RenameDatabaseForRestoreCommand
+ namespace: ignored
+ api_version: ""
+ strict: true
+ fields:
+ from:
+ description: "Current Database Name to change"
+ type: namespacestring
+ to:
+ description: "New Database Name"
+ type: namespacestring
diff --git a/src/mongo/embedded/mongo_embedded/mongo_embedded_test.cpp b/src/mongo/embedded/mongo_embedded/mongo_embedded_test.cpp
index 7d728bf451a..9e55e9ea0a7 100644
--- a/src/mongo/embedded/mongo_embedded/mongo_embedded_test.cpp
+++ b/src/mongo/embedded/mongo_embedded/mongo_embedded_test.cpp
@@ -602,6 +602,7 @@ TEST_F(MongodbCAPITest, RunListCommands) {
"refreshLogicalSessionCacheNow",
"refreshSessions",
"renameCollection",
+ "renameDatabaseForRestore",
"repairDatabase",
"serverStatus",
"setParameter",