jstests/sharding/internal_txns/libs/resharding_test.js
/*
     * Runs the commands specified in each 'testCase' inside an internal transaction of the
     * specified and then runs resharding to completion.
     * - If the type is non-retryable, verifies that none of the transactions has a
     *   config.transactions entry on the recipient if the recipient is not also a donor.
     * - If the type is retryable, verifies that none of the retryable write statements in each
     *   transaction is retryable on the recipient unless the transaction aborts without prepare
     *   on the donor.
     */
Runs the commands specified in each 'testCase' inside an internal transaction of the
specified and then runs resharding to completion.
- If the type is non-retryable, verifies that none of the transactions has a
config.transactions entry on the recipient if the recipient is not also a donor.
- If the type is retryable, verifies that none of the retryable write statements in each
transaction is retryable on the recipient unless the transaction aborts without prepare
on the donor.
Runs the commands specified in each ' testCase ' inside an internal transaction of the specified and then runs resharding to completion . - If the type is non - retryable verifies that none of the transactions has a config . transactions entry on the recipient if the recipient is not also a donor . - If the type is retryable verifies that none of the retryable write statements in each transaction is retryable on the recipient unless the transaction aborts without prepare on the donor .
function testTransactionsBeforeResharding(txnType, testCases) {
        jsTest.log("Start running retryable internal transactions before resharding");
        for (let testCase of testCases) {
            runInternalTransactionOnInitialTry(txnType, testCase);
        }
        jsTest.log("Finished running retryable internal transactions before resharding");
        reshardingTest.withReshardingInBackground({
            newShardKeyPattern: reshardingOptions.newShardKeyPattern,
            newChunks: reshardingOptions.newShardKeyChunks,
        });
        const recipientRst = reshardingTest.getReplSetForShard(recipientShardNames[0]);
        if (txnType == kInternalTxnType.kNonRetryable) {
            if (!reshardInPlace) {
                for (let testCase of testCases) {
                    const configTxnEntries = getTxnEntriesForSession(
                        recipientRst, testCase.childLsidForNonRetryableWrite);
                    assert.eq(configTxnEntries.length, 0, tojson(configTxnEntries));
                }
            }
            return;
        }
        assert.commandWorked(mongosConn.adminCommand({flushRouterConfig: 1}));
        let expectRetryForTestCaseToSucceed = (testCase) =>
            !testCase.isPreparedTxn && testCase.abortOnInitialTry;
        jsTest.log("Start retrying retryable internal transactions after resharding");
        for (let testCase of testCases) {
            const expectRetryToSucceed = expectRetryForTestCaseToSucceed(testCase);
            runInternalTransactionOnRetry(txnType,
                                          testCase,
                                          testCase.abortOnInitialTry ,
                                          expectRetryToSucceed);
            runRetryableWriteOnRetry(testCase, expectRetryToSucceed);
        }
        jsTest.log("Finished retrying retryable internal transactions after resharding");
        recipientRst.stopSet(null , true );
        recipientRst.startSet({restart: true});
        recipientRst.getPrimary();
        jsTest.log("Start retrying retryable internal transactions after restarting the recipient");
        for (let testCase of testCases) {
            const expectRetryToSucceed = expectRetryForTestCaseToSucceed(testCase);
            runInternalTransactionOnRetry(
                txnType, testCase, false , expectRetryToSucceed);
            runRetryableWriteOnRetry(testCase, expectRetryToSucceed);
        }
        jsTest.log(
            "Finished retrying retryable internal transactions after restarting the recipient");
    }
function testTransactionsBeforeResharding ( txnType , testCases ) { jsTest . log ( "Start running retryable internal transactions before resharding" ) ; for ( let testCase of testCases ) { runInternalTransactionOnInitialTry ( txnType , testCase ) ; } jsTest . log ( "Finished running retryable internal transactions before resharding" ) ; reshardingTest . withReshardingInBackground ( { newShardKeyPattern : reshardingOptions . newShardKeyPattern , newChunks : reshardingOptions . newShardKeyChunks , } ) ; const recipientRst = reshardingTest . getReplSetForShard ( recipientShardNames [ 0 ] ) ; if ( txnType == kInternalTxnType . kNonRetryable ) { if ( ! reshardInPlace ) { for ( let testCase of testCases ) { const configTxnEntries = getTxnEntriesForSession ( recipientRst , testCase . childLsidForNonRetryableWrite ) ; assert . eq ( configTxnEntries . length , 0 , tojson ( configTxnEntries ) ) ; } } return ; } assert . commandWorked ( mongosConn . adminCommand ( { flushRouterConfig : 1 } ) ) ; let expectRetryForTestCaseToSucceed = ( testCase ) => ! testCase . isPreparedTxn && testCase . abortOnInitialTry ; jsTest . log ( "Start retrying retryable internal transactions after resharding" ) ; for ( let testCase of testCases ) { const expectRetryToSucceed = expectRetryForTestCaseToSucceed ( testCase ) ; runInternalTransactionOnRetry ( txnType , testCase , testCase . abortOnInitialTry , expectRetryToSucceed ) ; runRetryableWriteOnRetry ( testCase , expectRetryToSucceed ) ; } jsTest . log ( "Finished retrying retryable internal transactions after resharding" ) ; recipientRst . stopSet ( null , true ) ; recipientRst . startSet ( { restart : true } ) ; recipientRst . getPrimary ( ) ; jsTest . log ( "Start retrying retryable internal transactions after restarting the recipient" ) ; for ( let testCase of testCases ) { const expectRetryToSucceed = expectRetryForTestCaseToSucceed ( testCase ) ; runInternalTransactionOnRetry ( txnType , testCase , false , expectRetryToSucceed ) ; runRetryableWriteOnRetry ( testCase , expectRetryToSucceed ) ; } jsTest . log ( "Finished retrying retryable internal transactions after restarting the recipient" ) ; }
Runs the commands specified in each 'testCase' inside an internal transaction of the
 specified and then runs resharding to completion.
Runs the commands specified in each ' testCase ' inside an internal transaction of the specified and then runs resharding to completion .
// Refresh the mongos so that write statements are routed to the recipient on retries. // To make retryable writes and transactions that existed prior to resharding not retryable // after resharding, each recipient performs a snapshot read of the the config.transactions // collection and then writes a dead-end noop oplog entry for every retryable write and // transaction that it finds. Therefore, a transaction that does not have a // config.transactions entry (i.e. an aborted unprepared transaction) is expected to be // retryable after resharding. /* isRetryAfterAbort */ // Also retry the write statements as retryable writes. /* signal */ /*forRestart */ /* isRetryAfterAbort */ // Also retry the write statements as retryable writes.