mirror of https://github.com/mongodb/mongo
SERVER-100072 Assert shard key is the same when forceRedistribution passed to reshardCollection (#34686)
GitOrigin-RevId: c3efe38c902eb66274623f1ffaf4babb513e7292
This commit is contained in:
parent
d314d0604d
commit
c9700d311e
|
|
@ -120,7 +120,7 @@ assert.commandFailedWithCode(db.adminCommand({
|
||||||
|
|
||||||
assert.commandFailedWithCode(db.adminCommand({
|
assert.commandFailedWithCode(db.adminCommand({
|
||||||
reshardCollection: ns,
|
reshardCollection: ns,
|
||||||
key: {newKey: 1},
|
key: {oldKey: 1},
|
||||||
forceRedistribution: true,
|
forceRedistribution: true,
|
||||||
zones: [
|
zones: [
|
||||||
{zone: newZoneName, min: {newKey: 'MinKey'}, max: {newKey: '0'}},
|
{zone: newZoneName, min: {newKey: 'MinKey'}, max: {newKey: '0'}},
|
||||||
|
|
@ -139,6 +139,23 @@ if (!TestData.implicitlyTrackUnshardedCollectionOnCreation) {
|
||||||
[ErrorCodes.NamespaceNotFound, ErrorCodes.NamespaceNotSharded]);
|
[ErrorCodes.NamespaceNotFound, ErrorCodes.NamespaceNotSharded]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO SERVER-103461 Remove version check when 9.0 becomes last LTS.
|
||||||
|
const binVersion = assert
|
||||||
|
.commandWorked(db.adminCommand({
|
||||||
|
serverStatus: 1,
|
||||||
|
}))
|
||||||
|
.version;
|
||||||
|
if (MongoRunner.compareBinVersions(binVersion, "8.2") >= 0) {
|
||||||
|
jsTest.log(
|
||||||
|
"Fail if using forceRedistribution and provide a different key than the existing shard key.");
|
||||||
|
assert.commandFailedWithCode(db.adminCommand({
|
||||||
|
reshardCollection: ns,
|
||||||
|
key: {newKey: 1},
|
||||||
|
forceRedistribution: true,
|
||||||
|
}),
|
||||||
|
ErrorCodes.InvalidOptions);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Success cases
|
* Success cases
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -118,9 +118,9 @@ const testShardDistribution = (mongos) => {
|
||||||
"reshardCollection cmd should fail when the shardId in shardDistribution is a shard url.");
|
"reshardCollection cmd should fail when the shardId in shardDistribution is a shard url.");
|
||||||
assert.commandFailedWithCode(mongos.adminCommand({
|
assert.commandFailedWithCode(mongos.adminCommand({
|
||||||
reshardCollection: ns,
|
reshardCollection: ns,
|
||||||
key: {newKey: 1},
|
key: {oldKey: 1},
|
||||||
forceRedistribution: true,
|
forceRedistribution: false,
|
||||||
shardDistribution: [{shard: shardHosts[0], min: {newKey: MinKey}, max: {newKey: MaxKey}}]
|
shardDistribution: [{shard: shardHosts[0], min: {oldKey: MinKey}, max: {oldKey: MaxKey}}]
|
||||||
}),
|
}),
|
||||||
ErrorCodes.ShardNotFound);
|
ErrorCodes.ShardNotFound);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -218,6 +218,16 @@ ExecutorFuture<void> ReshardCollectionCoordinator::_runImpl(
|
||||||
uassert(ErrorCodes::NamespaceNotSharded,
|
uassert(ErrorCodes::NamespaceNotSharded,
|
||||||
"Collection has to be a sharded collection.",
|
"Collection has to be a sharded collection.",
|
||||||
cmOld.isSharded());
|
cmOld.isSharded());
|
||||||
|
|
||||||
|
if (_doc.getForceRedistribution() && *_doc.getForceRedistribution()) {
|
||||||
|
uassert(ErrorCodes::InvalidOptions,
|
||||||
|
str::stream()
|
||||||
|
<< "The new shard key must be the same as the original shard key "
|
||||||
|
"when using the forceRedistribution option. The "
|
||||||
|
"forceRedistribution option is meant for redistributing the "
|
||||||
|
"collection to a different set of shards.",
|
||||||
|
cmOld.getShardKeyPattern().isShardKey(_doc.getKey()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
configsvrReshardCollection.setProvenance(provenance);
|
configsvrReshardCollection.setProvenance(provenance);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue