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-23 20:38:32 +0000
commit22964e1ae4dfe67e4d5e20520e6d91c9c58c105c (patch)
tree0d06ec3e748cd1751e711c5985970df1340f6875
parentd1ea4fa59d6aab66ebc19eee974249076f5d7e8a (diff)
downloadmongo-22964e1ae4dfe67e4d5e20520e6d91c9c58c105c.tar.gz
SERVER-64142 Add new enforceUniqueness to refineCollectionShardKey command
(cherry picked from commit b355fd53d1b13d217e32061c92d5ca902d6209c3)
-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/db/s/refine_collection_shard_key_coordinator.cpp9
-rw-r--r--src/mongo/db/s/refine_collection_shard_key_coordinator.h4
-rw-r--r--src/mongo/db/s/shardsvr_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
-rw-r--r--src/mongo/s/request_types/sharded_ddl_commands.idl6
9 files changed, 44 insertions, 5 deletions
diff --git a/etc/backports_required_for_multiversion_tests.yml b/etc/backports_required_for_multiversion_tests.yml
index fbfb8a2cc39..fdb64b847b6 100644
--- a/etc/backports_required_for_multiversion_tests.yml
+++ b/etc/backports_required_for_multiversion_tests.yml
@@ -112,6 +112,8 @@ last-continuous:
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
# Tests that should only be excluded from particular suites should be listed under that suite.
suites:
@@ -384,6 +386,8 @@ last-lts:
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
# Tests that should only be excluded from particular suites should be listed under that suite.
suites:
diff --git a/jstests/sharding/refine_collection_shard_key_basic.js b/jstests/sharding/refine_collection_shard_key_basic.js
index 79834405815..17edb023aa5 100644
--- a/jstests/sharding/refine_collection_shard_key_basic.js
+++ b/jstests/sharding/refine_collection_shard_key_basic.js
@@ -524,6 +524,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 e4be3f748a3..1371a9f1ed1 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
@@ -164,7 +164,7 @@ public:
newShardKeyPattern,
boost::none,
collType.getUnique(),
- true /* enforceUniquenessCheck */,
+ request().getEnforceUniquenessCheck().value_or(true),
shardkeyutil::ValidationBehaviorsRefineShardKey(opCtx, nss));
});
diff --git a/src/mongo/db/s/refine_collection_shard_key_coordinator.cpp b/src/mongo/db/s/refine_collection_shard_key_coordinator.cpp
index 89bd3658c1d..c00af057612 100644
--- a/src/mongo/db/s/refine_collection_shard_key_coordinator.cpp
+++ b/src/mongo/db/s/refine_collection_shard_key_coordinator.cpp
@@ -41,10 +41,14 @@
namespace mongo {
RefineCollectionShardKeyCoordinator::RefineCollectionShardKeyCoordinator(
- OperationContext* opCtx, const NamespaceString& nss, const KeyPattern newShardKey)
+ OperationContext* opCtx,
+ const NamespaceString& nss,
+ const KeyPattern newShardKey,
+ OptionalBool enforceUniquenessCheck)
: ShardingDDLCoordinator_NORESILIENT(opCtx, nss),
_serviceContext(opCtx->getServiceContext()),
- _newShardKey(std::move(newShardKey)){};
+ _newShardKey(std::move(newShardKey)),
+ _enforceUniquenessCheck(std::move(enforceUniquenessCheck)) {}
SemiFuture<void> RefineCollectionShardKeyCoordinator::runImpl(
std::shared_ptr<executor::TaskExecutor> executor) {
@@ -79,6 +83,7 @@ SemiFuture<void> RefineCollectionShardKeyCoordinator::runImpl(
configsvrRefineCollShardKey.setDbName(_nss.db().toString());
// TODO SERVER-54810 don't set `setIsFromPrimaryShard` once 5.0 becomes last-LTS
configsvrRefineCollShardKey.setIsFromPrimaryShard(true);
+ configsvrRefineCollShardKey.setEnforceUniquenessCheck(_enforceUniquenessCheck);
auto configShard = Grid::get(opCtx)->shardRegistry()->getConfigShard();
auto cmdResponse = uassertStatusOK(configShard->runCommandWithFixedRetryAttempts(
diff --git a/src/mongo/db/s/refine_collection_shard_key_coordinator.h b/src/mongo/db/s/refine_collection_shard_key_coordinator.h
index 417278bd008..174dffb8c93 100644
--- a/src/mongo/db/s/refine_collection_shard_key_coordinator.h
+++ b/src/mongo/db/s/refine_collection_shard_key_coordinator.h
@@ -40,7 +40,8 @@ class RefineCollectionShardKeyCoordinator final
public:
RefineCollectionShardKeyCoordinator(OperationContext* opCtx,
const NamespaceString& nss,
- const KeyPattern newShardKey);
+ const KeyPattern newShardKey,
+ OptionalBool enforceUniquenessCheck);
private:
SemiFuture<void> runImpl(std::shared_ptr<executor::TaskExecutor> executor) override;
@@ -48,6 +49,7 @@ private:
ServiceContext* _serviceContext;
const KeyPattern _newShardKey;
+ const OptionalBool _enforceUniquenessCheck;
};
} // namespace mongo
diff --git a/src/mongo/db/s/shardsvr_refine_collection_shard_key_command.cpp b/src/mongo/db/s/shardsvr_refine_collection_shard_key_command.cpp
index 976c52a7e33..9c05d01a1f2 100644
--- a/src/mongo/db/s/shardsvr_refine_collection_shard_key_command.cpp
+++ b/src/mongo/db/s/shardsvr_refine_collection_shard_key_command.cpp
@@ -64,7 +64,7 @@ public:
opCtx->setAlwaysInterruptAtStepDownOrUp();
auto refineCoordinator = std::make_shared<RefineCollectionShardKeyCoordinator>(
- opCtx, ns(), request().getNewShardKey());
+ opCtx, ns(), request().getNewShardKey(), request().getEnforceUniquenessCheck());
refineCoordinator->run(opCtx).get(opCtx);
}
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 ecd8266b483..a97deff2289 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
@@ -68,6 +68,8 @@ public:
// Send it to the primary shard
ShardsvrRefineCollectionShardKey refineCollectionShardKeyCommand(nss,
request().getKey());
+ refineCollectionShardKeyCommand.setEnforceUniquenessCheck(
+ request().getEnforceUniquenessCheck());
auto cmdResponse = executeCommandAgainstDatabasePrimary(
opCtx,
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 60fc4727be2..1af1a6e62da 100644
--- a/src/mongo/s/request_types/refine_collection_shard_key.idl
+++ b/src/mongo/s/request_types/refine_collection_shard_key.idl
@@ -47,6 +47,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:
command_name: _configsvrRefineCollectionShardKey
@@ -70,3 +76,7 @@ commands:
isFromPrimaryShard:
type: bool
optional: true
+ enforceUniquenessCheck:
+ description: >-
+ Verifies that the shard key index has the same unique setting as the command.
+ type: optionalBool
diff --git a/src/mongo/s/request_types/sharded_ddl_commands.idl b/src/mongo/s/request_types/sharded_ddl_commands.idl
index dba48fa57ac..33142a69328 100644
--- a/src/mongo/s/request_types/sharded_ddl_commands.idl
+++ b/src/mongo/s/request_types/sharded_ddl_commands.idl
@@ -307,6 +307,12 @@ commands:
type: KeyPattern
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
_configsvrCreateDatabase:
description: "The internal createDatabase command on the config server"