diff options
author | Gregory Noma <gregory.noma@gmail.com> | 2022-01-24 20:10:27 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-01-24 21:24:12 +0000 |
commit | 2d23c2650eee84f5bcbb9bef5acdad4a583d488b (patch) | |
tree | 1d5d632b12e088b2b06e97f043eda0ea9527c2fb /src | |
parent | ba25336add6ed39d8a5dc3d0371e3e34730aa83d (diff) | |
download | mongo-2d23c2650eee84f5bcbb9bef5acdad4a583d488b.tar.gz |
SERVER-62454 Add `collectionUUID` parameter to `shardCollection` command
Diffstat (limited to 'src')
5 files changed, 22 insertions, 0 deletions
diff --git a/src/mongo/db/s/create_collection_coordinator.cpp b/src/mongo/db/s/create_collection_coordinator.cpp index ad201f5caf4..f705250c347 100644 --- a/src/mongo/db/s/create_collection_coordinator.cpp +++ b/src/mongo/db/s/create_collection_coordinator.cpp @@ -34,6 +34,7 @@ #include "mongo/db/audit.h" #include "mongo/db/auth/authorization_session.h" #include "mongo/db/cancelable_operation_context.h" +#include "mongo/db/catalog/collection_uuid_mismatch.h" #include "mongo/db/catalog/create_collection.h" #include "mongo/db/catalog_raii.h" #include "mongo/db/commands/create_gen.h" @@ -473,6 +474,7 @@ ExecutorFuture<void> CreateCollectionCoordinator::_runImpl( getCollation(opCtx, nss(), _doc.getCollation()).second, _doc.getUnique().value_or(false))) { _result = createCollectionResponseOpt; + _checkCollectionUUIDMismatch(opCtx); // The collection was already created and commited but there was a // stepdown after the commit. RecoverableCriticalSectionService::get(opCtx) @@ -511,6 +513,7 @@ ExecutorFuture<void> CreateCollectionCoordinator::_runImpl( } } + _checkCollectionUUIDMismatch(opCtx); _createPolicy(opCtx); _createCollectionAndIndexes(opCtx); @@ -675,6 +678,11 @@ void CreateCollectionCoordinator::_checkCommandArguments(OperationContext* opCtx } } +void CreateCollectionCoordinator::_checkCollectionUUIDMismatch(OperationContext* opCtx) const { + AutoGetCollection coll{opCtx, nss(), MODE_IS}; + checkCollectionUUIDMismatch(opCtx, coll.getCollection(), _doc.getCollectionUUID()); +} + void CreateCollectionCoordinator::_createCollectionAndIndexes(OperationContext* opCtx) { LOGV2_DEBUG( 5277903, 2, "Create collection _createCollectionAndIndexes", "namespace"_attr = nss()); diff --git a/src/mongo/db/s/create_collection_coordinator.h b/src/mongo/db/s/create_collection_coordinator.h index 446f430b33f..bee8b8d2c79 100644 --- a/src/mongo/db/s/create_collection_coordinator.h +++ b/src/mongo/db/s/create_collection_coordinator.h @@ -98,6 +98,11 @@ private: void _checkCommandArguments(OperationContext* opCtx); /** + * Checks that the collection has UUID matching the collectionUUID parameter, if provided. + */ + void _checkCollectionUUIDMismatch(OperationContext* opCtx) const; + + /** * Ensures the collection is created locally and has the appropiate shard index. */ void _createCollectionAndIndexes(OperationContext* opCtx); diff --git a/src/mongo/s/commands/cluster_shard_collection_cmd.cpp b/src/mongo/s/commands/cluster_shard_collection_cmd.cpp index 3ed34e36f3e..218afb2f558 100644 --- a/src/mongo/s/commands/cluster_shard_collection_cmd.cpp +++ b/src/mongo/s/commands/cluster_shard_collection_cmd.cpp @@ -103,6 +103,7 @@ public: requestParamsObj.setPresplitHashedZones(shardCollRequest.getPresplitHashedZones()); requestParamsObj.setCollation(shardCollRequest.getCollation()); requestParamsObj.setTimeseries(shardCollRequest.getTimeseries()); + requestParamsObj.setCollectionUUID(shardCollRequest.getCollectionUUID()); shardsvrCollRequest.setCreateCollectionRequest(std::move(requestParamsObj)); shardsvrCollRequest.setDbName(nss.db()); diff --git a/src/mongo/s/commands/shard_collection.idl b/src/mongo/s/commands/shard_collection.idl index 478193f5154..005aa90c1b9 100644 --- a/src/mongo/s/commands/shard_collection.idl +++ b/src/mongo/s/commands/shard_collection.idl @@ -74,3 +74,7 @@ structs: description: "The options to create the time-series collection with." type: TimeseriesOptions optional: true + collectionUUID: + description: "The expected UUID of the collection." + type: uuid + optional: true diff --git a/src/mongo/s/request_types/sharded_ddl_commands.idl b/src/mongo/s/request_types/sharded_ddl_commands.idl index 564a5849800..77e851fdf1d 100644 --- a/src/mongo/s/request_types/sharded_ddl_commands.idl +++ b/src/mongo/s/request_types/sharded_ddl_commands.idl @@ -127,6 +127,10 @@ structs: type: object_owned description: "The collation to use for the shard key index." optional: true + collectionUUID: + type: uuid + description: "The expected UUID of the collection." + optional: true CreateCollectionResponse: description: "Response of the create collection command" |