jstests/core/txns/transactions_block_ddl.js
/**
 * Tests that DDL operations block on transactions but can succeed once the transaction commits.
 */
Tests that DDL operations block on transactions but can succeed once the transaction commits.
Tests that DDL operations block on transactions but can succeed once the transaction commits .
function testSuccessOnTxnCommit(cmdDBName, ddlCmd, currentOpFilter) {
    runSetup();
    jsTestLog("About to start tranasction");
    session.startTransaction();
    assert.commandWorked(sessionColl.insert({a: 5, b: 6}));
    jsTestLog("Transaction started, running ddl operation " + ddlCmd);
    let thread = new Thread(function(cmdDBName, ddlCmd) {
        return db.getSiblingDB(cmdDBName).runCommand(ddlCmd);
    }, cmdDBName, ddlCmd);
    thread.start();
    assert.soon(
        function() {
            return testDB.currentOp({$and: [currentOpFilter, {waitingForLock: true}]})
                       .inprog.length === 1;
        },
        function() {
            return "Failed to find DDL command in currentOp output: " +
                tojson(testDB.currentOp().inprog);
        });
    jsTestLog("Committing transaction");
    assert.commandWorked(session.commitTransaction_forTesting());
    jsTestLog("Transaction committed, waiting for ddl operation to complete.");
    thread.join();
    assert.commandWorked(thread.returnData());
}
function testSuccessOnTxnCommit ( cmdDBName , ddlCmd , currentOpFilter ) { runSetup ( ) ; jsTestLog ( "About to start tranasction" ) ; session . startTransaction ( ) ; assert . commandWorked ( sessionColl . insert ( { a : 5 , b : 6 } ) ) ; jsTestLog ( "Transaction started, running ddl operation " + ddlCmd ) ; let thread = new Thread ( function ( cmdDBName , ddlCmd ) { return db . getSiblingDB ( cmdDBName ) . runCommand ( ddlCmd ) ; } , cmdDBName , ddlCmd ) ; thread . start ( ) ; assert . soon ( function ( ) { return testDB . currentOp ( { $and : [ currentOpFilter , { waitingForLock : true } ] } ) . inprog . length === 1 ; } , function ( ) { return "Failed to find DDL command in currentOp output: " + tojson ( testDB . currentOp ( ) . inprog ) ; } ) ; jsTestLog ( "Committing transaction" ) ; assert . commandWorked ( session . commitTransaction_forTesting ( ) ) ; jsTestLog ( "Transaction committed, waiting for ddl operation to complete." ) ; thread . join ( ) ; assert . commandWorked ( thread . returnData ( ) ) ; }
Tests that DDL operations block on transactions but can succeed once the transaction commits.
Tests that DDL operations block on transactions but can succeed once the transaction commits .
// Setup. // Wait for the DDL operation to have pending locks. // Note that we cannot use the $currentOp agg stage because it acquires locks // (SERVER-35289).