Files
mongo/jstests/sharding/resharding_fails_on_nonempty_stash.js
Zac 591928c619 SERVER-108478 JS formatted by prettier and remove clang-format (#39656)
GitOrigin-RevId: 6c8f6aded47f260aa4f7c231b17dae3302cb1e04
2025-08-21 17:27:09 +00:00

60 lines
2.1 KiB
JavaScript

/**
* Tests that unrecoverable errors during resharding's oplog application are handled by the
* recipient.
*
* @tags: [
* uses_atclustertime
* ]
*/
import {ReshardingTest} from "jstests/sharding/libs/resharding_test_fixture.js";
const reshardingTest = new ReshardingTest({numDonors: 2, numRecipients: 2});
reshardingTest.setup();
const donorShardNames = reshardingTest.donorShardNames;
const inputCollection = reshardingTest.createShardedCollection({
ns: "reshardingDb.coll",
shardKeyPattern: {oldKey: 1},
chunks: [
{min: {oldKey: MinKey}, max: {oldKey: 0}, shard: donorShardNames[0]},
{min: {oldKey: 0}, max: {oldKey: MaxKey}, shard: donorShardNames[1]},
],
});
const recipientShardNames = reshardingTest.recipientShardNames;
reshardingTest.withReshardingInBackground(
{
newShardKeyPattern: {newKey: 1},
newChunks: [
{min: {newKey: MinKey}, max: {newKey: 0}, shard: recipientShardNames[0]},
{min: {newKey: 0}, max: {newKey: MaxKey}, shard: recipientShardNames[1]},
],
},
() => {
const mongos = inputCollection.getMongo();
assert.soon(() => {
const coordinatorDoc = mongos.getCollection("config.reshardingOperations").findOne({
ns: inputCollection.getFullName(),
});
return coordinatorDoc !== null && coordinatorDoc.cloneTimestamp !== undefined;
});
// The following documents violate the global _id uniqueness assumption of sharded
// collections. It is possible to construct such a sharded collection due to how each shard
// independently enforces the uniqueness of _id values for only the documents it owns. The
// resharding operation is expected to abort upon discovering this violation.
assert.commandWorked(
inputCollection.insert([
{_id: 0, info: `moves from ${donorShardNames[0]}`, oldKey: -10, newKey: 10},
{_id: 0, info: `moves from ${donorShardNames[1]}`, oldKey: 10, newKey: 10},
]),
);
},
{
expectedErrorCode: 5356800,
},
);
reshardingTest.teardown();