From ebd7eef1dbc0e61266e26b9511f426b44d93e92a Mon Sep 17 00:00:00 2001 From: Esha Maharishi Date: Wed, 16 Aug 2017 18:49:27 -0400 Subject: SERVER-30703 make _configsvrShardCollection return the newly sharded collection's UUID --- .../db/s/config/configsvr_shard_collection_command.cpp | 15 +++++++++------ src/mongo/s/commands/cluster_map_reduce_cmd.cpp | 2 +- src/mongo/s/commands/cluster_shard_collection_cmd.cpp | 2 +- src/mongo/s/request_types/shard_collection.idl | 16 ++++++++++++++-- src/mongo/util/uuid.h | 2 +- 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/mongo/db/s/config/configsvr_shard_collection_command.cpp b/src/mongo/db/s/config/configsvr_shard_collection_command.cpp index d041d40aabd..fe2aae3e918 100644 --- a/src/mongo/db/s/config/configsvr_shard_collection_command.cpp +++ b/src/mongo/db/s/config/configsvr_shard_collection_command.cpp @@ -132,7 +132,7 @@ void validateAndDeduceFullRequestOptions(OperationContext* opCtx, const ShardKeyPattern& shardKeyPattern, int numShards, ScopedDbConnection& conn, - ConfigsvrShardCollection* request) { + ConfigsvrShardCollectionRequest* request) { uassert( ErrorCodes::InvalidOptions, "cannot have empty shard key", !request->getKey().isEmpty()); @@ -249,7 +249,7 @@ void validateAndDeduceFullRequestOptions(OperationContext* opCtx, */ bool checkIfAlreadyShardedWithSameOptions(OperationContext* opCtx, const NamespaceString& nss, - const ConfigsvrShardCollection& request) { + const ConfigsvrShardCollectionRequest& request) { auto catalogCache = Grid::get(opCtx)->catalogCache(); // Until all metadata commands are on the config server, the CatalogCache on the config @@ -301,7 +301,7 @@ void validateShardKeyAgainstExistingIndexes(OperationContext* opCtx, const ShardKeyPattern& shardKeyPattern, const std::shared_ptr primaryShard, ScopedDbConnection& conn, - const ConfigsvrShardCollection& request) { + const ConfigsvrShardCollectionRequest& request) { // The proposed shard key must be validated against the set of existing indexes. // In particular, we must ensure the following constraints // @@ -452,7 +452,7 @@ void determinePresplittingPoints(OperationContext* opCtx, bool isEmpty, const BSONObj& proposedKey, const ShardKeyPattern& shardKeyPattern, - const ConfigsvrShardCollection& request, + const ConfigsvrShardCollectionRequest& request, std::vector* initSplits, std::vector* allSplits) { auto numChunks = request.getNumInitialChunks(); @@ -732,8 +732,8 @@ public: serverGlobalParams.clusterRole == ClusterRole::ConfigServer); const NamespaceString nss(parseNs(dbname, cmdObj)); - auto request = ConfigsvrShardCollection::parse( - IDLParserErrorContext("ConfigsvrShardCollection"), cmdObj); + auto request = ConfigsvrShardCollectionRequest::parse( + IDLParserErrorContext("ConfigsvrShardCollectionRequest"), cmdObj); auto const catalogManager = ShardingCatalogManager::get(opCtx); auto const catalogCache = Grid::get(opCtx)->catalogCache(); @@ -823,6 +823,9 @@ public: initSplits, distributeInitialChunks); result << "collectionsharded" << nss.ns(); + if (uuid) { + result << "collectionUUID" << *uuid; + } // Make sure the cached metadata for the collection knows that we are now sharded catalogCache->invalidateShardedCollection(nss); diff --git a/src/mongo/s/commands/cluster_map_reduce_cmd.cpp b/src/mongo/s/commands/cluster_map_reduce_cmd.cpp index 78ce450a3d6..eb5b42e2d0c 100644 --- a/src/mongo/s/commands/cluster_map_reduce_cmd.cpp +++ b/src/mongo/s/commands/cluster_map_reduce_cmd.cpp @@ -641,7 +641,7 @@ private: // collection the next time it's accessed, even if we receive a failure, e.g. NetworkError. ON_BLOCK_EXIT([catalogCache, nss] { catalogCache->invalidateShardedCollection(nss); }); - ConfigsvrShardCollection configShardCollRequest; + ConfigsvrShardCollectionRequest configShardCollRequest; configShardCollRequest.set_configsvrShardCollection(nss); configShardCollRequest.setKey(BSON("_id" << 1)); configShardCollRequest.setUnique(true); diff --git a/src/mongo/s/commands/cluster_shard_collection_cmd.cpp b/src/mongo/s/commands/cluster_shard_collection_cmd.cpp index 220be51da62..b2566ec7584 100644 --- a/src/mongo/s/commands/cluster_shard_collection_cmd.cpp +++ b/src/mongo/s/commands/cluster_shard_collection_cmd.cpp @@ -112,7 +112,7 @@ public: auto shardCollRequest = ShardCollection::parse(IDLParserErrorContext("ShardCollection"), cmdObj); - ConfigsvrShardCollection configShardCollRequest; + ConfigsvrShardCollectionRequest configShardCollRequest; configShardCollRequest.set_configsvrShardCollection(nss); configShardCollRequest.setKey(shardCollRequest.getKey()); configShardCollRequest.setUnique(shardCollRequest.getUnique()); diff --git a/src/mongo/s/request_types/shard_collection.idl b/src/mongo/s/request_types/shard_collection.idl index 054b633996e..6289b22e2fb 100644 --- a/src/mongo/s/request_types/shard_collection.idl +++ b/src/mongo/s/request_types/shard_collection.idl @@ -61,8 +61,8 @@ structs: description: "The collation to use for the shard key index." optional: true - ConfigsvrShardCollection: - description: "The internal shardCollection command on the config server" + ConfigsvrShardCollectionRequest: + description: "The request format of the internal shardCollection command on the config server" strict: false fields: _configsvrShardCollection: @@ -88,3 +88,15 @@ structs: type: object description: "The collation to use for the shard key index." optional: true + + ConfigsvrShardCollectionResponse: + description: "The response format of the internal shardCollection command on the config server" + strict: false + fields: + collectionsharded: + type: string + description: "The name of the collection that just got sharded." + collectionUUID: + type: uuid + description: "The UUID of the collection that just got sharded." + optional: true diff --git a/src/mongo/util/uuid.h b/src/mongo/util/uuid.h index 8436f5936ba..b4b8df30e90 100644 --- a/src/mongo/util/uuid.h +++ b/src/mongo/util/uuid.h @@ -53,7 +53,7 @@ class UUID { using UUIDStorage = std::array; // Make the IDL generated parser a friend - friend class ConfigsvrShardCollection; + friend class ConfigsvrShardCollectionResponse; friend class One_UUID; friend class LogicalSessionId; friend class LogicalSessionToClient; -- cgit v1.2.1