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-23 16:14:08 +0000 |
commit | 03eb1ef91a9a1f6555cdead19cf5d485406ffcd4 (patch) | |
tree | b5a11bc7cd450e0fb00c3d64492e41eee2378b94 | |
parent | 42d7af66d18a170f88b5457ade1e3dc2d3c8e356 (diff) | |
download | mongo-03eb1ef91a9a1f6555cdead19cf5d485406ffcd4.tar.gz |
SERVER-64573 Make implicitlyCreateIndex and enforceUniquenessCheck fields optional
(cherry picked from commit 2107c9df336901aea91fbc0bd701bea0591b96cf)
-rw-r--r-- | src/mongo/db/s/create_collection_coordinator.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/s/shard_collection_legacy.cpp | 22 | ||||
-rw-r--r-- | src/mongo/idl/basic_types.h | 7 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_commands.idl | 6 | ||||
-rw-r--r-- | src/mongo/s/request_types/shard_collection.idl | 6 | ||||
-rw-r--r-- | src/mongo/s/request_types/sharded_ddl_commands.idl | 6 |
6 files changed, 27 insertions, 26 deletions
diff --git a/src/mongo/db/s/create_collection_coordinator.cpp b/src/mongo/db/s/create_collection_coordinator.cpp index a80bacde92f..129818072c5 100644 --- a/src/mongo/db/s/create_collection_coordinator.cpp +++ b/src/mongo/db/s/create_collection_coordinator.cpp @@ -680,14 +680,14 @@ void CreateCollectionCoordinator::_createCollectionAndIndexes(OperationContext* } auto indexCreated = false; - if (_doc.getImplicitlyCreateIndex()) { + if (_doc.getImplicitlyCreateIndex().value_or(true)) { indexCreated = shardkeyutil::validateShardKeyIndexExistsOrCreateIfPossible( opCtx, nss(), *_shardKeyPattern, _collationBSON, _doc.getUnique().value_or(false), - _doc.getEnforceUniquenessCheck(), + _doc.getEnforceUniquenessCheck().value_or(true), shardkeyutil::ValidationBehaviorsShardCollection(opCtx)); } else { uassert(6373200, @@ -697,7 +697,7 @@ void CreateCollectionCoordinator::_createCollectionAndIndexes(OperationContext* *_shardKeyPattern, _collationBSON, _doc.getUnique().value_or(false) && - _doc.getEnforceUniquenessCheck(), + _doc.getEnforceUniquenessCheck().value_or(true), shardkeyutil::ValidationBehaviorsShardCollection(opCtx))); } diff --git a/src/mongo/db/s/shard_collection_legacy.cpp b/src/mongo/db/s/shard_collection_legacy.cpp index 6157140b802..ae231f35054 100644 --- a/src/mongo/db/s/shard_collection_legacy.cpp +++ b/src/mongo/db/s/shard_collection_legacy.cpp @@ -572,7 +572,7 @@ CreateCollectionResponse shardCollection(OperationContext* opCtx, checkCollation(opCtx, request); - if (request.getImplicitlyCreateIndex()) { + if (request.getImplicitlyCreateIndex().value_or(true)) { // Create the collection locally shardkeyutil::validateShardKeyIndexExistsOrCreateIfPossible( opCtx, @@ -580,18 +580,18 @@ CreateCollectionResponse shardCollection(OperationContext* opCtx, ShardKeyPattern(request.getKey()), *request.getCollation(), request.getUnique(), - request.getEnforceUniquenessCheck(), + request.getEnforceUniquenessCheck().value_or(true), shardkeyutil::ValidationBehaviorsShardCollection(opCtx)); } else { - uassert( - 6373201, - "Must have an index compatible with the proposed shard key", - validShardKeyIndexExists(opCtx, - nss, - ShardKeyPattern(request.getKey()), - *request.getCollation(), - request.getUnique() && request.getEnforceUniquenessCheck(), - shardkeyutil::ValidationBehaviorsShardCollection(opCtx))); + uassert(6373201, + "Must have an index compatible with the proposed shard key", + validShardKeyIndexExists( + opCtx, + nss, + ShardKeyPattern(request.getKey()), + *request.getCollation(), + request.getUnique() && request.getEnforceUniquenessCheck().value_or(true), + shardkeyutil::ValidationBehaviorsShardCollection(opCtx))); } // Wait until the index is majority written, to prevent having the collection commited to diff --git a/src/mongo/idl/basic_types.h b/src/mongo/idl/basic_types.h index e674b8ae1d4..ddc4304afba 100644 --- a/src/mongo/idl/basic_types.h +++ b/src/mongo/idl/basic_types.h @@ -72,6 +72,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/commands/cluster_commands.idl b/src/mongo/s/commands/cluster_commands.idl index ef4c95c21b1..002b5a7a098 100644 --- a/src/mongo/s/commands/cluster_commands.idl +++ b/src/mongo/s/commands/cluster_commands.idl @@ -103,11 +103,9 @@ 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 diff --git a/src/mongo/s/request_types/shard_collection.idl b/src/mongo/s/request_types/shard_collection.idl index 3c9f0124de5..3ad8dda88d2 100644 --- a/src/mongo/s/request_types/shard_collection.idl +++ b/src/mongo/s/request_types/shard_collection.idl @@ -120,14 +120,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" diff --git a/src/mongo/s/request_types/sharded_ddl_commands.idl b/src/mongo/s/request_types/sharded_ddl_commands.idl index 3e4ed4caefb..dba48fa57ac 100644 --- a/src/mongo/s/request_types/sharded_ddl_commands.idl +++ b/src/mongo/s/request_types/sharded_ddl_commands.idl @@ -128,15 +128,13 @@ 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 CreateCollectionResponse: description: "Response of the create collection command" |