jstests/libs/auto_retry_transaction_in_sharding.js
/**
     * Runs 'func' inside of a transaction started with 'txnOptions', and automatically retries
     * until it either succeeds or the server returns a non-TransientTransactionError error
     * response.
     *
     * The caller should take care to ensure 'func' doesn't modify any captured variables in a
     * speculative fashion where calling it multiple times would lead to unintended behavior. The
     * transaction started by the withTxnAndAutoRetryOnMongos() function is only known to have
     * committed after the withTxnAndAutoRetryOnMongos() function returns.
     *
     * This behaviour only applies if the client is a mongos
     *
     * TODO SERVER-39704: Once completed, the usages of this function should be revisited to
     * determine whether it is still necessary or the retries performed by MongoS make it
     * unnecessary
     */
Runs 'func' inside of a transaction started with 'txnOptions', and automatically retries
until it either succeeds or the server returns a non-TransientTransactionError error
response.

The caller should take care to ensure 'func' doesn't modify any captured variables in a
speculative fashion where calling it multiple times would lead to unintended behavior. The
transaction started by the withTxnAndAutoRetryOnMongos() function is only known to have
committed after the withTxnAndAutoRetryOnMongos() function returns.

This behaviour only applies if the client is a mongos


Runs ' func ' inside of a transaction started with ' txnOptions ' and automatically retries until it either succeeds or the server returns a non - TransientTransactionError error response . The caller should take care to ensure ' func ' doesn ' t modify any captured variables in a speculative fashion where calling it multiple times would lead to unintended behavior . The transaction started by the withTxnAndAutoRetryOnMongos () function is only known to have committed after the withTxnAndAutoRetryOnMongos () function returns . This behaviour only applies if the client is a mongos
function withTxnAndAutoRetryOnMongos(session, func, txnOptions) {
        if (session.getClient().isMongos()) {
            withTxnAndAutoRetry(session, func, {txnOptions});
        } else {
            session.startTransaction(txnOptions);
            func();
            assert.commandWorked(session.commitTransaction_forTesting());
        }
    }
function withTxnAndAutoRetryOnMongos ( session , func , txnOptions ) { if ( session . getClient ( ) . isMongos ( ) ) { withTxnAndAutoRetry ( session , func , { txnOptions } ) ; } else { session . startTransaction ( txnOptions ) ; func ( ) ; assert . commandWorked ( session . commitTransaction_forTesting ( ) ) ; } }
Runs 'func' inside of a transaction started with 'txnOptions', and automatically retries
 until it either succeeds or the server returns a non-TransientTransactionError error
 response.
Runs ' func ' inside of a transaction started with ' txnOptions ' and automatically retries until it either succeeds or the server returns a non - TransientTransactionError error response .