diff options
author | Randolph Tan <randolph@10gen.com> | 2022-03-18 15:23:48 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-08-29 19:24:15 +0000 |
commit | 743bf3063008f02ea3ffab17757d60d63862a1c9 (patch) | |
tree | 99736927c05787c9c13cea592133ee3c49580301 | |
parent | 99ac54df429f2df7a9e322c36f9528dfb405d869 (diff) | |
download | mongo-743bf3063008f02ea3ffab17757d60d63862a1c9.tar.gz |
SERVER-64573 Make implicitlyCreateIndex and enforceUniquenessCheck fields optional
(cherry picked from commit 47d72edb3235807314e3754646d31ee495505642)
-rw-r--r-- | src/mongo/db/s/shardsvr_shard_collection.cpp | 5 | ||||
-rw-r--r-- | src/mongo/idl/basic_types.h | 7 | ||||
-rw-r--r-- | src/mongo/s/request_types/shard_collection.idl | 18 |
3 files changed, 16 insertions, 14 deletions
diff --git a/src/mongo/db/s/shardsvr_shard_collection.cpp b/src/mongo/db/s/shardsvr_shard_collection.cpp index f0d6267c844..59acabe47e6 100644 --- a/src/mongo/db/s/shardsvr_shard_collection.cpp +++ b/src/mongo/db/s/shardsvr_shard_collection.cpp @@ -256,7 +256,8 @@ bool validShardKeyIndexExists(OperationContext* opCtx, // 3. If proposed key is required to be unique, additionally check for exact match. - if (hasUsefulIndexForKey && request.getUnique() && request.getEnforceUniquenessCheck()) { + if (hasUsefulIndexForKey && request.getUnique() && + request.getEnforceUniquenessCheck().value_or(true)) { BSONObj eqQuery = BSON("ns" << nss.ns() << "key" << proposedKey); BSONObj eqQueryResult; @@ -723,7 +724,7 @@ UUID shardCollection(OperationContext* opCtx, const auto proposedKey(request.getKey().getOwned()); const ShardKeyPattern shardKeyPattern(proposedKey); - if (request.getImplicitlyCreateIndex()) { + if (request.getImplicitlyCreateIndex().value_or(true)) { createIndexesOrValidateExisting(opCtx, nss, proposedKey, shardKeyPattern, request); } else { uassert(6373200, diff --git a/src/mongo/idl/basic_types.h b/src/mongo/idl/basic_types.h index 8eb66c53629..0836daa4b56 100644 --- a/src/mongo/idl/basic_types.h +++ b/src/mongo/idl/basic_types.h @@ -66,6 +66,13 @@ public: } /** + * Returns the stored value or the given defaultValue if nothing is stored. + */ + bool value_or(bool defaultValue) const { + return _value.value_or(defaultValue); + } + + /** * Returns true if the value has been populated, false otherwise. */ bool has_value() const { diff --git a/src/mongo/s/request_types/shard_collection.idl b/src/mongo/s/request_types/shard_collection.idl index c35f9e1445b..6c75180db61 100644 --- a/src/mongo/s/request_types/shard_collection.idl +++ b/src/mongo/s/request_types/shard_collection.idl @@ -64,14 +64,12 @@ structs: optional: true implicitlyCreateIndex: description: "Creates an index on the shard key pattern if the collection is empty." - type: bool - default: true + type: optionalBool enforceUniquenessCheck: description: >- Controls whether this command verifies that any unique indexes are prefixed by the shard key pattern if unique is true. If true then it will verify and if false then it won't. - type: bool - default: true + type: optionalBool ConfigsvrShardCollectionRequest: description: "The request format of the internal shardCollection command on the config server" @@ -106,14 +104,12 @@ structs: default: true implicitlyCreateIndex: description: "Creates an index on the shard key pattern if the collection is empty." - type: bool - default: true + type: optionalBool enforceUniquenessCheck: description: >- Controls whether this command verifies that any unique indexes are prefixed by the shard key pattern if unique is true. If true then it will verify and if false then it won't. - type: bool - default: true + type: optionalBool ConfigsvrShardCollectionResponse: description: "The response format of the internal shardCollection command on the config server" @@ -160,14 +156,12 @@ structs: default: true implicitlyCreateIndex: description: "Creates an index on the shard key pattern if the collection is empty." - type: bool - default: true + type: optionalBool enforceUniquenessCheck: description: >- Controls whether this command verifies that any unique indexes are prefixed by the shard key pattern if unique is true. If true then it will verify and if false then it won't. - type: bool - default: true + type: optionalBool ShardsvrShardCollectionResponse: description: "The response format of the internal shardCollection command on the primary shard" |