diff options
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/catalog/rename_collection.cpp | 24 | ||||
-rw-r--r-- | src/mongo/db/catalog/rename_collection.h | 10 | ||||
-rw-r--r-- | src/mongo/db/s/shardsvr_rename_collection_command.cpp | 10 |
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( |