diff options
author | Marcos José Grillo Ramirez <marcos.grillo@mongodb.com> | 2021-07-14 18:23:18 +0200 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-10-25 07:25:14 +0000 |
commit | 1b6756337268640c7e738ad7660a356c64ceb6b1 (patch) | |
tree | 706ab5efc75c28a35abc992b3a57a69c4bff96c8 | |
parent | caa2df849ff0287971c5ac1ea21e6168b593341e (diff) | |
download | mongo-1b6756337268640c7e738ad7660a356c64ceb6b1.tar.gz |
SERVER-58485 Add retry to insert inside transactions to prevent transient errors
(cherry picked from commit 987dfecbced2a5f8f84e0197c68649bb1c20e8c4)
-rw-r--r-- | jstests/core/txns/api_params_transaction.js | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/jstests/core/txns/api_params_transaction.js b/jstests/core/txns/api_params_transaction.js index 14c42414bb0..990ed4bad70 100644 --- a/jstests/core/txns/api_params_transaction.js +++ b/jstests/core/txns/api_params_transaction.js @@ -7,6 +7,9 @@ "use strict"; load("jstests/libs/fixture_helpers.js"); // For FixtureHelpers.isMongos(). +load( + "jstests/libs/auto_retry_transaction_in_sharding.js"); // For + // retryOnceOnTransientAndRestartTxnOnMongos(). const dbName = jsTestName(); const collName = "test"; @@ -42,10 +45,6 @@ for (const txnInitiatingParams of apiParamCombos) { const session = db.getMongo().startSession(); const sessionDb = session.getDatabase(dbName); - session.startTransaction(); - assert.commandWorked(sessionDb.runCommand( - addApiParams({insert: collName, documents: [{}, {}, {}]}, txnInitiatingParams))); - function checkCommand(db, command) { const commandWithParams = addApiParams(command, txnContinuingParams); jsTestLog(`Session ${session.getSessionId().id}, ` + @@ -63,10 +62,16 @@ for (const txnInitiatingParams of apiParamCombos) { } } - /* - * Check "insert" with API params in a transaction. - */ - checkCommand(sessionDb, {insert: collName, documents: [{}]}); + session.startTransaction(); + retryOnceOnTransientAndRestartTxnOnMongos(session, () => { + assert.commandWorked(sessionDb.runCommand(addApiParams( + {insert: collName, documents: [{}, {}, {}]}, txnInitiatingParams))); + + /* + * Check "insert" with API params in a transaction. + */ + checkCommand(sessionDb, {insert: collName, documents: [{}]}); + }, {}); /* * Check "commitTransaction" or "abortTransaction". |