SERVER-112288 Use Thread instead of startParallelShell in multi_writes_with_shard_version_ignored_dont_bubble_up_critical_section.js (#42509)

GitOrigin-RevId: 2ea4a5007ad5b1b54402f562a9f83c473c461537
This commit is contained in:
Cheahuychou Mao 2025-10-11 01:37:24 +07:00 committed by MongoDB Bot
parent 8e0de5838e
commit bb29ffcbb3
1 changed files with 27 additions and 33 deletions

View File

@ -10,7 +10,7 @@
*/
import {configureFailPoint} from "jstests/libs/fail_point_util.js";
import {funWithArgs} from "jstests/libs/parallel_shell_helpers.js";
import {Thread} from "jstests/libs/parallelTester.js";
import {ShardingTest} from "jstests/libs/shardingtest.js";
// Configure 'internalQueryExecYieldIterations' on both shards such that operations will yield on
@ -53,23 +53,6 @@ function setupTest() {
jsTest.log("Inserted initial data.");
}
function runMigration() {
const awaitResult = startParallelShell(
funWithArgs(
function (ns, toShard) {
jsTest.log("Starting migration.");
assert.commandWorked(db.adminCommand({moveChunk: ns, find: {x: -1}, to: toShard}));
jsTest.log("Completed migration.");
},
ns,
st.shard1.shardName,
),
st.s.port,
);
return awaitResult;
}
async function updateOperationFn(shardColl, numInitialDocsOnShard0) {
const {ShardVersioningUtil} = await import("jstests/sharding/libs/shard_versioning_util.js");
jsTest.log("Begin multi-update.");
@ -119,19 +102,19 @@ function runTest(writeOpFn) {
let fp1 = configureFailPoint(st.rs0.getPrimary(), "setYieldAllLocksHang", {namespace: coll.getFullName()});
const awaitWriteResult = startParallelShell(
funWithArgs(
function (writeOpFn, dbName, collName, numDocs) {
const shardColl = db.getSiblingDB(dbName)[collName];
writeOpFn(shardColl, numDocs);
},
writeOpFn,
coll.getDB().getName(),
coll.getName(),
numDocs,
),
st.rs0.getPrimary().port,
const writeThread = new Thread(
(shard0PrimaryHost, writeOpFn, dbName, collName, numDocs) => {
const mongos = new Mongo(shard0PrimaryHost);
const shardColl = mongos.getDB(dbName)[collName];
writeOpFn(shardColl, numDocs);
},
st.rs0.getPrimary().host,
writeOpFn,
coll.getDB().getName(),
coll.getName(),
numDocs,
);
writeThread.start();
// Wait for the write op to yield.
fp1.wait();
@ -139,7 +122,18 @@ function runTest(writeOpFn) {
// Start chunk migration and wait for it to enter the critical section.
let failpointHangMigrationWhileInCriticalSection = configureFailPoint(st.rs0.getPrimary(), "moveChunkHangAtStep5");
const awaitMigration = runMigration();
const migrationThread = new Thread(
(mongosHost, ns, toShard) => {
const mongos = new Mongo(mongosHost);
jsTest.log("Starting migration.");
assert.commandWorked(mongos.adminCommand({moveChunk: ns, find: {x: -1}, to: toShard}));
jsTest.log("Completed migration.");
},
st.s.host,
ns,
st.shard1.shardName,
);
migrationThread.start();
failpointHangMigrationWhileInCriticalSection.wait();
// Let the multi-write resume from the yield.
@ -153,10 +147,10 @@ function runTest(writeOpFn) {
// Let the migration continue and release the critical section.
jsTest.log("Letting migration exit its critical section and complete");
failpointHangMigrationWhileInCriticalSection.off();
awaitMigration();
migrationThread.join();
// Wait for the write op to finish. It should succeed.
awaitWriteResult();
writeThread.join();
}
runTest(updateOperationFn);