summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierlauro Sciarelli <pierlauro.sciarelli@mongodb.com>2021-04-12 07:51:02 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-04-12 14:51:43 +0000
commit7b292687d1587f5e2b1d110e995cc6fabec98ad3 (patch)
tree5e9168967220aaa692a1e5ba88404145902bbf69
parent48253bc972fa18dcd82ad928d8408fccf54dac89 (diff)
downloadmongo-7b292687d1587f5e2b1d110e995cc6fabec98ad3.tar.gz
SERVER-55974 Check for namespace validity before initializing a rename coordinator
-rw-r--r--src/mongo/db/catalog/rename_collection.cpp24
-rw-r--r--src/mongo/db/catalog/rename_collection.h10
-rw-r--r--src/mongo/db/s/shardsvr_rename_collection_command.cpp10
3 files changed, 31 insertions, 13 deletions
diff --git a/src/mongo/db/catalog/rename_collection.cpp b/src/mongo/db/catalog/rename_collection.cpp
index 7b60c794129..452ed2a6e01 100644
--- a/src/mongo/db/catalog/rename_collection.cpp
+++ b/src/mongo/db/catalog/rename_collection.cpp
@@ -745,10 +745,9 @@ void doLocalRenameIfOptionsAndIndexesHaveNotChanged(OperationContext* opCtx,
validateAndRunRenameCollection(opCtx, sourceNs, targetNs, options);
}
-void validateAndRunRenameCollection(OperationContext* opCtx,
- const NamespaceString& source,
- const NamespaceString& target,
- const RenameCollectionOptions& options) {
+void validateNamespacesForRenameCollection(OperationContext* opCtx,
+ const NamespaceString& source,
+ const NamespaceString& target) {
uassert(ErrorCodes::InvalidNamespace,
str::stream() << "Invalid source namespace: " << source.ns(),
source.isValid());
@@ -786,6 +785,23 @@ void validateAndRunRenameCollection(OperationContext* opCtx,
"allowed");
}
+ uassert(ErrorCodes::NamespaceNotFound,
+ str::stream() << "renameCollection cannot accept a source collection that is in a "
+ "drop-pending state: "
+ << source,
+ !source.isDropPendingNamespace());
+
+ uassert(ErrorCodes::IllegalOperation,
+ "renaming system.views collection or renaming to system.views is not allowed",
+ !source.isSystemDotViews() && !target.isSystemDotViews());
+}
+
+void validateAndRunRenameCollection(OperationContext* opCtx,
+ const NamespaceString& source,
+ const NamespaceString& target,
+ const RenameCollectionOptions& options) {
+ validateNamespacesForRenameCollection(opCtx, source, target);
+
OperationShardingState::ScopedAllowImplicitCollectionCreate_UNSAFE unsafeCreateCollection(
opCtx);
uassertStatusOK(renameCollection(opCtx, source, target, options));
diff --git a/src/mongo/db/catalog/rename_collection.h b/src/mongo/db/catalog/rename_collection.h
index 9b1c5ddf5ae..7b406ef3392 100644
--- a/src/mongo/db/catalog/rename_collection.h
+++ b/src/mongo/db/catalog/rename_collection.h
@@ -86,9 +86,17 @@ Status renameCollectionForApplyOps(OperationContext* opCtx,
Status renameCollectionForRollback(OperationContext* opCtx,
const NamespaceString& target,
const UUID& uuid);
+
+/**
+ * Performs validation checks to ensure source and target namespaces are eligible for rename.
+ */
+void validateNamespacesForRenameCollection(OperationContext* opCtx,
+ const NamespaceString& source,
+ const NamespaceString& target);
+
/**
* Runs renameCollection() with preliminary validation checks to ensure source
- * and target namespaces are elligible for rename.
+ * and target namespaces are eligible for rename.
*/
void validateAndRunRenameCollection(OperationContext* opCtx,
const NamespaceString& source,
diff --git a/src/mongo/db/s/shardsvr_rename_collection_command.cpp b/src/mongo/db/s/shardsvr_rename_collection_command.cpp
index 83cfa74b2bf..2ce50da2005 100644
--- a/src/mongo/db/s/shardsvr_rename_collection_command.cpp
+++ b/src/mongo/db/s/shardsvr_rename_collection_command.cpp
@@ -134,18 +134,12 @@ public:
<< opCtx->getWriteConcern().wMode,
opCtx->getWriteConcern().wMode == WriteConcernOptions::kMajority);
+ validateNamespacesForRenameCollection(opCtx, fromNss, toNss);
+
uassert(ErrorCodes::CommandFailed,
"Source and destination collections must be on the same database.",
fromNss.db() == toNss.db());
- uassert(ErrorCodes::InvalidNamespace,
- str::stream() << "Can't rename from internal namespace: " << fromNss,
- renameIsAllowedOnNS(fromNss));
-
- uassert(ErrorCodes::InvalidNamespace,
- str::stream() << "Can't rename to internal namespace: " << toNss,
- renameIsAllowedOnNS(toNss));
-
auto coordinatorDoc = RenameCollectionCoordinatorDocument();
coordinatorDoc.setRenameCollectionRequest(req.getRenameCollectionRequest());
coordinatorDoc.setShardingDDLCoordinatorMetadata(