summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandolph Tan <randolph@10gen.com>2022-03-18 15:23:48 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-08-25 15:39:48 +0000
commit47d72edb3235807314e3754646d31ee495505642 (patch)
treed32ad2f65e90227d3cbfc610850b1952d695261c
parent411a12ad600733fc80d9b6e8da86da51dd415ab0 (diff)
downloadmongo-47d72edb3235807314e3754646d31ee495505642.tar.gz
SERVER-64573 Make implicitlyCreateIndex and enforceUniquenessCheck fields optional
(cherry picked from commit 03eb1ef91a9a1f6555cdead19cf5d485406ffcd4)
-rw-r--r--src/mongo/db/s/shardsvr_shard_collection.cpp6
-rw-r--r--src/mongo/idl/basic_types.h7
-rw-r--r--src/mongo/s/request_types/shard_collection.idl18
3 files changed, 16 insertions, 15 deletions
diff --git a/src/mongo/db/s/shardsvr_shard_collection.cpp b/src/mongo/db/s/shardsvr_shard_collection.cpp
index 91cf4c92371..7ceecffe46b 100644
--- a/src/mongo/db/s/shardsvr_shard_collection.cpp
+++ b/src/mongo/db/s/shardsvr_shard_collection.cpp
@@ -327,7 +327,7 @@ ShardCollectionTargetState calculateTargetState(OperationContext* opCtx,
auto proposedKey(request.getKey().getOwned());
ShardKeyPattern shardKeyPattern(proposedKey);
- if (request.getImplicitlyCreateIndex()) {
+ if (request.getImplicitlyCreateIndex().value_or(true)) {
shardkeyutil::validateShardKeyIndexExistsOrCreateIfPossible(
opCtx,
nss,
@@ -335,7 +335,7 @@ ShardCollectionTargetState calculateTargetState(OperationContext* opCtx,
shardKeyPattern,
request.getCollation(),
request.getUnique(),
- request.getEnforceUniquenessCheck(),
+ request.getEnforceUniquenessCheck().value_or(true),
shardkeyutil::ValidationBehaviorsShardCollection(opCtx));
} else {
uassert(6373200,
@@ -346,7 +346,7 @@ ShardCollectionTargetState calculateTargetState(OperationContext* opCtx,
proposedKey,
shardKeyPattern,
request.getCollation(),
- request.getUnique() && request.getEnforceUniquenessCheck(),
+ request.getUnique() && request.getEnforceUniquenessCheck().value_or(true),
shardkeyutil::ValidationBehaviorsShardCollection(opCtx)));
}
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 f9591a810e0..b9194f70de7 100644
--- a/src/mongo/s/request_types/shard_collection.idl
+++ b/src/mongo/s/request_types/shard_collection.idl
@@ -68,14 +68,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"
@@ -114,14 +112,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"
@@ -172,14 +168,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"