jstests/replsets/tenant_migration_donor_rollback_recovery.js
/**
 * Starts a migration and waits for the donor's primary to insert the donor's state doc. Forces the
 * write to be rolled back. After the replication steady state is reached, asserts that
 * donorStartMigration can restart the migration on the new primary.
 */
Starts a migration and waits for the donor's primary to insert the donor's state doc. Forces the
write to be rolled back. After the replication steady state is reached, asserts that
donorStartMigration can restart the migration on the new primary.
Starts a migration and waits for the donor ' s primary to insert the donor ' s state doc . Forces the write to be rolled back . After the replication steady state is reached asserts that donorStartMigration can restart the migration on the new primary .
function testRollbackInitialState() {
    const migrationId = UUID();
    const migrationOpts = makeMigrationOpts(migrationId, kTenantId + "-initial");
    let migrationThread;
    let setUpFunc = (tenantMigrationTest, donorRstArgs) => {};
    let rollbackOpsFunc = (tenantMigrationTest, donorRstArgs) => {
        const donorPrimary = tenantMigrationTest.getDonorPrimary();
        migrationThread = new Thread(TenantMigrationUtil.runMigrationAsync,
                                     migrationOpts,
                                     donorRstArgs,
                                     {retryOnRetryableErrors: true});
        migrationThread.start();
        assert.soon(() => {
            return 1 === donorPrimary.getCollection(TenantMigrationTest.kConfigDonorsNS).count({
                _id: migrationId
            });
        });
    };
    let steadyStateFunc = (tenantMigrationTest) => {
        TenantMigrationTest.assertCommitted(assert.commandWorked(migrationThread.returnData()));
        tenantMigrationTest.waitForDonorNodesToReachState(
            tenantMigrationTest.getDonorRst().nodes,
            migrationId,
            migrationOpts.tenantId,
            TenantMigrationTest.DonorState.kCommitted);
        assert.commandWorked(tenantMigrationTest.forgetMigration(migrationOpts.migrationIdString));
    };
    testRollBack(setUpFunc, rollbackOpsFunc, steadyStateFunc);
}
function testRollbackInitialState ( ) { const migrationId = UUID ( ) ; const migrationOpts = makeMigrationOpts ( migrationId , kTenantId + "-initial" ) ; let migrationThread ; let setUpFunc = ( tenantMigrationTest , donorRstArgs ) => { } ; let rollbackOpsFunc = ( tenantMigrationTest , donorRstArgs ) => { const donorPrimary = tenantMigrationTest . getDonorPrimary ( ) ; migrationThread = new Thread ( TenantMigrationUtil . runMigrationAsync , migrationOpts , donorRstArgs , { retryOnRetryableErrors : true } ) ; migrationThread . start ( ) ; assert . soon ( ( ) => { return 1 === donorPrimary . getCollection ( TenantMigrationTest . kConfigDonorsNS ) . count ( { _id : migrationId } ) ; } ) ; } ; let steadyStateFunc = ( tenantMigrationTest ) => { TenantMigrationTest . assertCommitted ( assert . commandWorked ( migrationThread . returnData ( ) ) ) ; tenantMigrationTest . waitForDonorNodesToReachState ( tenantMigrationTest . getDonorRst ( ) . nodes , migrationId , migrationOpts . tenantId , TenantMigrationTest . DonorState . kCommitted ) ; assert . commandWorked ( tenantMigrationTest . forgetMigration ( migrationOpts . migrationIdString ) ) ; } ; testRollBack ( setUpFunc , rollbackOpsFunc , steadyStateFunc ) ; }
Starts a migration and waits for the donor's primary to insert the donor's state doc.
Starts a migration and waits for the donor ' s primary to insert the donor ' s state doc .
// Start the migration asynchronously and wait for the primary to insert the state doc. // Verify that the migration restarted successfully on the new primary despite rollback.