summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/internal_rename_if_options_and_indexes_match_cmd.cpp
diff options
context:
space:
mode:
authorPierlauro Sciarelli <pierlauro.sciarelli@mongodb.com>2021-01-13 13:37:45 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-01-13 17:15:36 +0000
commita2e32913f7f6321b4cf293066703e867391db431 (patch)
treef6b89f2f23c0f46ce24ad84663510e81f7ace0cc /src/mongo/db/commands/internal_rename_if_options_and_indexes_match_cmd.cpp
parent039760ee734c3a2c6d3eb147767423e3539f3fb5 (diff)
downloadmongo-a2e32913f7f6321b4cf293066703e867391db431.tar.gz
SERVER-53737 Check for sharded collections in renameCollectionLegacy
Diffstat (limited to 'src/mongo/db/commands/internal_rename_if_options_and_indexes_match_cmd.cpp')
-rw-r--r--src/mongo/db/commands/internal_rename_if_options_and_indexes_match_cmd.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/mongo/db/commands/internal_rename_if_options_and_indexes_match_cmd.cpp b/src/mongo/db/commands/internal_rename_if_options_and_indexes_match_cmd.cpp
index 627e20b351a..f9384853ac4 100644
--- a/src/mongo/db/commands/internal_rename_if_options_and_indexes_match_cmd.cpp
+++ b/src/mongo/db/commands/internal_rename_if_options_and_indexes_match_cmd.cpp
@@ -35,8 +35,18 @@
#include "mongo/db/catalog/rename_collection.h"
#include "mongo/db/commands.h"
#include "mongo/db/db_raii.h"
+#include "mongo/db/s/collection_sharding_state.h"
namespace mongo {
+namespace {
+
+bool isCollectionSharded(OperationContext* opCtx, const NamespaceString& nss) {
+ AutoGetCollectionForRead lock(opCtx, nss);
+ return opCtx->writesAreReplicated() &&
+ CollectionShardingState::get(opCtx, nss)->getCollectionDescription(opCtx).isSharded();
+}
+
+} // namespace
/**
* Rename a collection while checking collection option and indexes.
@@ -52,15 +62,20 @@ public:
void typedRun(OperationContext* opCtx) {
auto thisRequest = request();
+ auto toNss = thisRequest.getTo();
+
+ uassert(ErrorCodes::IllegalOperation,
+ str::stream() << "cannot rename to sharded collection '" << toNss << "'",
+ !isCollectionSharded(opCtx, toNss));
+
auto originalIndexes = thisRequest.getIndexes();
auto indexList = std::list<BSONObj>(originalIndexes.begin(), originalIndexes.end());
RenameCollectionOptions options;
options.dropTarget = true;
options.stayTemp = false;
- options.skipSourceCollectionShardedCheck = true;
doLocalRenameIfOptionsAndIndexesHaveNotChanged(opCtx,
thisRequest.getFrom(),
- thisRequest.getTo(),
+ toNss,
options,
std::move(indexList),
thisRequest.getCollectionOptions());