jstests/core/txns/new_transaction_waits_for_previous_txn_table_updates.js
/**
 * Launches a parallel shell to start a new transaction on the session with the given lsid. It
 * performs an insert and then commits. Assumes that there will be an already-prepared transaction
 * on the session, and blocks using a failpoint until the transaction in the parallel shell has
 * begun to block behind the prepared transaction.
 */
Launches a parallel shell to start a new transaction on the session with the given lsid. It
performs an insert and then commits. Assumes that there will be an already-prepared transaction
on the session, and blocks using a failpoint until the transaction in the parallel shell has
begun to block behind the prepared transaction.
Launches a parallel shell to start a new transaction on the session with the given lsid . It performs an insert and then commits . Assumes that there will be an already - prepared transaction on the session and blocks using a failpoint until the transaction in the parallel shell has begun to block behind the prepared transaction .
function runConcurrentTransactionOnSession(dbName, collName, lsid) {
    let awaitShell;
    const hangTxnFailPoint = configureFailPoint(db, "waitAfterNewStatementBlocksBehindPrepare");
    try {
        function runTransactionOnSession(dbName, collName, lsid) {
            const txnNumber = NumberLong(1);
            assert.commandWorked(db.getSiblingDB(dbName).runCommand({
                insert: collName,
                documents: [{x: "blocks_behind_prepare"}],
                readConcern: {level: "snapshot"},
                lsid: lsid,
                txnNumber: txnNumber,
                stmtId: NumberInt(0),
                startTransaction: true,
                autocommit: false
            }));
            assert.commandWorked(db.adminCommand(
                {commitTransaction: 1, lsid: lsid, txnNumber: txnNumber, autocommit: false}));
        }
        awaitShell =
            startParallelShell(funWithArgs(runTransactionOnSession, dbName, collName, lsid));
        hangTxnFailPoint.wait();
    } finally {
        hangTxnFailPoint.off();
    }
    return awaitShell;
}
function runConcurrentTransactionOnSession ( dbName , collName , lsid ) { let awaitShell ; const hangTxnFailPoint = configureFailPoint ( db , "waitAfterNewStatementBlocksBehindPrepare" ) ; try { function runTransactionOnSession ( dbName , collName , lsid ) { const txnNumber = NumberLong ( 1 ) ; assert . commandWorked ( db . getSiblingDB ( dbName ) . runCommand ( { insert : collName , documents : [ { x : "blocks_behind_prepare" } ] , readConcern : { level : "snapshot" } , lsid : lsid , txnNumber : txnNumber , stmtId : NumberInt ( 0 ) , startTransaction : true , autocommit : false } ) ) ; assert . commandWorked ( db . adminCommand ( { commitTransaction : 1 , lsid : lsid , txnNumber : txnNumber , autocommit : false } ) ) ; } awaitShell = startParallelShell ( funWithArgs ( runTransactionOnSession , dbName , collName , lsid ) ) ; hangTxnFailPoint . wait ( ) ; } finally { hangTxnFailPoint . off ( ) ; } return awaitShell ; }
Launches a parallel shell to start a new transaction on the session with the given lsid.
Launches a parallel shell to start a new transaction on the session with the given lsid .
// Turn on failpoint that the parallel shell will hit when blocked on prepare. // Use txnNumber : 1 since the active txnNumber will be 0. // Try to do an insert in a new transaction on the same session.  Note that we're // manually including the lsid and stmtId instead of using the session object directly // since there's no way to share a session with the parallel shell. // Launch a parallel shell to start a new transaction, insert a document, and commit. These // operations should block behind the previous prepared transaction on the session. // Wait until parallel shell insert is blocked on prepare. // Disable failpoint to allow the parallel shell to continue - it should still be blocked on // prepare. This is needed in a finally block so that if something fails we're guaranteed to // turn this failpoint off, so that it doesn't cause problems for subsequent tests.