mongo/jstests/sharding/abort_rewrite_collection_basic.js
Kruti Shah 7048f3e8fa SERVER-120392 Fix serverStatus metrics check in abort resharding tests (#48933)
GitOrigin-RevId: d7c8c8c8038432879b0ded4782f2944e5d28bd7f
2026-03-04 16:37:45 +00:00

75 lines
2.1 KiB
JavaScript

/**
* Tests for basic functionality of the abort rewrite collection feature.
*
* @tags: [
* requires_fcv_83,
* ]
*/
import {configureFailPoint} from "jstests/libs/fail_point_util.js";
import {funWithArgs} from "jstests/libs/parallel_shell_helpers.js";
import {ShardingTest} from "jstests/libs/shardingtest.js";
import {getReshardingCoordinatorMetrics} from "jstests/sharding/libs/reshard_collection_util.js";
let st = new ShardingTest({mongos: 1, shards: 2});
const dbName = "test";
const collName = "foo";
const ns = dbName + "." + collName;
let mongos = st.s0;
let shard0 = st.shard0.shardName;
let shard1 = st.shard1.shardName;
let shardKeyMin = -500;
let shardKeyMax = 500;
assert.commandWorked(st.s.adminCommand({enableSharding: dbName, primaryShard: shard0}));
const coll = mongos.getDB(dbName)[collName];
for (let i = shardKeyMin; i < shardKeyMax; ++i) {
assert.commandWorked(coll.insert({_id: i}));
}
mongos.getDB(dbName).adminCommand({shardCollection: ns, key: {_id: 1}});
let failpoint = configureFailPoint(st.rs1.getPrimary(), "reshardingPauseRecipientDuringCloning");
const awaitResult = startParallelShell(
funWithArgs(function (ns) {
assert.commandFailedWithCode(db.adminCommand({rewriteCollection: ns}), ErrorCodes.ReshardCollectionAborted);
}, ns),
st.s.port,
);
failpoint.wait();
// Verify that the provenance field is appended to the currentOp
const filter = {
type: "op",
"originatingCommand.reshardCollection": ns,
"provenance": "rewriteCollection",
};
assert.soon(() => {
return (
st.s
.getDB("admin")
.aggregate([{$currentOp: {allUsers: true, localOps: false}}, {$match: filter}])
.toArray().length >= 1
);
});
assert.commandWorked(mongos.adminCommand({abortRewriteCollection: ns}));
failpoint.off();
awaitResult();
// Confirm that the operation started and was cancelled.
const metrics = getReshardingCoordinatorMetrics(st.configRS, "rewriteCollection");
assert.eq(metrics.countStarted, 1);
assert.eq(metrics.countSucceeded, 0);
assert.eq(metrics.countFailed, 0);
assert.eq(metrics.countCanceled, 1);
st.stop();