jstests/replsets/tenant_migration_donor_rollback_recovery.js
/**
 * Starts a donor ReplSetTest and creates a TenantMigrationTest for it. Runs 'setUpFunc' after
 * initiating the donor. Then, runs 'rollbackOpsFunc' while replication is disabled on the
 * secondaries, shuts down the primary and restarts it after re-election to force the operations in
 * 'rollbackOpsFunc' to be rolled back. Finally, runs 'steadyStateFunc' after it is back in the
 * replication steady state.
 */
Starts a donor ReplSetTest and creates a TenantMigrationTest for it. Runs 'setUpFunc' after
initiating the donor. Then, runs 'rollbackOpsFunc' while replication is disabled on the
secondaries, shuts down the primary and restarts it after re-election to force the operations in
'rollbackOpsFunc' to be rolled back. Finally, runs 'steadyStateFunc' after it is back in the
replication steady state.
Starts a donor ReplSetTest and creates a TenantMigrationTest for it . Runs ' setUpFunc ' after initiating the donor . Then runs ' rollbackOpsFunc ' while replication is disabled on the secondaries shuts down the primary and restarts it after re - election to force the operations in ' rollbackOpsFunc ' to be rolled back . Finally runs ' steadyStateFunc ' after it is back in the replication steady state .
function testRollBack(setUpFunc, rollbackOpsFunc, steadyStateFunc) {
    const donorRst = new ReplSetTest({
        name: "donorRst",
        nodes: 3,
        nodeOptions: Object.assign({}, migrationX509Options.donor, {
            setParameter: {
                tenantMigrationGarbageCollectionDelayMS: kGarbageCollectionDelayMS,
                ttlMonitorSleepSecs: 1,
            }
        })
    });
    donorRst.startSet();
    donorRst.initiate();
    assert.commandWorked(donorRst.getPrimary().adminCommand(
        {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}}));
    donorRst.awaitReplication();
    const tenantMigrationTest =
        new TenantMigrationTest({name: jsTestName(), donorRst, recipientRst});
    const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst);
    setUpFunc(tenantMigrationTest, donorRstArgs);
    let originalDonorPrimary = donorRst.getPrimary();
    const originalDonorSecondaries = donorRst.getSecondaries();
    donorRst.awaitLastOpCommitted();
    stopServerReplication(originalDonorSecondaries);
    rollbackOpsFunc(tenantMigrationTest, donorRstArgs);
    donorRst.stop(originalDonorPrimary);
    restartServerReplication(originalDonorSecondaries);
    const newDonorPrimary = donorRst.getPrimary();
    assert.neq(originalDonorPrimary, newDonorPrimary);
    originalDonorPrimary =
        donorRst.start(originalDonorPrimary, {waitForConnect: true}, true );
    originalDonorPrimary.setSecondaryOk();
    donorRst.awaitReplication();
    steadyStateFunc(tenantMigrationTest);
    donorRst.stopSet();
}
function testRollBack ( setUpFunc , rollbackOpsFunc , steadyStateFunc ) { const donorRst = new ReplSetTest ( { name : "donorRst" , nodes : 3 , nodeOptions : Object . assign ( { } , migrationX509Options . donor , { setParameter : { tenantMigrationGarbageCollectionDelayMS : kGarbageCollectionDelayMS , ttlMonitorSleepSecs : 1 , } } ) } ) ; donorRst . startSet ( ) ; donorRst . initiate ( ) ; assert . commandWorked ( donorRst . getPrimary ( ) . adminCommand ( { setDefaultRWConcern : 1 , defaultWriteConcern : { w : 1 } , writeConcern : { w : "majority" } } ) ) ; donorRst . awaitReplication ( ) ; const tenantMigrationTest = new TenantMigrationTest ( { name : jsTestName ( ) , donorRst , recipientRst } ) ; const donorRstArgs = TenantMigrationUtil . createRstArgs ( donorRst ) ; setUpFunc ( tenantMigrationTest , donorRstArgs ) ; let originalDonorPrimary = donorRst . getPrimary ( ) ; const originalDonorSecondaries = donorRst . getSecondaries ( ) ; donorRst . awaitLastOpCommitted ( ) ; stopServerReplication ( originalDonorSecondaries ) ; rollbackOpsFunc ( tenantMigrationTest , donorRstArgs ) ; donorRst . stop ( originalDonorPrimary ) ; restartServerReplication ( originalDonorSecondaries ) ; const newDonorPrimary = donorRst . getPrimary ( ) ; assert . neq ( originalDonorPrimary , newDonorPrimary ) ; originalDonorPrimary = donorRst . start ( originalDonorPrimary , { waitForConnect : true } , true ) ; originalDonorPrimary . setSecondaryOk ( ) ; donorRst . awaitReplication ( ) ; steadyStateFunc ( tenantMigrationTest ) ; donorRst . stopSet ( ) ; }
Starts a donor ReplSetTest and creates a TenantMigrationTest for it.
Starts a donor ReplSetTest and creates a TenantMigrationTest for it .
// The default WC is majority and stopServerReplication will prevent satisfying any majority // writes. // Disable replication on the secondaries so that writes during this step will be rolled back. // Shut down the primary and re-enable replication to allow one of the secondaries to get // elected, and make the writes above get rolled back on the original primary when it comes // back up. // Restart the original primary. /* restart */