diff options
Diffstat (limited to 'jstests/sharding/transactions_stale_shard_version_errors.js')
-rw-r--r-- | jstests/sharding/transactions_stale_shard_version_errors.js | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/jstests/sharding/transactions_stale_shard_version_errors.js b/jstests/sharding/transactions_stale_shard_version_errors.js index 2ff76e94b0c..12debac39ab 100644 --- a/jstests/sharding/transactions_stale_shard_version_errors.js +++ b/jstests/sharding/transactions_stale_shard_version_errors.js @@ -1,10 +1,15 @@ // Tests mongos behavior on stale shard version errors received in a transaction. // -// @tags: [requires_sharding, uses_transactions, uses_multi_shard_transaction] +// @tags: [ +// requires_sharding, +// uses_transactions, +// uses_multi_shard_transaction, +// ] (function() { "use strict"; load("jstests/sharding/libs/sharded_transactions_helpers.js"); +load("jstests/multiVersion/libs/verify_versions.js"); function expectChunks(st, ns, chunks) { for (let i = 0; i < chunks.length; i++) { @@ -208,13 +213,24 @@ session.startTransaction(); assert.commandWorked(sessionDB.runCommand({insert: collName, documents: [{_id: -4}]})); // Targets Shard2, which is stale. -res = assert.commandFailedWithCode(sessionDB.runCommand({insert: collName, documents: [{_id: 7}]}), - ErrorCodes.StaleConfig); -assert.eq(res.errorLabels, ["TransientTransactionError"]); - -// The transaction should have been implicitly aborted on all shards. -assertNoSuchTransactionOnAllShards(st, session.getSessionId(), session.getTxnNumber_forTesting()); -assert.commandFailedWithCode(session.abortTransaction_forTesting(), ErrorCodes.NoSuchTransaction); +let shard2Version = st.shard2.getBinVersion(); +jsTest.log("Binary version of shard2: " + MongoRunner.getBinVersionFor(shard2Version)); +if (MongoRunner.compareBinVersions(shard2Version, "4.9") < 0) { + // TODO SERVER-52782 remove this if branch when 5.0 becomes last-lts + res = assert.commandFailedWithCode( + sessionDB.runCommand({insert: collName, documents: [{_id: 7}]}), ErrorCodes.StaleConfig); + assert.eq(res.errorLabels, ["TransientTransactionError"]); + + // The transaction should have been implicitly aborted on all shards. + assertNoSuchTransactionOnAllShards( + st, session.getSessionId(), session.getTxnNumber_forTesting()); + assert.commandFailedWithCode(session.abortTransaction_forTesting(), + ErrorCodes.NoSuchTransaction); +} else { + assert.commandWorked(sessionDB.runCommand({insert: collName, documents: [{_id: 7}]})); + + assert.commandWorked(session.abortTransaction_forTesting()); +} // // The final StaleConfig error should be returned if the router exhausts its retries. |