summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Zolnierz <nicholas.zolnierz@mongodb.com>2020-02-25 13:12:34 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-02-28 15:46:37 +0000
commit76e1e97f064016a86e56561a098d6dab8f5c7d21 (patch)
tree9818e576e78b8bc174d7d1d5f714956d79ea5466 /src
parent887fe798e0a09546ffdbb39903b4992f5321b98f (diff)
downloadmongo-76e1e97f064016a86e56561a098d6dab8f5c7d21.tar.gz
SERVER-46264 Change the rename command so it is passed through IDL rather than manually constructed BSON
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/commands/SConscript11
-rw-r--r--src/mongo/db/commands/rename_collection.idl55
-rw-r--r--src/mongo/db/commands/rename_collection_cmd.cpp23
-rw-r--r--src/mongo/s/commands/SConscript1
-rw-r--r--src/mongo/s/commands/commands_public.cpp14
5 files changed, 81 insertions, 23 deletions
diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript
index cd31c5daa87..5211d3854a2 100644
--- a/src/mongo/db/commands/SConscript
+++ b/src/mongo/db/commands/SConscript
@@ -319,6 +319,7 @@ env.Library(
'kill_common',
'list_collections_filter',
'list_databases_command',
+ 'rename_collection_idl',
'test_commands_enabled',
'write_commands_common',
],
@@ -351,6 +352,16 @@ env.Library(
],
)
+env.Library(
+ target='rename_collection_idl',
+ source=[
+ env.Idlc('rename_collection.idl')[0],
+ ],
+ LIBDEPS_PRIVATE=[
+ '$BUILD_DIR/mongo/idl/idl_parser',
+ ],
+)
+
# Commands that should only be present in mongod
env.Library(
target="mongod",
diff --git a/src/mongo/db/commands/rename_collection.idl b/src/mongo/db/commands/rename_collection.idl
new file mode 100644
index 00000000000..37a2bcba946
--- /dev/null
+++ b/src/mongo/db/commands/rename_collection.idl
@@ -0,0 +1,55 @@
+# Copyright (C) 2020-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:
+ renameCollection:
+ description: "Parser for the 'renameCollection' command."
+ cpp_name: RenameCollectionCommand
+ strict: true
+ namespace: type
+ type: namespacestring
+ fields:
+ to:
+ description: "The new namespace for the collection being renamed."
+ type: namespacestring
+ dropTarget:
+ description: "If true, mongod will drop the target of renameCollection prior to
+ renaming the collection."
+ type: bool
+ default: false
+ stayTemp:
+ description: "If true, the original collection will remain temp if it was temp
+ before the rename."
+ type: bool
+ default: false
diff --git a/src/mongo/db/commands/rename_collection_cmd.cpp b/src/mongo/db/commands/rename_collection_cmd.cpp
index 4778255072e..3226d38c550 100644
--- a/src/mongo/db/commands/rename_collection_cmd.cpp
+++ b/src/mongo/db/commands/rename_collection_cmd.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/client.h"
#include "mongo/db/commands.h"
#include "mongo/db/commands/rename_collection.h"
+#include "mongo/db/commands/rename_collection_gen.h"
#include "mongo/db/db_raii.h"
#include "mongo/db/index/index_descriptor.h"
#include "mongo/db/namespace_string.h"
@@ -84,21 +85,13 @@ public:
const BSONObj& cmdObj,
string& errmsg,
BSONObjBuilder& result) {
- const auto sourceNsElt = cmdObj[getName()];
- const auto targetNsElt = cmdObj["to"];
-
- uassert(ErrorCodes::TypeMismatch,
- "'renameCollection' must be of type String",
- sourceNsElt.type() == BSONType::String);
- uassert(ErrorCodes::TypeMismatch,
- "'to' must be of type String",
- targetNsElt.type() == BSONType::String);
-
- const NamespaceString source(sourceNsElt.valueStringData());
- const NamespaceString target(targetNsElt.valueStringData());
- bool dropTarget = cmdObj["dropTarget"].trueValue();
- bool stayTemp = cmdObj["stayTemp"].trueValue();
- validateAndRunRenameCollection(opCtx, source, target, dropTarget, stayTemp);
+ auto renameRequest =
+ RenameCollectionCommand::parse(IDLParserErrorContext("renameCollection"), cmdObj);
+ validateAndRunRenameCollection(opCtx,
+ renameRequest.getCommandParameter(),
+ renameRequest.getTo(),
+ renameRequest.getDropTarget(),
+ renameRequest.getStayTemp());
return true;
}
diff --git a/src/mongo/s/commands/SConscript b/src/mongo/s/commands/SConscript
index ca56afe77a1..51590af5ad8 100644
--- a/src/mongo/s/commands/SConscript
+++ b/src/mongo/s/commands/SConscript
@@ -116,6 +116,7 @@ env.Library(
'$BUILD_DIR/mongo/db/commands/test_commands_enabled',
'$BUILD_DIR/mongo/db/commands/write_commands_common',
'$BUILD_DIR/mongo/db/commands/server_status',
+ '$BUILD_DIR/mongo/db/commands/rename_collection_idl',
'$BUILD_DIR/mongo/db/ftdc/ftdc_server',
'$BUILD_DIR/mongo/db/shared_request_handling',
'$BUILD_DIR/mongo/db/logical_session_cache_impl',
diff --git a/src/mongo/s/commands/commands_public.cpp b/src/mongo/s/commands/commands_public.cpp
index ee7315b3a85..1c3426ae3e0 100644
--- a/src/mongo/s/commands/commands_public.cpp
+++ b/src/mongo/s/commands/commands_public.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/auth/privilege.h"
#include "mongo/db/commands.h"
#include "mongo/db/commands/rename_collection.h"
+#include "mongo/db/commands/rename_collection_gen.h"
#include "mongo/executor/task_executor_pool.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/cluster_commands_helpers.h"
@@ -228,14 +229,11 @@ public:
const std::string& dbName,
const BSONObj& cmdObj,
BSONObjBuilder& result) override {
- const NamespaceString fromNss(parseNs(dbName, cmdObj));
- const NamespaceString toNss([&cmdObj] {
- const auto fullnsToElt = cmdObj["to"];
- uassert(ErrorCodes::InvalidNamespace,
- "'to' must be of type String",
- fullnsToElt.type() == BSONType::String);
- return fullnsToElt.valueStringData();
- }());
+ auto renameRequest =
+ RenameCollectionCommand::parse(IDLParserErrorContext("renameCollection"), cmdObj);
+ auto fromNss = renameRequest.getCommandParameter();
+ auto toNss = renameRequest.getTo();
+
uassert(ErrorCodes::InvalidNamespace,
str::stream() << "Invalid target namespace: " << toNss.ns(),
toNss.isValid());