SERVER-112931 Update mongos_not_retry_commands_in_transactions.js once we start retrying on startTransaction for read operations (#43130)

GitOrigin-RevId: 19ac29d67a5ed6706199e0fa7161a56d712c335c
This commit is contained in:
Silvia Surroca 2025-10-31 08:58:03 +01:00 committed by MongoDB Bot
parent b1e08aa1be
commit 663b6a145b
1 changed files with 28 additions and 9 deletions

View File

@ -1,9 +1,13 @@
/** /**
* Tests that mongos doesn't retry commands with startTransaction=true. * Tests retryability on mongos commands within transactions.
*
* @tags: [
* requires_fcv_83,
* ]
*/ */
import {ShardingTest} from "jstests/libs/shardingtest.js"; import {ShardingTest} from "jstests/libs/shardingtest.js";
const setCommandToFail = (nodeConnection, command, namespace) => { const setCommandToFailOnce = (nodeConnection, command, namespace) => {
return nodeConnection.adminCommand({ return nodeConnection.adminCommand({
configureFailPoint: "failCommand", configureFailPoint: "failCommand",
mode: {times: 1}, mode: {times: 1},
@ -49,13 +53,11 @@ assert.commandWorked(
// Set the failCommand failpoint to make the next 'find' command fail once due to a failover. // Set the failCommand failpoint to make the next 'find' command fail once due to a failover.
// Start a transaction & execute a find command. // Start a transaction & execute a find command.
// It should fail once due to the 'failCommand' failpoint and should not be retried. // It should succeed since the command will be retried.
jsTest.log( jsTest.log("Testing that mongos retries read commands with startTransaction=true on replication set failover.");
"Testing that mongos doesn't retry the read command with startTransaction=true on replication set failover.", assert.commandWorked(setCommandToFailOnce(primaryConnection, "find", kNs));
);
assert.commandWorked(setCommandToFail(primaryConnection, "find", kNs));
assert.commandFailedWithCode( assert.commandWorked(
mongosDB.runCommand({ mongosDB.runCommand({
find: kCollName, find: kCollName,
filter: kDoc0, filter: kDoc0,
@ -64,11 +66,28 @@ assert.commandFailedWithCode(
stmtId: NumberInt(0), stmtId: NumberInt(0),
autocommit: false, autocommit: false,
}), }),
);
// Set the failCommand failpoint to make the next 'update' command fail once due to a failover.
// Start a transaction & execute a find command.
// It should fail once due to the 'failCommand' failpoint and should not be retried.
jsTest.log("Testing that mongos doesn't retry writes with startTransaction=true on replication set failover.");
assert.commandWorked(setCommandToFailOnce(primaryConnection, "update", kNs));
assert.commandFailedWithCode(
mongosDB.runCommand({
update: kCollName,
updates: [{q: kDoc0, u: {$set: {a: 1}}}],
startTransaction: true,
txnNumber: NumberLong(transactionNumber++),
stmtId: NumberInt(0),
autocommit: false,
}),
ErrorCodes.doMongosRewrite(st.s0, ErrorCodes.InterruptedDueToReplStateChange), ErrorCodes.doMongosRewrite(st.s0, ErrorCodes.InterruptedDueToReplStateChange),
); );
jsTest.log("Testing that mongos retries retryable writes on failover."); jsTest.log("Testing that mongos retries retryable writes on failover.");
assert.commandWorked(setCommandToFail(primaryConnection, "insert", kNs)); assert.commandWorked(setCommandToFailOnce(primaryConnection, "insert", kNs));
assert.commandWorked( assert.commandWorked(
mongosDB.runCommand({insert: kCollName, documents: [kDoc1], txnNumber: NumberLong(transactionNumber++)}), mongosDB.runCommand({insert: kCollName, documents: [kDoc1], txnNumber: NumberLong(transactionNumber++)}),