jstests/sharding/internal_txns/libs/resharding_test.js
/*
     * Retries the commands defined inside 'testCase' in an internal transaction of the specified
     * type. If this retry is expected to fail, asserts that the command to start the transaction
     * fails with an IncompleteTransactionHistory error.
     */
Retries the commands defined inside 'testCase' in an internal transaction of the specified
type. If this retry is expected to fail, asserts that the command to start the transaction
fails with an IncompleteTransactionHistory error.
Retries the commands defined inside ' testCase ' in an internal transaction of the specified type . If this retry is expected to fail asserts that the command to start the transaction fails with an IncompleteTransactionHistory error .
function runInternalTransactionOnRetry(
        txnType, testCase, isRetryAfterAbort, expectRetryToSucceed) {
        jsTest.log(
            `Retrying write statements executed in an internal transaction with options ${tojson({
                id: testCase.id,
                isPreparedTxn: testCase.isPreparedTxn,
                isLargeTxn: testCase.isLargeTxn,
                abortOnInitialTry: testCase.abortOnInitialTry,
                imageType: testCase.imageType,
                isRetryAfterAbort: isRetryAfterAbort,
                expectRetryToSucceed: expectRetryToSucceed
            })} in another internal transaction`);
        const lsid = getTransactionSessionId(txnType, testCase);
        lsid.txnUUID = UUID();
        while (true) {
            const txnNumber = getNextTxnNumber(txnType, testCase);
            try {
                for (let i = 0; i < testCase.commands.length; i++) {
                    const command = testCase.commands[i];
                    if (!isRetryAfterAbort && command.cmdObj.stmtId == -1) {
                        continue;
                    }
                    const cmdObj =
                        Object.assign({}, command.cmdObj, {lsid, txnNumber, autocommit: false});
                    if (i == 0) {
                        cmdObj.startTransaction = true;
                    }
                    const res = mongosConn.getDB(kDbName).runCommand(cmdObj);
                    if (expectRetryToSucceed) {
                        assert.commandWorked(res);
                        command.checkResponseFunc(res);
                    } else {
                        assert.commandFailedWithCode(res, ErrorCodes.IncompleteTransactionHistory);
                        return;
                    }
                }
                commitTransaction(lsid, txnNumber);
                break;
            } catch (e) {
                if (e.hasOwnProperty('errorLabels') &&
                    e.errorLabels.includes('TransientTransactionError') &&
                    e.code != ErrorCodes.NoSuchTransaction) {
                    jsTest.log("Failed to run transaction due to a transient error " + tojson(e));
                } else {
                    throw e;
                }
            }
        }
        testCase.checkDocsFunc(true );
    }
function runInternalTransactionOnRetry ( txnType , testCase , isRetryAfterAbort , expectRetryToSucceed ) { jsTest . log ( ` ${ tojson ( { id : testCase . id , isPreparedTxn : testCase . isPreparedTxn , isLargeTxn : testCase . isLargeTxn , abortOnInitialTry : testCase . abortOnInitialTry , imageType : testCase . imageType , isRetryAfterAbort : isRetryAfterAbort , expectRetryToSucceed : expectRetryToSucceed } ) } ` ) ; const lsid = getTransactionSessionId ( txnType , testCase ) ; lsid . txnUUID = UUID ( ) ; while ( true ) { const txnNumber = getNextTxnNumber ( txnType , testCase ) ; try { for ( let i = 0 ; i < testCase . commands . length ; i ++ ) { const command = testCase . commands [ i ] ; if ( ! isRetryAfterAbort && command . cmdObj . stmtId == - 1 ) { continue ; } const cmdObj = Object . assign ( { } , command . cmdObj , { lsid , txnNumber , autocommit : false } ) ; if ( i == 0 ) { cmdObj . startTransaction = true ; } const res = mongosConn . getDB ( kDbName ) . runCommand ( cmdObj ) ; if ( expectRetryToSucceed ) { assert . commandWorked ( res ) ; command . checkResponseFunc ( res ) ; } else { assert . commandFailedWithCode ( res , ErrorCodes . IncompleteTransactionHistory ) ; return ; } } commitTransaction ( lsid , txnNumber ) ; break ; } catch ( e ) { if ( e . hasOwnProperty ( 'errorLabels' ) && e . errorLabels . includes ( 'TransientTransactionError' ) && e . code != ErrorCodes . NoSuchTransaction ) { jsTest . log ( "Failed to run transaction due to a transient error " + tojson ( e ) ) ; } else { throw e ; } } } testCase . checkDocsFunc ( true ) ; }
Retries the commands defined inside 'testCase' in an internal transaction of the specified
 type.
Retries the commands defined inside ' testCase ' in an internal transaction of the specified type .
// Give the session a different txnUUID to simulate a retry from a different mongos. // The transaction has already committed and the statement in this command // is not retryable so do not retry it. /* isTxnCommitted */