mongo/jstests/sharding/test_resharding_test_fixture.js
Sam Frank 82f724418a SERVER-117664 Support collection options in ReshardingTest.createShardedCollection (#50351)
GitOrigin-RevId: e3a105c9df884bc43966f43dbf237db8a0730e7e
2026-03-31 17:57:51 +00:00

70 lines
2.6 KiB
JavaScript

/**
* Test for the ReshardingTest fixture itself.
*
* Verifies that the reshardCollection command is run and kept suspended in the "applying" state.
*
* @tags: [
* uses_atclustertime
* ]
*/
import {ReshardingTest} from "jstests/sharding/libs/resharding_test_fixture.js";
const reshardingTest = new ReshardingTest({numDonors: 2, numRecipients: 2, reshardInPlace: true});
reshardingTest.setup();
const ns = "reshardingDb.coll";
const donorShardNames = reshardingTest.donorShardNames;
const sourceCollection = reshardingTest.createShardedCollection({
ns,
shardKeyPattern: {oldKey: 1},
chunks: [
{min: {oldKey: MinKey}, max: {oldKey: 0}, shard: donorShardNames[0]},
{min: {oldKey: 0}, max: {oldKey: MaxKey}, shard: donorShardNames[1]},
],
createCollOptions: {clusteredIndex: {key: {_id: 1}, unique: true}},
});
// Perform some inserts before resharding starts so there's data to clone.
assert.commandWorked(
sourceCollection.insert([
{_id: "stays on shard0", oldKey: -10, newKey: -10},
{_id: "moves to shard0", oldKey: 10, newKey: -10},
{_id: "moves to shard1", oldKey: -10, newKey: 10},
{_id: "stays on shard1", oldKey: 10, newKey: 10},
]),
);
const recipientShardNames = reshardingTest.recipientShardNames;
reshardingTest.startReshardingInBackground({
newShardKeyPattern: {newKey: 1},
newChunks: [
{min: {newKey: MinKey}, max: {newKey: 0}, shard: recipientShardNames[0]},
{min: {newKey: 0}, max: {newKey: MaxKey}, shard: recipientShardNames[1]},
],
});
// Wait for the recipients to have finished cloning and then perform some updates so there's oplog
// entries to fetch and apply.
const mongos = sourceCollection.getMongo();
assert.soon(() => {
const coordinatorDoc = mongos.getCollection("config.reshardingOperations").findOne();
return coordinatorDoc !== null && coordinatorDoc.state === "applying";
});
assert.commandWorked(sourceCollection.update({_id: 0}, {$inc: {extra: 1}}, {multi: true}));
// The reshardCollection command should still be actively running on mongos.
const ops = mongos
.getDB("admin")
.aggregate([{$currentOp: {allUsers: true, localOps: true}}, {$match: {"command.reshardCollection": ns}}])
.toArray();
assert.eq(1, ops.length, "failed to find reshardCollection in $currentOp output");
// Test options parsing
const collectionInfos = sourceCollection.getDB().getCollectionInfos({name: sourceCollection.getName()});
const collInfo = collectionInfos[0];
assert(collInfo.options.clusteredIndex, "collection should have a clustered index: " + tojson(collInfo));
reshardingTest.teardown();