Skip to content

Instantly share code, notes, and snippets.

@ajdavis
Last active December 23, 2021 03:53
Show Gist options
  • Save ajdavis/45bba075efb563801e6c2956fc067132 to your computer and use it in GitHub Desktop.
Save ajdavis/45bba075efb563801e6c2956fc067132 to your computer and use it in GitHub Desktop.
Test majority read after tenant migration
/**
* Test majority reads on the recipient.
*
* 1. Before migration, insert docs on donor D.
* 2. Enable fpAfterCollectionClonerDone failpoint on R.
* 3. Run the migration until it hits fpAfterCollectionClonerDone.
* 4. Hold back R's stable timestamp.
* 5. Insert newDoc on D, applied on R at recipient timestamp 90.
* 6. Disable fpAfterCollectionClonerDone.
* 7. Wait for the migration to commit, it commits at ts 100.
* 8. Untimestamped recipient read at lastApplied=110 should see newDoc.
* 9. Majority R read at ts >= 100, even though stable is still pinned < 90, should see newDoc.
*
* @tags: [
* featureFlagShardMerge,
* incompatible_with_eft,
* incompatible_with_macos,
* incompatible_with_windows_tls,
* requires_fcv_52,
* requires_majority_read_concern,
* requires_persistence,
* ]
*/
(function() {
"use strict";
load("jstests/libs/fail_point_util.js");
load("jstests/replsets/libs/tenant_migration_test.js");
load("jstests/libs/uuid_util.js"); // For extractUUIDFromObject().
load("jstests/replsets/rslib.js");
const tenantId = "testTenantId"
const dbName = tenantId + "_db";
const collName = "foo";
const migrationId = UUID();
const migrationOpts = {
migrationIdString: extractUUIDFromObject(migrationId),
tenantId: tenantId,
};
const tmt = new TenantMigrationTest({name: jsTestName()});
const donorPrimary = tmt.getDonorPrimary();
const recipientPrimary = tmt.getRecipientPrimary();
const recipientDb = recipientPrimary.getDB("admin");
jsTestLog("1. Insert docs on donor D");
tmt.insertDonorDB(dbName, collName);
jsTestLog("2. Enable fpAfterCollectionClonerDone failpoint on R.");
const waitAfterCloning =
configureFailPoint(recipientDb, "fpAfterCollectionClonerDone", {action: "hang"});
jsTestLog("3. Run the migration until it hits fpAfterCollectionClonerDone.")
assert.commandWorked(tmt.startMigration(migrationOpts));
// waitAfterCloning.wait();
jsTestLog("4. Hold back R's stable timestamp.")
const pauseStableTS = configureFailPoint(recipientDb, "WTPauseStableTimestamp", {mode: "alwaysOn"});
const stableTS = recipientPrimary.adminCommand({replSetGetStatus: 1}).lastStableRecoveryTimestamp;
jsTestLog(`R stable ts: ${tojson(stableTS)}`);
jsTestLog("5. Insert newDoc on D.")
donorPrimary.getDB(dbName)[collName].insertOne({_id: "newDoc"});
jsTestLog("6. Disable fpAfterCollectionClonerDone.");
waitAfterCloning.off();
jsTestLog("7. Wait for the migration to commit.");
TenantMigrationTest.assertCommitted(tmt.waitForMigrationToComplete(migrationOpts));
jsTestLog("8. Untimestamped R read should see newDoc.");
const recipientColl = recipientPrimary.getDB(dbName)[collName];
assert(recipientColl.findOne({_id: "newDoc"}));
jsTestLog("9. Majority R read should see newDoc.");
assert(recipientColl.findOne({_id: "newDoc"}, {readConcern: {level: "majority"}}));
pauseStableTS.off();
tmt.stop();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment