jstests/replsets/tenant_migration_recipient_access_blocker_rollback.js
// 4) Ensures that a read is possible from the primary.
4) Ensures that a read is possible from the primary.
4 ) Ensures that a read is possible from the primary .
function runRollbackAfterMigrationCommitted(tenantId) {
    jsTestLog("Testing a rollback after the migration has been committed and marked forgotten.");
    const tenantMigrationTest = new TenantMigrationTest(
        {name: jsTestName(), recipientRst: recipientRst, sharedOptions: {nodes: 1}});
    const kMigrationId = UUID();
    const kTenantId = tenantId;
    const kReadPreference = {mode: "primary"};
    const migrationOpts = {
        migrationIdString: extractUUIDFromObject(kMigrationId),
        tenantId: kTenantId,
        readPreference: kReadPreference
    };
    const dbName = tenantMigrationTest.tenantDB(kTenantId, "testDB");
    const collName = "testColl";
    const numDocs = 20;
    tenantMigrationTest.insertDonorDB(
        dbName,
        collName,
        [...Array(numDocs).keys()].map((i) => ({a: i, band: "Air", song: "La Femme d'Argent"})));
    jsTestLog(`Starting tenant migration with migrationId ${kMigrationId}, tenantId: ${kTenantId}`);
    assert.commandWorked(tenantMigrationTest.startMigration(migrationOpts));
    jsTestLog("Waiting for migration to complete and commit.");
    TenantMigrationTest.assertCommitted(
        tenantMigrationTest.waitForMigrationToComplete(migrationOpts));
    assert.commandWorked(tenantMigrationTest.forgetMigration(migrationOpts.migrationIdString));
    recipientRst.awaitReplication();
    jsTestLog("Reading from the recipient primary on the tenant collection.");
    const originalPrimary = recipientRst.getPrimary();
    assert.eq(numDocs, originalPrimary.getDB(dbName)[collName].find().itcount());
    jsTestLog("Halting replication on the secondaries.");
    const secondaries = recipientRst.getSecondaries();
    stopServerReplication(secondaries);
    jsTestLog("Inserting random data on recipient primary.");
    const randomColl = originalPrimary.getDB("randomDB")["random_coll"];
    assert.commandWorked(randomColl.insert({x: "The Real Folk Blues"}, {writeConcern: {w: 1}}));
    jsTestLog("Stepping up one of the secondaries.");
    const newRecipientPrimary = secondaries[0];
    assert.commandWorked(newRecipientPrimary.adminCommand({replSetStepUp: 1}));
    jsTestLog("Restarting server replication.");
    restartServerReplication(secondaries);
    recipientRst.awaitReplication();
    jsTestLog("Stepping up the original primary back to primary.");
    assert.commandWorked(originalPrimary.adminCommand({replSetStepUp: 1}));
    jsTestLog("Perform a read against the original primary on the tenant collection.");
    assert.eq(numDocs, originalPrimary.getDB(dbName)[collName].find().itcount());
    tenantMigrationTest.stop();
}
function runRollbackAfterMigrationCommitted ( tenantId ) { jsTestLog ( "Testing a rollback after the migration has been committed and marked forgotten." ) ; const tenantMigrationTest = new TenantMigrationTest ( { name : jsTestName ( ) , recipientRst : recipientRst , sharedOptions : { nodes : 1 } } ) ; const kMigrationId = UUID ( ) ; const kTenantId = tenantId ; const kReadPreference = { mode : "primary" } ; const migrationOpts = { migrationIdString : extractUUIDFromObject ( kMigrationId ) , tenantId : kTenantId , readPreference : kReadPreference } ; const dbName = tenantMigrationTest . tenantDB ( kTenantId , "testDB" ) ; const collName = "testColl" ; const numDocs = 20 ; tenantMigrationTest . insertDonorDB ( dbName , collName , [ ... Array ( numDocs ) . keys ( ) ] . map ( ( i ) => ( { a : i , band : "Air" , song : "La Femme d'Argent" } ) ) ) ; jsTestLog ( ` ${ kMigrationId } ${ kTenantId } ` ) ; assert . commandWorked ( tenantMigrationTest . startMigration ( migrationOpts ) ) ; jsTestLog ( "Waiting for migration to complete and commit." ) ; TenantMigrationTest . assertCommitted ( tenantMigrationTest . waitForMigrationToComplete ( migrationOpts ) ) ; assert . commandWorked ( tenantMigrationTest . forgetMigration ( migrationOpts . migrationIdString ) ) ; recipientRst . awaitReplication ( ) ; jsTestLog ( "Reading from the recipient primary on the tenant collection." ) ; const originalPrimary = recipientRst . getPrimary ( ) ; assert . eq ( numDocs , originalPrimary . getDB ( dbName ) [ collName ] . find ( ) . itcount ( ) ) ; jsTestLog ( "Halting replication on the secondaries." ) ; const secondaries = recipientRst . getSecondaries ( ) ; stopServerReplication ( secondaries ) ; jsTestLog ( "Inserting random data on recipient primary." ) ; const randomColl = originalPrimary . getDB ( "randomDB" ) [ "random_coll" ] ; assert . commandWorked ( randomColl . insert ( { x : "The Real Folk Blues" } , { writeConcern : { w : 1 } } ) ) ; jsTestLog ( "Stepping up one of the secondaries." ) ; const newRecipientPrimary = secondaries [ 0 ] ; assert . commandWorked ( newRecipientPrimary . adminCommand ( { replSetStepUp : 1 } ) ) ; jsTestLog ( "Restarting server replication." ) ; restartServerReplication ( secondaries ) ; recipientRst . awaitReplication ( ) ; jsTestLog ( "Stepping up the original primary back to primary." ) ; assert . commandWorked ( originalPrimary . adminCommand ( { replSetStepUp : 1 } ) ) ; jsTestLog ( "Perform a read against the original primary on the tenant collection." ) ; assert . eq ( numDocs , originalPrimary . getDB ( dbName ) [ collName ] . find ( ) . itcount ( ) ) ; tenantMigrationTest . stop ( ) ; }
4) Ensures that a read is possible from the primary.
4 ) Ensures that a read is possible from the primary .
// Populate the donor side with data. // Complete and commit the migration, and then forget it as well. // It should be possible to read from the recipient now. // Prepare the recipient primary for rollback, by inserting non-tenant related data on it while // replication has been halted. // Stepping up one of the secondaries should cause the original primary to rollback.