jstests/replsets/tenant_migration_recipient_rollback_recovery.js
/**
 * Runs donorForgetMigration after completing a migration. Waits for the recipient's primary to
 * mark the recipient's state doc as garbage collectable, then forces the write to be rolled back.
 * After the replication steady state is reached, asserts that recipientForgetMigration can be
 * retried on the new primary and that the state doc is eventually garbage collected.
 */
Runs donorForgetMigration after completing a migration. Waits for the recipient's primary to
mark the recipient's state doc as garbage collectable, then forces the write to be rolled back.
After the replication steady state is reached, asserts that recipientForgetMigration can be
retried on the new primary and that the state doc is eventually garbage collected.
Runs donorForgetMigration after completing a migration . Waits for the recipient ' s primary to mark the recipient ' s state doc as garbage collectable then forces the write to be rolled back . After the replication steady state is reached asserts that recipientForgetMigration can be retried on the new primary and that the state doc is eventually garbage collected .
function testRollBackMarkingStateGarbageCollectable() {
    const migrationId = UUID();
    let migrationOpts;
    let forgetMigrationThread;
    let setUpFunc = (tenantMigrationTest, donorRstArgs) => {
        migrationOpts = makeMigrationOpts(
            tenantMigrationTest, migrationId, kTenantId + "-markGarbageCollectable");
        TenantMigrationTest.assertCommitted(
            tenantMigrationTest.runMigration(migrationOpts, {automaticForgetMigration: false}));
    };
    let rollbackOpsFunc = (tenantMigrationTest, donorRstArgs) => {
        const recipientPrimary = tenantMigrationTest.getRecipientPrimary();
        forgetMigrationThread = new Thread(TenantMigrationUtil.forgetMigrationAsync,
                                           migrationOpts.migrationIdString,
                                           donorRstArgs,
                                           false );
        forgetMigrationThread.start();
        assert.soon(() => {
            return 1 ===
                recipientPrimary.getCollection(TenantMigrationTest.kConfigRecipientsNS)
                    .count({_id: migrationId, expireAt: {$exists: 1}});
        });
    };
    let steadyStateFunc = (tenantMigrationTest) => {
        assert.commandWorked(forgetMigrationThread.returnData());
        tenantMigrationTest.waitForMigrationGarbageCollection(
            migrationId,
            migrationOpts.tenantId,
            tenantMigrationTest.getDonorRst().nodes,
            tenantMigrationTest.getRecipientRst().nodes);
    };
    testRollBack(setUpFunc, rollbackOpsFunc, steadyStateFunc);
}
function testRollBackMarkingStateGarbageCollectable ( ) { const migrationId = UUID ( ) ; let migrationOpts ; let forgetMigrationThread ; let setUpFunc = ( tenantMigrationTest , donorRstArgs ) => { migrationOpts = makeMigrationOpts ( tenantMigrationTest , migrationId , kTenantId + "-markGarbageCollectable" ) ; TenantMigrationTest . assertCommitted ( tenantMigrationTest . runMigration ( migrationOpts , { automaticForgetMigration : false } ) ) ; } ; let rollbackOpsFunc = ( tenantMigrationTest , donorRstArgs ) => { const recipientPrimary = tenantMigrationTest . getRecipientPrimary ( ) ; forgetMigrationThread = new Thread ( TenantMigrationUtil . forgetMigrationAsync , migrationOpts . migrationIdString , donorRstArgs , false ) ; forgetMigrationThread . start ( ) ; assert . soon ( ( ) => { return 1 === recipientPrimary . getCollection ( TenantMigrationTest . kConfigRecipientsNS ) . count ( { _id : migrationId , expireAt : { $exists : 1 } } ) ; } ) ; } ; let steadyStateFunc = ( tenantMigrationTest ) => { assert . commandWorked ( forgetMigrationThread . returnData ( ) ) ; tenantMigrationTest . waitForMigrationGarbageCollection ( migrationId , migrationOpts . tenantId , tenantMigrationTest . getDonorRst ( ) . nodes , tenantMigrationTest . getRecipientRst ( ) . nodes ) ; } ; testRollBack ( setUpFunc , rollbackOpsFunc , steadyStateFunc ) ; }
Runs donorForgetMigration after completing a migration.
Runs donorForgetMigration after completing a migration .
// Run donorForgetMigration and wait for the primary to do the write to mark the state doc // as garbage collectable. /* retryOnRetryableErrors */ // Verify that the migration state got garbage collected successfully despite the rollback.