summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandolph Tan <randolph@10gen.com>2022-03-28 14:39:08 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-08-25 17:51:21 +0000
commitdcf72568d8355d4326af801d32b86521a2144ae7 (patch)
tree0d0079de2e8203ba5f2d7c3dfb8b3c25100f9b1a
parent47d72edb3235807314e3754646d31ee495505642 (diff)
downloadmongo-dcf72568d8355d4326af801d32b86521a2144ae7.tar.gz
SERVER-64142 Add new enforceUniqueness to refineCollectionShardKey command
(cherry picked from commit 22964e1ae4dfe67e4d5e20520e6d91c9c58c105c)
-rw-r--r--etc/backports_required_for_multiversion_tests.yml4
-rw-r--r--jstests/sharding/refine_collection_shard_key_basic.js10
-rw-r--r--src/mongo/db/s/config/configsvr_refine_collection_shard_key_command.cpp2
-rw-r--r--src/mongo/s/commands/cluster_refine_collection_shard_key_cmd.cpp2
-rw-r--r--src/mongo/s/request_types/refine_collection_shard_key.idl10
5 files changed, 27 insertions, 1 deletions
diff --git a/etc/backports_required_for_multiversion_tests.yml b/etc/backports_required_for_multiversion_tests.yml
index 1b5de58ba6f..0797b5487fc 100644
--- a/etc/backports_required_for_multiversion_tests.yml
+++ b/etc/backports_required_for_multiversion_tests.yml
@@ -227,6 +227,8 @@ all:
test_file: jstests/sharding/append_oplog_note_mongos.js
- ticket: SERVER-63732
test_file: jstests/sharding/shard_collection_basic.js
+ - ticket: SERVER-64142
+ test_file: jstests/sharding/refine_collection_shard_key_basic.js
suites:
@@ -271,3 +273,5 @@ suites:
test_file: jstests/sharding/retryable_writes_nested_shard_key.js
- ticket: SERVER-63732
test_file: jstests/sharding/shard_collection_basic.js
+ - ticket: SERVER-64142
+ test_file: jstests/sharding/refine_collection_shard_key_basic.js
diff --git a/jstests/sharding/refine_collection_shard_key_basic.js b/jstests/sharding/refine_collection_shard_key_basic.js
index 16a77f731bc..bd7bdb38db8 100644
--- a/jstests/sharding/refine_collection_shard_key_basic.js
+++ b/jstests/sharding/refine_collection_shard_key_basic.js
@@ -534,6 +534,16 @@ assert.commandWorked(
mongos.adminCommand({refineCollectionShardKey: kNsName, key: {_id: 1, aKey: 1}}));
validateConfigCollectionsUnique(true);
+// Verify that enforceUniquenessCheck: false allows non-unique indexes.
+assert.commandWorked(mongos.getDB(kDbName).runCommand({drop: kCollName}));
+assert.commandWorked(mongos.getCollection(kNsName).createIndex({a: 1, b: 1}));
+assert.commandWorked(mongos.adminCommand({enableSharding: kDbName}));
+assert.commandWorked(mongos.adminCommand(
+ {shardCollection: kNsName, key: {a: 1}, unique: true, enforceUniquenessCheck: false}));
+assert.commandWorked(mongos.adminCommand(
+ {refineCollectionShardKey: kNsName, key: {a: 1, b: 1}, enforceUniquenessCheck: false}));
+validateConfigCollectionsUnique(true);
+
assert.commandWorked(mongos.getDB(kDbName).dropDatabase());
jsTestLog('********** INTEGRATION TESTS **********');
diff --git a/src/mongo/db/s/config/configsvr_refine_collection_shard_key_command.cpp b/src/mongo/db/s/config/configsvr_refine_collection_shard_key_command.cpp
index 5a400678daf..5e21b841e83 100644
--- a/src/mongo/db/s/config/configsvr_refine_collection_shard_key_command.cpp
+++ b/src/mongo/db/s/config/configsvr_refine_collection_shard_key_command.cpp
@@ -147,7 +147,7 @@ public:
newShardKeyPattern,
boost::none,
collType.getUnique(),
- true /* enforceUniquenessCheck */,
+ request().getEnforceUniquenessCheck().value_or(true),
shardkeyutil::ValidationBehaviorsRefineShardKey(opCtx, nss));
});
diff --git a/src/mongo/s/commands/cluster_refine_collection_shard_key_cmd.cpp b/src/mongo/s/commands/cluster_refine_collection_shard_key_cmd.cpp
index 3f115594172..16935f3d814 100644
--- a/src/mongo/s/commands/cluster_refine_collection_shard_key_cmd.cpp
+++ b/src/mongo/s/commands/cluster_refine_collection_shard_key_cmd.cpp
@@ -66,6 +66,8 @@ public:
ConfigsvrRefineCollectionShardKey configsvrRefineCollShardKey(
nss, request().getKey(), routingInfo.cm()->getVersion().epoch());
configsvrRefineCollShardKey.setDbName(request().getDbName());
+ configsvrRefineCollShardKey.setEnforceUniquenessCheck(
+ request().getEnforceUniquenessCheck());
auto configShard = Grid::get(opCtx)->shardRegistry()->getConfigShard();
auto cmdResponse = uassertStatusOK(configShard->runCommandWithFixedRetryAttempts(
diff --git a/src/mongo/s/request_types/refine_collection_shard_key.idl b/src/mongo/s/request_types/refine_collection_shard_key.idl
index 5b03128620f..0ba3cfb0658 100644
--- a/src/mongo/s/request_types/refine_collection_shard_key.idl
+++ b/src/mongo/s/request_types/refine_collection_shard_key.idl
@@ -45,6 +45,12 @@ commands:
type: object
description: "The index specification document to use as the new shard key."
optional: false
+ 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: optionalBool
_configsvrRefineCollectionShardKey:
cpp_name: ConfigsvrRefineCollectionShardKey
@@ -62,3 +68,7 @@ commands:
description: "The expected epoch of the namespace provided to
refineCollectionShardKey."
optional: false
+ enforceUniquenessCheck:
+ description: >-
+ Verifies that the shard key index has the same unique setting as the command.
+ type: optionalBool