jstests/sharding/internal_txns/libs/resharding_test.js
/*
     * Runs the commands defined in each 'testCase' inside an internal transaction of the specified
     * type while resharding is running in the background.
     * - 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 the retryable write statements in each transaction
     *   are retryable on the recipient after resharding completes regardless of whether the
     *   transaction committed or aborted on the donor(s).
     */
Runs the commands defined in each 'testCase' inside an internal transaction of the specified
type while resharding is running in the background.
- 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 the retryable write statements in each transaction
are retryable on the recipient after resharding completes regardless of whether the
transaction committed or aborted on the donor(s).
Runs the commands defined in each ' testCase ' inside an internal transaction of the specified type while resharding is running in the background . - 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 the retryable write statements in each transaction are retryable on the recipient after resharding completes regardless of whether the transaction committed or aborted on the donor ( s ) .
function testTransactionsDuringResharding(txnType, testCases) {
        reshardingTest.withReshardingInBackground(
            {
                newShardKeyPattern: reshardingOptions.newShardKeyPattern,
                newChunks: reshardingOptions.newShardKeyChunks,
            },
            () => {
                assert.soon(() => {
                    const coordinatorDoc =
                        mongosConn.getCollection("config.reshardingOperations").findOne({ns: kNs});
                    return coordinatorDoc !== null && coordinatorDoc.cloneTimestamp !== undefined;
                });
                jsTest.log("Start running retryable internal transactions during resharding");
                for (let testCase of testCases) {
                    runInternalTransactionOnInitialTry(txnType, testCase);
                }
                jsTest.log("Finished running retryable internal transactions during resharding");
            });
        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}));
        const expectRetryToSucceed = true;
        jsTest.log("Start retrying retryable internal transactions after resharding");
        for (let testCase of testCases) {
            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) {
            runInternalTransactionOnRetry(
                txnType, testCase, false , expectRetryToSucceed);
            runRetryableWriteOnRetry(testCase, expectRetryToSucceed);
        }
        jsTest.log("Finished retrying retryable internal transactions after restart the recipient");
    }
function testTransactionsDuringResharding ( txnType , testCases ) { reshardingTest . withReshardingInBackground ( { newShardKeyPattern : reshardingOptions . newShardKeyPattern , newChunks : reshardingOptions . newShardKeyChunks , } , ( ) => { assert . soon ( ( ) => { const coordinatorDoc = mongosConn . getCollection ( "config.reshardingOperations" ) . findOne ( { ns : kNs } ) ; return coordinatorDoc !== null && coordinatorDoc . cloneTimestamp !== undefined ; } ) ; jsTest . log ( "Start running retryable internal transactions during resharding" ) ; for ( let testCase of testCases ) { runInternalTransactionOnInitialTry ( txnType , testCase ) ; } jsTest . log ( "Finished running retryable internal transactions during resharding" ) ; } ) ; 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 } ) ) ; const expectRetryToSucceed = true ; jsTest . log ( "Start retrying retryable internal transactions after resharding" ) ; for ( let testCase of testCases ) { 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 ) { runInternalTransactionOnRetry ( txnType , testCase , false , expectRetryToSucceed ) ; runRetryableWriteOnRetry ( testCase , expectRetryToSucceed ) ; } jsTest . log ( "Finished retrying retryable internal transactions after restart the recipient" ) ; }
Runs the commands defined in each 'testCase' inside an internal transaction of the specified
 type while resharding is running in the background.
Runs the commands defined in each ' testCase ' inside an internal transaction of the specified type while resharding is running in the background .
// The cloneTimestamp is the boundary for whether a retryable write statement will // be retryable after the resharding operation completes. // Refresh the mongos so that write statements are routed to the recipient on retries. /* isRetryAfterAbort */ // Also retry the write statements as retryable writes. /* signal */ /*forRestart */ /* isRetryAfterAbort */ // Also retry the write statements as retryable writes.