SERVER-115107: Retry on transient transaction error in write_concern_all_commands (#44996)

GitOrigin-RevId: 2e1a12efd83b54e8ec8ec909dd2d1e5f3a220868
This commit is contained in:
seanzimm 2025-12-09 14:28:32 -05:00 committed by MongoDB Bot
parent a1715c51e2
commit 43a056c5f0
1 changed files with 95 additions and 86 deletions

View File

@ -11,6 +11,7 @@
*/ */
import {TimeseriesTest} from "jstests/core/timeseries/libs/timeseries.js"; import {TimeseriesTest} from "jstests/core/timeseries/libs/timeseries.js";
import {AllCommandsTest} from "jstests/libs/all_commands_test.js"; import {AllCommandsTest} from "jstests/libs/all_commands_test.js";
import {withRetryOnTransientTxnError} from "jstests/libs/auto_retry_transaction_in_sharding.js";
import {getCommandName} from "jstests/libs/cmd_object_utils.js"; import {getCommandName} from "jstests/libs/cmd_object_utils.js";
import {configureFailPoint} from "jstests/libs/fail_point_util.js"; import {configureFailPoint} from "jstests/libs/fail_point_util.js";
import {FeatureFlagUtil} from "jstests/libs/feature_flag_util.js"; import {FeatureFlagUtil} from "jstests/libs/feature_flag_util.js";
@ -234,48 +235,50 @@ const wcCommandsTests = {
lsid: getLSID(), lsid: getLSID(),
}), }),
setupFunc: (coll, cluster, clusterType, secondariesRunning, optionalArgs) => { setupFunc: (coll, cluster, clusterType, secondariesRunning, optionalArgs) => {
assert.commandWorked(coll.insert({_id: 0})); withRetryOnTransientTxnError(() => {
assert.commandWorked(coll.insert({_id: 0}));
if (clusterType == "sharded" && bsonWoCompare(getShardKey(coll, fullNs), {}) == 0) {
// Set the primary shard to shard0 so we can assume that it's okay to run
// prepareTransaction on it
assert.commandWorked(
coll.getDB().adminCommand({moveCollection: fullNs, toShard: cluster.shard0.shardName}),
);
}
if (clusterType == "sharded" && bsonWoCompare(getShardKey(coll, fullNs), {}) == 0) {
// Set the primary shard to shard0 so we can assume that it's okay to run
// prepareTransaction on it
assert.commandWorked( assert.commandWorked(
coll.getDB().adminCommand({moveCollection: fullNs, toShard: cluster.shard0.shardName}), coll.getDB().runCommand({
insert: collName,
documents: [{_id: 1}],
lsid: getLSID(),
stmtIds: [NumberInt(0)],
txnNumber: getTxnNumber(),
startTransaction: true,
autocommit: false,
}),
); );
}
assert.commandWorked( assert.commandWorked(
coll.getDB().runCommand({ coll.getDB().runCommand({
insert: collName, update: collName,
documents: [{_id: 1}], updates: [{q: {}, u: {$set: {a: 1}}}],
lsid: getLSID(), lsid: getLSID(),
stmtIds: [NumberInt(0)], stmtIds: [NumberInt(1)],
txnNumber: getTxnNumber(), txnNumber: getTxnNumber(),
startTransaction: true, autocommit: false,
autocommit: false, }),
}), );
);
assert.commandWorked( let primary = clusterType == "sharded" ? cluster.rs0.getPrimary() : cluster.getPrimary();
coll.getDB().runCommand({ assert.commandWorked(
update: collName, primary.getDB(dbName).adminCommand({
updates: [{q: {}, u: {$set: {a: 1}}}], prepareTransaction: 1,
lsid: getLSID(), lsid: getLSID(),
stmtIds: [NumberInt(1)], txnNumber: getTxnNumber(),
txnNumber: getTxnNumber(), autocommit: false,
autocommit: false, }),
}), );
); });
let primary = clusterType == "sharded" ? cluster.rs0.getPrimary() : cluster.getPrimary();
assert.commandWorked(
primary.getDB(dbName).adminCommand({
prepareTransaction: 1,
lsid: getLSID(),
txnNumber: getTxnNumber(),
autocommit: false,
}),
);
}, },
confirmFunc: (res, coll) => { confirmFunc: (res, coll) => {
assert.commandWorkedIgnoringWriteConcernErrors(res); assert.commandWorkedIgnoringWriteConcernErrors(res);
@ -292,25 +295,27 @@ const wcCommandsTests = {
lsid: getLSID(), lsid: getLSID(),
}), }),
setupFunc: (coll) => { setupFunc: (coll) => {
assert.commandWorked( withRetryOnTransientTxnError(() => {
coll.getDB().runCommand({ assert.commandWorked(
insert: collName, coll.getDB().runCommand({
documents: [{_id: 1}], insert: collName,
lsid: getLSID(), documents: [{_id: 1}],
stmtIds: [NumberInt(0)], lsid: getLSID(),
txnNumber: getTxnNumber(), stmtIds: [NumberInt(0)],
startTransaction: true, txnNumber: getTxnNumber(),
autocommit: false, startTransaction: true,
}), autocommit: false,
); }),
assert.commandWorked( );
coll.getDB().adminCommand({ assert.commandWorked(
commitTransaction: 1, coll.getDB().adminCommand({
lsid: getLSID(), commitTransaction: 1,
txnNumber: getTxnNumber(), lsid: getLSID(),
autocommit: false, txnNumber: getTxnNumber(),
}), autocommit: false,
); }),
);
});
}, },
confirmFunc: (res, coll) => { confirmFunc: (res, coll) => {
assert.commandFailedWithCode(res, ErrorCodes.TransactionCommitted); assert.commandFailedWithCode(res, ErrorCodes.TransactionCommitted);
@ -674,25 +679,27 @@ const wcCommandsTests = {
lsid: getLSID(), lsid: getLSID(),
}), }),
setupFunc: (coll) => { setupFunc: (coll) => {
assert.commandWorked( withRetryOnTransientTxnError(() => {
coll.getDB().runCommand({ assert.commandWorked(
insert: collName, coll.getDB().runCommand({
documents: [{_id: 1}], insert: collName,
lsid: getLSID(), documents: [{_id: 1}],
stmtIds: [NumberInt(0)], lsid: getLSID(),
txnNumber: getTxnNumber(), stmtIds: [NumberInt(0)],
startTransaction: true, txnNumber: getTxnNumber(),
autocommit: false, startTransaction: true,
}), autocommit: false,
); }),
assert.commandWorked( );
coll.getDB().adminCommand({ assert.commandWorked(
commitTransaction: 1, coll.getDB().adminCommand({
txnNumber: getTxnNumber(), commitTransaction: 1,
autocommit: false, txnNumber: getTxnNumber(),
lsid: getLSID(), autocommit: false,
}), lsid: getLSID(),
); }),
);
});
}, },
confirmFunc: (res, coll) => { confirmFunc: (res, coll) => {
assert.commandWorkedIgnoringWriteConcernErrors(res); assert.commandWorkedIgnoringWriteConcernErrors(res);
@ -709,17 +716,19 @@ const wcCommandsTests = {
lsid: getLSID(), lsid: getLSID(),
}), }),
setupFunc: (coll) => { setupFunc: (coll) => {
assert.commandWorked( withRetryOnTransientTxnError(() => {
coll.getDB().runCommand({ assert.commandWorked(
insert: collName, coll.getDB().runCommand({
documents: [{_id: 1}], insert: collName,
lsid: getLSID(), documents: [{_id: 1}],
stmtIds: [NumberInt(0)], lsid: getLSID(),
txnNumber: getTxnNumber(), stmtIds: [NumberInt(0)],
startTransaction: true, txnNumber: getTxnNumber(),
autocommit: false, startTransaction: true,
}), autocommit: false,
); }),
);
});
}, },
confirmFunc: (res, coll) => { confirmFunc: (res, coll) => {
assert.commandWorkedIgnoringWriteConcernErrors(res); assert.commandWorkedIgnoringWriteConcernErrors(res);