jstests/concurrency/fsm_workload_helpers/auto_retry_transaction.js
// Throws if the commit fails and cannot be retried.
Throws if the commit fails and cannot be retried.
Throws if the commit fails and cannot be retried .
function commitTransactionWithRetries(session, retryOnKilledSession) {
        while (true) {
            const commitRes = session.commitTransaction_forTesting();
            const failedWithInterruption =
                !commitRes.ok && KilledSessionUtil.isKilledSessionCode(commitRes.code);
            const wcFailedWithInterruption = KilledSessionUtil.hasKilledSessionWCError(commitRes);
            if (retryOnKilledSession && (failedWithInterruption || wcFailedWithInterruption)) {
                print("-=-=-=- Retrying commit after killed session code, sessionId: " +
                      tojsononeline(session.getSessionId()) +
                      ", txnNumber: " + tojsononeline(session.getTxnNumber_forTesting()) +
                      ", res: " + tojsononeline(commitRes));
                continue;
            }
            if (commitRes.code === ErrorCodes.FailedToSatisfyReadPreference) {
                print("-=-=-=- Retrying commit due to FailedToSatisfyReadPreference, sessionId: " +
                      tojsononeline(session.getSessionId()) +
                      ", txnNumber: " + tojsononeline(session.getTxnNumber_forTesting()) +
                      ", res: " + tojsononeline(commitRes));
                continue;
            }
            quietly(() => {
                assert.commandWorked(commitRes);
            });
            return;
        }
    }
function commitTransactionWithRetries ( session , retryOnKilledSession ) { while ( true ) { const commitRes = session . commitTransaction_forTesting ( ) ; const failedWithInterruption = ! commitRes . ok && KilledSessionUtil . isKilledSessionCode ( commitRes . code ) ; const wcFailedWithInterruption = KilledSessionUtil . hasKilledSessionWCError ( commitRes ) ; if ( retryOnKilledSession && ( failedWithInterruption || wcFailedWithInterruption ) ) { print ( "-=-=-=- Retrying commit after killed session code, sessionId: " + tojsononeline ( session . getSessionId ( ) ) + ", txnNumber: " + tojsononeline ( session . getTxnNumber_forTesting ( ) ) + ", res: " + tojsononeline ( commitRes ) ) ; continue ; } if ( commitRes . code === ErrorCodes . FailedToSatisfyReadPreference ) { print ( "-=-=-=- Retrying commit due to FailedToSatisfyReadPreference, sessionId: " + tojsononeline ( session . getSessionId ( ) ) + ", txnNumber: " + tojsononeline ( session . getTxnNumber_forTesting ( ) ) + ", res: " + tojsononeline ( commitRes ) ) ; continue ; } quietly ( ( ) => { assert . commandWorked ( commitRes ) ; } ) ; return ; } }
Throws if the commit fails and cannot be retried.
Throws if the commit fails and cannot be retried .
// If commit fails with a killed session code, the commit must be retried because it is // unknown if the interrupted commit succeeded. This is safe because commitTransaction // is a retryable write. // Use assert.commandWorked() because it throws an exception in the format expected by // the caller of this function if the commit failed. Committing may fail with a // transient error that can be retried on at a higher level, so suppress unnecessary // logging.