diff options
author | Matt Broadstone <mbroadst@mongodb.com> | 2023-01-09 20:19:37 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-01-09 21:45:19 +0000 |
commit | 9c2d2f716db7924c7fe12af379437f637efba744 (patch) | |
tree | e99092be92661f42ea1fca941043e9a7754a95a2 /jstests/replsets | |
parent | 112b333163e4014b24b098ea229c2a0d4184e1aa (diff) | |
download | mongo-9c2d2f716db7924c7fe12af379437f637efba744.tar.gz |
SERVER-72577 Convert tenant migrations tests to use es modules
Diffstat (limited to 'jstests/replsets')
130 files changed, 2125 insertions, 2431 deletions
diff --git a/jstests/replsets/libs/tenant_migration_recipient_sync_source.js b/jstests/replsets/libs/tenant_migration_recipient_sync_source.js index a052b0f5268..92e80d462b8 100644 --- a/jstests/replsets/libs/tenant_migration_recipient_sync_source.js +++ b/jstests/replsets/libs/tenant_migration_recipient_sync_source.js @@ -2,11 +2,12 @@ * Helper functions for running tests related to sync source selection during a tenant migration. */ +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {makeX509OptionsForTest} from "jstests/replsets/libs/tenant_migration_util.js"; + load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); load("jstests/libs/write_concern_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); load('jstests/replsets/rslib.js'); /** @@ -18,12 +19,12 @@ load('jstests/replsets/rslib.js'); * 'startApplyingDonorOpTime' stored in the recipient state document. As a result, neither nodes are * eligible sync sources for the migration. */ -const setUpMigrationSyncSourceTest = function() { +export function setUpMigrationSyncSourceTest() { const donorRst = new ReplSetTest({ name: `${jsTestName()}_donor`, nodes: 3, settings: {chainingAllowed: false}, - nodeOptions: Object.assign(TenantMigrationUtil.makeX509OptionsForTest().donor, { + nodeOptions: Object.assign(makeX509OptionsForTest().donor, { setParameter: { tenantMigrationExcludeDonorHostTimeoutMS: 30 * 1000, // Allow non-timestamped reads on donor after migration completes for testing. @@ -153,4 +154,4 @@ const setUpMigrationSyncSourceTest = function() { delayedSecondary, hangAfterCreatingConnections: hangNewRecipientPrimaryAfterCreatingConnections }; -}; +} diff --git a/jstests/replsets/libs/tenant_migration_test.js b/jstests/replsets/libs/tenant_migration_test.js index c158be4da82..799a27d01ab 100644 --- a/jstests/replsets/libs/tenant_migration_test.js +++ b/jstests/replsets/libs/tenant_migration_test.js @@ -4,8 +4,33 @@ "use strict"; +import { + makeX509OptionsForTest, + makeMigrationCertificatesForTest, + createTenantMigrationRecipientRoleIfNotExist, + createTenantMigrationDonorRoleIfNotExist, + runTenantMigrationCommand, + isMigrationCompleted, + checkTenantDBHashes, + getExternalKeys, + isShardMergeEnabled, + isNamespaceForTenant, + getTenantMigrationAccessBlocker, +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/aggregation/extras/utils.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); + +function loadDummyData() { + const numDocs = 20; + const testData = []; + for (let i = 0; i < numDocs; ++i) { + testData.push({_id: i, x: i}); + } + return testData; +} + +function buildErrorMsg(migrationId, expectedState, expectedAccessState, configDoc, recipientMtab) { + return tojson({migrationId, expectedState, expectedAccessState, configDoc, recipientMtab}); +} /** * This fixture allows the user to optionally pass in a custom ReplSetTest for the donor and @@ -13,138 +38,160 @@ load("jstests/replsets/libs/tenant_migration_util.js"); * * If the caller does not provide their own replica set, a two node replset will be initialized * instead, with all nodes running the latest version. - * - * @param {string} [name] the name of the replica sets - * @param {boolean} [enableRecipientTesting] whether recipient would actually migrate tenant data - * @param {Object} [donorRst] the ReplSetTest instance to adopt for the donor - * @param {Object} [recipientRst] the ReplSetTest instance to adopt for the recipient - * @param {Object} [sharedOptions] an object that can contain 'nodes' <number>, the number of nodes - * each RST will contain, and 'setParameter' <object>, an object with various server parameters. - * @param {boolean} [allowDonorReadAfterMigration] whether donor would allow reads after a committed - * migration. - * @param {boolean} [initiateRstWithHighElectionTimeout] whether donor and recipient replica sets - * should be initiated with high election timeout. - * @param {boolean} [quickGarbageCollection] whether to set a low garbageCollectionDelayMS. - * @param {string} [insertDataForTenant] create dummy data in <tenantId>_test database. */ -function TenantMigrationTest({ - name = "TenantMigrationTest", - enableRecipientTesting = true, - donorRst, - recipientRst, - sharedOptions = {}, - // Default this to true so it is easier for data consistency checks. - allowStaleReadsOnDonor = true, - initiateRstWithHighElectionTimeout = true, - quickGarbageCollection = false, - insertDataForTenant, - optimizeMigrations = true, -}) { - const donorPassedIn = (donorRst !== undefined); - const recipientPassedIn = (recipientRst !== undefined); - - const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); - const migrationCertificates = TenantMigrationUtil.makeMigrationCertificatesForTest(); - - const nodes = sharedOptions.nodes || 2; - const setParameterOpts = sharedOptions.setParameter || {}; - if (optimizeMigrations) { - // A tenant migration recipient's `OplogFetcher` uses aggregation which does not support - // tailable awaitdata cursors. For aggregation commands `OplogFetcher` will default to half - // the election timeout (e.g: 5 seconds) between getMores. That wait is largely unnecessary. - setParameterOpts["failpoint.setSmallOplogGetMoreMaxTimeMS"] = tojson({"mode": "alwaysOn"}); +export class TenantMigrationTest { + /** + * Takes in the response to the donarStartMigration command and asserts the command + * works and the state is 'committed'. + */ + static assertCommitted(stateRes) { + assert.commandWorked(stateRes); + assert.eq(stateRes.state, TenantMigrationTest.DonorState.kCommitted, tojson(stateRes)); + return stateRes; } - if (quickGarbageCollection) { - setParameterOpts.tenantMigrationGarbageCollectionDelayMS = 0; - setParameterOpts.ttlMonitorSleepSecs = 1; + + /** + * Takes in the response to the donarStartMigration command and asserts the command + * works and the state is 'aborted', with optional errorCode. + */ + static assertAborted(stateRes, errorCode) { + assert.commandWorked(stateRes); + assert.eq(stateRes.state, TenantMigrationTest.DonorState.kAborted, tojson(stateRes)); + if (errorCode !== undefined) { + assert.eq(stateRes.abortReason.code, errorCode, tojson(stateRes)); + } + return stateRes; } - donorRst = donorPassedIn ? donorRst : performSetUp(true /* isDonor */); - recipientRst = recipientPassedIn ? recipientRst : performSetUp(false /* isDonor */); - - donorRst.asCluster(donorRst.nodes, () => { - donorRst.getPrimary(); - donorRst.awaitReplication(); - TenantMigrationUtil.createTenantMigrationRecipientRoleIfNotExist(donorRst); - }); - - recipientRst.asCluster(recipientRst.nodes, () => { - recipientRst.getPrimary(); - recipientRst.awaitReplication(); - TenantMigrationUtil.createTenantMigrationDonorRoleIfNotExist(recipientRst); - }); - - function loadDummyData() { - const numDocs = 20; - const testData = []; - for (let i = 0; i < numDocs; ++i) { - testData.push({_id: i, x: i}); + /** + * Make a new TenantMigrationTest + * + * @param {string} [name] the name of the replica sets + * @param {boolean} [enableRecipientTesting] whether recipient would actually migrate tenant + * data + * @param {Object} [donorRst] the ReplSetTest instance to adopt for the donor + * @param {Object} [recipientRst] the ReplSetTest instance to adopt for the recipient + * @param {Object} [sharedOptions] an object that can contain 'nodes' <number>, the number of + * nodes each RST will contain, and 'setParameter' <object>, an object with various server + * parameters. + * @param {boolean} [allowDonorReadAfterMigration] whether donor would allow reads after a + * committed migration. + * @param {boolean} [initiateRstWithHighElectionTimeout] whether donor and recipient replica + * sets should be initiated with high election timeout. + * @param {boolean} [quickGarbageCollection] whether to set a low garbageCollectionDelayMS. + * @param {string} [insertDataForTenant] create dummy data in <tenantId>_test database. + */ + constructor({ + name = "TenantMigrationTest", + enableRecipientTesting = true, + donorRst, + recipientRst, + sharedOptions = {}, + // Default this to true so it is easier for data consistency checks. + allowStaleReadsOnDonor = true, + initiateRstWithHighElectionTimeout = true, + quickGarbageCollection = false, + insertDataForTenant, + optimizeMigrations = true, + }) { + this._donorPassedIn = (donorRst !== undefined); + this._recipientPassedIn = (recipientRst !== undefined); + const migrationX509Options = makeX509OptionsForTest(); + const nodes = sharedOptions.nodes || 2; + const setParameterOpts = sharedOptions.setParameter || {}; + if (optimizeMigrations) { + // A tenant migration recipient's `OplogFetcher` uses aggregation which does not support + // tailable awaitdata cursors. For aggregation commands `OplogFetcher` will default to + // half the election timeout (e.g: 5 seconds) between getMores. That wait is largely + // unnecessary. + setParameterOpts["failpoint.setSmallOplogGetMoreMaxTimeMS"] = + tojson({"mode": "alwaysOn"}); + } + if (quickGarbageCollection) { + setParameterOpts.tenantMigrationGarbageCollectionDelayMS = 0; + setParameterOpts.ttlMonitorSleepSecs = 1; + } + + /** + * Creates a ReplSetTest instance. The repl set will have 2 nodes if not otherwise + * specified. + */ + function performSetUp(isDonor) { + if (TestData.logComponentVerbosity) { + setParameterOpts["logComponentVerbosity"] = + tojsononeline(TestData.logComponentVerbosity); + } + + if (!(isDonor || enableRecipientTesting)) { + setParameterOpts["failpoint.returnResponseOkForRecipientSyncDataCmd"] = + tojson({mode: 'alwaysOn'}); + } + + if (allowStaleReadsOnDonor) { + setParameterOpts["failpoint.tenantMigrationDonorAllowsNonTimestampedReads"] = + tojson({mode: 'alwaysOn'}); + } + + let nodeOptions = isDonor ? migrationX509Options.donor : migrationX509Options.recipient; + nodeOptions["setParameter"] = setParameterOpts; + + const rstName = `${name}_${(isDonor ? "donor" : "recipient")}`; + const rst = new ReplSetTest({name: rstName, nodes, serverless: true, nodeOptions}); + rst.startSet(); + if (initiateRstWithHighElectionTimeout) { + rst.initiateWithHighElectionTimeout(); + } else { + rst.initiate(); + } + + return rst; + } + + this._donorRst = this._donorPassedIn ? donorRst : performSetUp(true /* isDonor */); + this._recipientRst = + this._recipientPassedIn ? recipientRst : performSetUp(false /* isDonor */); + + this._donorRst.asCluster(this._donorRst.nodes, () => { + this._donorRst.getPrimary(); + this._donorRst.awaitReplication(); + createTenantMigrationRecipientRoleIfNotExist(this._donorRst); + }); + + this._recipientRst.asCluster(this._recipientRst.nodes, () => { + this._recipientRst.getPrimary(); + this._recipientRst.awaitReplication(); + createTenantMigrationDonorRoleIfNotExist(this._recipientRst); + }); + + // Shard Merge installs TenantRecipientAccessBlockers only for tenants with data, so most + // tests require some data. + if (insertDataForTenant !== undefined) { + this.insertDonorDB(`${insertDataForTenant}_test`, "test"); } - return testData; } /** * Inserts documents into the specified collection on the donor primary. */ - this.insertDonorDB = function(dbName, collName, data = loadDummyData()) { + insertDonorDB(dbName, collName, data = loadDummyData()) { jsTestLog(`Inserting data into collection ${collName} of DB ${dbName} on the donor`); - const primary = donorRst.getPrimary(); + const primary = this._donorRst.getPrimary(); const db = primary.getDB(dbName); const res = assert.commandWorked( db.runCommand({insert: collName, documents: data, writeConcern: {w: 'majority'}})); jsTestLog(`Inserted with w: majority, opTime ${tojson(res.operationTime)}`); - }; + } /** * Inserts documents into the specified collection on the recipient primary. */ - this.insertRecipientDB = function(dbName, collName, data = loadDummyData()) { + insertRecipientDB(dbName, collName, data = loadDummyData()) { jsTestLog(`Inserting data into collection ${collName} of DB ${dbName} on the recipient`); - const primary = recipientRst.getPrimary(); + const primary = this._recipientRst.getPrimary(); const db = primary.getDB(dbName); const res = assert.commandWorked( db.runCommand({insert: collName, documents: data, writeConcern: {w: 'majority'}})); jsTestLog(`Inserted with w: majority, opTime ${tojson(res.operationTime)}`); - }; - - // Shard Merge installs TenantRecipientAccessBlockers only for tenants with data, so most tests - // require some data. - if (insertDataForTenant !== undefined) { - this.insertDonorDB(`${insertDataForTenant}_test`, "test"); - } - - /** - * Creates a ReplSetTest instance. The repl set will have 2 nodes if not otherwise specified. - */ - function performSetUp(isDonor) { - if (TestData.logComponentVerbosity) { - setParameterOpts["logComponentVerbosity"] = - tojsononeline(TestData.logComponentVerbosity); - } - - if (!(isDonor || enableRecipientTesting)) { - setParameterOpts["failpoint.returnResponseOkForRecipientSyncDataCmd"] = - tojson({mode: 'alwaysOn'}); - } - - if (allowStaleReadsOnDonor) { - setParameterOpts["failpoint.tenantMigrationDonorAllowsNonTimestampedReads"] = - tojson({mode: 'alwaysOn'}); - } - - let nodeOptions = isDonor ? migrationX509Options.donor : migrationX509Options.recipient; - nodeOptions["setParameter"] = setParameterOpts; - - const rstName = `${name}_${(isDonor ? "donor" : "recipient")}`; - const rst = new ReplSetTest({name: rstName, nodes, serverless: true, nodeOptions}); - rst.startSet(); - if (initiateRstWithHighElectionTimeout) { - rst.initiateWithHighElectionTimeout(); - } else { - rst.initiate(); - } - - return rst; } /** @@ -155,12 +202,8 @@ function TenantMigrationTest({ * returns the command response containing the migration state on the donor after the * migration has completed. */ - this.runMigration = function(migrationOpts, opts = {}) { - const { - retryOnRetryableErrors = false, - automaticForgetMigration = true, - enableDonorStartMigrationFsync = false - } = opts; + runMigration(migrationOpts, opts = {}) { + const {retryOnRetryableErrors = false, automaticForgetMigration = true} = opts; const startRes = this.startMigration(migrationOpts, opts); if (!startRes.ok) { @@ -178,21 +221,20 @@ function TenantMigrationTest({ } return completeRes; - }; + } /** * Starts a tenant migration by running the 'donorStartMigration' command once. * * Returns the result of the 'donorStartMigration' command. */ - this.startMigration = function( - migrationOpts, - {retryOnRetryableErrors = false, enableDonorStartMigrationFsync = false} = {}) { + startMigration(migrationOpts, + {retryOnRetryableErrors = false, enableDonorStartMigrationFsync = false} = {}) { return this.runDonorStartMigration(migrationOpts, { retryOnRetryableErrors, enableDonorStartMigrationFsync, }); - }; + } /** * Waits for a migration to complete by continuously polling the donor primary with @@ -201,8 +243,9 @@ function TenantMigrationTest({ * * Returns the result of the last 'donorStartMigration' command executed. */ - this.waitForMigrationToComplete = function( - migrationOpts, retryOnRetryableErrors = false, forgetMigration = false) { + waitForMigrationToComplete(migrationOpts, + retryOnRetryableErrors = false, + forgetMigration = false) { // Assert that the migration has already been started. assert(this.getDonorPrimary().getCollection(TenantMigrationTest.kConfigDonorsNS).findOne({ _id: UUID(migrationOpts.migrationIdString) @@ -216,7 +259,7 @@ function TenantMigrationTest({ this.forgetMigration(migrationOpts.migrationIdString, retryOnRetryableErrors); return donorStartReply; - }; + } /** * Executes the 'donorStartMigration' command on the donor primary. @@ -228,17 +271,23 @@ function TenantMigrationTest({ * If 'retryOnRetryableErrors' is set, this function will retry if the command fails * with a NotPrimary or network error. */ - this.runDonorStartMigration = function({ + runDonorStartMigration({ migrationIdString, tenantId, protocol, tenantIds, - recipientConnectionString = recipientRst.getURL(), + recipientConnectionString = this._recipientRst.getURL(), readPreference = {mode: "primary"}, - donorCertificateForRecipient = migrationCertificates.donorCertificateForRecipient, - recipientCertificateForDonor = migrationCertificates.recipientCertificateForDonor, + donorCertificateForRecipient, + recipientCertificateForDonor, }, - opts = {}) { + opts = {}) { + const migrationCertificates = makeMigrationCertificatesForTest(); + donorCertificateForRecipient = + donorCertificateForRecipient || migrationCertificates.donorCertificateForRecipient; + recipientCertificateForDonor = + recipientCertificateForDonor || migrationCertificates.recipientCertificateForDonor; + const { waitForMigrationToComplete = false, retryOnRetryableErrors = false, @@ -257,22 +306,22 @@ function TenantMigrationTest({ protocol }; - const stateRes = TenantMigrationUtil.runTenantMigrationCommand(cmdObj, this.getDonorRst(), { + const stateRes = runTenantMigrationCommand(cmdObj, this.getDonorRst(), { enableDonorStartMigrationFsync, retryOnRetryableErrors, shouldStopFunc: stateRes => - (!waitForMigrationToComplete || TenantMigrationUtil.isMigrationCompleted(stateRes)) + (!waitForMigrationToComplete || isMigrationCompleted(stateRes)) }); // If the migration has been successfully committed, check the db hashes for the tenantId // between the donor and recipient. if (stateRes.state === TenantMigrationTest.State.kCommitted) { - TenantMigrationUtil.checkTenantDBHashes( + checkTenantDBHashes( {donorRst: this.getDonorRst(), recipientRst: this.getRecipientRst(), tenantId}); } return stateRes; - }; + } /** * Runs the donorForgetMigration command with the given migrationId and returns the response. @@ -280,10 +329,9 @@ function TenantMigrationTest({ * If 'retryOnRetryableErrors' is set, this function will retry if the command fails with a * NotPrimary or network error. */ - this.forgetMigration = function(migrationIdString, retryOnRetryableErrors = false) { + forgetMigration(migrationIdString, retryOnRetryableErrors = false) { const cmdObj = {donorForgetMigration: 1, migrationId: UUID(migrationIdString)}; - const res = TenantMigrationUtil.runTenantMigrationCommand( - cmdObj, this.getDonorRst(), {retryOnRetryableErrors}); + const res = runTenantMigrationCommand(cmdObj, this.getDonorRst(), {retryOnRetryableErrors}); // If the command succeeded, we expect that the migration is marked garbage collectable on // the donor and the recipient. Check the state docs for expireAt, check that the oplog @@ -313,8 +361,7 @@ function TenantMigrationTest({ configDBCollections); this.getDonorRst().asCluster(donorPrimary, () => { - const donorKeys = - TenantMigrationUtil.getExternalKeys(donorPrimary, UUID(migrationIdString)); + const donorKeys = getExternalKeys(donorPrimary, UUID(migrationIdString)); if (donorKeys.length) { donorKeys.forEach(key => { assert(key.hasOwnProperty("ttlExpiresAt"), tojson(key)); @@ -323,8 +370,7 @@ function TenantMigrationTest({ }); this.getRecipientRst().asCluster(recipientPrimary, () => { - const recipientKeys = - TenantMigrationUtil.getExternalKeys(recipientPrimary, UUID(migrationIdString)); + const recipientKeys = getExternalKeys(recipientPrimary, UUID(migrationIdString)); if (recipientKeys.length) { recipientKeys.forEach(key => { assert(key.hasOwnProperty("ttlExpiresAt"), tojson(key)); @@ -334,29 +380,27 @@ function TenantMigrationTest({ } return res; - }; + } /** * Runs the donorAbortMigration command with the given migration options and returns the * response. */ - this.tryAbortMigration = function(migrationOpts, retryOnRetryableErrors = false) { + tryAbortMigration(migrationOpts, retryOnRetryableErrors = false) { const cmdObj = { donorAbortMigration: 1, migrationId: UUID(migrationOpts.migrationIdString), }; - return TenantMigrationUtil.runTenantMigrationCommand( - cmdObj, this.getDonorRst(), {retryOnRetryableErrors}); - }; + return runTenantMigrationCommand(cmdObj, this.getDonorRst(), {retryOnRetryableErrors}); + } /** * Asserts that durable and in-memory state for the migration 'migrationId' and 'tenantId' is * eventually deleted from the given nodes. */ - this.waitForMigrationGarbageCollection = function( - migrationId, tenantId, donorNodes, recipientNodes) { - donorNodes = donorNodes || donorRst.nodes; - recipientNodes = recipientNodes || recipientRst.nodes; + waitForMigrationGarbageCollection(migrationId, tenantId, donorNodes, recipientNodes) { + donorNodes = donorNodes || this._donorRst.nodes; + recipientNodes = recipientNodes || this._recipientRst.nodes; if (typeof migrationId === "string") { migrationId = UUID(migrationId); @@ -385,34 +429,34 @@ function TenantMigrationTest({ return !mtab; }, tojson(mtab)); }); - }; + } /** * Asserts that the migration 'migrationId' and 'tenantId' eventually goes to the * expected state on all the given donor nodes. */ - this.waitForDonorNodesToReachState = function(nodes, migrationId, tenantId, expectedState) { + waitForDonorNodesToReachState(nodes, migrationId, tenantId, expectedState) { nodes.forEach(node => { assert.soon( () => this.isDonorNodeInExpectedState(node, migrationId, tenantId, expectedState)); }); - }; + } /** * Asserts that the migration 'migrationId' and 'tenantId' is in the expected state on all the * given donor nodes. */ - this.assertDonorNodesInExpectedState = function(nodes, migrationId, tenantId, expectedState) { + assertDonorNodesInExpectedState(nodes, migrationId, tenantId, expectedState) { nodes.forEach(node => { assert(this.isDonorNodeInExpectedState(node, migrationId, tenantId, expectedState)); }); - }; + } /** * Returns true if the durable and in-memory state for the migration 'migrationId' and * 'tenantId' is in the expected state, and false otherwise. */ - this.isDonorNodeInExpectedState = function(node, migrationId, tenantId, expectedState) { + isDonorNodeInExpectedState(node, migrationId, tenantId, expectedState) { const configDonorsColl = this.getDonorPrimary().getCollection(TenantMigrationTest.kConfigDonorsNS); const configDoc = configDonorsColl.findOne({_id: migrationId}); @@ -425,18 +469,13 @@ function TenantMigrationTest({ : TenantMigrationTest.DonorAccessState.kAborted; const mtab = this.getTenantMigrationAccessBlocker({donorNode: node, tenantId}); return (mtab.donor.state === expectedAccessState); - }; - - function buildErrorMsg( - migrationId, expectedState, expectedAccessState, configDoc, recipientMtab) { - return tojson({migrationId, expectedState, expectedAccessState, configDoc, recipientMtab}); } /** * Asserts that the migration 'migrationId' and 'tenantId' eventually goes to the expected state * on all the given recipient nodes. */ - this.waitForRecipientNodesToReachState = function( + waitForRecipientNodesToReachState( nodes, migrationId, tenantId, expectedState, expectedAccessState) { nodes.forEach(node => { let result = {}; @@ -455,13 +494,13 @@ function TenantMigrationTest({ result.recipientMtab); }); }); - }; + } /** * Asserts that the migration 'migrationId' and 'tenantId' is in the expected state on all the * given recipient nodes. */ - this.assertRecipientNodesInExpectedState = function({ + assertRecipientNodesInExpectedState({ nodes, migrationId, tenantId, @@ -480,13 +519,13 @@ function TenantMigrationTest({ result.recipientMtab); }); }); - }; + } /** * Returns true if the durable and in-memory state for the migration 'migrationId' and * 'tenantId' is in the expected state, and false otherwise. */ - this.isRecipientNodeInExpectedState = function({ + isRecipientNodeInExpectedState({ node, migrationId, tenantId, @@ -506,17 +545,17 @@ function TenantMigrationTest({ }; return {value: checkStates(), configDoc: configDoc, recipientMtab: mtab.recipient}; - }; + } /** * Verifies that the documents on the recipient primary are correct. */ - this.verifyRecipientDB = function( + verifyRecipientDB( tenantId, dbName, collName, migrationCommitted = true, data = loadDummyData()) { // We should migrate all data regardless of tenant id for shard merge. const shouldMigrate = migrationCommitted && - (TenantMigrationUtil.isShardMergeEnabled(this.getRecipientPrimary().getDB("admin")) || - TenantMigrationUtil.isNamespaceForTenant(tenantId, dbName)); + (isShardMergeEnabled(this.getRecipientPrimary().getDB("admin")) || + isNamespaceForTenant(tenantId, dbName)); jsTestLog(`Verifying that data in collection ${collName} of DB ${dbName} was ${ (shouldMigrate ? "" : "not")} migrated to the recipient`); @@ -544,107 +583,84 @@ function TenantMigrationTest({ const docsReturned = findRes.sort({_id: 1}).toArray(); assert(arrayEq(docsReturned, data), () => (`${tojson(docsReturned)} is not equal to ${tojson(data)}`)); - }; + } /** * Crafts a tenant database name. */ - this.tenantDB = function(tenantId, dbName) { + tenantDB(tenantId, dbName) { return `${tenantId}_${dbName}`; - }; + } /** * Crafts a database name that does not belong to the tenant. */ - this.nonTenantDB = function(tenantId, dbName) { + nonTenantDB(tenantId, dbName) { return `non_${tenantId}_${dbName}`; - }; + } /** * Returns the TenantMigrationAccessBlocker serverStatus output for the migration or shard merge * for the given node. */ - this.getTenantMigrationAccessBlocker = function(obj) { - return TenantMigrationUtil.getTenantMigrationAccessBlocker(obj); - }; + getTenantMigrationAccessBlocker(obj) { + return getTenantMigrationAccessBlocker(obj); + } /** * Returns the TenantMigrationStats on the node. */ - this.getTenantMigrationStats = function(node) { + getTenantMigrationStats(node) { return assert.commandWorked(node.adminCommand({serverStatus: 1})).tenantMigrations; - }; + } /** * Returns the donor ReplSetTest. */ - this.getDonorRst = function() { - return donorRst; - }; + getDonorRst() { + return this._donorRst; + } /** * Returns the recipient ReplSetTest. */ - this.getRecipientRst = function() { - return recipientRst; - }; + getRecipientRst() { + return this._recipientRst; + } /** * Returns the donor's primary. */ - this.getDonorPrimary = function() { + getDonorPrimary() { return this.getDonorRst().getPrimary(); - }; + } /** * Returns the recipient's primary. */ - this.getRecipientPrimary = function() { + getRecipientPrimary() { return this.getRecipientRst().getPrimary(); - }; + } /** * Returns the recipient's connection string. */ - this.getRecipientConnString = function() { + getRecipientConnString() { return this.getRecipientRst().getURL(); - }; + } /** * Shuts down the donor and recipient sets, only if they were not passed in as parameters. * If they were passed in, the test that initialized them should be responsible for shutting * them down. */ - this.stop = function() { - if (!donorPassedIn) - donorRst.stopSet(); - if (!recipientPassedIn) - recipientRst.stopSet(); - }; -} - -/** - * Takes in the response to the donarStartMigration command and asserts the command - * works and the state is 'committed'. - */ -TenantMigrationTest.assertCommitted = function(stateRes) { - assert.commandWorked(stateRes); - assert.eq(stateRes.state, TenantMigrationTest.DonorState.kCommitted, tojson(stateRes)); - return stateRes; -}; - -/** - * Takes in the response to the donarStartMigration command and asserts the command - * works and the state is 'aborted', with optional errorCode. - */ -TenantMigrationTest.assertAborted = function(stateRes, errorCode) { - assert.commandWorked(stateRes); - assert.eq(stateRes.state, TenantMigrationTest.DonorState.kAborted, tojson(stateRes)); - if (errorCode !== undefined) { - assert.eq(stateRes.abortReason.code, errorCode, tojson(stateRes)); + stop() { + if (!this._donorPassedIn) + this._donorRst.stopSet(); + if (!this._recipientPassedIn) + this._recipientRst.stopSet(); } - return stateRes; -}; +} TenantMigrationTest.DonorState = { kCommitted: "committed", diff --git a/jstests/replsets/libs/tenant_migration_util.js b/jstests/replsets/libs/tenant_migration_util.js index 9ac12f63737..93926f527ce 100644 --- a/jstests/replsets/libs/tenant_migration_util.js +++ b/jstests/replsets/libs/tenant_migration_util.js @@ -1,586 +1,562 @@ /** * Utilities for testing tenant migrations. */ -var TenantMigrationUtil = (function() { - load("jstests/replsets/rslib.js"); - - const kExternalKeysNs = "config.external_validation_keys"; - - /** - * Returns true if feature flag 'featureFlagShardMerge' is enabled, false otherwise. - */ - function isShardMergeEnabled(db) { - const adminDB = db.getSiblingDB("admin"); - const flagDoc = - assert.commandWorked(adminDB.adminCommand({getParameter: 1, featureFlagShardMerge: 1})); - const fcvDoc = assert.commandWorked( - adminDB.adminCommand({getParameter: 1, featureCompatibilityVersion: 1})); - return flagDoc.hasOwnProperty("featureFlagShardMerge") && - flagDoc.featureFlagShardMerge.value && - MongoRunner.compareBinVersions(fcvDoc.featureCompatibilityVersion.version, - flagDoc.featureFlagShardMerge.version) >= 0; - } +export const kExternalKeysNs = "config.external_validation_keys"; - /** - * Checks the FCV and the command object passed to see if tenantIds should be set for shard - * merge. - */ - function shouldUseMergeTenantIds(db) { - const fcvDoc = assert.commandWorked( - db.adminCommand({getParameter: 1, featureCompatibilityVersion: 1})); +/** + * Returns true if feature flag 'featureFlagShardMerge' is enabled, false otherwise. + */ +export function isShardMergeEnabled(db) { + const adminDB = db.getSiblingDB("admin"); + const flagDoc = + assert.commandWorked(adminDB.adminCommand({getParameter: 1, featureFlagShardMerge: 1})); + const fcvDoc = assert.commandWorked( + adminDB.adminCommand({getParameter: 1, featureCompatibilityVersion: 1})); + return flagDoc.hasOwnProperty("featureFlagShardMerge") && flagDoc.featureFlagShardMerge.value && + MongoRunner.compareBinVersions(fcvDoc.featureCompatibilityVersion.version, + flagDoc.featureFlagShardMerge.version) >= 0; +} - return MongoRunner.compareBinVersions(fcvDoc.featureCompatibilityVersion.version, "6.3") >= - 0; - } +/** + * Checks the FCV and the command object passed to see if tenantIds should be set for shard + * merge. + */ +function shouldUseMergeTenantIds(db) { + const fcvDoc = + assert.commandWorked(db.adminCommand({getParameter: 1, featureCompatibilityVersion: 1})); - /** - * Construct a donorStartMigration command object with protocol: "shard merge" if the feature - * flag is enabled. - */ - function donorStartMigrationWithProtocol(cmd, db) { - // If we don't pass "protocol" and shard merge is enabled, we set the protocol to - // "shard merge". Otherwise, the provided protocol is used, which defaults to - // "multitenant migrations" if not provided. - if (cmd["protocol"] === undefined && isShardMergeEnabled(db)) { - const cmdCopy = Object.assign({}, cmd); - - if (shouldUseMergeTenantIds(db)) { - cmdCopy.tenantIds = cmdCopy.tenantIds || [ObjectId(cmdCopy.tenantId)]; - } + return MongoRunner.compareBinVersions(fcvDoc.featureCompatibilityVersion.version, "6.3") >= 0; +} - delete cmdCopy.tenantId; - cmdCopy.protocol = "shard merge"; - return cmdCopy; - } else if (cmd["protocol"] == "shard merge") { - const cmdCopy = Object.assign({}, cmd); - delete cmdCopy.tenantId; - return cmdCopy; - } else { - const cmdCopy = Object.assign({}, cmd); - delete cmdCopy.tenantIds; - return cmdCopy; +/** + * Construct a donorStartMigration command object with protocol: "shard merge" if the feature + * flag is enabled. + */ +export function donorStartMigrationWithProtocol(cmd, db) { + // If we don't pass "protocol" and shard merge is enabled, we set the protocol to + // "shard merge". Otherwise, the provided protocol is used, which defaults to + // "multitenant migrations" if not provided. + if (cmd["protocol"] === undefined && isShardMergeEnabled(db)) { + const cmdCopy = Object.assign({}, cmd); + + if (shouldUseMergeTenantIds(db)) { + cmdCopy.tenantIds = cmdCopy.tenantIds || [ObjectId(cmdCopy.tenantId)]; } - } - /** - * Returns the external keys for the given migration id. - */ - function getExternalKeys(conn, migrationId) { - return conn.getCollection(kExternalKeysNs).find({migrationId}).toArray(); + delete cmdCopy.tenantId; + cmdCopy.protocol = "shard merge"; + return cmdCopy; + } else if (cmd["protocol"] == "shard merge") { + const cmdCopy = Object.assign({}, cmd); + delete cmdCopy.tenantId; + return cmdCopy; + } else { + const cmdCopy = Object.assign({}, cmd); + delete cmdCopy.tenantIds; + return cmdCopy; } +} - /** - * Returns X509 options for ReplSetTest with the given certificate-key file and CA pem file. - */ - function makeX509Options(certPemFile, caPemFile = "jstests/libs/ca.pem") { - return { - // When the global sslMode is preferSSL or requireSSL, the transport layer would do the - // SSL handshake regardless of the specified sslMode for the connection. So we use a - // allowTLS to verify that the donor and recipient use SSL to authenticate to each other - // regardless of the global sslMode. - tlsMode: "allowTLS", - tlsCertificateKeyFile: certPemFile, - tlsCAFile: caPemFile, - tlsAllowInvalidHostnames: '' - }; - } +/** + * Returns the external keys for the given migration id. + */ +export function getExternalKeys(conn, migrationId) { + return conn.getCollection(kExternalKeysNs).find({migrationId}).toArray(); +} - /** - * Returns an object containing the certificate and private key extracted from the given - * pem file. - */ - function getCertificateAndPrivateKey(pemFile) { - const lines = cat(pemFile); - const certificate = - lines.match(new RegExp("-*BEGIN CERTIFICATE-*\\n(.*\\n)*-*END CERTIFICATE-*\\n"))[0]; - const privateKey = - lines.match(new RegExp("-*BEGIN PRIVATE KEY-*\\n(.*\\n)*-*END PRIVATE KEY-*\\n"))[0]; - return {certificate, privateKey}; - } +/** + * Returns X509 options for ReplSetTest with the given certificate-key file and CA pem file. + */ +export function makeX509Options(certPemFile, caPemFile = "jstests/libs/ca.pem") { + return { + // When the global sslMode is preferSSL or requireSSL, the transport layer would do the + // SSL handshake regardless of the specified sslMode for the connection. So we use a + // allowTLS to verify that the donor and recipient use SSL to authenticate to each other + // regardless of the global sslMode. + tlsMode: "allowTLS", + tlsCertificateKeyFile: certPemFile, + tlsCAFile: caPemFile, + tlsAllowInvalidHostnames: '' + }; +} - /** - * Returns an object containing the donor and recipient ReplSetTest X509 options for tenant - * migration testing. - */ - function makeX509OptionsForTest() { - return { - donor: makeX509Options("jstests/libs/rs0.pem"), - recipient: makeX509Options("jstests/libs/rs1.pem") - }; - } +/** + * Returns an object containing the certificate and private key extracted from the given + * pem file. + */ +export function getCertificateAndPrivateKey(pemFile) { + const lines = cat(pemFile); + const certificate = + lines.match(new RegExp("-*BEGIN CERTIFICATE-*\\n(.*\\n)*-*END CERTIFICATE-*\\n"))[0]; + const privateKey = + lines.match(new RegExp("-*BEGIN PRIVATE KEY-*\\n(.*\\n)*-*END PRIVATE KEY-*\\n"))[0]; + return {certificate, privateKey}; +} - /** - * Returns an object containing the donor and recipient's certificate and private key for - * tenant migration testing. - */ - function makeMigrationCertificatesForTest() { - return { - donorCertificateForRecipient: - getCertificateAndPrivateKey("jstests/libs/tenant_migration_donor.pem"), - recipientCertificateForDonor: - getCertificateAndPrivateKey("jstests/libs/tenant_migration_recipient.pem") - }; - } +/** + * Returns an object containing the donor and recipient ReplSetTest X509 options for tenant + * migration testing. + */ +export function makeX509OptionsForTest() { + return { + donor: makeX509Options("jstests/libs/rs0.pem"), + recipient: makeX509Options("jstests/libs/rs1.pem") + }; +} - /** - * Takes in the response to the donorStartMigration command and returns true if the state is - * "committed" or "aborted". - */ - function isMigrationCompleted(res) { - return res.state === "committed" || res.state === "aborted"; - } +/** + * Returns an object containing the donor and recipient's certificate and private key for + * tenant migration testing. + */ +export function makeMigrationCertificatesForTest() { + return { + donorCertificateForRecipient: + getCertificateAndPrivateKey("jstests/libs/tenant_migration_donor.pem"), + recipientCertificateForDonor: + getCertificateAndPrivateKey("jstests/libs/tenant_migration_recipient.pem") + }; +} - /** - * Runs the donorStartMigration command with the given migration options - * until the migration commits or aborts, or until the command fails. Returns the last command - * response. - * - * If 'retryOnRetryableErrors' is set, this function will retry if the command fails with a - * retryable error. - * - * Only use when it is necessary to run the donorStartMigration command in its own thread. For - * all other use cases, please consider the runMigration() function in the TenantMigrationTest - * fixture. - */ - function runMigrationAsync(migrationOpts, donorRstArgs, opts = {}) { - const { - retryOnRetryableErrors = false, - enableDonorStartMigrationFsync = false, - } = opts; - load("jstests/replsets/libs/tenant_migration_util.js"); - const donorRst = TenantMigrationUtil.createRst(donorRstArgs, retryOnRetryableErrors); - - const migrationCertificates = TenantMigrationUtil.makeMigrationCertificatesForTest(); - const cmdObj = { - donorStartMigration: 1, - migrationId: UUID(migrationOpts.migrationIdString), - tenantId: migrationOpts.tenantId, - tenantIds: eval(migrationOpts.tenantIds), - recipientConnectionString: migrationOpts.recipientConnString, - readPreference: migrationOpts.readPreference || {mode: "primary"}, - donorCertificateForRecipient: migrationOpts.donorCertificateForRecipient || - migrationCertificates.donorCertificateForRecipient, - recipientCertificateForDonor: migrationOpts.recipientCertificateForDonor || - migrationCertificates.recipientCertificateForDonor, - }; +/** + * Takes in the response to the donorStartMigration command and returns true if the state is + * "committed" or "aborted". + */ +export function isMigrationCompleted(res) { + return res.state === "committed" || res.state === "aborted"; +} - return TenantMigrationUtil.runTenantMigrationCommand(cmdObj, donorRst, { - retryOnRetryableErrors, - enableDonorStartMigrationFsync, - shouldStopFunc: TenantMigrationUtil.isMigrationCompleted - }); - } +/** + * Runs the donorStartMigration command with the given migration options + * until the migration commits or aborts, or until the command fails. Returns the last command + * response. + * + * If 'retryOnRetryableErrors' is set, this function will retry if the command fails with a + * retryable error. + * + * Only use when it is necessary to run the donorStartMigration command in its own thread. For + * all other use cases, please consider the runMigration() function in the TenantMigrationTest + * fixture. + */ +export async function runMigrationAsync(migrationOpts, donorRstArgs, opts = {}) { + const {isMigrationCompleted, makeMigrationCertificatesForTest, runTenantMigrationCommand} = + await import("jstests/replsets/libs/tenant_migration_util.js"); + load("jstests/replsets/rslib.js"); // createRst - /** - * Runs the donorForgetMigration command with the given migrationId and returns the response. - * - * If 'retryOnRetryableErrors' is set, this function will retry if the command fails with a - * retryable error. - * - * Only use when it is necessary to run the donorForgetMigration command in its own thread. For - * all other use cases, please consider the forgetMigration() function in the - * TenantMigrationTest fixture. - */ - function forgetMigrationAsync(migrationIdString, donorRstArgs, retryOnRetryableErrors = false) { - load("jstests/replsets/libs/tenant_migration_util.js"); - const donorRst = TenantMigrationUtil.createRst(donorRstArgs, retryOnRetryableErrors); - const cmdObj = {donorForgetMigration: 1, migrationId: UUID(migrationIdString)}; - return TenantMigrationUtil.runTenantMigrationCommand( - cmdObj, donorRst, {retryOnRetryableErrors}); - } + const { + retryOnRetryableErrors = false, + enableDonorStartMigrationFsync = false, + } = opts; + + const donorRst = createRst(donorRstArgs, retryOnRetryableErrors); + const migrationCertificates = makeMigrationCertificatesForTest(); + const cmdObj = { + donorStartMigration: 1, + migrationId: UUID(migrationOpts.migrationIdString), + tenantId: migrationOpts.tenantId, + tenantIds: eval(migrationOpts.tenantIds), + recipientConnectionString: migrationOpts.recipientConnString, + readPreference: migrationOpts.readPreference || {mode: "primary"}, + donorCertificateForRecipient: migrationOpts.donorCertificateForRecipient || + migrationCertificates.donorCertificateForRecipient, + recipientCertificateForDonor: migrationOpts.recipientCertificateForDonor || + migrationCertificates.recipientCertificateForDonor, + }; - /** - * Runs the donorAbortMigration command with the given migration options and returns the - * response. - * - * If 'retryOnRetryableErrors' is set, this function will retry if the command fails with a - * retryable error. - * - * Only use when it is necessary to run the donorAbortMigration command in its own thread. For - * all other use cases, please consider the tryAbortMigration() function in the - * TenantMigrationTest fixture. - */ - function tryAbortMigrationAsync(migrationOpts, donorRstArgs, retryOnRetryableErrors = false) { - load("jstests/replsets/libs/tenant_migration_util.js"); - const donorRst = TenantMigrationUtil.createRst(donorRstArgs, retryOnRetryableErrors); - const cmdObj = { - donorAbortMigration: 1, - migrationId: UUID(migrationOpts.migrationIdString), - }; - return TenantMigrationUtil.runTenantMigrationCommand( - cmdObj, donorRst, {retryOnRetryableErrors}); - } + return runTenantMigrationCommand(cmdObj, donorRst, { + retryOnRetryableErrors, + enableDonorStartMigrationFsync, + shouldStopFunc: isMigrationCompleted + }); +} - /** - * Runs the given tenant migration command against the primary of the given replica set until - * the command succeeds or fails with a non-retryable error (if 'retryOnRetryableErrors' is - * true) or until 'shouldStopFunc' returns true. Returns the last response. - */ - function runTenantMigrationCommand(cmdObj, rst, { - retryOnRetryableErrors = false, - shouldStopFunc = () => true, - enableDonorStartMigrationFsync = false - } = {}) { - let primary = rst.getPrimary(); - let localCmdObj = cmdObj; - let run = () => primary.adminCommand(localCmdObj); - if (Object.keys(cmdObj)[0] === "donorStartMigration") { - run = () => { - const adminDB = primary.getDB("admin"); - localCmdObj = donorStartMigrationWithProtocol(cmdObj, adminDB); - if (enableDonorStartMigrationFsync) { - rst.awaitLastOpCommitted(); - assert.commandWorked(primary.adminCommand({fsync: 1})); - } - return primary.adminCommand(localCmdObj); - }; - } +/** + * Runs the donorForgetMigration command with the given migrationId and returns the response. + * + * If 'retryOnRetryableErrors' is set, this function will retry if the command fails with a + * retryable error. + * + * Only use when it is necessary to run the donorForgetMigration command in its own thread. For + * all other use cases, please consider the forgetMigration() function in the + * TenantMigrationTest fixture. + */ +export async function forgetMigrationAsync( + migrationIdString, donorRstArgs, retryOnRetryableErrors = false) { + const {runTenantMigrationCommand} = + await import("jstests/replsets/libs/tenant_migration_util.js"); + load("jstests/replsets/rslib.js"); // createRst - let res; - assert.soon(() => { - try { - // Note: assert.commandWorked() considers command responses with embedded - // writeErrors and WriteConcernErrors as a failure even if the command returned - // "ok: 1". And, admin commands(like, donorStartMigration) - // doesn't generate writeConcernErros or WriteErrors. So, it's safe to wrap up - // run() with assert.commandWorked() here. However, in few scenarios, like - // Mongo.prototype.recordRerouteDueToTenantMigration(), it's not safe to wrap up - // run() with commandWorked() as retrying on retryable writeConcernErrors can - // cause the retry attempt to fail with writeErrors. - res = undefined; - res = run(); - assert.commandWorked(res); - return shouldStopFunc(res); - } catch (e) { - if (retryOnRetryableErrors && isRetryableError(e)) { - jsTestLog(`Retryable error runing runTenantMigrationCommand. Command: ${ - tojson(localCmdObj)}, Error: ${tojson(e)}`); - - primary = rst.getPrimary(); - return false; - } - jsTestLog(`Error running runTenantMigrationCommand. Command: ${ - tojson(localCmdObj)}, Error: ${tojson(e)}`); + const donorRst = createRst(donorRstArgs, retryOnRetryableErrors); + const cmdObj = {donorForgetMigration: 1, migrationId: UUID(migrationIdString)}; + return runTenantMigrationCommand(cmdObj, donorRst, {retryOnRetryableErrors}); +} - // If res is defined, return true to exit assert.soon and return res to the caller. - // Otherwise rethrow e to propagate it to the caller. - if (res) - return true; +/** + * Runs the donorAbortMigration command with the given migration options and returns the + * response. + * + * If 'retryOnRetryableErrors' is set, this function will retry if the command fails with a + * retryable error. + * + * Only use when it is necessary to run the donorAbortMigration command in its own thread. For + * all other use cases, please consider the tryAbortMigration() function in the + * TenantMigrationTest fixture. + */ +export async function tryAbortMigrationAsync( + migrationOpts, donorRstArgs, retryOnRetryableErrors = false) { + const {runTenantMigrationCommand} = + await import("jstests/replsets/libs/tenant_migration_util.js"); + load("jstests/replsets/rslib.js"); // createRst + + const donorRst = createRst(donorRstArgs, retryOnRetryableErrors); + const cmdObj = { + donorAbortMigration: 1, + migrationId: UUID(migrationOpts.migrationIdString), + }; + return runTenantMigrationCommand(cmdObj, donorRst, {retryOnRetryableErrors}); +} - throw e; +/** + * Runs the given tenant migration command against the primary of the given replica set until + * the command succeeds or fails with a non-retryable error (if 'retryOnRetryableErrors' is + * true) or until 'shouldStopFunc' returns true. Returns the last response. + */ +export function runTenantMigrationCommand(cmdObj, rst, { + retryOnRetryableErrors = false, + shouldStopFunc = () => true, + enableDonorStartMigrationFsync = false +} = {}) { + let primary = rst.getPrimary(); + let localCmdObj = cmdObj; + let run = () => primary.adminCommand(localCmdObj); + if (Object.keys(cmdObj)[0] === "donorStartMigration") { + run = () => { + const adminDB = primary.getDB("admin"); + localCmdObj = donorStartMigrationWithProtocol(cmdObj, adminDB); + if (enableDonorStartMigrationFsync) { + rst.awaitLastOpCommitted(); + assert.commandWorked(primary.adminCommand({fsync: 1})); } - }); - return res; + return primary.adminCommand(localCmdObj); + }; } - const ServerlessLockType = - {None: 0, ShardSplitDonor: 1, TenantMigrationDonor: 2, TenantMigrationRecipient: 3}; + let res; + assert.soon(() => { + try { + // Note: assert.commandWorked() considers command responses with embedded + // writeErrors and WriteConcernErrors as a failure even if the command returned + // "ok: 1". And, admin commands(like, donorStartMigration) + // doesn't generate writeConcernErros or WriteErrors. So, it's safe to wrap up + // run() with assert.commandWorked() here. However, in few scenarios, like + // Mongo.prototype.recordRerouteDueToTenantMigration(), it's not safe to wrap up + // run() with commandWorked() as retrying on retryable writeConcernErrors can + // cause the retry attempt to fail with writeErrors. + res = undefined; + res = run(); + assert.commandWorked(res); + return shouldStopFunc(res); + } catch (e) { + if (retryOnRetryableErrors && isRetryableError(e)) { + jsTestLog(`Retryable error running runTenantMigrationCommand. Command: ${ + tojson(localCmdObj)}, Error: ${tojson(e)}`); - /** - * Return the active serverless operation lock, if one is acquired. - */ - function getServerlessOperationLock(node) { - return assert.commandWorked(node.adminCommand({serverStatus: 1, serverless: 1})) - .serverless.operationLock; - } + primary = rst.getPrimary(); + return false; + } + jsTestLog(`Error running runTenantMigrationCommand. Command: ${ + tojson(localCmdObj)}, Error: ${tojson(e)}`); - /** - * Returns the TenantMigrationAccessBlocker serverStatus output for the multi-tenant migration - * or shard merge for the given node. - */ - function getTenantMigrationAccessBlocker({donorNode, recipientNode, tenantId}) { - assert(donorNode || recipientNode, "missing required parameter donorNode or recipientNode"); - if (donorNode && recipientNode) { - throw new Error("please specify either 'donorNode' or 'recipientNode' but not both"); + // If res is defined, return true to exit assert.soon and return res to the caller. + // Otherwise rethrow e to propagate it to the caller. + if (res) + return true; + + throw e; } + }); + return res; +} - const node = donorNode || recipientNode; - const {tenantMigrationAccessBlocker} = - assert.commandWorked(node.adminCommand({serverStatus: 1})); +export const ServerlessLockType = { + None: 0, + ShardSplitDonor: 1, + TenantMigrationDonor: 2, + TenantMigrationRecipient: 3 +}; - if (tenantMigrationAccessBlocker && tenantId && - tenantMigrationAccessBlocker.hasOwnProperty(tenantId)) { - return tenantMigrationAccessBlocker[tenantId]; - } +/** + * Return the active serverless operation lock, if one is acquired. + */ +export function getServerlessOperationLock(node) { + return assert.commandWorked(node.adminCommand({serverStatus: 1, serverless: 1})) + .serverless.operationLock; +} - return tenantMigrationAccessBlocker; +/** + * Returns the TenantMigrationAccessBlocker serverStatus output for the multi-tenant migration + * or shard merge for the given node. + */ +export function getTenantMigrationAccessBlocker({donorNode, recipientNode, tenantId}) { + assert(donorNode || recipientNode, "missing required parameter donorNode or recipientNode"); + if (donorNode && recipientNode) { + throw new Error("please specify either 'donorNode' or 'recipientNode' but not both"); } - /** - * Returns all TenantMigrationAccessBlocker serverStatus output for the multi-tenant migration - * or shard merge associated with the provided tenantId for the given nodes, filtering out any - * empty entries. - */ - function getTenantMigrationAccessBlockers({donorNodes = [], recipientNodes = [], tenantId}) { - const recipientAccessBlockers = recipientNodes.reduce((acc, node) => { - const accessBlocker = getTenantMigrationAccessBlocker({recipientNode: node, tenantId}); - return accessBlocker && accessBlocker.recipient ? acc.concat(accessBlocker.recipient) - : acc; - }, []); - - const donorAccessBlockers = donorNodes.reduce((acc, node) => { - const accessBlocker = getTenantMigrationAccessBlocker({donorNode: node, tenantId}); - return accessBlocker && accessBlocker.donor ? acc.concat(accessBlocker.donor) : acc; - }, []); - - return {recipientAccessBlockers, donorAccessBlockers}; - } + const node = donorNode || recipientNode; + const {tenantMigrationAccessBlocker} = + assert.commandWorked(node.adminCommand({serverStatus: 1})); - /** - * Returns the number of reads on the given donor node that were blocked due to tenant migration - * for the given tenant. - */ - function getNumBlockedReads(donorNode, tenantId) { - const mtab = getTenantMigrationAccessBlocker({donorNode, tenantId}); - if (!mtab) { - return 0; - } - return mtab.donor.numBlockedReads; + if (tenantMigrationAccessBlocker && tenantId && + tenantMigrationAccessBlocker.hasOwnProperty(tenantId)) { + return tenantMigrationAccessBlocker[tenantId]; } - /** - * Returns the number of writes on the given donor node that were blocked due to tenant - * migration for the given tenant. - */ - function getNumBlockedWrites(donorNode, tenantId) { - const mtab = getTenantMigrationAccessBlocker({donorNode, tenantId}); - if (!mtab) { - return 0; - } - return mtab.donor.numBlockedWrites; + return tenantMigrationAccessBlocker; +} + +/** + * Returns all TenantMigrationAccessBlocker serverStatus output for the multi-tenant migration + * or shard merge associated with the provided tenantId for the given nodes, filtering out any + * empty entries. + */ +export function getTenantMigrationAccessBlockers({donorNodes = [], recipientNodes = [], tenantId}) { + const recipientAccessBlockers = recipientNodes.reduce((acc, node) => { + const accessBlocker = getTenantMigrationAccessBlocker({recipientNode: node, tenantId}); + return accessBlocker && accessBlocker.recipient ? acc.concat(accessBlocker.recipient) : acc; + }, []); + + const donorAccessBlockers = donorNodes.reduce((acc, node) => { + const accessBlocker = getTenantMigrationAccessBlocker({donorNode: node, tenantId}); + return accessBlocker && accessBlocker.donor ? acc.concat(accessBlocker.donor) : acc; + }, []); + + return {recipientAccessBlockers, donorAccessBlockers}; +} + +/** + * Returns the number of reads on the given donor node that were blocked due to tenant migration + * for the given tenant. + */ +export function getNumBlockedReads(donorNode, tenantId) { + const mtab = getTenantMigrationAccessBlocker({donorNode, tenantId}); + if (!mtab) { + return 0; } + return mtab.donor.numBlockedReads; +} - /** - * Determines if a database name belongs to the given tenant. - */ - function isNamespaceForTenant(tenantId, dbName) { - return dbName.startsWith(`${tenantId}_`); +/** + * Returns the number of writes on the given donor node that were blocked due to tenant + * migration for the given tenant. + */ +export function getNumBlockedWrites(donorNode, tenantId) { + const mtab = getTenantMigrationAccessBlocker({donorNode, tenantId}); + if (!mtab) { + return 0; } + return mtab.donor.numBlockedWrites; +} - /** - * Compares the hashes for DBs that belong to the specified tenant between the donor and - * recipient primaries. - */ - function checkTenantDBHashes({ - donorRst, - recipientRst, - tenantId, - excludedDBs = [], - msgPrefix = 'checkTenantDBHashes', - ignoreUUIDs = false, - skipTempCollections = false - }) { - // Always skip db hash checks for the config, admin, and local database. - excludedDBs = [...excludedDBs, "config", "admin", "local"]; - - while (true) { - try { - const donorPrimaryConn = donorRst.getPrimary(); - const recipientPrimaryConn = recipientRst.getPrimary(); - - // Allows listCollections and listIndexes on donor after migration for consistency - // checks. - const donorAllowsReadsAfterMigration = - assert - .commandWorked(donorPrimaryConn.adminCommand({ - getParameter: 1, - "failpoint.tenantMigrationDonorAllowsNonTimestampedReads": 1 - }))["failpoint.tenantMigrationDonorAllowsNonTimestampedReads"] - .mode; - // Only turn on the failpoint if it is not already. - if (!donorAllowsReadsAfterMigration) { - assert.commandWorked(donorPrimaryConn.adminCommand({ - configureFailPoint: "tenantMigrationDonorAllowsNonTimestampedReads", - mode: "alwaysOn" - })); - } +/** + * Determines if a database name belongs to the given tenant. + */ +export function isNamespaceForTenant(tenantId, dbName) { + return dbName.startsWith(`${tenantId}_`); +} - // Filter out all dbs that don't belong to the tenant. - let combinedDBNames = - [...donorPrimaryConn.getDBNames(), ...recipientPrimaryConn.getDBNames()]; - combinedDBNames = - combinedDBNames.filter(dbName => (isNamespaceForTenant(tenantId, dbName) && - !excludedDBs.includes(dbName))); - combinedDBNames = new Set(combinedDBNames); - - for (const dbName of combinedDBNames) { - // Pass in an empty array for the secondaries, since we only wish to compare - // the DB hashes between the donor and recipient primary in this test. - const donorDBHash = assert.commandWorked( - donorRst.getHashes(dbName, [], skipTempCollections).primary); - const recipientDBHash = assert.commandWorked( - recipientRst.getHashes(dbName, [], skipTempCollections).primary); - - const donorCollections = Object.keys(donorDBHash.collections); - const donorCollInfos = new CollInfos(donorPrimaryConn, 'donorPrimary', dbName); - donorCollInfos.filter(donorCollections); - - const recipientCollections = Object.keys(recipientDBHash.collections); - const recipientCollInfos = - new CollInfos(recipientPrimaryConn, 'recipientPrimary', dbName); - recipientCollInfos.filter(recipientCollections); - - print(`checking db hash for tenant '${tenantId}' between donor: ${ - donorPrimaryConn.host}, and recipient: ${recipientPrimaryConn.host}`); - - const collectionPrinted = new Set(); - const success = DataConsistencyChecker.checkDBHash(donorDBHash, - donorCollInfos, - recipientDBHash, - recipientCollInfos, - msgPrefix, - ignoreUUIDs, - true, /* syncingHasIndexes */ - collectionPrinted); - if (!success) { - print(`checkTenantDBHashes dumping donor and recipient primary oplogs`); - donorRst.dumpOplog(donorPrimaryConn, {}, 100); - recipientRst.dumpOplog(recipientPrimaryConn, {}, 100); - } - assert(success, 'dbhash mismatch between donor and recipient primaries'); - } +/** + * Compares the hashes for DBs that belong to the specified tenant between the donor and + * recipient primaries. + */ +export function checkTenantDBHashes({ + donorRst, + recipientRst, + tenantId, + excludedDBs = [], + msgPrefix = 'checkTenantDBHashes', + ignoreUUIDs = false, + skipTempCollections = false +}) { + // Always skip db hash checks for the config, admin, and local database. + excludedDBs = [...excludedDBs, "config", "admin", "local"]; + + while (true) { + try { + const donorPrimaryConn = donorRst.getPrimary(); + const recipientPrimaryConn = recipientRst.getPrimary(); + + // Allows listCollections and listIndexes on donor after migration for consistency + // checks. + const donorAllowsReadsAfterMigration = + assert + .commandWorked(donorPrimaryConn.adminCommand({ + getParameter: 1, + "failpoint.tenantMigrationDonorAllowsNonTimestampedReads": 1 + }))["failpoint.tenantMigrationDonorAllowsNonTimestampedReads"] + .mode; + // Only turn on the failpoint if it is not already. + if (!donorAllowsReadsAfterMigration) { + assert.commandWorked(donorPrimaryConn.adminCommand({ + configureFailPoint: "tenantMigrationDonorAllowsNonTimestampedReads", + mode: "alwaysOn" + })); + } - // Reset failpoint on the donor after consistency checks if it wasn't enabled - // before. - if (!donorAllowsReadsAfterMigration) { - // We unset the failpoint for every node in case there was a failover at some - // point before this. - donorRst.nodes.forEach(node => { - assert.commandWorked(node.adminCommand({ - configureFailPoint: "tenantMigrationDonorAllowsNonTimestampedReads", - mode: "off" - })); - }); + // Filter out all dbs that don't belong to the tenant. + let combinedDBNames = + [...donorPrimaryConn.getDBNames(), ...recipientPrimaryConn.getDBNames()]; + combinedDBNames = + combinedDBNames.filter(dbName => (isNamespaceForTenant(tenantId, dbName) && + !excludedDBs.includes(dbName))); + combinedDBNames = new Set(combinedDBNames); + + for (const dbName of combinedDBNames) { + // Pass in an empty array for the secondaries, since we only wish to compare + // the DB hashes between the donor and recipient primary in this test. + const donorDBHash = assert.commandWorked( + donorRst.getHashes(dbName, [], skipTempCollections).primary); + const recipientDBHash = assert.commandWorked( + recipientRst.getHashes(dbName, [], skipTempCollections).primary); + + const donorCollections = Object.keys(donorDBHash.collections); + const donorCollInfos = new CollInfos(donorPrimaryConn, 'donorPrimary', dbName); + donorCollInfos.filter(donorCollections); + + const recipientCollections = Object.keys(recipientDBHash.collections); + const recipientCollInfos = + new CollInfos(recipientPrimaryConn, 'recipientPrimary', dbName); + recipientCollInfos.filter(recipientCollections); + + print(`checking db hash for tenant '${tenantId}' between donor: ${ + donorPrimaryConn.host}, and recipient: ${recipientPrimaryConn.host}`); + + const collectionPrinted = new Set(); + const success = DataConsistencyChecker.checkDBHash(donorDBHash, + donorCollInfos, + recipientDBHash, + recipientCollInfos, + msgPrefix, + ignoreUUIDs, + true, /* syncingHasIndexes */ + collectionPrinted); + if (!success) { + print(`checkTenantDBHashes dumping donor and recipient primary oplogs`); + donorRst.dumpOplog(donorPrimaryConn, {}, 100); + recipientRst.dumpOplog(recipientPrimaryConn, {}, 100); } + assert(success, 'dbhash mismatch between donor and recipient primaries'); + } - break; - } catch (e) { - if (!checkIfRetryableErrorForTenantDbHashCheck(e)) { - throw e; - } else { - print(`Got error: ${tojson(e)}. Failover occurred during tenant dbhash check,` + - ` retrying tenant dbhash check.`); - } + // Reset failpoint on the donor after consistency checks if it wasn't enabled + // before. + if (!donorAllowsReadsAfterMigration) { + // We unset the failpoint for every node in case there was a failover at some + // point before this. + donorRst.nodes.forEach(node => { + assert.commandWorked(node.adminCommand({ + configureFailPoint: "tenantMigrationDonorAllowsNonTimestampedReads", + mode: "off" + })); + }); + } + + break; + } catch (e) { + if (!checkIfRetryableErrorForTenantDbHashCheck(e)) { + throw e; + } else { + print(`Got error: ${tojson(e)}. Failover occurred during tenant dbhash check,` + + ` retrying tenant dbhash check.`); } } } +} - /** - * Creates a role for tenant migration donor if it doesn't exist. - */ - function createTenantMigrationDonorRoleIfNotExist(rst) { - const adminDB = rst.getPrimary().getDB("admin"); - - if (roleExists(adminDB, "tenantMigrationDonorRole")) { - return; - } +/** + * Creates a role for tenant migration donor if it doesn't exist. + */ +export function createTenantMigrationDonorRoleIfNotExist(rst) { + const adminDB = rst.getPrimary().getDB("admin"); - assert.commandWorked(adminDB.runCommand({ - createRole: "tenantMigrationDonorRole", - privileges: [ - {resource: {cluster: true}, actions: ["runTenantMigration"]}, - {resource: {db: "admin", collection: "system.keys"}, actions: ["find"]} - ], - roles: [] - })); + if (roleExists(adminDB, "tenantMigrationDonorRole")) { + return; } - /** - * Checks if an error gotten while doing a tenant dbhash check is retryable. - */ - function checkIfRetryableErrorForTenantDbHashCheck(error) { - // Due to the shell not propagating error codes correctly, if we get any of the following - // error messages, we can retry the operation. - const retryableErrorMessages = [ - "The server is in quiesce mode and will shut down", - "can't connect to new replica set primary" - ]; - - // The following shell helper methods check if the error message contains some - // notion of retryability. This is in case the error does not contain an error code. - return isRetryableError(error) || isNetworkError(error) || - // If there's a failover while we're running a dbhash check, the elected secondary might - // not have set the tenantMigrationDonorAllowsNonTimestampedReads failpoint, which means - // that the listCollections command run when we call CollInfos would throw a - // TenantMigrationCommitted error. - ErrorCodes.isTenantMigrationError(error.code) || - // If there's a failover as we're creating a ReplSetTest from either the donor or - // recipient URLs, it's possible to get back a NotYetInitialized error, so we want to - // retry creating the ReplSetTest. - error.code == ErrorCodes.NotYetInitialized || - // TODO (SERVER-54026): Remove check for error message once the shell correctly - // propagates the error code. - retryableErrorMessages.some(msg => error.message.includes(msg)); - } + assert.commandWorked(adminDB.runCommand({ + createRole: "tenantMigrationDonorRole", + privileges: [ + {resource: {cluster: true}, actions: ["runTenantMigration"]}, + {resource: {db: "admin", collection: "system.keys"}, actions: ["find"]} + ], + roles: [] + })); +} - /** - * Creates a role for tenant migration recipient if it doesn't exist. - */ - function createTenantMigrationRecipientRoleIfNotExist(rst) { - const adminDB = rst.getPrimary().getDB("admin"); +/** + * Checks if an error gotten while doing a tenant dbhash check is retryable. + */ +export function checkIfRetryableErrorForTenantDbHashCheck(error) { + // Due to the shell not propagating error codes correctly, if we get any of the following + // error messages, we can retry the operation. + const retryableErrorMessages = [ + "The server is in quiesce mode and will shut down", + "can't connect to new replica set primary" + ]; + + // The following shell helper methods check if the error message contains some + // notion of retryability. This is in case the error does not contain an error code. + return isRetryableError(error) || isNetworkError(error) || + // If there's a failover while we're running a dbhash check, the elected secondary might + // not have set the tenantMigrationDonorAllowsNonTimestampedReads failpoint, which means + // that the listCollections command run when we call CollInfos would throw a + // TenantMigrationCommitted error. + ErrorCodes.isTenantMigrationError(error.code) || + // If there's a failover as we're creating a ReplSetTest from either the donor or + // recipient URLs, it's possible to get back a NotYetInitialized error, so we want to + // retry creating the ReplSetTest. + error.code == ErrorCodes.NotYetInitialized || + // TODO (SERVER-54026): Remove check for error message once the shell correctly + // propagates the error code. + retryableErrorMessages.some(msg => error.message.includes(msg)); +} - if (roleExists(adminDB, "tenantMigrationRecipientRole")) { - return; - } +/** + * Creates a role for tenant migration recipient if it doesn't exist. + */ +export function createTenantMigrationRecipientRoleIfNotExist(rst) { + const adminDB = rst.getPrimary().getDB("admin"); - assert.commandWorked(adminDB.runCommand({ - createRole: "tenantMigrationRecipientRole", - privileges: [ - { - resource: {cluster: true}, - actions: ["listDatabases", "useUUID", "advanceClusterTime"] - }, - {resource: {db: "", collection: ""}, actions: ["listCollections"]}, - { - resource: {anyResource: true}, - actions: ["dbStats", "collStats", "find", "listIndexes"] - } - ], - roles: [] - })); + if (roleExists(adminDB, "tenantMigrationRecipientRole")) { + return; } - /** - * Returns true if the given database role already exists. - */ - function roleExists(db, roleName) { - const roles = db.getRoles({rolesInfo: 1, showPrivileges: false, showBuiltinRoles: false}); - const fullRoleName = `${db.getName()}.${roleName}`; - for (let role of roles) { - if (role._id == fullRoleName) { - return true; + assert.commandWorked(adminDB.runCommand({ + createRole: "tenantMigrationRecipientRole", + privileges: [ + { + resource: {cluster: true}, + actions: ["listDatabases", "useUUID", "advanceClusterTime"] + }, + {resource: {db: "", collection: ""}, actions: ["listCollections"]}, + { + resource: {anyResource: true}, + actions: ["dbStats", "collStats", "find", "listIndexes"] } + ], + roles: [] + })); +} + +/** + * Returns true if the given database role already exists. + */ +export function roleExists(db, roleName) { + const roles = db.getRoles({rolesInfo: 1, showPrivileges: false, showBuiltinRoles: false}); + const fullRoleName = `${db.getName()}.${roleName}`; + for (let role of roles) { + if (role._id == fullRoleName) { + return true; } - return false; } - - return { - kExternalKeysNs, - isShardMergeEnabled, - donorStartMigrationWithProtocol, - getExternalKeys, - runMigrationAsync, - forgetMigrationAsync, - tryAbortMigrationAsync, - createRstArgs, - createRst, - runTenantMigrationCommand, - getCertificateAndPrivateKey, - makeX509Options, - makeMigrationCertificatesForTest, - makeX509OptionsForTest, - isMigrationCompleted, - ServerlessLockType, - getServerlessOperationLock, - getTenantMigrationAccessBlocker, - getTenantMigrationAccessBlockers, - getNumBlockedReads, - getNumBlockedWrites, - isNamespaceForTenant, - checkTenantDBHashes, - createTenantMigrationDonorRoleIfNotExist, - createTenantMigrationRecipientRoleIfNotExist, - roleExists, - checkIfRetryableErrorForTenantDbHashCheck - }; -})(); + return false; +} diff --git a/jstests/replsets/shard_merge_enabled.js b/jstests/replsets/shard_merge_enabled.js index dabb0ca7116..4796e2646f7 100644 --- a/jstests/replsets/shard_merge_enabled.js +++ b/jstests/replsets/shard_merge_enabled.js @@ -3,10 +3,10 @@ * @tags: [featureFlagShardMerge] */ -(function() { -"use strict"; - -load("jstests/replsets/libs/tenant_migration_util.js"); +import { + isShardMergeEnabled, + makeMigrationCertificatesForTest +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); function runTest(downgradeFCV) { @@ -20,7 +20,7 @@ function runTest(downgradeFCV) { // suites will execute this test without featureFlagShardMerge enabled (despite the // presence of the featureFlagShardMerge tag above), which means the test will attempt // to run a multi-tenant migration and fail. - if (!TenantMigrationUtil.isShardMergeEnabled(primary.getDB("admin"))) { + if (!isShardMergeEnabled(primary.getDB("admin"))) { rst.stopSet(); jsTestLog("Skipping Shard Merge-specific test"); return; @@ -29,7 +29,7 @@ function runTest(downgradeFCV) { const adminDB = primary.getDB("admin"); const kDummyConnStr = "mongodb://localhost/?replicaSet=foo"; const readPreference = {mode: 'primary'}; - const migrationCertificates = TenantMigrationUtil.makeMigrationCertificatesForTest(); + const migrationCertificates = makeMigrationCertificatesForTest(); // A function, not a constant, to ensure unique UUIDs. function donorStartMigrationCmd() { @@ -109,7 +109,7 @@ function runTest(downgradeFCV) { configureFailPoint(primary, "returnResponseOkForRecipientForgetMigrationCmd"); // Preconditions: the shard merge feature is enabled and our fresh RS is on the latest FCV. - assert(TenantMigrationUtil.isShardMergeEnabled(adminDB)); + assert(isShardMergeEnabled(adminDB)); assert.eq(getFCVConstants().latest, adminDB.system.version.findOne({_id: 'featureCompatibilityVersion'}).version); @@ -135,4 +135,3 @@ function runTest(downgradeFCV) { } runFeatureFlagMultiversionTest('featureFlagShardMerge', runTest); -})(); diff --git a/jstests/replsets/shard_merge_invalid_options.js b/jstests/replsets/shard_merge_invalid_options.js index 78c3dece7f7..d461cbc16d1 100644 --- a/jstests/replsets/shard_merge_invalid_options.js +++ b/jstests/replsets/shard_merge_invalid_options.js @@ -6,10 +6,10 @@ * ] */ -(function() { -"use strict"; - -load("jstests/replsets/libs/tenant_migration_util.js"); +import { + isShardMergeEnabled, + makeMigrationCertificatesForTest +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); function runTest(nodeOptions) { @@ -21,7 +21,7 @@ function runTest(nodeOptions) { // suites will execute this test without featureFlagShardMerge enabled (despite the // presence of the featureFlagShardMerge tag above), which means the test will attempt // to run a multi-tenant migration and fail. - if (!TenantMigrationUtil.isShardMergeEnabled(rst.getPrimary().getDB("admin"))) { + if (!isShardMergeEnabled(rst.getPrimary().getDB("admin"))) { rst.stopSet(); jsTestLog("Skipping Shard Merge-specific test"); return; @@ -31,7 +31,7 @@ function runTest(nodeOptions) { const adminDB = primary.getDB("admin"); const kDummyConnStr = "mongodb://localhost/?replicaSet=foo"; const readPreference = {mode: 'primary'}; - const migrationCertificates = TenantMigrationUtil.makeMigrationCertificatesForTest(); + const migrationCertificates = makeMigrationCertificatesForTest(); // Enable below fail points to prevent starting the donor/recipient POS instance. configureFailPoint(primary, "returnResponseCommittedForDonorStartMigrationCmd"); @@ -39,7 +39,7 @@ function runTest(nodeOptions) { configureFailPoint(primary, "returnResponseOkForRecipientForgetMigrationCmd"); // Ensure the feature flag is enabled and FCV is latest - assert(TenantMigrationUtil.isShardMergeEnabled(adminDB)); + assert(isShardMergeEnabled(adminDB)); assert.eq(getFCVConstants().latest, adminDB.system.version.findOne({_id: 'featureCompatibilityVersion'}).version); @@ -165,4 +165,3 @@ runTest({directoryperdb: ""}); // Shard merge is not allowed when directoryForIndexes is enabled runTest({"wiredTigerDirectoryForIndexes": ""}); -})(); diff --git a/jstests/replsets/tenant_migration_abort_forget_retry.js b/jstests/replsets/tenant_migration_abort_forget_retry.js index 4990b014730..53f8d16d097 100644 --- a/jstests/replsets/tenant_migration_abort_forget_retry.js +++ b/jstests/replsets/tenant_migration_abort_forget_retry.js @@ -13,14 +13,16 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + runTenantMigrationCommand, + tryAbortMigrationAsync +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load("jstests/replsets/rslib.js"); // 'createRstArgs' function makeTenantId() { return ObjectId().str; @@ -75,11 +77,11 @@ const tenantMigrationTest = fp.wait(); - const donorRstArgs = TenantMigrationUtil.createRstArgs(tenantMigrationTest.getDonorRst()); - const tryAbortThread = new Thread(TenantMigrationUtil.tryAbortMigrationAsync, + const donorRstArgs = createRstArgs(tenantMigrationTest.getDonorRst()); + const tryAbortThread = new Thread(tryAbortMigrationAsync, {migrationIdString: migrationId1, tenantId: tenantId}, donorRstArgs, - TenantMigrationUtil.runTenantMigrationCommand); + runTenantMigrationCommand); tryAbortThread.start(); // Wait for donorAbortMigration command to start. @@ -112,4 +114,3 @@ const tenantMigrationTest = })(); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_aborted_buildindex.js b/jstests/replsets/tenant_migration_aborted_buildindex.js index 1b63967536b..fd6c9baf57c 100644 --- a/jstests/replsets/tenant_migration_aborted_buildindex.js +++ b/jstests/replsets/tenant_migration_aborted_buildindex.js @@ -10,14 +10,15 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + runMigrationAsync, +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load("jstests/replsets/rslib.js"); // 'createRstArgs' const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()}); @@ -44,7 +45,7 @@ const migrationOpts = { recipientConnString: tenantMigrationTest.getRecipientConnString(), tenantId: kTenantId, }; -const donorRstArgs = TenantMigrationUtil.createRstArgs(tenantMigrationTest.getDonorRst()); +const donorRstArgs = createRstArgs(tenantMigrationTest.getDonorRst()); // Put some data in the non-empty collection, and create the empty one. const db = donorPrimary.getDB(kDbName); @@ -68,8 +69,7 @@ indexBuildFp.wait(); jsTestLog("Starting a migration and pausing after majority-committing the initial state doc."); const dataSyncFp = configureFailPoint(donorPrimary, "pauseTenantMigrationBeforeLeavingDataSyncState"); -const migrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); +const migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); migrationThread.start(); dataSyncFp.wait(); @@ -154,4 +154,3 @@ assert.commandWorked(db[kNonEmptyCollName].createIndex({a: 1, b: 1})); assert.commandWorked(tenantMigrationTest.forgetMigration(migrationOpts.migrationIdString)); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_advance_stable_ts_after_clone.js b/jstests/replsets/tenant_migration_advance_stable_ts_after_clone.js index 4959af76798..af4a9897c19 100644 --- a/jstests/replsets/tenant_migration_advance_stable_ts_after_clone.js +++ b/jstests/replsets/tenant_migration_advance_stable_ts_after_clone.js @@ -12,11 +12,10 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {isShardMergeEnabled} from "jstests/replsets/libs/tenant_migration_util.js"; 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"); @@ -40,10 +39,10 @@ const recipientPrimary = tmt.getRecipientPrimary(); // suites will execute this test without featureFlagShardMerge enabled (despite the // presence of the featureFlagShardMerge tag above), which means the test will attempt // to run a multi-tenant migration and fail. -if (!TenantMigrationUtil.isShardMergeEnabled(recipientPrimary.getDB("admin"))) { +if (!isShardMergeEnabled(recipientPrimary.getDB("admin"))) { tmt.stop(); jsTestLog("Skipping Shard Merge-specific test"); - return; + quit(); } // Insert a doc on the recipient with {writeConcern: majority} to advance the stable timestamp. We @@ -121,4 +120,3 @@ assert(bsonWoCompare(majorityWriteTs, donorAdvancedStableTs) >= 0); TenantMigrationTest.assertCommitted(tmt.waitForMigrationToComplete(migrationOpts)); tmt.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_blocking_state_timeout.js b/jstests/replsets/tenant_migration_blocking_state_timeout.js index 5129d38944f..57d9790e508 100644 --- a/jstests/replsets/tenant_migration_blocking_state_timeout.js +++ b/jstests/replsets/tenant_migration_blocking_state_timeout.js @@ -10,14 +10,15 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + runMigrationAsync, +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); load("jstests/libs/parallelTester.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load("jstests/replsets/rslib.js"); // 'createRstArgs' const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()}); @@ -40,7 +41,7 @@ function testTimeoutBlockingState() { recipientConnString: tenantMigrationTest.getRecipientConnString(), }; - const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst); + const donorRstArgs = createRstArgs(donorRst); // Fail point to pause right before entering the blocking mode. let afterDataSyncFp = @@ -48,8 +49,7 @@ function testTimeoutBlockingState() { // Run the migration in its own thread, since the initial 'donorStartMigration' command will // hang due to the fail point. - let migrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); + let migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); migrationThread.start(); afterDataSyncFp.wait(); @@ -76,4 +76,3 @@ jsTest.log("Test timeout of the blocking state"); testTimeoutBlockingState(); tenantMigrationTest.stop(); -}()); diff --git a/jstests/replsets/tenant_migration_buildindex.js b/jstests/replsets/tenant_migration_buildindex.js index b0efd5df416..9745ddfd049 100644 --- a/jstests/replsets/tenant_migration_buildindex.js +++ b/jstests/replsets/tenant_migration_buildindex.js @@ -10,23 +10,24 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + isShardMergeEnabled, + runMigrationAsync +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load("jstests/replsets/rslib.js"); // 'createRstArgs' const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()}); // TODO (SERVER-63517): This test assumes the donor blocks only some tenants. Replace this test with // tenant_migration_buildindex_shard_merge.js. -if (TenantMigrationUtil.isShardMergeEnabled( - tenantMigrationTest.getDonorPrimary().getDB("adminDB"))) { +if (isShardMergeEnabled(tenantMigrationTest.getDonorPrimary().getDB("adminDB"))) { jsTestLog("Skip: incompatible with featureFlagShardMerge"); tenantMigrationTest.stop(); - return; + quit(); } const kTenantId = ObjectId().str; @@ -62,7 +63,7 @@ const migrationOpts = { recipientConnString: tenantMigrationTest.getRecipientConnString(), tenantId: kTenantId, }; -const donorRstArgs = TenantMigrationUtil.createRstArgs(tenantMigrationTest.getDonorRst()); +const donorRstArgs = createRstArgs(tenantMigrationTest.getDonorRst()); // Put some data in the non-empty collections, and create the empty one. const db = donorPrimary.getDB(kDbName); @@ -105,8 +106,7 @@ jsTestLog("Starting a migration and pausing after majority-committing the initia // Start a migration, and pause it after the donor has majority-committed the initial state doc. const dataSyncFp = configureFailPoint(donorPrimary, "pauseTenantMigrationBeforeLeavingDataSyncState"); -const migrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); +const migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); migrationThread.start(); dataSyncFp.wait(); @@ -163,4 +163,3 @@ assert.commandFailedWithCode(db[kNewCollName2].createIndex({b: 1}), assert.commandWorked(tenantMigrationTest.forgetMigration(migrationOpts.migrationIdString)); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_buildindex_shard_merge.js b/jstests/replsets/tenant_migration_buildindex_shard_merge.js index 1a1a2655e5c..b7ec757f8b3 100644 --- a/jstests/replsets/tenant_migration_buildindex_shard_merge.js +++ b/jstests/replsets/tenant_migration_buildindex_shard_merge.js @@ -13,14 +13,16 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + isShardMergeEnabled, + runMigrationAsync +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load("jstests/replsets/rslib.js"); // 'createRstArgs' // Index builds should be blocked by the tenant access blocker, not maxNumActiveUserIndexBuilds. const tenantMigrationTest = new TenantMigrationTest( @@ -32,10 +34,10 @@ const donorPrimary = tenantMigrationTest.getDonorPrimary(); // suites will execute this test without featureFlagShardMerge enabled (despite the // presence of the featureFlagShardMerge tag above), which means the test will attempt // to run a multi-tenant migration and fail. -if (!TenantMigrationUtil.isShardMergeEnabled(donorPrimary.getDB("admin"))) { +if (!isShardMergeEnabled(donorPrimary.getDB("admin"))) { tenantMigrationTest.stop(); jsTestLog("Skipping Shard Merge-specific test"); - return; + quit(); } const kTenant1Id = ObjectId().str; @@ -64,7 +66,7 @@ const migrationOpts = { recipientConnString: tenantMigrationTest.getRecipientConnString(), tenantIds: tojson([ObjectId(kTenant1Id), ObjectId(kTenant2Id)]) }; -const donorRstArgs = TenantMigrationUtil.createRstArgs(tenantMigrationTest.getDonorRst()); +const donorRstArgs = createRstArgs(tenantMigrationTest.getDonorRst()); // Put some data in the non-empty collections, and create the empty one. const db1 = donorPrimary.getDB(kTenant1DbName); @@ -107,8 +109,7 @@ jsTestLog("Starting a migration and pausing after majority-committing the initia // Start a migration, and pause it after the donor has majority-committed the initial state doc. const dataSyncFp = configureFailPoint(donorPrimary, "pauseTenantMigrationBeforeLeavingDataSyncState"); -const migrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); +const migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); migrationThread.start(); dataSyncFp.wait(); @@ -179,4 +180,3 @@ assert.commandFailedWithCode(db2[kNewCollName2].createIndex({d: 1}), assert.commandWorked(tenantMigrationTest.forgetMigration(migrationOpts.migrationIdString)); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_causal_consistency_commit_optime_before_last_cloning_optime.js b/jstests/replsets/tenant_migration_causal_consistency_commit_optime_before_last_cloning_optime.js index e7da3a678d3..2e4200c3829 100644 --- a/jstests/replsets/tenant_migration_causal_consistency_commit_optime_before_last_cloning_optime.js +++ b/jstests/replsets/tenant_migration_causal_consistency_commit_optime_before_last_cloning_optime.js @@ -16,12 +16,11 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {makeX509OptionsForTest} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); load("jstests/replsets/rslib.js"); function assertCanFindWithReadConcern(conn, dbName, collName, expectedDoc, readConcern) { @@ -38,7 +37,7 @@ let makeTenantId = function() { // Local read concern case. (() => { - const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); + const migrationX509Options = makeX509OptionsForTest(); // Simulate a lagged node by setting secondaryDelaySecs on one recipient secondary. Verify this // does not prevent reading all the tenant's data after the migration commits. @@ -204,4 +203,3 @@ let makeTenantId = function() { })(); // Snapshot read concern is tested in replsets/tenant_migration_concurrent_reads_on_recipient.js -})(); diff --git a/jstests/replsets/tenant_migration_cloner_stats.js b/jstests/replsets/tenant_migration_cloner_stats.js index 6b2a2f6e8a3..ae793bcc00c 100644 --- a/jstests/replsets/tenant_migration_cloner_stats.js +++ b/jstests/replsets/tenant_migration_cloner_stats.js @@ -15,12 +15,9 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/libs/uuid_util.js"); // For extractUUIDFromObject(). load("jstests/libs/fail_point_util.js"); // For configureFailPoint(). -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); // Limit the batch size to test the stat in between batches. const tenantMigrationTest = new TenantMigrationTest( @@ -195,4 +192,3 @@ assertNothingClonedBeforeFailover(res); assert.eq(currOp.remainingReceiveEstimatedMillis, 0, res); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_cloner_stats_with_failover.js b/jstests/replsets/tenant_migration_cloner_stats_with_failover.js index 6f963c4aa5c..5dca785ee39 100644 --- a/jstests/replsets/tenant_migration_cloner_stats_with_failover.js +++ b/jstests/replsets/tenant_migration_cloner_stats_with_failover.js @@ -21,12 +21,9 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/libs/uuid_util.js"); // For extractUUIDFromObject(). load("jstests/libs/fail_point_util.js"); // For configureFailPoint(). -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); // Limit the batch size to test the stat in between batches. const tenantMigrationTest = new TenantMigrationTest( @@ -147,4 +144,3 @@ assert.eq(currOp.databases.databasesClonedBeforeFailover, 1, res); assert.eq(currOp.databases[dbName2].clonedCollectionsBeforeFailover, 1, res); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_clones_system_views.js b/jstests/replsets/tenant_migration_clones_system_views.js index 27721e53389..b1a93f254f3 100644 --- a/jstests/replsets/tenant_migration_clones_system_views.js +++ b/jstests/replsets/tenant_migration_clones_system_views.js @@ -11,11 +11,8 @@ * ] */ -(function() { -"use strict"; - +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()}); @@ -59,4 +56,3 @@ assert.eq(1, findRes.length, `find result: ${tojson(findRes)}`); assert.eq([doc1], findRes); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_cloning_uses_read_concern_majority.js b/jstests/replsets/tenant_migration_cloning_uses_read_concern_majority.js index 0fe36350ede..4c0713019c5 100644 --- a/jstests/replsets/tenant_migration_cloning_uses_read_concern_majority.js +++ b/jstests/replsets/tenant_migration_cloning_uses_read_concern_majority.js @@ -15,15 +15,14 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {runMigrationAsync} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); // for 'extractUUIDFromObject' load("jstests/libs/parallelTester.js"); // for 'Thread' load("jstests/libs/write_concern_util.js"); // for 'stopReplicationOnSecondaries' -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load("jstests/replsets/rslib.js"); // 'createRstArgs' const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()}); @@ -65,9 +64,8 @@ const waitBeforeCloning = configureFailPoint(recipientDb, "hangBeforeClonerStage // Start a migration and wait for recipient to hang before querying the donor in the cloning phase. // At this point, we have waited for the listIndex results to be majority committed on the donor, // so we can stop server replication. -const donorRstArgs = TenantMigrationUtil.createRstArgs(tenantMigrationTest.getDonorRst()); -const migrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); +const donorRstArgs = createRstArgs(tenantMigrationTest.getDonorRst()); +const migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); migrationThread.start(); waitBeforeCloning.wait(); stopReplicationOnSecondaries(donorRst); @@ -100,4 +98,3 @@ restartReplicationOnSecondaries(donorRst); waitBeforeFetchingTransactions.off(); TenantMigrationTest.assertCommitted(migrationThread.returnData()); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_cluster_time_keys_cloning.js b/jstests/replsets/tenant_migration_cluster_time_keys_cloning.js index a165db82781..5d80e412f9f 100644 --- a/jstests/replsets/tenant_migration_cluster_time_keys_cloning.js +++ b/jstests/replsets/tenant_migration_cluster_time_keys_cloning.js @@ -14,13 +14,15 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + isShardMergeEnabled, + makeX509OptionsForTest +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); load("jstests/libs/write_concern_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); const kInternalKeysNs = "admin.system.keys"; const kExternalKeysNs = "config.external_validation_keys"; @@ -70,7 +72,7 @@ function assertHasExternalKeys(conn, migrationId) { const kTenantId1 = "testTenantId1"; const kTenantId2 = "testTenantId2"; -const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); +const migrationX509Options = makeX509OptionsForTest(); (() => { jsTest.log("Test that the donor and recipient correctly copy each other's cluster time keys " + @@ -133,7 +135,7 @@ const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); new ReplSetTest({nodes: 3, name: "donorRst", nodeOptions: migrationX509Options.donor}); donorRst.startSet(); donorRst.initiate(); - if (TenantMigrationUtil.isShardMergeEnabled(donorRst.getPrimary().getDB("adminDB"))) { + if (isShardMergeEnabled(donorRst.getPrimary().getDB("adminDB"))) { jsTestLog("Skip: featureFlagShardMerge enabled, but shard merge does not survive failover"); donorRst.stopSet(); return; @@ -178,7 +180,7 @@ const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); {nodes: 3, name: "recipientRst", nodeOptions: migrationX509Options.recipient}); recipientRst.startSet(); recipientRst.initiate(); - if (TenantMigrationUtil.isShardMergeEnabled(recipientRst.getPrimary().getDB("adminDB"))) { + if (isShardMergeEnabled(recipientRst.getPrimary().getDB("adminDB"))) { jsTestLog("Skip: featureFlagShardMerge enabled, but shard merge does not survive failover"); recipientRst.stopSet(); return; @@ -231,8 +233,7 @@ const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); const tenantMigrationTest = new TenantMigrationTest({name: jsTestName(), donorRst}); function runTest(tenantId, withFailover) { - if (withFailover && - TenantMigrationUtil.isShardMergeEnabled(donorRst.getPrimary().getDB("adminDB"))) { + if (withFailover && isShardMergeEnabled(donorRst.getPrimary().getDB("adminDB"))) { jsTestLog( "Skip: featureFlagShardMerge enabled, but shard merge does not survive failover"); tenantMigrationTest.stop(); @@ -306,4 +307,3 @@ const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); donorRst.stopSet(); tenantMigrationTest.stop(); })(); -})(); diff --git a/jstests/replsets/tenant_migration_collection_rename.js b/jstests/replsets/tenant_migration_collection_rename.js index 1564a0c2de1..b7cd2d0d2fb 100644 --- a/jstests/replsets/tenant_migration_collection_rename.js +++ b/jstests/replsets/tenant_migration_collection_rename.js @@ -16,14 +16,13 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {runMigrationAsync} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load("jstests/replsets/rslib.js"); // 'createRstArgs' function insertData(collection) { // Enough for several batches. @@ -39,7 +38,7 @@ const kDbName = tenantMigrationTest.tenantDB(kTenantId, "testDB"); const kCollectionName = "toBeRenamed"; const donorPrimary = tenantMigrationTest.getDonorPrimary(); const recipientPrimary = tenantMigrationTest.getRecipientPrimary(); -const donorRstArgs = TenantMigrationUtil.createRstArgs(tenantMigrationTest.getDonorRst()); +const donorRstArgs = createRstArgs(tenantMigrationTest.getDonorRst()); const db = donorPrimary.getDB(kDbName); jsTestLog("Populate collection"); @@ -57,8 +56,7 @@ const fpAfterBatch = configureFailPoint( recipientPrimary, "tenantMigrationHangCollectionClonerAfterHandlingBatchResponse"); jsTestLog("Start a migration and pause after first batch"); -const migrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); +const migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); migrationThread.start(); jsTestLog("Wait to reach failpoint"); @@ -75,4 +73,3 @@ fpAfterBatch.off(); TenantMigrationTest.assertAborted(migrationThread.returnData(), ErrorCodes.DuplicateKey); assert.commandWorked(tenantMigrationTest.forgetMigration(migrationOpts.migrationIdString)); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_collection_ttl.js b/jstests/replsets/tenant_migration_collection_ttl.js index 77277579fc4..105fa1d3108 100644 --- a/jstests/replsets/tenant_migration_collection_ttl.js +++ b/jstests/replsets/tenant_migration_collection_ttl.js @@ -12,13 +12,11 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {isShardMergeEnabled} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); const garbageCollectionOpts = { // Set the delay before a donor state doc is garbage collected to be short to speed @@ -108,7 +106,7 @@ function assertTTLDeleteExpiredDocs(dbName, node) { // 1. At the recipient, the TTL deletions are suspended during the cloning phase. // 2. At the donor, TTL deletions are not suspended before blocking state. (() => { - if (TenantMigrationUtil.isShardMergeEnabled(donorPrimary.getDB("admin"))) { + if (isShardMergeEnabled(donorPrimary.getDB("admin"))) { jsTestLog( "Skip: featureFlagShardMerge enabled, but shard merge does not use logical cloning"); return; @@ -234,4 +232,3 @@ function assertTTLDeleteExpiredDocs(dbName, node) { })(); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_commit_transaction_retry.js b/jstests/replsets/tenant_migration_commit_transaction_retry.js index c0b55b799b3..f2f0d946584 100644 --- a/jstests/replsets/tenant_migration_commit_transaction_retry.js +++ b/jstests/replsets/tenant_migration_commit_transaction_retry.js @@ -10,11 +10,7 @@ * ] */ -(function() { -"use strict"; - -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/replsets/rslib.js"); load("jstests/libs/uuid_util.js"); @@ -136,4 +132,3 @@ tenantMigrationTest2.waitForMigrationGarbageCollection(migrationId2, kTenantId); tenantMigrationTest2.stop(); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_concurrent_bulk_writes.js b/jstests/replsets/tenant_migration_concurrent_bulk_writes.js index 8b87bbdbfe4..d630988fea9 100644 --- a/jstests/replsets/tenant_migration_concurrent_bulk_writes.js +++ b/jstests/replsets/tenant_migration_concurrent_bulk_writes.js @@ -10,14 +10,17 @@ * serverless, * ] */ -(function() { -'use strict'; + +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + makeX509OptionsForTest, + runMigrationAsync +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load("jstests/replsets/rslib.js"); // 'createRstArgs' const kMaxBatchSize = 2; const kCollName = "testColl"; @@ -27,14 +30,9 @@ const kNumWriteBatchesWithoutMigrationConflict = 2; // num of write batches we allow to complete before migration blocks writes. const kNumUpdatesWithoutMigrationConflict = 2; const kMaxSleepTimeMS = 1000; -const kBatchTypes = { - insert: 1, - update: 2, - remove: 3 -}; function setup() { - const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); + const migrationX509Options = makeX509OptionsForTest(); const donorRst = new ReplSetTest({ nodes: 1, name: 'donor', @@ -228,7 +226,7 @@ function bulkMultiUpdateDocsUnordered(primaryHost, dbName, collName, numDocs) { recipientConnString: recipientRst.getURL(), tenantId, }; - const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst); + const donorRstArgs = createRstArgs(donorRst); const dbName = tenantMigrationTest.tenantDB(tenantId, kTenantDefinedDbName); const primary = donorRst.getPrimary(); @@ -242,8 +240,7 @@ function bulkMultiUpdateDocsUnordered(primaryHost, dbName, collName, numDocs) { new Thread(bulkInsertDocsUnordered, primary.host, dbName, kCollName, kNumWriteOps); const blockFp = configureFailPoint(primaryDB, "pauseTenantMigrationBeforeLeavingBlockingState"); - const migrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); + const migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); bulkWriteThread.start(); writeFp.wait(); @@ -293,7 +290,7 @@ function bulkMultiUpdateDocsUnordered(primaryHost, dbName, collName, numDocs) { recipientConnString: tenantMigrationTest.getRecipientConnString(), tenantId, }; - const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst); + const donorRstArgs = createRstArgs(donorRst); const dbName = tenantMigrationTest.tenantDB(tenantId, kTenantDefinedDbName); const primary = donorRst.getPrimary(); @@ -312,8 +309,7 @@ function bulkMultiUpdateDocsUnordered(primaryHost, dbName, collName, numDocs) { // TenantMigrationConflict in the op observer. Without this failpoint, the migration // could have already aborted by the time the write gets to the op observer. const blockFp = configureFailPoint(primaryDB, "pauseTenantMigrationBeforeLeavingBlockingState"); - const migrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); + const migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); bulkWriteThread.start(); writeFp.wait(); @@ -409,7 +405,7 @@ function bulkMultiUpdateDocsUnordered(primaryHost, dbName, collName, numDocs) { recipientConnString: tenantMigrationTest.getRecipientConnString(), tenantId, }; - const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst); + const donorRstArgs = createRstArgs(donorRst); const dbName = tenantMigrationTest.tenantDB(tenantId, kTenantDefinedDbName); const primary = donorRst.getPrimary(); @@ -423,8 +419,7 @@ function bulkMultiUpdateDocsUnordered(primaryHost, dbName, collName, numDocs) { new Thread(bulkInsertDocsOrdered, primary.host, dbName, kCollName, kNumWriteOps); const blockFp = configureFailPoint(primaryDB, "pauseTenantMigrationBeforeLeavingBlockingState"); - const migrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); + const migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); bulkWriteThread.start(); writeFp.wait(); @@ -466,7 +461,7 @@ function bulkMultiUpdateDocsUnordered(primaryHost, dbName, collName, numDocs) { recipientConnString: tenantMigrationTest.getRecipientConnString(), tenantId, }; - const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst); + const donorRstArgs = createRstArgs(donorRst); const dbName = tenantMigrationTest.tenantDB(tenantId, kTenantDefinedDbName); const primary = donorRst.getPrimary(); @@ -485,8 +480,7 @@ function bulkMultiUpdateDocsUnordered(primaryHost, dbName, collName, numDocs) { // TenantMigrationConflict in the op observer. Without this failpoint, the migration // could have already aborted by the time the write gets to the op observer. const blockFp = configureFailPoint(primaryDB, "pauseTenantMigrationBeforeLeavingBlockingState"); - const migrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); + const migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); bulkWriteThread.start(); writeFp.wait(); @@ -531,7 +525,7 @@ function bulkMultiUpdateDocsUnordered(primaryHost, dbName, collName, numDocs) { recipientConnString: recipientRst.getURL(), tenantId, }; - const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst); + const donorRstArgs = createRstArgs(donorRst); const dbName = tenantMigrationTest.tenantDB(tenantId, kTenantDefinedDbName); const primary = donorRst.getPrimary(); @@ -545,8 +539,7 @@ function bulkMultiUpdateDocsUnordered(primaryHost, dbName, collName, numDocs) { new Thread(bulkMultiUpdateDocsUnordered, primary.host, dbName, kCollName, kNumWriteOps); const blockFp = configureFailPoint(primaryDB, "pauseTenantMigrationBeforeLeavingBlockingState"); - const migrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); + const migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); bulkWriteThread.start(); writeFp.wait(); @@ -584,7 +577,7 @@ function bulkMultiUpdateDocsUnordered(primaryHost, dbName, collName, numDocs) { recipientConnString: recipientRst.getURL(), tenantId, }; - const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst); + const donorRstArgs = createRstArgs(donorRst); const dbName = tenantMigrationTest.tenantDB(tenantId, kTenantDefinedDbName); const primary = donorRst.getPrimary(); @@ -598,8 +591,7 @@ function bulkMultiUpdateDocsUnordered(primaryHost, dbName, collName, numDocs) { new Thread(bulkMultiUpdateDocsOrdered, primary.host, dbName, kCollName, kNumWriteOps); const blockFp = configureFailPoint(primaryDB, "pauseTenantMigrationBeforeLeavingBlockingState"); - const migrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); + const migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); bulkWriteThread.start(); writeFp.wait(); @@ -703,4 +695,3 @@ function bulkMultiUpdateDocsUnordered(primaryHost, dbName, collName, numDocs) { tojson(bulkWriteRes)); teardown(); })(); -})(); diff --git a/jstests/replsets/tenant_migration_concurrent_migrations.js b/jstests/replsets/tenant_migration_concurrent_migrations.js index ef8d7638f68..efba49f9d16 100644 --- a/jstests/replsets/tenant_migration_concurrent_migrations.js +++ b/jstests/replsets/tenant_migration_concurrent_migrations.js @@ -13,18 +13,16 @@ * ] */ -(function() { -'use strict'; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {makeX509Options} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); -const x509Options0 = TenantMigrationUtil.makeX509Options("jstests/libs/rs0.pem"); -const x509Options1 = TenantMigrationUtil.makeX509Options("jstests/libs/rs1.pem"); -const x509Options2 = TenantMigrationUtil.makeX509Options("jstests/libs/rs2.pem"); +const x509Options0 = makeX509Options("jstests/libs/rs0.pem"); +const x509Options1 = makeX509Options("jstests/libs/rs1.pem"); +const x509Options2 = makeX509Options("jstests/libs/rs2.pem"); const rst0 = new ReplSetTest({nodes: 1, name: 'rst0', nodeOptions: x509Options0}); const rst1 = new ReplSetTest({nodes: 1, name: 'rst1', nodeOptions: x509Options1}); @@ -193,4 +191,3 @@ const kTenantIdPrefix = "testTenantId"; rst0.stopSet(); rst1.stopSet(); rst2.stopSet(); -})(); diff --git a/jstests/replsets/tenant_migration_concurrent_migrations_recipient.js b/jstests/replsets/tenant_migration_concurrent_migrations_recipient.js index 47642073e9e..d76e100cf3c 100644 --- a/jstests/replsets/tenant_migration_concurrent_migrations_recipient.js +++ b/jstests/replsets/tenant_migration_concurrent_migrations_recipient.js @@ -14,13 +14,9 @@ * ] */ -(function() { -"use strict"; - +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); // for 'extractUUIDFromObject' -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); TestData.logComponentVerbosity = { accessControl: {verbosity: 3} @@ -78,4 +74,3 @@ migrationOptsArray.forEach((migrationOpts) => { }); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_concurrent_migrations_stress_test.js b/jstests/replsets/tenant_migration_concurrent_migrations_stress_test.js index 3f95d39fe99..7dbfaec2884 100644 --- a/jstests/replsets/tenant_migration_concurrent_migrations_stress_test.js +++ b/jstests/replsets/tenant_migration_concurrent_migrations_stress_test.js @@ -14,13 +14,9 @@ * ] */ -(function() { -"use strict"; - +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); // for 'extractUUIDFromObject' -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); load("jstests/replsets/rslib.js"); // for 'setLogVerbosity' const kMigrationsCount = 300; @@ -221,4 +217,3 @@ for (let i = 0; i < kMigrationsCount; ++i) { } tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_concurrent_reads_on_donor.js b/jstests/replsets/tenant_migration_concurrent_reads_on_donor.js index 086cb67e1a3..7a346f2ec09 100644 --- a/jstests/replsets/tenant_migration_concurrent_reads_on_donor.js +++ b/jstests/replsets/tenant_migration_concurrent_reads_on_donor.js @@ -16,14 +16,12 @@ * ] */ -(function() { -'use strict'; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {getTenantMigrationAccessBlocker} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); const tenantMigrationTest = new TenantMigrationTest({ name: jsTestName(), @@ -44,8 +42,7 @@ function checkTenantMigrationAccessBlocker(node, tenantId, { numTenantMigrationCommittedErrors = 0, numTenantMigrationAbortedErrors = 0 }) { - const mtab = - TenantMigrationUtil.getTenantMigrationAccessBlocker({donorNode: node, tenantId}).donor; + const mtab = getTenantMigrationAccessBlocker({donorNode: node, tenantId}).donor; if (!mtab) { assert.eq(0, numBlockedReads); assert.eq(0, numTenantMigrationCommittedErrors); @@ -64,14 +61,10 @@ function checkTenantMigrationAccessBlocker(node, tenantId, { * To be used to resume a migration that is paused after entering the blocking state. Waits for the * number of blocked reads to reach 'targetNumBlockedReads' and unpauses the migration. */ -function resumeMigrationAfterBlockingRead(host, tenantId, targetNumBlockedReads) { - load("jstests/libs/fail_point_util.js"); - load("jstests/replsets/libs/tenant_migration_util.js"); +async function resumeMigrationAfterBlockingRead(host, tenantId, targetNumBlockedReads) { + const {getNumBlockedReads} = await import("jstests/replsets/libs/tenant_migration_util.js"); const primary = new Mongo(host); - - assert.soon(() => TenantMigrationUtil.getNumBlockedReads(primary, tenantId) == - targetNumBlockedReads); - + assert.soon(() => getNumBlockedReads(primary, tenantId) == targetNumBlockedReads); assert.commandWorked(primary.adminCommand( {configureFailPoint: "pauseTenantMigrationBeforeLeavingBlockingState", mode: "off"})); } @@ -516,4 +509,3 @@ for (const [testName, testFunc] of Object.entries(testFuncs)) { } tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_concurrent_reads_on_recipient.js b/jstests/replsets/tenant_migration_concurrent_reads_on_recipient.js index a15299b6171..21bcb2c55f9 100644 --- a/jstests/replsets/tenant_migration_concurrent_reads_on_recipient.js +++ b/jstests/replsets/tenant_migration_concurrent_reads_on_recipient.js @@ -17,15 +17,13 @@ * ] */ -(function() { -'use strict'; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {runMigrationAsync} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); -load("jstests/replsets/rslib.js"); +load("jstests/replsets/rslib.js"); // 'createRstArgs' const kCollName = "testColl"; const kTenantDefinedDbName = "0"; @@ -69,9 +67,8 @@ function testRejectAllReadsAfterCloningDone({testCase, dbName, collName, tenantM let beforeFetchingTransactionsFp = configureFailPoint( recipientPrimary, "fpBeforeFetchingCommittedTransactions", {action: "hang"}); - const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst); - const runMigrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); + const donorRstArgs = createRstArgs(donorRst); + const runMigrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); runMigrationThread.start(); beforeFetchingTransactionsFp.wait(); @@ -118,9 +115,8 @@ function testRejectOnlyReadsWithAtClusterTimeLessThanRejectReadsBeforeTimestamp( let waitForRejectReadsBeforeTsFp = configureFailPoint( recipientPrimary, "fpAfterWaitForRejectReadsBeforeTimestamp", {action: "hang"}); - const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst); - const runMigrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); + const donorRstArgs = createRstArgs(donorRst); + const runMigrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); runMigrationThread.start(); waitForRejectReadsBeforeTsFp.wait(); @@ -446,4 +442,3 @@ for (const [testName, testFunc] of Object.entries(testFuncs)) { } } tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_concurrent_reconfig.js b/jstests/replsets/tenant_migration_concurrent_reconfig.js index a33f2456675..e766b7c5342 100644 --- a/jstests/replsets/tenant_migration_concurrent_reconfig.js +++ b/jstests/replsets/tenant_migration_concurrent_reconfig.js @@ -10,13 +10,9 @@ * ] */ -(function() { -"use strict"; - +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); // for 'extractUUIDFromObject' -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); function runTest({failPoint, shouldFail = false}) { const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()}); @@ -83,4 +79,3 @@ runTest({failPoint: "pauseTenantMigrationAfterPersistingInitialDonorStateDoc", s jsTestLog("[4] Testing reconfig before fetching keys."); runTest({failPoint: "pauseTenantMigrationBeforeFetchingKeys", shouldFail: false}); -})(); diff --git a/jstests/replsets/tenant_migration_concurrent_state_doc_removal_and_stepdown.js b/jstests/replsets/tenant_migration_concurrent_state_doc_removal_and_stepdown.js index 05823af3d59..242ebcbf03c 100644 --- a/jstests/replsets/tenant_migration_concurrent_state_doc_removal_and_stepdown.js +++ b/jstests/replsets/tenant_migration_concurrent_state_doc_removal_and_stepdown.js @@ -11,14 +11,13 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {forgetMigrationAsync} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/parallelTester.js"); load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load("jstests/replsets/rslib.js"); // 'createRstArgs' const tenantMigrationTest = new TenantMigrationTest( {name: jsTestName(), quickGarbageCollection: true, initiateRstWithHighElectionTimeout: false}); @@ -26,7 +25,7 @@ const tenantMigrationTest = new TenantMigrationTest( const kTenantId = ObjectId().str; const donorRst = tenantMigrationTest.getDonorRst(); -const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst); +const donorRstArgs = createRstArgs(donorRst); let donorPrimary = tenantMigrationTest.getDonorPrimary(); const migrationId = UUID(); @@ -40,7 +39,7 @@ TenantMigrationTest.assertCommitted( let fp = configureFailPoint(donorPrimary, "pauseTenantMigrationDonorAfterMarkingStateGarbageCollectable"); -const forgetMigrationThread = new Thread(TenantMigrationUtil.forgetMigrationAsync, +const forgetMigrationThread = new Thread(forgetMigrationAsync, migrationOpts.migrationIdString, donorRstArgs, false /* retryOnRetryableErrors */); @@ -59,4 +58,3 @@ assert.commandFailedWithCode(forgetMigrationThread.returnData(), donorRst.stopSet(); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_concurrent_writes_on_donor.js b/jstests/replsets/tenant_migration_concurrent_writes_on_donor.js index c1d5b02f969..78bf93d2c92 100644 --- a/jstests/replsets/tenant_migration_concurrent_writes_on_donor.js +++ b/jstests/replsets/tenant_migration_concurrent_writes_on_donor.js @@ -9,15 +9,17 @@ * serverless, * ] */ -(function() { -'use strict'; + +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + runCommandForConcurrentWritesTest, + runTestForConcurrentWritesTest, + TenantMigrationConcurrentWriteUtil +} from "jstests/replsets/tenant_migration_concurrent_writes_on_donor_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); -load("jstests/replsets/tenant_migration_concurrent_writes_on_donor_util.js"); const tenantMigrationTest = new TenantMigrationTest({ name: jsTestName(), @@ -74,4 +76,3 @@ for (const [commandName, testCase] of Object.entries(testCases)) { } tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_concurrent_writes_on_donor_aborted.js b/jstests/replsets/tenant_migration_concurrent_writes_on_donor_aborted.js index cbe12347a3c..7cbe5af8db9 100644 --- a/jstests/replsets/tenant_migration_concurrent_writes_on_donor_aborted.js +++ b/jstests/replsets/tenant_migration_concurrent_writes_on_donor_aborted.js @@ -9,15 +9,20 @@ * serverless, * ] */ -(function() { -'use strict'; + +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {getTenantMigrationAccessBlocker} from "jstests/replsets/libs/tenant_migration_util.js"; +import { + checkTenantMigrationAccessBlockerForConcurrentWritesTest, + makeTestOptionsForConcurrentWritesTest, + runCommandForConcurrentWritesTest, + setupTestForConcurrentWritesTest, + TenantMigrationConcurrentWriteUtil +} from "jstests/replsets/tenant_migration_concurrent_writes_on_donor_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); -load("jstests/replsets/tenant_migration_concurrent_writes_on_donor_util.js"); const tenantMigrationTest = new TenantMigrationTest({ name: jsTestName(), @@ -47,8 +52,7 @@ function testDoNotRejectWritesAfterMigrationAborted(testCase, testOpts) { // committed the abort decision. Otherwise, the command below is expected to block and then get // rejected. assert.soon(() => { - const mtab = TenantMigrationUtil.getTenantMigrationAccessBlocker( - {donorNode: testOpts.primaryDB, tenantId}); + const mtab = getTenantMigrationAccessBlocker({donorNode: testOpts.primaryDB, tenantId}); return mtab.donor.state === TenantMigrationTest.DonorAccessState.kAborted; }); @@ -143,4 +147,3 @@ assert.commandWorked(tenantMigrationTest.forgetMigration(migrationOpts.migration tenantMigrationTest.waitForMigrationGarbageCollection(migrationOpts.migrationIdString); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_concurrent_writes_on_donor_blocking.js b/jstests/replsets/tenant_migration_concurrent_writes_on_donor_blocking.js index 6dd6f1846bd..dd2b09321bc 100644 --- a/jstests/replsets/tenant_migration_concurrent_writes_on_donor_blocking.js +++ b/jstests/replsets/tenant_migration_concurrent_writes_on_donor_blocking.js @@ -10,15 +10,19 @@ * serverless, * ] */ -(function() { -'use strict'; + +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + checkTenantMigrationAccessBlockerForConcurrentWritesTest, + makeTestOptionsForConcurrentWritesTest, + runCommandForConcurrentWritesTest, + setupTestForConcurrentWritesTest, + TenantMigrationConcurrentWriteUtil +} from "jstests/replsets/tenant_migration_concurrent_writes_on_donor_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); -load("jstests/replsets/tenant_migration_concurrent_writes_on_donor_util.js"); const tenantMigrationTest = new TenantMigrationTest({ name: jsTestName(), @@ -175,4 +179,3 @@ assert.commandWorked(tenantMigrationTest.forgetMigration(migrationOpts.migration tenantMigrationTest.waitForMigrationGarbageCollection(migrationOpts.migrationIdString); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_concurrent_writes_on_donor_blocking_then_aborted.js b/jstests/replsets/tenant_migration_concurrent_writes_on_donor_blocking_then_aborted.js index 9d1d99bb941..2dc3e2546b9 100644 --- a/jstests/replsets/tenant_migration_concurrent_writes_on_donor_blocking_then_aborted.js +++ b/jstests/replsets/tenant_migration_concurrent_writes_on_donor_blocking_then_aborted.js @@ -10,15 +10,18 @@ * serverless, * ] */ -(function() { -'use strict'; + +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + checkTenantMigrationAccessBlockerForConcurrentWritesTest, + runCommandForConcurrentWritesTest, + runTestForConcurrentWritesTest, + TenantMigrationConcurrentWriteUtil +} from "jstests/replsets/tenant_migration_concurrent_writes_on_donor_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); -load("jstests/replsets/tenant_migration_concurrent_writes_on_donor_util.js"); const tenantMigrationTest = new TenantMigrationTest({ name: jsTestName(), @@ -36,14 +39,10 @@ const kTenantDefinedDbName = "0"; * To be used to resume a migration that is paused after entering the blocking state. Waits for the * number of blocked reads to reach 'targetNumBlockedWrites' and unpauses the migration. */ -function resumeMigrationAfterBlockingWrite(host, tenantId, targetNumBlockedWrites) { - load("jstests/libs/fail_point_util.js"); - load("jstests/replsets/libs/tenant_migration_util.js"); +async function resumeMigrationAfterBlockingWrite(host, tenantId, targetNumBlockedWrites) { + const {getNumBlockedWrites} = await import("jstests/replsets/libs/tenant_migration_util.js"); const primary = new Mongo(host); - - assert.soon(() => TenantMigrationUtil.getNumBlockedWrites(primary, tenantId) == - targetNumBlockedWrites); - + assert.soon(() => getNumBlockedWrites(primary, tenantId) == targetNumBlockedWrites); assert.commandWorked(primary.adminCommand( {configureFailPoint: "pauseTenantMigrationBeforeLeavingBlockingState", mode: "off"})); } @@ -126,4 +125,3 @@ for (const [commandName, testCase] of Object.entries(testCases)) { } tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_concurrent_writes_on_donor_blocking_then_committed.js b/jstests/replsets/tenant_migration_concurrent_writes_on_donor_blocking_then_committed.js index 8d7b5023c19..17da4d0a93e 100644 --- a/jstests/replsets/tenant_migration_concurrent_writes_on_donor_blocking_then_committed.js +++ b/jstests/replsets/tenant_migration_concurrent_writes_on_donor_blocking_then_committed.js @@ -10,15 +10,18 @@ * serverless, * ] */ -(function() { -'use strict'; + +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + checkTenantMigrationAccessBlockerForConcurrentWritesTest, + runCommandForConcurrentWritesTest, + runTestForConcurrentWritesTest, + TenantMigrationConcurrentWriteUtil +} from "jstests/replsets/tenant_migration_concurrent_writes_on_donor_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); -load("jstests/replsets/tenant_migration_concurrent_writes_on_donor_util.js"); const tenantMigrationTest = new TenantMigrationTest({ name: jsTestName(), @@ -36,14 +39,10 @@ const kTenantDefinedDbName = "0"; * To be used to resume a migration that is paused after entering the blocking state. Waits for the * number of blocked reads to reach 'targetNumBlockedWrites' and unpauses the migration. */ -function resumeMigrationAfterBlockingWrite(host, tenantId, targetNumBlockedWrites) { - load("jstests/libs/fail_point_util.js"); - load("jstests/replsets/libs/tenant_migration_util.js"); +async function resumeMigrationAfterBlockingWrite(host, tenantId, targetNumBlockedWrites) { + const {getNumBlockedWrites} = await import("jstests/replsets/libs/tenant_migration_util.js"); const primary = new Mongo(host); - - assert.soon(() => TenantMigrationUtil.getNumBlockedWrites(primary, tenantId) == - targetNumBlockedWrites); - + assert.soon(() => getNumBlockedWrites(primary, tenantId) == targetNumBlockedWrites); assert.commandWorked(primary.adminCommand( {configureFailPoint: "pauseTenantMigrationBeforeLeavingBlockingState", mode: "off"})); } @@ -125,4 +124,3 @@ for (const [commandName, testCase] of Object.entries(testCases)) { } tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_concurrent_writes_on_donor_committed.js b/jstests/replsets/tenant_migration_concurrent_writes_on_donor_committed.js index 01aff3d2aa1..f77889c42c9 100644 --- a/jstests/replsets/tenant_migration_concurrent_writes_on_donor_committed.js +++ b/jstests/replsets/tenant_migration_concurrent_writes_on_donor_committed.js @@ -9,15 +9,19 @@ * serverless, * ] */ -(function() { -'use strict'; + +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + checkTenantMigrationAccessBlockerForConcurrentWritesTest, + makeTestOptionsForConcurrentWritesTest, + runCommandForConcurrentWritesTest, + setupTestForConcurrentWritesTest, + TenantMigrationConcurrentWriteUtil +} from "jstests/replsets/tenant_migration_concurrent_writes_on_donor_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); -load("jstests/replsets/tenant_migration_concurrent_writes_on_donor_util.js"); const tenantMigrationTest = new TenantMigrationTest({ name: jsTestName(), @@ -133,4 +137,3 @@ assert.commandWorked(tenantMigrationTest.forgetMigration(migrationOpts.migration tenantMigrationTest.waitForMigrationGarbageCollection(migrationOpts.migrationIdString); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_concurrent_writes_on_donor_util.js b/jstests/replsets/tenant_migration_concurrent_writes_on_donor_util.js index 18a42e90818..19b9b3fd637 100644 --- a/jstests/replsets/tenant_migration_concurrent_writes_on_donor_util.js +++ b/jstests/replsets/tenant_migration_concurrent_writes_on_donor_util.js @@ -3,21 +3,36 @@ * tenant_migration_concurrent_writes_on_donor*tests. */ -'use strict'; +import {getTenantMigrationAccessBlocker} from "jstests/replsets/libs/tenant_migration_util.js"; -var TenantMigrationConcurrentWriteUtil = (function() {}); +const kTestDoc = { + x: -1 +}; +const kTestDoc2 = { + x: -2 +}; +const kTestIndexKey = { + x: 1 +}; +const kExpireAfterSeconds = 1000000; +const kTestIndex = { + key: kTestIndexKey, + name: "testIndex", + expireAfterSeconds: kExpireAfterSeconds +}; +const kNumInitialDocs = 2; // num initial docs to insert into test collections. +const kTxnNumber = NumberLong(0); /** * Asserts that the TenantMigrationAccessBlocker for the given tenant on the given node has the * expected statistics. */ -function checkTenantMigrationAccessBlockerForConcurrentWritesTest(node, tenantId, { +export function checkTenantMigrationAccessBlockerForConcurrentWritesTest(node, tenantId, { numBlockedWrites = 0, numTenantMigrationCommittedErrors = 0, numTenantMigrationAbortedErrors = 0 }) { - const mtab = - TenantMigrationUtil.getTenantMigrationAccessBlocker({donorNode: node, tenantId}).donor; + const mtab = getTenantMigrationAccessBlocker({donorNode: node, tenantId}).donor; if (!mtab) { assert.eq(0, numBlockedWrites); assert.eq(0, numTenantMigrationCommittedErrors); @@ -32,7 +47,7 @@ function checkTenantMigrationAccessBlockerForConcurrentWritesTest(node, tenantId assert.eq(mtab.numTenantMigrationAbortedErrors, numTenantMigrationAbortedErrors, tojson(mtab)); } -function runCommandForConcurrentWritesTest(testOpts, expectedError) { +export function runCommandForConcurrentWritesTest(testOpts, expectedError) { let res; if (testOpts.isMultiUpdate && !testOpts.testInTransaction) { // Multi writes outside a transaction cannot be automatically retried, so we return a @@ -101,8 +116,8 @@ function runCommandForConcurrentWritesTest(testOpts, expectedError) { } } -function createCollectionAndInsertDocsForConcurrentWritesTest( - primaryDB, collName, numDocs = TenantMigrationConcurrentWriteUtil.kNumInitialDocs) { +export function createCollectionAndInsertDocsForConcurrentWritesTest( + primaryDB, collName, numDocs = kNumInitialDocs) { const createCollCommand = {create: collName}; assert.commandWorked(primaryDB.runCommand(createCollCommand)); @@ -120,7 +135,7 @@ function cleanUpForConcurrentWritesTest(dbName, donorPrimary) { assert.commandWorked(donorDB.dropDatabase()); } -function makeTestOptionsForConcurrentWritesTest( +export function makeTestOptionsForConcurrentWritesTest( primary, testCase, dbName, collName, testInTransaction, testAsRetryableWrite) { assert(!testInTransaction || !testAsRetryableWrite); @@ -131,7 +146,7 @@ function makeTestOptionsForConcurrentWritesTest( let command = testCase.command(dbName, collName); if (testInTransaction || testAsRetryableWrite) { - command.txnNumber = TenantMigrationConcurrentWriteUtil.kTxnNumber; + command.txnNumber = kTxnNumber; } if (testInTransaction) { command.startTransaction = true; @@ -153,7 +168,7 @@ function makeTestOptionsForConcurrentWritesTest( }; } -function runTestForConcurrentWritesTest( +export function runTestForConcurrentWritesTest( primary, testCase, testFunc, dbName, collName, {testInTransaction, testAsRetryableWrite} = {}) { const testOpts = makeTestOptionsForConcurrentWritesTest( primary, testCase, dbName, collName, testInTransaction, testAsRetryableWrite); @@ -173,7 +188,7 @@ function runTestForConcurrentWritesTest( cleanUpForConcurrentWritesTest(dbName, primary); } -function setupTestForConcurrentWritesTest(testCase, collName, testOpts) { +export function setupTestForConcurrentWritesTest(testCase, collName, testOpts) { if (testCase.explicitlyCreateCollection) { createCollectionAndInsertDocsForConcurrentWritesTest(testOpts.primaryDB, collName); } @@ -191,41 +206,17 @@ const isOnlySupportedOnStandalone = "is only supported on standalone"; const isOnlySupportedOnShardedCluster = "is only supported on sharded cluster"; const isDeprecated = "is deprecated"; -TenantMigrationConcurrentWriteUtil.kTestDoc = { - x: -1 -}; -TenantMigrationConcurrentWriteUtil.kTestDoc2 = { - x: -2 -}; - -TenantMigrationConcurrentWriteUtil.kTestIndexKey = { - x: 1 -}; -TenantMigrationConcurrentWriteUtil.kExpireAfterSeconds = 1000000; -TenantMigrationConcurrentWriteUtil.kTestIndex = { - key: TenantMigrationConcurrentWriteUtil.kTestIndexKey, - name: "testIndex", - expireAfterSeconds: TenantMigrationConcurrentWriteUtil.kExpireAfterSeconds -}; - function insertTestDoc(primaryDB, collName) { - assert.commandWorked(primaryDB.runCommand( - {insert: collName, documents: [TenantMigrationConcurrentWriteUtil.kTestDoc]})); + assert.commandWorked(primaryDB.runCommand({insert: collName, documents: [kTestDoc]})); } function insertTwoTestDocs(primaryDB, collName) { - assert.commandWorked(primaryDB.runCommand({ - insert: collName, - documents: [ - TenantMigrationConcurrentWriteUtil.kTestDoc, - TenantMigrationConcurrentWriteUtil.kTestDoc2 - ] - })); + assert.commandWorked( + primaryDB.runCommand({insert: collName, documents: [kTestDoc, kTestDoc2]})); } function createTestIndex(primaryDB, collName) { - assert.commandWorked(primaryDB.runCommand( - {createIndexes: collName, indexes: [TenantMigrationConcurrentWriteUtil.kTestIndex]})); + assert.commandWorked(primaryDB.runCommand({createIndexes: collName, indexes: [kTestIndex]})); } function countDocs(db, collName, query) { @@ -250,494 +241,475 @@ function indexExists(db, collName, targetIndex) { bsonWoCompare(index.expireAfterSeconds, targetIndex.expireAfterSeconds) === 0); } -TenantMigrationConcurrentWriteUtil.kNumInitialDocs = - 2; // num initial docs to insert into test collections. -TenantMigrationConcurrentWriteUtil.kTxnNumber = NumberLong(0); - -TenantMigrationConcurrentWriteUtil.testCases = { - _addShard: {skip: isNotRunOnUserDatabase}, - _cloneCollectionOptionsFromPrimaryShard: {skip: isNotRunOnUserDatabase}, - _configsvrAddShard: {skip: isNotRunOnUserDatabase}, - _configsvrAddShardToZone: {skip: isNotRunOnUserDatabase}, - _configsvrBalancerCollectionStatus: {skip: isNotRunOnUserDatabase}, - _configsvrBalancerStart: {skip: isNotRunOnUserDatabase}, - _configsvrBalancerStatus: {skip: isNotRunOnUserDatabase}, - _configsvrBalancerStop: {skip: isNotRunOnUserDatabase}, - _configsvrClearJumboFlag: {skip: isNotRunOnUserDatabase}, - _configsvrCommitChunksMerge: {skip: isNotRunOnUserDatabase}, - _configsvrCommitChunkMigration: {skip: isNotRunOnUserDatabase}, - _configsvrCommitChunkSplit: {skip: isNotRunOnUserDatabase}, - _configsvrCommitIndex: {skip: isNotRunOnUserDatabase}, - _configsvrCommitMovePrimary: - {skip: isNotRunOnUserDatabase}, // Can be removed once 6.0 is last LTS - _configsvrCreateDatabase: {skip: isNotRunOnUserDatabase}, - _configsvrDropIndexCatalogEntry: {skip: isNotRunOnUserDatabase}, - _configsvrEnsureChunkVersionIsGreaterThan: {skip: isNotRunOnUserDatabase}, - _configsvrMoveChunk: {skip: isNotRunOnUserDatabase}, // Can be removed once 6.0 is last LTS - _configsvrMovePrimary: {skip: isNotRunOnUserDatabase}, - _configsvrMoveRange: {skip: isNotRunOnUserDatabase}, - _configsvrRefineCollectionShardKey: {skip: isNotRunOnUserDatabase}, - _configsvrRemoveShard: {skip: isNotRunOnUserDatabase}, - _configsvrRemoveShardFromZone: {skip: isNotRunOnUserDatabase}, - _configsvrUpdateZoneKeyRange: {skip: isNotRunOnUserDatabase}, - _flushDatabaseCacheUpdates: {skip: isNotRunOnUserDatabase}, - _flushDatabaseCacheUpdatesWithWriteConcern: {skip: isNotRunOnUserDatabase}, - _flushReshardingStateChange: {skip: isNotRunOnUserDatabase}, - _flushRoutingTableCacheUpdates: {skip: isNotRunOnUserDatabase}, - _flushRoutingTableCacheUpdatesWithWriteConcern: {skip: isNotRunOnUserDatabase}, - _getNextSessionMods: {skip: isNotRunOnUserDatabase}, - _getUserCacheGeneration: {skip: isNotRunOnUserDatabase}, - _hashBSONElement: {skip: isNotRunOnUserDatabase}, - _isSelf: {skip: isNotRunOnUserDatabase}, - _killOperations: {skip: isNotRunOnUserDatabase}, - _mergeAuthzCollections: {skip: isNotRunOnUserDatabase}, - _migrateClone: {skip: isNotRunOnUserDatabase}, - _recvChunkAbort: {skip: isNotRunOnUserDatabase}, - _recvChunkCommit: {skip: isNotRunOnUserDatabase}, - _recvChunkReleaseCritSec: {skip: isNotRunOnUserDatabase}, - _recvChunkStart: {skip: isNotRunOnUserDatabase}, - _recvChunkStatus: {skip: isNotRunOnUserDatabase}, - _shardsvrCloneCatalogData: {skip: isNotRunOnUserDatabase}, - _shardsvrCommitIndexParticipant: {skip: isOnlySupportedOnShardedCluster}, - _shardsvrCompactStructuredEncryptionData: {skip: isOnlySupportedOnShardedCluster}, - _shardsvrCreateCollection: {skip: isOnlySupportedOnShardedCluster}, - _shardsvrCreateCollectionParticipant: {skip: isOnlySupportedOnShardedCluster}, - _shardsvrRegisterIndex: {skip: isOnlySupportedOnShardedCluster}, - _shardsvrDropIndexCatalogEntryParticipant: {skip: isOnlySupportedOnShardedCluster}, - _shardsvrMovePrimary: {skip: isNotRunOnUserDatabase}, - _shardsvrSetAllowMigrations: {skip: isOnlySupportedOnShardedCluster}, - _shardsvrRenameCollection: {skip: isOnlySupportedOnShardedCluster}, - _shardsvrUnregisterIndex: {skip: isOnlySupportedOnShardedCluster}, - _transferMods: {skip: isNotRunOnUserDatabase}, - abortTransaction: { - skip: isNotWriteCommand // aborting unprepared transaction doesn't create an abort oplog - // entry. - }, - aggregate: { - explicitlyCreateCollection: true, - command: function(dbName, collName) { - return { - aggregate: collName, - pipeline: [{$out: collName + "Out"}], - cursor: {batchSize: 1} - }; - }, - assertCommandSucceeded: function(db, dbName, collName) { - assert(collectionExists(db, collName + "Out")); - }, - assertCommandFailed: function(db, dbName, collName) { - assert(!collectionExists(db, collName + "Out")); - } - }, - appendOplogNote: {skip: isNotRunOnUserDatabase}, - applyOps: {skip: isNotSupportedInServerless}, - authenticate: {skip: isAuthCommand}, - buildInfo: {skip: isNotWriteCommand}, - captrunc: {skip: isNotSupportedInServerless}, - checkShardingIndex: {skip: isNotRunOnUserDatabase}, - cleanupOrphaned: {skip: isNotRunOnUserDatabase}, - clearLog: {skip: isNotRunOnUserDatabase}, - cloneCollectionAsCapped: {skip: isNotSupportedInServerless}, - collMod: { - explicitlyCreateCollection: true, - setUp: createTestIndex, - command: function(dbName, collName) { - return { - collMod: collName, - index: { - keyPattern: TenantMigrationConcurrentWriteUtil.kTestIndexKey, - expireAfterSeconds: TenantMigrationConcurrentWriteUtil.kExpireAfterSeconds + 1 - } - }; - }, - assertCommandSucceeded: function(db, dbName, collName) { - assert(indexExists(db, collName, { - key: TenantMigrationConcurrentWriteUtil.kTestIndexKey, - expireAfterSeconds: TenantMigrationConcurrentWriteUtil.kExpireAfterSeconds + 1 - })); - }, - assertCommandFailed: function(db, dbName, collName) { - assert(!indexExists(db, collName, { - key: TenantMigrationConcurrentWriteUtil.kTestIndexKey, - expireAfterSeconds: TenantMigrationConcurrentWriteUtil.kExpireAfterSeconds + 1 - })); - } - }, - collStats: {skip: isNotWriteCommand}, - commitTransaction: { - isTransactionCommand: true, - runAgainstAdminDb: true, - setUp: function(primaryDB, collName) { - assert.commandWorked(primaryDB.runCommand({ - insert: collName, - documents: [TenantMigrationConcurrentWriteUtil.kTestDoc], - txnNumber: NumberLong(TenantMigrationConcurrentWriteUtil.kTxnNumber), - startTransaction: true, - autocommit: false - })); - }, - command: function(dbName, collName) { - return { - commitTransaction: 1, - txnNumber: NumberLong(TenantMigrationConcurrentWriteUtil.kTxnNumber), - autocommit: false, - writeConcern: {w: "majority"} - }; - }, - assertCommandSucceeded: function(db, dbName, collName) { - assert.eq(countDocs(db, collName), 1); - }, - assertCommandFailed: function(db, dbName, collName) { - assert.eq(countDocs(db, collName), 0); - } - }, - compact: {skip: isNotSupportedInServerless}, - configureFailPoint: {skip: isNotRunOnUserDatabase}, - connPoolStats: {skip: isNotRunOnUserDatabase}, - connPoolSync: {skip: isNotRunOnUserDatabase}, - connectionStatus: {skip: isNotRunOnUserDatabase}, - convertToCapped: {skip: isNotSupportedInServerless}, - coordinateCommitTransaction: {skip: isNotRunOnUserDatabase}, - count: {skip: isNotWriteCommand}, - cpuload: {skip: isNotRunOnUserDatabase}, - create: { - testInTransaction: true, - command: function(dbName, collName) { - return {create: collName}; - }, - assertCommandSucceeded: function(db, dbName, collName) { - assert(collectionExists(db, collName)); - }, - assertCommandFailed: function(db, dbName, collName) { - assert(!collectionExists(db, collName)); - } - }, - createIndexes: { - testInTransaction: true, - explicitlyCreateCollection: true, - setUp: function(primaryDB, collName, testInTransaction) { - if (testInTransaction) { - // Drop the collection that was explicitly created above since inside transactions - // the index to create must either be on a non-existing collection, or on a new - // empty collection created earlier in the same transaction. - assert.commandWorked(primaryDB.runCommand({drop: collName})); +export const TenantMigrationConcurrentWriteUtil = { + kTestDoc, + kTestDoc2, + kTestIndexKey, + kExpireAfterSeconds, + kTestIndex, + kNumInitialDocs, + kTxnNumber, + testCases: { + _addShard: {skip: isNotRunOnUserDatabase}, + _cloneCollectionOptionsFromPrimaryShard: {skip: isNotRunOnUserDatabase}, + _configsvrAddShard: {skip: isNotRunOnUserDatabase}, + _configsvrAddShardToZone: {skip: isNotRunOnUserDatabase}, + _configsvrBalancerCollectionStatus: {skip: isNotRunOnUserDatabase}, + _configsvrBalancerStart: {skip: isNotRunOnUserDatabase}, + _configsvrBalancerStatus: {skip: isNotRunOnUserDatabase}, + _configsvrBalancerStop: {skip: isNotRunOnUserDatabase}, + _configsvrClearJumboFlag: {skip: isNotRunOnUserDatabase}, + _configsvrCommitChunksMerge: {skip: isNotRunOnUserDatabase}, + _configsvrCommitChunkMigration: {skip: isNotRunOnUserDatabase}, + _configsvrCommitChunkSplit: {skip: isNotRunOnUserDatabase}, + _configsvrCommitIndex: {skip: isNotRunOnUserDatabase}, + _configsvrCommitMovePrimary: + {skip: isNotRunOnUserDatabase}, // Can be removed once 6.0 is last LTS + _configsvrCreateDatabase: {skip: isNotRunOnUserDatabase}, + _configsvrDropIndexCatalogEntry: {skip: isNotRunOnUserDatabase}, + _configsvrEnsureChunkVersionIsGreaterThan: {skip: isNotRunOnUserDatabase}, + _configsvrMoveChunk: {skip: isNotRunOnUserDatabase}, // Can be removed once 6.0 is last LTS + _configsvrMovePrimary: {skip: isNotRunOnUserDatabase}, + _configsvrMoveRange: {skip: isNotRunOnUserDatabase}, + _configsvrRefineCollectionShardKey: {skip: isNotRunOnUserDatabase}, + _configsvrRemoveShard: {skip: isNotRunOnUserDatabase}, + _configsvrRemoveShardFromZone: {skip: isNotRunOnUserDatabase}, + _configsvrUpdateZoneKeyRange: {skip: isNotRunOnUserDatabase}, + _flushDatabaseCacheUpdates: {skip: isNotRunOnUserDatabase}, + _flushDatabaseCacheUpdatesWithWriteConcern: {skip: isNotRunOnUserDatabase}, + _flushReshardingStateChange: {skip: isNotRunOnUserDatabase}, + _flushRoutingTableCacheUpdates: {skip: isNotRunOnUserDatabase}, + _flushRoutingTableCacheUpdatesWithWriteConcern: {skip: isNotRunOnUserDatabase}, + _getNextSessionMods: {skip: isNotRunOnUserDatabase}, + _getUserCacheGeneration: {skip: isNotRunOnUserDatabase}, + _hashBSONElement: {skip: isNotRunOnUserDatabase}, + _isSelf: {skip: isNotRunOnUserDatabase}, + _killOperations: {skip: isNotRunOnUserDatabase}, + _mergeAuthzCollections: {skip: isNotRunOnUserDatabase}, + _migrateClone: {skip: isNotRunOnUserDatabase}, + _recvChunkAbort: {skip: isNotRunOnUserDatabase}, + _recvChunkCommit: {skip: isNotRunOnUserDatabase}, + _recvChunkReleaseCritSec: {skip: isNotRunOnUserDatabase}, + _recvChunkStart: {skip: isNotRunOnUserDatabase}, + _recvChunkStatus: {skip: isNotRunOnUserDatabase}, + _shardsvrCloneCatalogData: {skip: isNotRunOnUserDatabase}, + _shardsvrCommitIndexParticipant: {skip: isOnlySupportedOnShardedCluster}, + _shardsvrCompactStructuredEncryptionData: {skip: isOnlySupportedOnShardedCluster}, + _shardsvrCreateCollection: {skip: isOnlySupportedOnShardedCluster}, + _shardsvrCreateCollectionParticipant: {skip: isOnlySupportedOnShardedCluster}, + _shardsvrRegisterIndex: {skip: isOnlySupportedOnShardedCluster}, + _shardsvrDropIndexCatalogEntryParticipant: {skip: isOnlySupportedOnShardedCluster}, + _shardsvrMovePrimary: {skip: isNotRunOnUserDatabase}, + _shardsvrSetAllowMigrations: {skip: isOnlySupportedOnShardedCluster}, + _shardsvrRenameCollection: {skip: isOnlySupportedOnShardedCluster}, + _shardsvrUnregisterIndex: {skip: isOnlySupportedOnShardedCluster}, + _transferMods: {skip: isNotRunOnUserDatabase}, + abortTransaction: { + skip: isNotWriteCommand // aborting unprepared transaction doesn't create an abort + // oplog entry. + }, + aggregate: { + explicitlyCreateCollection: true, + command: function(dbName, collName) { + return { + aggregate: collName, + pipeline: [{$out: collName + "Out"}], + cursor: {batchSize: 1} + }; + }, + assertCommandSucceeded: function(db, dbName, collName) { + assert(collectionExists(db, collName + "Out")); + }, + assertCommandFailed: function(db, dbName, collName) { + assert(!collectionExists(db, collName + "Out")); } }, - command: function(dbName, collName) { - return { - createIndexes: collName, - indexes: [TenantMigrationConcurrentWriteUtil.kTestIndex] - }; - }, - assertCommandSucceeded: function(db, dbName, collName) { - assert(indexExists(db, collName, TenantMigrationConcurrentWriteUtil.kTestIndex)); - }, - assertCommandFailed: function(db, dbName, collName) { - assert(!collectionExists(db, collName) || - !indexExists(db, collName, TenantMigrationConcurrentWriteUtil.kTestIndex)); - } - }, - createRole: {skip: isAuthCommand}, - createUser: {skip: isAuthCommand}, - currentOp: {skip: isNotRunOnUserDatabase}, - dataSize: {skip: isNotWriteCommand}, - dbCheck: {skip: isNotWriteCommand}, - dbHash: {skip: isNotWriteCommand}, - dbStats: {skip: isNotWriteCommand}, - delete: { - testInTransaction: true, - testAsRetryableWrite: true, - setUp: insertTestDoc, - command: function(dbName, collName) { - return { - delete: collName, - deletes: [{q: TenantMigrationConcurrentWriteUtil.kTestDoc, limit: 1}] - }; - }, - isBatchWrite: true, - assertCommandSucceeded: function(db, dbName, collName) { - assert.eq(countDocs(db, collName, TenantMigrationConcurrentWriteUtil.kTestDoc), 0); - }, - assertCommandFailed: function(db, dbName, collName) { - assert.eq(countDocs(db, collName, TenantMigrationConcurrentWriteUtil.kTestDoc), 1); - } - }, - distinct: {skip: isNotWriteCommand}, - donorForgetMigration: {skip: isNotRunOnUserDatabase}, - donorStartMigration: {skip: isNotRunOnUserDatabase}, - donorWaitForMigrationToCommit: {skip: isNotRunOnUserDatabase}, - driverOIDTest: {skip: isNotRunOnUserDatabase}, - drop: { - explicitlyCreateCollection: true, - command: function(dbName, collName) { - return {drop: collName}; - }, - assertCommandSucceeded: function(db, dbName, collName) { - assert(!collectionExists(db, collName)); - }, - assertCommandFailed: function(db, dbName, collName) { - assert(collectionExists(db, collName)); - } - }, - dropAllRolesFromDatabase: {skip: isAuthCommand}, - dropAllUsersFromDatabase: {skip: isAuthCommand}, - dropConnections: {skip: isNotRunOnUserDatabase}, - dropDatabase: { - explicitlyCreateCollection: true, - command: function(dbName, collName) { - return {dropDatabase: 1}; - }, - assertCommandSucceeded: function(db, dbName, collName) { - assert(!databaseExists(db, dbName)); - }, - assertCommandFailed: function(db, dbName, collName) { - assert(databaseExists(db, dbName)); - } - }, - dropIndexes: { - explicitlyCreateCollection: true, - setUp: createTestIndex, - command: function(dbName, collName) { - return {dropIndexes: collName, index: "*"}; + appendOplogNote: {skip: isNotRunOnUserDatabase}, + applyOps: {skip: isNotSupportedInServerless}, + authenticate: {skip: isAuthCommand}, + buildInfo: {skip: isNotWriteCommand}, + captrunc: {skip: isNotSupportedInServerless}, + checkShardingIndex: {skip: isNotRunOnUserDatabase}, + cleanupOrphaned: {skip: isNotRunOnUserDatabase}, + clearLog: {skip: isNotRunOnUserDatabase}, + cloneCollectionAsCapped: {skip: isNotSupportedInServerless}, + collMod: { + explicitlyCreateCollection: true, + setUp: createTestIndex, + command: function(dbName, collName) { + return { + collMod: collName, + index: {keyPattern: kTestIndexKey, expireAfterSeconds: kExpireAfterSeconds + 1} + }; + }, + assertCommandSucceeded: function(db, dbName, collName) { + assert( + indexExists(db, + collName, + {key: kTestIndexKey, expireAfterSeconds: kExpireAfterSeconds + 1})); + }, + assertCommandFailed: function(db, dbName, collName) { + assert(!indexExists( + db, + collName, + {key: kTestIndexKey, expireAfterSeconds: kExpireAfterSeconds + 1})); + } }, - assertCommandSucceeded: function(db, dbName, collName) { - assert(!indexExists(db, collName, TenantMigrationConcurrentWriteUtil.kTestIndex)); + collStats: {skip: isNotWriteCommand}, + commitTransaction: { + isTransactionCommand: true, + runAgainstAdminDb: true, + setUp: function(primaryDB, collName) { + assert.commandWorked(primaryDB.runCommand({ + insert: collName, + documents: [kTestDoc], + txnNumber: NumberLong(kTxnNumber), + startTransaction: true, + autocommit: false + })); + }, + command: function(dbName, collName) { + return { + commitTransaction: 1, + txnNumber: NumberLong(kTxnNumber), + autocommit: false, + writeConcern: {w: "majority"} + }; + }, + assertCommandSucceeded: function(db, dbName, collName) { + assert.eq(countDocs(db, collName), 1); + }, + assertCommandFailed: function(db, dbName, collName) { + assert.eq(countDocs(db, collName), 0); + } }, - assertCommandFailed: function(db, dbName, collName) { - assert(indexExists(db, collName, TenantMigrationConcurrentWriteUtil.kTestIndex)); - } - }, - dropRole: {skip: isAuthCommand}, - dropUser: {skip: isAuthCommand}, - echo: {skip: isNotRunOnUserDatabase}, - emptycapped: {skip: isNotSupportedInServerless}, - endSessions: {skip: isNotRunOnUserDatabase}, - explain: {skip: isNotRunOnUserDatabase}, - features: {skip: isNotRunOnUserDatabase}, - filemd5: {skip: isNotWriteCommand}, - find: {skip: isNotWriteCommand}, - findAndModify: { - testInTransaction: true, - testAsRetryableWrite: true, - setUp: insertTestDoc, - command: function(dbName, collName) { - return { - findAndModify: collName, - query: TenantMigrationConcurrentWriteUtil.kTestDoc, - remove: true - }; + compact: {skip: isNotSupportedInServerless}, + configureFailPoint: {skip: isNotRunOnUserDatabase}, + connPoolStats: {skip: isNotRunOnUserDatabase}, + connPoolSync: {skip: isNotRunOnUserDatabase}, + connectionStatus: {skip: isNotRunOnUserDatabase}, + convertToCapped: {skip: isNotSupportedInServerless}, + coordinateCommitTransaction: {skip: isNotRunOnUserDatabase}, + count: {skip: isNotWriteCommand}, + cpuload: {skip: isNotRunOnUserDatabase}, + create: { + testInTransaction: true, + command: function(dbName, collName) { + return {create: collName}; + }, + assertCommandSucceeded: function(db, dbName, collName) { + assert(collectionExists(db, collName)); + }, + assertCommandFailed: function(db, dbName, collName) { + assert(!collectionExists(db, collName)); + } }, - assertCommandSucceeded: function(db, dbName, collName) { - assert.eq(countDocs(db, collName, TenantMigrationConcurrentWriteUtil.kTestDoc), 0); + createIndexes: { + testInTransaction: true, + explicitlyCreateCollection: true, + setUp: function(primaryDB, collName, testInTransaction) { + if (testInTransaction) { + // Drop the collection that was explicitly created above since inside + // transactions the index to create must either be on a non-existing + // collection, or on a new empty collection created earlier in the same + // transaction. + assert.commandWorked(primaryDB.runCommand({drop: collName})); + } + }, + command: function(dbName, collName) { + return {createIndexes: collName, indexes: [kTestIndex]}; + }, + assertCommandSucceeded: function(db, dbName, collName) { + assert(indexExists(db, collName, kTestIndex)); + }, + assertCommandFailed: function(db, dbName, collName) { + assert(!collectionExists(db, collName) || !indexExists(db, collName, kTestIndex)); + } }, - assertCommandFailed: function(db, dbName, collName) { - assert.eq(countDocs(db, collName, TenantMigrationConcurrentWriteUtil.kTestDoc), 1); - } - }, - flushRouterConfig: {skip: isNotRunOnUserDatabase}, - fsync: {skip: isNotRunOnUserDatabase}, - fsyncUnlock: {skip: isNotRunOnUserDatabase}, - getCmdLineOpts: {skip: isNotRunOnUserDatabase}, - getDatabaseVersion: {skip: isNotRunOnUserDatabase}, - getDefaultRWConcern: {skip: isNotRunOnUserDatabase}, - getDiagnosticData: {skip: isNotRunOnUserDatabase}, - getFreeMonitoringStatus: {skip: isNotRunOnUserDatabase}, - getLog: {skip: isNotRunOnUserDatabase}, - getMore: {skip: isNotWriteCommand}, - getParameter: {skip: isNotRunOnUserDatabase}, - getShardMap: {skip: isNotRunOnUserDatabase}, - getShardVersion: {skip: isNotRunOnUserDatabase}, - getnonce: {skip: "removed in v6.3"}, - godinsert: {skip: isNotRunOnUserDatabase}, - grantPrivilegesToRole: {skip: isAuthCommand}, - grantRolesToRole: {skip: isAuthCommand}, - grantRolesToUser: {skip: isAuthCommand}, - hello: {skip: isNotRunOnUserDatabase}, - hostInfo: {skip: isNotRunOnUserDatabase}, - httpClientRequest: {skip: isNotRunOnUserDatabase}, - insert: { - testInTransaction: true, - testAsRetryableWrite: true, - explicitlyCreateCollection: true, - command: function(dbName, collName) { - return {insert: collName, documents: [TenantMigrationConcurrentWriteUtil.kTestDoc]}; + createRole: {skip: isAuthCommand}, + createUser: {skip: isAuthCommand}, + currentOp: {skip: isNotRunOnUserDatabase}, + dataSize: {skip: isNotWriteCommand}, + dbCheck: {skip: isNotWriteCommand}, + dbHash: {skip: isNotWriteCommand}, + dbStats: {skip: isNotWriteCommand}, + delete: { + testInTransaction: true, + testAsRetryableWrite: true, + setUp: insertTestDoc, + command: function(dbName, collName) { + return {delete: collName, deletes: [{q: kTestDoc, limit: 1}]}; + }, + isBatchWrite: true, + assertCommandSucceeded: function(db, dbName, collName) { + assert.eq(countDocs(db, collName, kTestDoc), 0); + }, + assertCommandFailed: function(db, dbName, collName) { + assert.eq(countDocs(db, collName, kTestDoc), 1); + } }, - isBatchWrite: true, - assertCommandSucceeded: function(db, dbName, collName) { - assert.eq(countDocs(db, collName, TenantMigrationConcurrentWriteUtil.kTestDoc), 1); + distinct: {skip: isNotWriteCommand}, + donorForgetMigration: {skip: isNotRunOnUserDatabase}, + donorStartMigration: {skip: isNotRunOnUserDatabase}, + donorWaitForMigrationToCommit: {skip: isNotRunOnUserDatabase}, + driverOIDTest: {skip: isNotRunOnUserDatabase}, + drop: { + explicitlyCreateCollection: true, + command: function(dbName, collName) { + return {drop: collName}; + }, + assertCommandSucceeded: function(db, dbName, collName) { + assert(!collectionExists(db, collName)); + }, + assertCommandFailed: function(db, dbName, collName) { + assert(collectionExists(db, collName)); + } }, - assertCommandFailed: function(db, dbName, collName) { - assert.eq(countDocs(db, collName, TenantMigrationConcurrentWriteUtil.kTestDoc), 0); - } - }, - internalRenameIfOptionsAndIndexesMatch: {skip: isNotRunOnUserDatabase}, - invalidateUserCache: {skip: isNotRunOnUserDatabase}, - killAllSessions: {skip: isNotRunOnUserDatabase}, - killAllSessionsByPattern: {skip: isNotRunOnUserDatabase}, - killCursors: {skip: isNotWriteCommand}, - killOp: {skip: isNotRunOnUserDatabase}, - killSessions: {skip: isNotRunOnUserDatabase}, - listCollections: {skip: isNotRunOnUserDatabase}, - listCommands: {skip: isNotRunOnUserDatabase}, - listDatabases: {skip: isNotRunOnUserDatabase}, - listIndexes: {skip: isNotWriteCommand}, - lockInfo: {skip: isNotRunOnUserDatabase}, - logRotate: {skip: isNotRunOnUserDatabase}, - logout: {skip: isNotRunOnUserDatabase}, - makeSnapshot: {skip: isNotRunOnUserDatabase}, - mapReduce: { - command: function(dbName, collName) { - return { - mapReduce: collName, - map: function mapFunc() { - emit(this.x, 1); - }, - reduce: function reduceFunc(key, values) { - return Array.sum(values); - }, - out: {replace: collName + "MrOut"}, - }; + dropAllRolesFromDatabase: {skip: isAuthCommand}, + dropAllUsersFromDatabase: {skip: isAuthCommand}, + dropConnections: {skip: isNotRunOnUserDatabase}, + dropDatabase: { + explicitlyCreateCollection: true, + command: function(dbName, collName) { + return {dropDatabase: 1}; + }, + assertCommandSucceeded: function(db, dbName, collName) { + assert(!databaseExists(db, dbName)); + }, + assertCommandFailed: function(db, dbName, collName) { + assert(databaseExists(db, dbName)); + } }, - assertCommandSucceeded: function(db, dbName, collName) { - assert(collectionExists(db, collName + "MrOut")); + dropIndexes: { + explicitlyCreateCollection: true, + setUp: createTestIndex, + command: function(dbName, collName) { + return {dropIndexes: collName, index: "*"}; + }, + assertCommandSucceeded: function(db, dbName, collName) { + assert(!indexExists(db, collName, kTestIndex)); + }, + assertCommandFailed: function(db, dbName, collName) { + assert(indexExists(db, collName, kTestIndex)); + } }, - assertCommandFailed: function(db, dbName, collName) { - assert(!collectionExists(db, collName + "MrOut")); - } - }, - mergeChunks: {skip: isNotRunOnUserDatabase}, - moveChunk: {skip: isNotRunOnUserDatabase}, - ping: {skip: isNotRunOnUserDatabase}, - planCacheClear: {skip: isNotWriteCommand}, - planCacheClearFilters: {skip: isNotWriteCommand}, - planCacheListFilters: {skip: isNotWriteCommand}, - planCacheSetFilter: {skip: isNotWriteCommand}, - prepareTransaction: {skip: isOnlySupportedOnShardedCluster}, - profile: {skip: isNotRunOnUserDatabase}, - reIndex: {skip: isOnlySupportedOnStandalone}, - reapLogicalSessionCacheNow: {skip: isNotRunOnUserDatabase}, - refreshLogicalSessionCacheNow: {skip: isNotRunOnUserDatabase}, - refreshSessions: {skip: isNotRunOnUserDatabase}, - recipientVoteImportedFiles: {skip: isNotRunOnUserDatabase}, - renameCollection: { - runAgainstAdminDb: true, - explicitlyCreateCollection: true, - command: function(dbName, collName) { - return { - renameCollection: dbName + "." + collName, - to: dbName + "." + collName + "Renamed" - }; + dropRole: {skip: isAuthCommand}, + dropUser: {skip: isAuthCommand}, + echo: {skip: isNotRunOnUserDatabase}, + emptycapped: {skip: isNotSupportedInServerless}, + endSessions: {skip: isNotRunOnUserDatabase}, + explain: {skip: isNotRunOnUserDatabase}, + features: {skip: isNotRunOnUserDatabase}, + filemd5: {skip: isNotWriteCommand}, + find: {skip: isNotWriteCommand}, + findAndModify: { + testInTransaction: true, + testAsRetryableWrite: true, + setUp: insertTestDoc, + command: function(dbName, collName) { + return {findAndModify: collName, query: kTestDoc, remove: true}; + }, + assertCommandSucceeded: function(db, dbName, collName) { + assert.eq(countDocs(db, collName, kTestDoc), 0); + }, + assertCommandFailed: function(db, dbName, collName) { + assert.eq(countDocs(db, collName, kTestDoc), 1); + } }, - assertCommandSucceeded: function(db, dbName, collName) { - assert(!collectionExists(db, collName)); - assert(collectionExists(db, collName + "Renamed")); + flushRouterConfig: {skip: isNotRunOnUserDatabase}, + fsync: {skip: isNotRunOnUserDatabase}, + fsyncUnlock: {skip: isNotRunOnUserDatabase}, + getCmdLineOpts: {skip: isNotRunOnUserDatabase}, + getDatabaseVersion: {skip: isNotRunOnUserDatabase}, + getDefaultRWConcern: {skip: isNotRunOnUserDatabase}, + getDiagnosticData: {skip: isNotRunOnUserDatabase}, + getFreeMonitoringStatus: {skip: isNotRunOnUserDatabase}, + getLog: {skip: isNotRunOnUserDatabase}, + getMore: {skip: isNotWriteCommand}, + getParameter: {skip: isNotRunOnUserDatabase}, + getShardMap: {skip: isNotRunOnUserDatabase}, + getShardVersion: {skip: isNotRunOnUserDatabase}, + getnonce: {skip: "removed in v6.3"}, + godinsert: {skip: isNotRunOnUserDatabase}, + grantPrivilegesToRole: {skip: isAuthCommand}, + grantRolesToRole: {skip: isAuthCommand}, + grantRolesToUser: {skip: isAuthCommand}, + hello: {skip: isNotRunOnUserDatabase}, + hostInfo: {skip: isNotRunOnUserDatabase}, + httpClientRequest: {skip: isNotRunOnUserDatabase}, + insert: { + testInTransaction: true, + testAsRetryableWrite: true, + explicitlyCreateCollection: true, + command: function(dbName, collName) { + return {insert: collName, documents: [kTestDoc]}; + }, + isBatchWrite: true, + assertCommandSucceeded: function(db, dbName, collName) { + assert.eq(countDocs(db, collName, kTestDoc), 1); + }, + assertCommandFailed: function(db, dbName, collName) { + assert.eq(countDocs(db, collName, kTestDoc), 0); + } }, - assertCommandFailed: function(db, dbName, collName) { - assert(collectionExists(db, collName)); - assert(!collectionExists(db, collName + "Renamed")); - } - }, - replSetAbortPrimaryCatchUp: {skip: isNotRunOnUserDatabase}, - replSetFreeze: {skip: isNotRunOnUserDatabase}, - replSetGetConfig: {skip: isNotRunOnUserDatabase}, - replSetGetRBID: {skip: isNotRunOnUserDatabase}, - replSetGetStatus: {skip: isNotRunOnUserDatabase}, - replSetHeartbeat: {skip: isNotRunOnUserDatabase}, - replSetInitiate: {skip: isNotRunOnUserDatabase}, - replSetMaintenance: {skip: isNotRunOnUserDatabase}, - replSetReconfig: {skip: isNotRunOnUserDatabase}, - replSetRequestVotes: {skip: isNotRunOnUserDatabase}, - replSetResizeOplog: {skip: isNotRunOnUserDatabase}, - replSetStepDown: {skip: isNotRunOnUserDatabase}, - replSetStepUp: {skip: isNotRunOnUserDatabase}, - replSetSyncFrom: {skip: isNotRunOnUserDatabase}, - replSetTest: {skip: isNotRunOnUserDatabase}, - replSetTestEgress: {skip: isNotRunOnUserDatabase}, - replSetUpdatePosition: {skip: isNotRunOnUserDatabase}, - revokePrivilegesFromRole: {skip: isAuthCommand}, - revokeRolesFromRole: {skip: isAuthCommand}, - revokeRolesFromUser: {skip: isAuthCommand}, - rolesInfo: {skip: isNotWriteCommand}, - rotateCertificates: {skip: isAuthCommand}, - saslContinue: {skip: isAuthCommand}, - saslStart: {skip: isAuthCommand}, - sbe: {skip: isNotRunOnUserDatabase}, - serverStatus: {skip: isNotRunOnUserDatabase}, - setAllowMigrations: {skip: isNotRunOnUserDatabase}, - setCommittedSnapshot: {skip: isNotRunOnUserDatabase}, - setDefaultRWConcern: {skip: isNotRunOnUserDatabase}, - setFeatureCompatibilityVersion: {skip: isNotRunOnUserDatabase}, - setFreeMonitoring: {skip: isNotRunOnUserDatabase}, - setIndexCommitQuorum: {skip: isNotRunOnUserDatabase}, - setParameter: {skip: isNotRunOnUserDatabase}, - setShardVersion: {skip: isNotRunOnUserDatabase}, - shardingState: {skip: isNotRunOnUserDatabase}, - shutdown: {skip: isNotRunOnUserDatabase}, - sleep: {skip: isNotRunOnUserDatabase}, - splitChunk: {skip: isNotRunOnUserDatabase}, - splitVector: {skip: isNotRunOnUserDatabase}, - stageDebug: {skip: isNotRunOnUserDatabase}, - startRecordingTraffic: {skip: isNotRunOnUserDatabase}, - startSession: {skip: isNotRunOnUserDatabase}, - stopRecordingTraffic: {skip: isNotRunOnUserDatabase}, - top: {skip: isNotRunOnUserDatabase}, - update: { - testInTransaction: true, - testAsRetryableWrite: true, - setUp: insertTestDoc, - command: function(dbName, collName) { - return { - update: collName, - updates: [{ - q: TenantMigrationConcurrentWriteUtil.kTestDoc, - u: {$set: {y: 0}}, - upsert: false, - multi: false - }] - }; + internalRenameIfOptionsAndIndexesMatch: {skip: isNotRunOnUserDatabase}, + invalidateUserCache: {skip: isNotRunOnUserDatabase}, + killAllSessions: {skip: isNotRunOnUserDatabase}, + killAllSessionsByPattern: {skip: isNotRunOnUserDatabase}, + killCursors: {skip: isNotWriteCommand}, + killOp: {skip: isNotRunOnUserDatabase}, + killSessions: {skip: isNotRunOnUserDatabase}, + listCollections: {skip: isNotRunOnUserDatabase}, + listCommands: {skip: isNotRunOnUserDatabase}, + listDatabases: {skip: isNotRunOnUserDatabase}, + listIndexes: {skip: isNotWriteCommand}, + lockInfo: {skip: isNotRunOnUserDatabase}, + logRotate: {skip: isNotRunOnUserDatabase}, + logout: {skip: isNotRunOnUserDatabase}, + makeSnapshot: {skip: isNotRunOnUserDatabase}, + mapReduce: { + command: function(dbName, collName) { + return { + mapReduce: collName, + map: function mapFunc() { + emit(this.x, 1); + }, + reduce: function reduceFunc(key, values) { + return Array.sum(values); + }, + out: {replace: collName + "MrOut"}, + }; + }, + assertCommandSucceeded: function(db, dbName, collName) { + assert(collectionExists(db, collName + "MrOut")); + }, + assertCommandFailed: function(db, dbName, collName) { + assert(!collectionExists(db, collName + "MrOut")); + } }, - isBatchWrite: true, - assertCommandSucceeded: function(db, dbName, collName) { - assert.eq(countDocs(db, - collName, - Object.assign({y: 0}, TenantMigrationConcurrentWriteUtil.kTestDoc)), - 1); + mergeChunks: {skip: isNotRunOnUserDatabase}, + moveChunk: {skip: isNotRunOnUserDatabase}, + ping: {skip: isNotRunOnUserDatabase}, + planCacheClear: {skip: isNotWriteCommand}, + planCacheClearFilters: {skip: isNotWriteCommand}, + planCacheListFilters: {skip: isNotWriteCommand}, + planCacheSetFilter: {skip: isNotWriteCommand}, + prepareTransaction: {skip: isOnlySupportedOnShardedCluster}, + profile: {skip: isNotRunOnUserDatabase}, + reIndex: {skip: isOnlySupportedOnStandalone}, + reapLogicalSessionCacheNow: {skip: isNotRunOnUserDatabase}, + refreshLogicalSessionCacheNow: {skip: isNotRunOnUserDatabase}, + refreshSessions: {skip: isNotRunOnUserDatabase}, + recipientVoteImportedFiles: {skip: isNotRunOnUserDatabase}, + renameCollection: { + runAgainstAdminDb: true, + explicitlyCreateCollection: true, + command: function(dbName, collName) { + return { + renameCollection: dbName + "." + collName, + to: dbName + "." + collName + "Renamed" + }; + }, + assertCommandSucceeded: function(db, dbName, collName) { + assert(!collectionExists(db, collName)); + assert(collectionExists(db, collName + "Renamed")); + }, + assertCommandFailed: function(db, dbName, collName) { + assert(collectionExists(db, collName)); + assert(!collectionExists(db, collName + "Renamed")); + } }, - assertCommandFailed: function(db, dbName, collName) { - assert.eq(countDocs(db, - collName, - Object.assign({y: 0}, TenantMigrationConcurrentWriteUtil.kTestDoc)), - 0); - } - }, - multiUpdate: { - testInTransaction: true, - testAsRetryableWrite: false, - setUp: insertTwoTestDocs, - command: function(dbName, collName) { - return { - update: collName, - updates: [{q: {}, u: {$set: {y: 0}}, upsert: false, multi: true}] - }; + replSetAbortPrimaryCatchUp: {skip: isNotRunOnUserDatabase}, + replSetFreeze: {skip: isNotRunOnUserDatabase}, + replSetGetConfig: {skip: isNotRunOnUserDatabase}, + replSetGetRBID: {skip: isNotRunOnUserDatabase}, + replSetGetStatus: {skip: isNotRunOnUserDatabase}, + replSetHeartbeat: {skip: isNotRunOnUserDatabase}, + replSetInitiate: {skip: isNotRunOnUserDatabase}, + replSetMaintenance: {skip: isNotRunOnUserDatabase}, + replSetReconfig: {skip: isNotRunOnUserDatabase}, + replSetRequestVotes: {skip: isNotRunOnUserDatabase}, + replSetResizeOplog: {skip: isNotRunOnUserDatabase}, + replSetStepDown: {skip: isNotRunOnUserDatabase}, + replSetStepUp: {skip: isNotRunOnUserDatabase}, + replSetSyncFrom: {skip: isNotRunOnUserDatabase}, + replSetTest: {skip: isNotRunOnUserDatabase}, + replSetTestEgress: {skip: isNotRunOnUserDatabase}, + replSetUpdatePosition: {skip: isNotRunOnUserDatabase}, + revokePrivilegesFromRole: {skip: isAuthCommand}, + revokeRolesFromRole: {skip: isAuthCommand}, + revokeRolesFromUser: {skip: isAuthCommand}, + rolesInfo: {skip: isNotWriteCommand}, + rotateCertificates: {skip: isAuthCommand}, + saslContinue: {skip: isAuthCommand}, + saslStart: {skip: isAuthCommand}, + sbe: {skip: isNotRunOnUserDatabase}, + serverStatus: {skip: isNotRunOnUserDatabase}, + setAllowMigrations: {skip: isNotRunOnUserDatabase}, + setCommittedSnapshot: {skip: isNotRunOnUserDatabase}, + setDefaultRWConcern: {skip: isNotRunOnUserDatabase}, + setFeatureCompatibilityVersion: {skip: isNotRunOnUserDatabase}, + setFreeMonitoring: {skip: isNotRunOnUserDatabase}, + setIndexCommitQuorum: {skip: isNotRunOnUserDatabase}, + setParameter: {skip: isNotRunOnUserDatabase}, + setShardVersion: {skip: isNotRunOnUserDatabase}, + shardingState: {skip: isNotRunOnUserDatabase}, + shutdown: {skip: isNotRunOnUserDatabase}, + sleep: {skip: isNotRunOnUserDatabase}, + splitChunk: {skip: isNotRunOnUserDatabase}, + splitVector: {skip: isNotRunOnUserDatabase}, + stageDebug: {skip: isNotRunOnUserDatabase}, + startRecordingTraffic: {skip: isNotRunOnUserDatabase}, + startSession: {skip: isNotRunOnUserDatabase}, + stopRecordingTraffic: {skip: isNotRunOnUserDatabase}, + top: {skip: isNotRunOnUserDatabase}, + update: { + testInTransaction: true, + testAsRetryableWrite: true, + setUp: insertTestDoc, + command: function(dbName, collName) { + return { + update: collName, + updates: [{q: kTestDoc, u: {$set: {y: 0}}, upsert: false, multi: false}] + }; + }, + isBatchWrite: true, + assertCommandSucceeded: function(db, dbName, collName) { + assert.eq(countDocs(db, collName, Object.assign({y: 0}, kTestDoc)), 1); + }, + assertCommandFailed: function(db, dbName, collName) { + assert.eq(countDocs(db, collName, Object.assign({y: 0}, kTestDoc)), 0); + } }, - isBatchWrite: true, - isMultiUpdate: true, - assertCommandSucceeded: function(db, dbName, collName) { - assert.eq(countDocs(db, collName, Object.assign({y: 0})), 2); + multiUpdate: { + testInTransaction: true, + testAsRetryableWrite: false, + setUp: insertTwoTestDocs, + command: function(dbName, collName) { + return { + update: collName, + updates: [{q: {}, u: {$set: {y: 0}}, upsert: false, multi: true}] + }; + }, + isBatchWrite: true, + isMultiUpdate: true, + assertCommandSucceeded: function(db, dbName, collName) { + assert.eq(countDocs(db, collName, Object.assign({y: 0})), 2); + }, + assertCommandFailed: function(db, dbName, collName) { + assert.eq(countDocs(db, collName, Object.assign({y: 0})), 0); + } }, - assertCommandFailed: function(db, dbName, collName) { - assert.eq(countDocs(db, collName, Object.assign({y: 0})), 0); - } - }, - updateRole: {skip: isAuthCommand}, - updateUser: {skip: isNotRunOnUserDatabase}, - usersInfo: {skip: isNotRunOnUserDatabase}, - validate: {skip: isNotWriteCommand}, - voteCommitIndexBuild: {skip: isNotRunOnUserDatabase}, - waitForFailPoint: {skip: isNotRunOnUserDatabase}, - waitForOngoingChunkSplits: {skip: isNotRunOnUserDatabase}, - whatsmysni: {skip: isNotRunOnUserDatabase}, - whatsmyuri: {skip: isNotRunOnUserDatabase} + updateRole: {skip: isAuthCommand}, + updateUser: {skip: isNotRunOnUserDatabase}, + usersInfo: {skip: isNotRunOnUserDatabase}, + validate: {skip: isNotWriteCommand}, + voteCommitIndexBuild: {skip: isNotRunOnUserDatabase}, + waitForFailPoint: {skip: isNotRunOnUserDatabase}, + waitForOngoingChunkSplits: {skip: isNotRunOnUserDatabase}, + whatsmysni: {skip: isNotRunOnUserDatabase}, + whatsmyuri: {skip: isNotRunOnUserDatabase} + } }; function validateTestCase(testCase) { diff --git a/jstests/replsets/tenant_migration_concurrent_writes_on_recipient.js b/jstests/replsets/tenant_migration_concurrent_writes_on_recipient.js index c2acc7b800b..5ce9f27a128 100644 --- a/jstests/replsets/tenant_migration_concurrent_writes_on_recipient.js +++ b/jstests/replsets/tenant_migration_concurrent_writes_on_recipient.js @@ -11,14 +11,16 @@ * ] */ -(function() { -'use strict'; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + isShardMergeEnabled, + runMigrationAsync +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load("jstests/replsets/rslib.js"); // 'createRstArgs' const tenantMigrationTest = new TenantMigrationTest({name: jsTestName(), quickGarbageCollection: true}); @@ -57,13 +59,12 @@ function cleanup(dbName) { let waitForRejectReadsBeforeTsFp = configureFailPoint( recipientPrimary, "fpAfterWaitForRejectReadsBeforeTimestamp", {action: "hang"}); - const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst); - const runMigrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); + const donorRstArgs = createRstArgs(donorRst); + const runMigrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); runMigrationThread.start(); startOplogFetcherFp.wait(); - if (!TenantMigrationUtil.isShardMergeEnabled(donorPrimary.getDB("adminDB"))) { + if (!isShardMergeEnabled(donorPrimary.getDB("adminDB"))) { // Write before cloning is done. assert.commandFailedWithCode(tenantCollOnRecipient.remove({_id: 1}), ErrorCodes.SnapshotTooOld); @@ -178,4 +179,3 @@ function cleanup(dbName) { cleanup(donorDB); })(); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_conflicting_donor_start_migration_cmds.js b/jstests/replsets/tenant_migration_conflicting_donor_start_migration_cmds.js index a5be8afa983..9cbd20de21f 100644 --- a/jstests/replsets/tenant_migration_conflicting_donor_start_migration_cmds.js +++ b/jstests/replsets/tenant_migration_conflicting_donor_start_migration_cmds.js @@ -10,11 +10,15 @@ * serverless, * ] */ -(function() { -'use strict'; + +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + getCertificateAndPrivateKey, + isShardMergeEnabled, + makeX509OptionsForTest, +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); function getRecipientSyncDataMetrics(recipientPrimary) { return recipientPrimary.adminCommand({serverStatus: 1}).metrics.commands.recipientSyncData; @@ -47,7 +51,7 @@ function assertNoCertificateOrPrivateKey(string) { assert(!string.includes("PRIVATE KEY"), "found private key"); } -const {donor: donorNodeOptions} = TenantMigrationUtil.makeX509OptionsForTest(); +const {donor: donorNodeOptions} = makeX509OptionsForTest(); donorNodeOptions.setParameter = donorNodeOptions.setParameter || {}; Object.assign(donorNodeOptions.setParameter, { tenantMigrationGarbageCollectionDelayMS: 1 * 1000, @@ -270,7 +274,7 @@ function testConcurrentConflictingMigrations({ // Test different tenantIds. (() => { - if (TenantMigrationUtil.isShardMergeEnabled(donorPrimary.getDB("admin"))) { + if (isShardMergeEnabled(donorPrimary.getDB("admin"))) { jsTestLog( "Skip: featureFlagShardMerge is enabled and this test tests migrations with different tenant ids."); return; @@ -325,7 +329,7 @@ function testConcurrentConflictingMigrations({ // Test different cloning read preference. (() => { - if (TenantMigrationUtil.isShardMergeEnabled(donorPrimary.getDB("admin"))) { + if (isShardMergeEnabled(donorPrimary.getDB("admin"))) { jsTestLog( "Skip: featureFlagShardMerge is enabled and this test tests migration's secondary read preference."); return; @@ -351,13 +355,13 @@ function testConcurrentConflictingMigrations({ })(); const kDonorCertificateAndPrivateKey = - TenantMigrationUtil.getCertificateAndPrivateKey("jstests/libs/tenant_migration_donor.pem"); -const kExpiredDonorCertificateAndPrivateKey = TenantMigrationUtil.getCertificateAndPrivateKey( - "jstests/libs/tenant_migration_donor_expired.pem"); + getCertificateAndPrivateKey("jstests/libs/tenant_migration_donor.pem"); +const kExpiredDonorCertificateAndPrivateKey = + getCertificateAndPrivateKey("jstests/libs/tenant_migration_donor_expired.pem"); const kRecipientCertificateAndPrivateKey = - TenantMigrationUtil.getCertificateAndPrivateKey("jstests/libs/tenant_migration_recipient.pem"); -const kExpiredRecipientCertificateAndPrivateKey = TenantMigrationUtil.getCertificateAndPrivateKey( - "jstests/libs/tenant_migration_recipient_expired.pem"); + getCertificateAndPrivateKey("jstests/libs/tenant_migration_recipient.pem"); +const kExpiredRecipientCertificateAndPrivateKey = + getCertificateAndPrivateKey("jstests/libs/tenant_migration_recipient_expired.pem"); // Test different donor certificates. (() => { @@ -408,4 +412,3 @@ const kExpiredRecipientCertificateAndPrivateKey = TenantMigrationUtil.getCertifi })(); teardown(); -})(); diff --git a/jstests/replsets/tenant_migration_conflicting_recipient_sync_data_cmds.js b/jstests/replsets/tenant_migration_conflicting_recipient_sync_data_cmds.js index a8278e285dc..e916860da16 100644 --- a/jstests/replsets/tenant_migration_conflicting_recipient_sync_data_cmds.js +++ b/jstests/replsets/tenant_migration_conflicting_recipient_sync_data_cmds.js @@ -10,16 +10,18 @@ * serverless, * ] */ -(function() { -"use strict"; +import { + getCertificateAndPrivateKey, + makeX509OptionsForTest +} from "jstests/replsets/libs/tenant_migration_util.js"; + +load("jstests/libs/fail_point_util.js"); load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); -var rst = - new ReplSetTest({nodes: 1, nodeOptions: TenantMigrationUtil.makeX509OptionsForTest().donor}); +var rst = new ReplSetTest({nodes: 1, nodeOptions: makeX509OptionsForTest().donor}); rst.startSet(); rst.initiate(); const primary = rst.getPrimary(); @@ -35,9 +37,9 @@ const kSecondaryReadPreference = { mode: "secondary" }; const kRecipientCertificateForDonor = - TenantMigrationUtil.getCertificateAndPrivateKey("jstests/libs/tenant_migration_recipient.pem"); -const kExpiredRecipientCertificateForDonor = TenantMigrationUtil.getCertificateAndPrivateKey( - "jstests/libs/tenant_migration_recipient_expired.pem"); + getCertificateAndPrivateKey("jstests/libs/tenant_migration_recipient.pem"); +const kExpiredRecipientCertificateForDonor = + getCertificateAndPrivateKey("jstests/libs/tenant_migration_recipient_expired.pem"); TestData.stopFailPointErrorCode = 4880402; @@ -296,4 +298,3 @@ function testConcurrentConflictingMigration(migrationOpts0, migrationOpts1) { })(); rst.stopSet(); -})(); diff --git a/jstests/replsets/tenant_migration_donor_abort_state_transition.js b/jstests/replsets/tenant_migration_donor_abort_state_transition.js index 2cb3de475e2..34541c6f078 100644 --- a/jstests/replsets/tenant_migration_donor_abort_state_transition.js +++ b/jstests/replsets/tenant_migration_donor_abort_state_transition.js @@ -9,14 +9,14 @@ * serverless, * ] */ -(function() { -"use strict"; + +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {runMigrationAsync} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); load("jstests/libs/parallelTester.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load("jstests/replsets/rslib.js"); // 'createRstArgs' /** * Starts a migration and forces the write to insert the donor's state doc to abort on the first few @@ -43,12 +43,11 @@ function testAbortInitialState() { recipientConnString: tenantMigrationTest.getRecipientConnString(), }; - const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst); + const donorRstArgs = createRstArgs(donorRst); // Run the migration in its own thread, since the initial 'donorStartMigration' command will // hang due to the failpoint. - let migrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); + let migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); migrationThread.start(); writeConflictFp.wait(); @@ -149,4 +148,3 @@ jsTest.log("Test aborting donor's state doc update"); }].forEach(({pauseFailPoint, setUpFailPoints = [], nextState}) => { testAbortStateTransition(pauseFailPoint, setUpFailPoints, nextState); }); -}()); diff --git a/jstests/replsets/tenant_migration_donor_current_op.js b/jstests/replsets/tenant_migration_donor_current_op.js index 6c922ff185f..62c17b21862 100644 --- a/jstests/replsets/tenant_migration_donor_current_op.js +++ b/jstests/replsets/tenant_migration_donor_current_op.js @@ -12,13 +12,11 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {isShardMergeEnabled} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); // An object that mirrors the donor migration states. const migrationStates = { @@ -50,8 +48,7 @@ function checkStandardFieldsOK(ops, { assert(op.migrationStart instanceof Date); assert.eq(op.recipientConnectionString, tenantMigrationTest.getRecipientRst().getURL()); - if (TenantMigrationUtil.isShardMergeEnabled( - tenantMigrationTest.getDonorPrimary().getDB("admin"))) { + if (isShardMergeEnabled(tenantMigrationTest.getDonorPrimary().getDB("admin"))) { assert.eq(op.tenantId, undefined); } else { assert.eq(bsonWoCompare(op.tenantId, kTenantId), 0); @@ -237,4 +234,3 @@ function checkStandardFieldsOK(ops, { tenantMigrationTest.stop(); })(); -})(); diff --git a/jstests/replsets/tenant_migration_donor_directly_deletes_its_state_doc.js b/jstests/replsets/tenant_migration_donor_directly_deletes_its_state_doc.js index e90a8ab4ce7..2646c9c2943 100644 --- a/jstests/replsets/tenant_migration_donor_directly_deletes_its_state_doc.js +++ b/jstests/replsets/tenant_migration_donor_directly_deletes_its_state_doc.js @@ -14,12 +14,9 @@ * ] */ -(function() { -"use strict"; - +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); (() => { jsTest.log("Test case where the TTL monitor deletes the state doc first"); @@ -136,4 +133,3 @@ load("jstests/replsets/libs/tenant_migration_test.js"); tmt.stop(); })(); -})(); diff --git a/jstests/replsets/tenant_migration_donor_initial_sync_cloning.js b/jstests/replsets/tenant_migration_donor_initial_sync_cloning.js index cafe4f72af1..4f3971a1cee 100644 --- a/jstests/replsets/tenant_migration_donor_initial_sync_cloning.js +++ b/jstests/replsets/tenant_migration_donor_initial_sync_cloning.js @@ -24,12 +24,9 @@ * ] */ -(function() { -"use strict"; - +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); load('jstests/replsets/rslib.js'); // for waitForNewlyAddedRemovalForNodeToBeCommitted const testDBName = 'testDB'; @@ -111,4 +108,3 @@ TenantMigrationTest.assertCommitted(tenantMigrationTest.waitForMigrationToComple assert.commandWorked(tenantMigrationTest.forgetMigration(migrationOpts.migrationIdString)); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_donor_initial_sync_recovery.js b/jstests/replsets/tenant_migration_donor_initial_sync_recovery.js index f8943e56854..4d08a30524a 100644 --- a/jstests/replsets/tenant_migration_donor_initial_sync_recovery.js +++ b/jstests/replsets/tenant_migration_donor_initial_sync_recovery.js @@ -12,15 +12,16 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + getServerlessOperationLock, + ServerlessLockType +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/write_concern_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -const {ServerlessLockType, getServerlessOperationLock} = TenantMigrationUtil; const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()}); @@ -174,4 +175,3 @@ if (kMigrationFpNames[index] === "abortTenantMigrationBeforeLeavingBlockingState } assert.commandWorked(tenantMigrationTest.forgetMigration(migrationOpts.migrationIdString)); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_donor_interrupt_on_stepdown_and_shutdown.js b/jstests/replsets/tenant_migration_donor_interrupt_on_stepdown_and_shutdown.js index d5eba83be7c..d423aa0e02c 100644 --- a/jstests/replsets/tenant_migration_donor_interrupt_on_stepdown_and_shutdown.js +++ b/jstests/replsets/tenant_migration_donor_interrupt_on_stepdown_and_shutdown.js @@ -10,14 +10,18 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + forgetMigrationAsync, + isShardMergeEnabled, + runMigrationAsync, + tryAbortMigrationAsync +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load("jstests/replsets/rslib.js"); // 'createRstArgs' const kMaxSleepTimeMS = 100; const kTenantId = "testTenantId"; @@ -39,7 +43,7 @@ function testDonorStartMigrationInterrupt(interruptFunc, verifyCmdResponseFunc) const donorRst = tenantMigrationTest.getDonorRst(); const donorPrimary = tenantMigrationTest.getDonorPrimary(); - if (TenantMigrationUtil.isShardMergeEnabled(donorPrimary.getDB("admin"))) { + if (isShardMergeEnabled(donorPrimary.getDB("admin"))) { // TODO SERVER-63390: Remove this conditional and ensure test(s) run // successfully for shard merge. jsTestLog("Skipping Shard Merge-incompatible test"); @@ -54,10 +58,9 @@ function testDonorStartMigrationInterrupt(interruptFunc, verifyCmdResponseFunc) recipientConnString: tenantMigrationTest.getRecipientConnString(), }; - const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst); + const donorRstArgs = createRstArgs(donorRst); - const runMigrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); + const runMigrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); runMigrationThread.start(); // Wait for donorStartMigration command to start. @@ -82,7 +85,7 @@ function testDonorForgetMigrationInterrupt(interruptFunc, verifyCmdResponseFunc) const donorRst = tenantMigrationTest.getDonorRst(); const donorPrimary = tenantMigrationTest.getDonorPrimary(); - if (TenantMigrationUtil.isShardMergeEnabled(donorPrimary.getDB("admin"))) { + if (isShardMergeEnabled(donorPrimary.getDB("admin"))) { // TODO SERVER-63390: Remove this conditional and ensure test(s) run // successfully for shard merge. jsTestLog("Skipping Shard Merge-incompatible test"); @@ -97,12 +100,12 @@ function testDonorForgetMigrationInterrupt(interruptFunc, verifyCmdResponseFunc) recipientConnString: tenantMigrationTest.getRecipientConnString(), }; - const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst); + const donorRstArgs = createRstArgs(donorRst); TenantMigrationTest.assertCommitted( tenantMigrationTest.runMigration(migrationOpts, {automaticForgetMigration: false})); - const forgetMigrationThread = new Thread( - TenantMigrationUtil.forgetMigrationAsync, migrationOpts.migrationIdString, donorRstArgs); + const forgetMigrationThread = + new Thread(forgetMigrationAsync, migrationOpts.migrationIdString, donorRstArgs); forgetMigrationThread.start(); // Wait for the donorForgetMigration command to start. @@ -130,7 +133,7 @@ function testDonorAbortMigrationInterrupt(interruptFunc, verifyCmdResponseFunc, const donorRst = tenantMigrationTest.getDonorRst(); const donorPrimary = tenantMigrationTest.getDonorPrimary(); - if (TenantMigrationUtil.isShardMergeEnabled(donorPrimary.getDB("admin"))) { + if (isShardMergeEnabled(donorPrimary.getDB("admin"))) { // TODO SERVER-63390: Remove this conditional and ensure test(s) run // successfully for shard merge. jsTestLog("Skipping Shard Merge-incompatible test"); @@ -145,7 +148,7 @@ function testDonorAbortMigrationInterrupt(interruptFunc, verifyCmdResponseFunc, recipientConnString: tenantMigrationTest.getRecipientConnString(), }; - const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst); + const donorRstArgs = createRstArgs(donorRst); // If we passed in a valid failpoint we set it, otherwise we let the migration run normally. if (fpName) { @@ -154,9 +157,8 @@ function testDonorAbortMigrationInterrupt(interruptFunc, verifyCmdResponseFunc, assert.commandWorked(tenantMigrationTest.startMigration(migrationOpts)); - const tryAbortThread = new Thread(TenantMigrationUtil.tryAbortMigrationAsync, - {migrationIdString: migrationOpts.migrationIdString}, - donorRstArgs); + const tryAbortThread = new Thread( + tryAbortMigrationAsync, {migrationIdString: migrationOpts.migrationIdString}, donorRstArgs); tryAbortThread.start(); // Wait for donorAbortMigration command to start. @@ -260,4 +262,3 @@ function assertCmdSucceededOrInterruptedDueToShutDown(cmdThread) { }, assertCmdSucceededOrInterruptedDueToShutDown, fpName); }); })(); -})(); diff --git a/jstests/replsets/tenant_migration_donor_kill_op_retry.js b/jstests/replsets/tenant_migration_donor_kill_op_retry.js index 2b747d21130..69dc32f9853 100644 --- a/jstests/replsets/tenant_migration_donor_kill_op_retry.js +++ b/jstests/replsets/tenant_migration_donor_kill_op_retry.js @@ -11,20 +11,23 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + createTenantMigrationDonorRoleIfNotExist, + createTenantMigrationRecipientRoleIfNotExist, + forgetMigrationAsync, + makeX509OptionsForTest, + runMigrationAsync +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load("jstests/replsets/rslib.js"); // 'createRstArgs' const kGarbageCollectionDelayMS = 5 * 1000; -const kDelayMS = 100000; // Set some arbitrarily large blockTimeMS to let recipientSyncData command - // hang until we use kill op to kill it. -const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); +const migrationX509Options = makeX509OptionsForTest(); const garbageCollectionOpts = { // Set the delay before a donor state doc is garbage collected to be short to speed // up the test. @@ -59,10 +62,9 @@ function makeTenantId() { const donorPrimary = tenantMigrationTest.getDonorPrimary(); let fp = configureFailPoint(donorPrimary, fpName); - const donorRstArgs = TenantMigrationUtil.createRstArgs(tenantMigrationTest.getDonorRst()); + const donorRstArgs = createRstArgs(tenantMigrationTest.getDonorRst()); - const runMigrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); + const runMigrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); runMigrationThread.start(); fp.wait(); @@ -103,8 +105,7 @@ function makeTenantId() { // waits for a rebuild, which is why this test is tagged as 'multiversion_incompatible'. tenantMigrationTest.getDonorRst().initiate( null, null, {doNotWaitForPrimaryOnlyServices: true}); - TenantMigrationUtil.createTenantMigrationRecipientRoleIfNotExist( - tenantMigrationTest.getDonorRst()); + createTenantMigrationRecipientRoleIfNotExist(tenantMigrationTest.getDonorRst()); jsTestLog( "Setting failpoint \"" + fpName + @@ -118,9 +119,8 @@ function makeTenantId() { }; const donorPrimary = tenantMigrationTest.getDonorPrimary(); - const donorRstArgs = TenantMigrationUtil.createRstArgs(tenantMigrationTest.getDonorRst()); - const runMigrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); + const donorRstArgs = createRstArgs(tenantMigrationTest.getDonorRst()); + const runMigrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); runMigrationThread.start(); const res = assert.commandWorked(donorPrimary.adminCommand({ @@ -154,15 +154,13 @@ function makeTenantId() { tenantMigrationTest.getDonorRst().startSet( Object.assign({}, migrationX509Options.donor, {setParameter: garbageCollectionOpts})); tenantMigrationTest.getDonorRst().initiate(); - TenantMigrationUtil.createTenantMigrationRecipientRoleIfNotExist( - tenantMigrationTest.getDonorRst()); + createTenantMigrationRecipientRoleIfNotExist(tenantMigrationTest.getDonorRst()); tenantMigrationTest.getRecipientRst().stopSet(); tenantMigrationTest.getRecipientRst().startSet(Object.assign( {}, migrationX509Options.recipient, {setParameter: garbageCollectionOpts})); tenantMigrationTest.getRecipientRst().initiate(); - TenantMigrationUtil.createTenantMigrationDonorRoleIfNotExist( - tenantMigrationTest.getRecipientRst()); + createTenantMigrationDonorRoleIfNotExist(tenantMigrationTest.getRecipientRst()); jsTestLog( "Setting failpoint \"" + fpName + @@ -182,10 +180,9 @@ function makeTenantId() { tenantMigrationTest.runMigration(migrationOpts, {automaticForgetMigration: false})); const donorPrimary = tenantMigrationTest.getDonorPrimary(); - const donorRstArgs = TenantMigrationUtil.createRstArgs(tenantMigrationTest.getDonorRst()); - const forgetMigrationThread = new Thread(TenantMigrationUtil.forgetMigrationAsync, - migrationOpts.migrationIdString, - donorRstArgs); + const donorRstArgs = createRstArgs(tenantMigrationTest.getDonorRst()); + const forgetMigrationThread = + new Thread(forgetMigrationAsync, migrationOpts.migrationIdString, donorRstArgs); forgetMigrationThread.start(); fp.wait(); @@ -205,4 +202,3 @@ function makeTenantId() { tenantMigrationTest.stop(); } } -})(); diff --git a/jstests/replsets/tenant_migration_donor_resume_on_stepup_and_restart.js b/jstests/replsets/tenant_migration_donor_resume_on_stepup_and_restart.js index d6cbe11b703..f6db7adcdac 100644 --- a/jstests/replsets/tenant_migration_donor_resume_on_stepup_and_restart.js +++ b/jstests/replsets/tenant_migration_donor_resume_on_stepup_and_restart.js @@ -16,14 +16,19 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + forgetMigrationAsync, + isShardMergeEnabled, + makeX509OptionsForTest, + runMigrationAsync, + tryAbortMigrationAsync +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load("jstests/replsets/rslib.js"); // 'createRstArgs' const kMaxSleepTimeMS = 100; const kTenantId = "testTenantId"; @@ -41,7 +46,7 @@ const kGarbageCollectionDelayMS = 30 * 1000; // Set the TTL monitor to run at a smaller interval to speed up the test. const kTTLMonitorSleepSecs = 1; -const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); +const migrationX509Options = makeX509OptionsForTest(); /** * Runs the donorStartMigration command to start a migration, and interrupts the migration on the @@ -60,8 +65,7 @@ function testDonorStartMigrationInterrupt(interruptFunc, let donorPrimary = tenantMigrationTest.getDonorPrimary(); const recipientPrimary = tenantMigrationTest.getRecipientPrimary(); - if (disableForShardMerge && - TenantMigrationUtil.isShardMergeEnabled(recipientPrimary.getDB("admin"))) { + if (disableForShardMerge && isShardMergeEnabled(recipientPrimary.getDB("admin"))) { jsTest.log("Skipping test for shard merge"); tenantMigrationTest.stop(); donorRst.stopSet(); @@ -74,12 +78,10 @@ function testDonorStartMigrationInterrupt(interruptFunc, tenantId: kTenantId, recipientConnString: tenantMigrationTest.getRecipientConnString(), }; - const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst); + const donorRstArgs = createRstArgs(donorRst); - const runMigrationThread = new Thread(TenantMigrationUtil.runMigrationAsync, - migrationOpts, - donorRstArgs, - {retryOnRetryableErrors: true}); + const runMigrationThread = + new Thread(runMigrationAsync, migrationOpts, donorRstArgs, {retryOnRetryableErrors: true}); runMigrationThread.start(); // Wait for donorStartMigration command to start. @@ -161,11 +163,11 @@ function testDonorForgetMigrationInterrupt(interruptFunc) { tenantId: kTenantId, recipientConnString: recipientRst.getURL(), }; - const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst); + const donorRstArgs = createRstArgs(donorRst); TenantMigrationTest.assertCommitted( tenantMigrationTest.runMigration(migrationOpts, {automaticForgetMigration: false})); - const forgetMigrationThread = new Thread(TenantMigrationUtil.forgetMigrationAsync, + const forgetMigrationThread = new Thread(forgetMigrationAsync, migrationOpts.migrationIdString, donorRstArgs, true /* retryOnRetryableErrors */); @@ -235,7 +237,7 @@ function testDonorAbortMigrationInterrupt( tenantId: kTenantId, recipientConnString: recipientRst.getURL(), }; - const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst); + const donorRstArgs = createRstArgs(donorRst); let donorPrimary = tenantMigrationTest.getDonorPrimary(); // If we passed in a valid failpoint we set it, otherwise we let the migration run normally. @@ -250,7 +252,7 @@ function testDonorAbortMigrationInterrupt( fp.wait(); } - const tryAbortThread = new Thread(TenantMigrationUtil.tryAbortMigrationAsync, + const tryAbortThread = new Thread(tryAbortMigrationAsync, {migrationIdString: migrationOpts.migrationIdString}, donorRstArgs, true /* retryOnRetryableErrors */); @@ -480,4 +482,3 @@ function testStateDocPersistenceOnFailover(interruptFunc, fpName, isShutdown = f }, fpName); }); })(); -})(); diff --git a/jstests/replsets/tenant_migration_donor_retry.js b/jstests/replsets/tenant_migration_donor_retry.js index c81a08e85b8..02264a41445 100644 --- a/jstests/replsets/tenant_migration_donor_retry.js +++ b/jstests/replsets/tenant_migration_donor_retry.js @@ -12,14 +12,16 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + makeX509OptionsForTest, + runMigrationAsync +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load("jstests/replsets/rslib.js"); // 'createRstArgs' const kTenantIdPrefix = "testTenantId"; let testNum = 0; @@ -28,7 +30,7 @@ function setup() { const donorRst = new ReplSetTest({ name: "donorRst", nodes: 1, - nodeOptions: Object.assign(TenantMigrationUtil.makeX509OptionsForTest().donor, { + nodeOptions: Object.assign(makeX509OptionsForTest().donor, { setParameter: { // Set the delay before a donor state doc is garbage collected to be short to speed // up the test. @@ -247,12 +249,11 @@ const kWriteErrorTimeMS = 50; collectionNS: TenantMigrationTest.kConfigDonorsNS, }); - const donorRstArgs = TenantMigrationUtil.createRstArgs(tenantMigrationTest.getDonorRst()); + const donorRstArgs = createRstArgs(tenantMigrationTest.getDonorRst()); // Start up a new thread to run this migration, since the 'failCollectionInserts' failpoint will // cause the initial 'donorStartMigration' command to loop forever without returning. - const migrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); + const migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); migrationThread.start(); // Make the insert keep failing for some time. @@ -284,7 +285,7 @@ const kWriteErrorTimeMS = 50; recipientConnString: tenantMigrationTest.getRecipientConnString(), }; - const donorRstArgs = TenantMigrationUtil.createRstArgs(tenantMigrationTest.getDonorRst()); + const donorRstArgs = createRstArgs(tenantMigrationTest.getDonorRst()); // Use a random number of skips to fail a random update to config.tenantMigrationDonors. const fp = configureFailPoint(tenantMigrationTest.getDonorPrimary(), @@ -296,11 +297,12 @@ const kWriteErrorTimeMS = 50; // Start up a new thread to run this migration, since we want to continuously send // 'donorStartMigration' commands while the 'failCollectionUpdates' failpoint is on. - const migrationThread = new Thread((migrationOpts, donorRstArgs) => { - load("jstests/replsets/libs/tenant_migration_util.js"); - assert.commandWorked(TenantMigrationUtil.runMigrationAsync(migrationOpts, donorRstArgs)); - assert.commandWorked(TenantMigrationUtil.forgetMigrationAsync( - migrationOpts.migrationIdString, donorRstArgs)); + const migrationThread = new Thread(async (migrationOpts, donorRstArgs) => { + const {runMigrationAsync, forgetMigrationAsync} = + await import("jstests/replsets/libs/tenant_migration_util.js"); + assert.commandWorked(await runMigrationAsync(migrationOpts, donorRstArgs)); + assert.commandWorked( + await forgetMigrationAsync(migrationOpts.migrationIdString, donorRstArgs)); }, migrationOpts, donorRstArgs); migrationThread.start(); @@ -316,4 +318,3 @@ const kWriteErrorTimeMS = 50; teardown(); })(); -})(); diff --git a/jstests/replsets/tenant_migration_donor_rollback_during_cloning.js b/jstests/replsets/tenant_migration_donor_rollback_during_cloning.js index 7451055c3aa..1f124b70b81 100644 --- a/jstests/replsets/tenant_migration_donor_rollback_during_cloning.js +++ b/jstests/replsets/tenant_migration_donor_rollback_during_cloning.js @@ -15,16 +15,14 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {makeX509OptionsForTest} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); // for 'extractUUIDFromObject' load("jstests/libs/write_concern_util.js"); // for 'stopReplicationOnSecondaries' -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); -const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); +const migrationX509Options = makeX509OptionsForTest(); const recipientRst = new ReplSetTest({name: "recipientRst", nodes: 1, nodeOptions: migrationX509Options.recipient}); @@ -353,4 +351,3 @@ runTest('tenantId3', "tenantCollectionClonerHangAfterGettingOperationTime"); recipientRst.stopSet(); -})(); diff --git a/jstests/replsets/tenant_migration_donor_rollback_recovery.js b/jstests/replsets/tenant_migration_donor_rollback_recovery.js index 9c12c0c8c30..8c4ddd86e60 100644 --- a/jstests/replsets/tenant_migration_donor_rollback_recovery.js +++ b/jstests/replsets/tenant_migration_donor_rollback_recovery.js @@ -12,15 +12,19 @@ * serverless, * ] */ -(function() { -"use strict"; + +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + forgetMigrationAsync, + makeX509OptionsForTest, + runMigrationAsync, +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/replsets/libs/rollback_test.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load("jstests/replsets/rslib.js"); // 'createRstArgs' const kTenantId = ObjectId().str; @@ -31,7 +35,7 @@ const kMaxSleepTimeMS = 250; // state. const kGarbageCollectionDelayMS = 30 * 1000; -const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); +const migrationX509Options = makeX509OptionsForTest(); const recipientRst = new ReplSetTest({ name: "recipientRst", @@ -83,7 +87,7 @@ function testRollBack(setUpFunc, rollbackOpsFunc, steadyStateFunc) { const tenantMigrationTest = new TenantMigrationTest({name: jsTestName(), donorRst, recipientRst}); - const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst); + const donorRstArgs = createRstArgs(donorRst); setUpFunc(tenantMigrationTest, donorRstArgs); let originalDonorPrimary = donorRst.getPrimary(); @@ -129,10 +133,8 @@ function testRollbackInitialState() { const donorPrimary = tenantMigrationTest.getDonorPrimary(); // Start the migration asynchronously and wait for the primary to insert the state doc. - migrationThread = new Thread(TenantMigrationUtil.runMigrationAsync, - migrationOpts, - donorRstArgs, - {retryOnRetryableErrors: true}); + migrationThread = new Thread( + runMigrationAsync, migrationOpts, donorRstArgs, {retryOnRetryableErrors: true}); migrationThread.start(); assert.soon(() => { return 1 === donorPrimary.getCollection(TenantMigrationTest.kConfigDonorsNS).count({ @@ -175,10 +177,8 @@ function testRollBackStateTransition(pauseFailPoint, setUpFailPoints, nextState) setUpFailPoints.forEach(failPoint => configureFailPoint(donorPrimary, failPoint)); pauseFp = configureFailPoint(donorPrimary, pauseFailPoint); - migrationThread = new Thread(TenantMigrationUtil.runMigrationAsync, - migrationOpts, - donorRstArgs, - {retryOnRetryableErrors: true}); + migrationThread = new Thread( + runMigrationAsync, migrationOpts, donorRstArgs, {retryOnRetryableErrors: true}); migrationThread.start(); pauseFp.wait(); }; @@ -230,7 +230,7 @@ function testRollBackMarkingStateGarbageCollectable() { // Run donorForgetMigration and wait for the primary to do the write to mark the state doc // as garbage collectable. - forgetMigrationThread = new Thread(TenantMigrationUtil.forgetMigrationAsync, + forgetMigrationThread = new Thread(forgetMigrationAsync, migrationOpts.migrationIdString, donorRstArgs, true /* retryOnRetryableErrors */); @@ -273,11 +273,12 @@ function testRollBackRandom() { let migrationThread; let setUpFunc = (tenantMigrationTest, donorRstArgs) => { - migrationThread = new Thread((donorRstArgs, migrationOpts) => { - load("jstests/replsets/libs/tenant_migration_util.js"); - assert.commandWorked(TenantMigrationUtil.runMigrationAsync( + migrationThread = new Thread(async (donorRstArgs, migrationOpts) => { + const {runMigrationAsync, forgetMigrationAsync} = + await import("jstests/replsets/libs/tenant_migration_util.js"); + assert.commandWorked(await runMigrationAsync( migrationOpts, donorRstArgs, {retryOnRetryableErrors: true})); - assert.commandWorked(TenantMigrationUtil.forgetMigrationAsync( + assert.commandWorked(await forgetMigrationAsync( migrationOpts.migrationIdString, donorRstArgs, true /* retryOnRetryableErrors */)); }, donorRstArgs, migrationOpts); @@ -328,4 +329,3 @@ jsTest.log("Test roll back random"); testRollBackRandom(); recipientRst.stopSet(); -}()); diff --git a/jstests/replsets/tenant_migration_donor_shutdown_while_blocking_reads.js b/jstests/replsets/tenant_migration_donor_shutdown_while_blocking_reads.js index eb992df328f..010408b8d49 100644 --- a/jstests/replsets/tenant_migration_donor_shutdown_while_blocking_reads.js +++ b/jstests/replsets/tenant_migration_donor_shutdown_while_blocking_reads.js @@ -11,14 +11,12 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {getNumBlockedReads} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/parallelTester.js"); load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()}); @@ -62,10 +60,9 @@ let readThread = new Thread((host, dbName, collName, afterClusterTime) => { readThread.start(); // Shut down the donor after the read starts blocking. -assert.soon(() => TenantMigrationUtil.getNumBlockedReads(donorPrimary, kTenantId) == 1); +assert.soon(() => getNumBlockedReads(donorPrimary, kTenantId) == 1); donorRst.stop(donorPrimary); readThread.join(); donorRst.stopSet(); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_donor_startup_recovery.js b/jstests/replsets/tenant_migration_donor_startup_recovery.js index 7dbbcb56f8c..16c5139adea 100644 --- a/jstests/replsets/tenant_migration_donor_startup_recovery.js +++ b/jstests/replsets/tenant_migration_donor_startup_recovery.js @@ -15,18 +15,20 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {makeX509OptionsForTest} from "jstests/replsets/libs/tenant_migration_util.js"; +import { + getServerlessOperationLock, + ServerlessLockType +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -const {ServerlessLockType, getServerlessOperationLock} = TenantMigrationUtil; const donorRst = new ReplSetTest({ nodes: 1, name: 'donor', - nodeOptions: Object.assign(TenantMigrationUtil.makeX509OptionsForTest().donor, { + nodeOptions: Object.assign(makeX509OptionsForTest().donor, { setParameter: // In order to deterministically validate that in-memory state is preserved during // recovery, this failpoint prevents active migrations from continuing on process @@ -145,4 +147,3 @@ if (donorDoc && !donorDoc.expireAt) { tenantMigrationTest.stop(); donorRst.stopSet(); -})(); diff --git a/jstests/replsets/tenant_migration_donor_state_machine.js b/jstests/replsets/tenant_migration_donor_state_machine.js index 9ce4fa86f28..fddbafa7051 100644 --- a/jstests/replsets/tenant_migration_donor_state_machine.js +++ b/jstests/replsets/tenant_migration_donor_state_machine.js @@ -13,12 +13,15 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + getTenantMigrationAccessBlocker, + isShardMergeEnabled, + makeX509OptionsForTest, +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); let expectedNumRecipientSyncDataCmdSent = 0; let expectedNumRecipientForgetMigrationCmdSent = 0; @@ -45,8 +48,7 @@ function testDonorForgetMigrationAfterMigrationCompletes( // Wait for garbage collection on donor. donorRst.nodes.forEach((node) => { - assert.soon(() => null == - TenantMigrationUtil.getTenantMigrationAccessBlocker({donorNode: node})); + assert.soon(() => null == getTenantMigrationAccessBlocker({donorNode: node})); }); assert.soon(() => 0 === donorPrimary.getCollection(TenantMigrationTest.kConfigDonorsNS).count({ @@ -62,8 +64,7 @@ function testDonorForgetMigrationAfterMigrationCompletes( // Wait for garbage collection on recipient. recipientRst.nodes.forEach((node) => { - assert.soon(() => null == - TenantMigrationUtil.getTenantMigrationAccessBlocker({recipientNode: node})); + assert.soon(() => null == getTenantMigrationAccessBlocker({recipientNode: node})); }); assert.soon(() => 0 === @@ -86,7 +87,7 @@ const sharedOptions = { ttlMonitorSleepSecs: 1, } }; -const x509Options = TenantMigrationUtil.makeX509OptionsForTest(); +const x509Options = makeX509OptionsForTest(); const donorRst = new ReplSetTest({ nodes: [{}, {rsConfig: {priority: 0}}, {rsConfig: {priority: 0}}], @@ -144,8 +145,7 @@ function testStats(node, { // Wait for the migration to enter the blocking state. blockingFp.wait(); - let mtab = TenantMigrationUtil.getTenantMigrationAccessBlocker( - {donorNode: donorPrimary, tenantId: kTenantId}); + let mtab = getTenantMigrationAccessBlocker({donorNode: donorPrimary, tenantId: kTenantId}); assert.eq(mtab.donor.state, TenantMigrationTest.DonorAccessState.kBlockWritesAndReads); assert(mtab.donor.blockTimestamp); @@ -158,7 +158,7 @@ function testStats(node, { .next(); assert.eq(donorDoc.state, "blocking"); assert.eq(donorDoc.blockTimestamp, blockOplogEntry.ts); - if (TenantMigrationUtil.isShardMergeEnabled(donorPrimary.getDB("admin"))) { + if (isShardMergeEnabled(donorPrimary.getDB("admin"))) { assert.eq(donorDoc.protocol, "shard merge"); assert.eq(donorDoc.tenantIds, [ObjectId(kTenantId)]); } @@ -183,8 +183,7 @@ function testStats(node, { assert.eq(donorDoc.commitOrAbortOpTime.ts, commitOplogEntry.ts); assert.soon(() => { - mtab = TenantMigrationUtil.getTenantMigrationAccessBlocker( - {donorNode: donorPrimary, tenantId: kTenantId}); + mtab = getTenantMigrationAccessBlocker({donorNode: donorPrimary, tenantId: kTenantId}); return mtab.donor.state === TenantMigrationTest.DonorAccessState.kReject; }); assert(mtab.donor.commitOpTime); @@ -227,8 +226,7 @@ function testStats(node, { let mtab; assert.soon(() => { - mtab = TenantMigrationUtil.getTenantMigrationAccessBlocker( - {donorNode: donorPrimary, tenantId: kTenantId}); + mtab = getTenantMigrationAccessBlocker({donorNode: donorPrimary, tenantId: kTenantId}); return mtab.donor.state === TenantMigrationTest.DonorAccessState.kAborted; }); assert(mtab.donor.abortOpTime); @@ -269,8 +267,7 @@ function testStats(node, { let mtab; assert.soon(() => { - mtab = TenantMigrationUtil.getTenantMigrationAccessBlocker( - {donorNode: donorPrimary, tenantId: kTenantId}); + mtab = getTenantMigrationAccessBlocker({donorNode: donorPrimary, tenantId: kTenantId}); return mtab.donor.state === TenantMigrationTest.DonorAccessState.kAborted; }); assert(mtab.donor.abortOpTime); @@ -317,4 +314,3 @@ configDonorsColl.dropIndex({expireAt: 1}); tenantMigrationTest.stop(); donorRst.stopSet(); recipientRst.stopSet(); -})(); diff --git a/jstests/replsets/tenant_migration_donor_try_abort.js b/jstests/replsets/tenant_migration_donor_try_abort.js index 2c1340b8422..8fa33cd9d86 100644 --- a/jstests/replsets/tenant_migration_donor_try_abort.js +++ b/jstests/replsets/tenant_migration_donor_try_abort.js @@ -10,22 +10,26 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + isShardMergeEnabled, + makeX509OptionsForTest, + runMigrationAsync, + tryAbortMigrationAsync +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); load("jstests/libs/write_concern_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load("jstests/replsets/rslib.js"); // 'createRstArgs' const kTenantId = ObjectId().str; const kDelayMS = 500000; // Using some arbitrarily large delay time in to make sure that the donor is not // waiting this long when it receives a donorAbortMigration command. -const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); +const migrationX509Options = makeX509OptionsForTest(); (() => { jsTestLog("Test sending donorAbortMigration before an instance's future chain begins."); @@ -43,16 +47,14 @@ const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); recipientConnString: tmt.getRecipientConnString(), }; - const donorRstArgs = TenantMigrationUtil.createRstArgs(tmt.getDonorRst()); + const donorRstArgs = createRstArgs(tmt.getDonorRst()); - const startMigrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); + const startMigrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); startMigrationThread.start(); fp.wait(); - const tryAbortThread = - new Thread(TenantMigrationUtil.tryAbortMigrationAsync, migrationOpts, donorRstArgs); + const tryAbortThread = new Thread(tryAbortMigrationAsync, migrationOpts, donorRstArgs); tryAbortThread.start(); // Wait for donorAbortMigration command to start. @@ -81,8 +83,7 @@ const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); "command repeatedly fails with retryable errors."); const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()}); - if (TenantMigrationUtil.isShardMergeEnabled( - tenantMigrationTest.getDonorPrimary().getDB("admin"))) { + if (isShardMergeEnabled(tenantMigrationTest.getDonorPrimary().getDB("admin"))) { tenantMigrationTest.stop(); jsTestLog("Skipping test, Shard Merge does not support retry"); return; @@ -122,8 +123,7 @@ const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); "against admin.system.keys repeatedly fails with retryable errors."); const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()}); - if (TenantMigrationUtil.isShardMergeEnabled( - tenantMigrationTest.getDonorPrimary().getDB("admin"))) { + if (isShardMergeEnabled(tenantMigrationTest.getDonorPrimary().getDB("admin"))) { tenantMigrationTest.stop(); jsTestLog("Skipping test, Shard Merge does not support retry"); return; @@ -276,9 +276,8 @@ const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); barrierBeforeFetchingKeys.wait(); - const donorRstArgs = TenantMigrationUtil.createRstArgs(tmt.getDonorRst()); - const tryAbortThread = - new Thread(TenantMigrationUtil.tryAbortMigrationAsync, migrationOpts, donorRstArgs); + const donorRstArgs = createRstArgs(tmt.getDonorRst()); + const tryAbortThread = new Thread(tryAbortMigrationAsync, migrationOpts, donorRstArgs); tryAbortThread.start(); // Wait for donorAbortMigration command to start. @@ -374,9 +373,8 @@ const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); fp.wait(); - const donorRstArgs = TenantMigrationUtil.createRstArgs(tenantMigrationTest.getDonorRst()); - const tryAbortThread = - new Thread(TenantMigrationUtil.tryAbortMigrationAsync, migrationOpts, donorRstArgs); + const donorRstArgs = createRstArgs(tenantMigrationTest.getDonorRst()); + const tryAbortThread = new Thread(tryAbortMigrationAsync, migrationOpts, donorRstArgs); tryAbortThread.start(); // Wait for donorAbortMigration command to start. @@ -418,9 +416,8 @@ const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); fp.wait(); - const donorRstArgs = TenantMigrationUtil.createRstArgs(tenantMigrationTest.getDonorRst()); - const tryAbortThread = - new Thread(TenantMigrationUtil.tryAbortMigrationAsync, migrationOpts, donorRstArgs); + const donorRstArgs = createRstArgs(tenantMigrationTest.getDonorRst()); + const tryAbortThread = new Thread(tryAbortMigrationAsync, migrationOpts, donorRstArgs); tryAbortThread.start(); // Wait for donorAbortMigration command to start. @@ -537,4 +534,3 @@ const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); tenantMigrationTest.stop(); donorRst.stopSet(); })(); -})(); diff --git a/jstests/replsets/tenant_migration_donor_unblock_reads_and_writes_on_completion.js b/jstests/replsets/tenant_migration_donor_unblock_reads_and_writes_on_completion.js index fb0f9795ebc..2e65e8fe6d8 100644 --- a/jstests/replsets/tenant_migration_donor_unblock_reads_and_writes_on_completion.js +++ b/jstests/replsets/tenant_migration_donor_unblock_reads_and_writes_on_completion.js @@ -11,15 +11,17 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + getNumBlockedReads, + getNumBlockedWrites, + makeX509OptionsForTest +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/parallelTester.js"); load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); load("jstests/libs/write_concern_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); function startReadThread(node, dbName, collName, afterClusterTime) { let readThread = new Thread((host, dbName, collName, afterClusterTime) => { @@ -49,7 +51,7 @@ function setup() { const donorRst = new ReplSetTest({ nodes: 3, name: "donorRst", - nodeOptions: Object.assign(TenantMigrationUtil.makeX509OptionsForTest().donor, { + nodeOptions: Object.assign(makeX509OptionsForTest().donor, { setParameter: { tenantMigrationGarbageCollectionDelayMS: 1, ttlMonitorSleepSecs: 1, @@ -109,7 +111,7 @@ const kCollName = "testColl"; const donorDoc = donorsColl.findOne({_id: migrationId}); assert.neq(null, donorDoc); const readThread = startReadThread(laggedSecondary, dbName, kCollName, donorDoc.blockTimestamp); - assert.soon(() => TenantMigrationUtil.getNumBlockedReads(laggedSecondary, tenantId) == 1); + assert.soon(() => getNumBlockedReads(laggedSecondary, tenantId) == 1); // Disable snapshotting on that secondary, and wait for the migration to abort and be garbage // collected. That way the secondary is guaranteed to observe the write to set expireAt before @@ -157,7 +159,7 @@ const kCollName = "testColl"; const donorDoc = donorsColl.findOne({_id: migrationId}); assert.neq(null, donorDoc); const readThread = startReadThread(laggedSecondary, dbName, kCollName, donorDoc.blockTimestamp); - assert.soon(() => TenantMigrationUtil.getNumBlockedReads(laggedSecondary, tenantId) == 1); + assert.soon(() => getNumBlockedReads(laggedSecondary, tenantId) == 1); // Disable snapshotting on that secondary, and wait for the migration to commit and be garbage // collected. That way the secondary is guaranteed to observe the write to set expireAt before @@ -203,8 +205,8 @@ const kCollName = "testColl"; assert.neq(null, donorDoc); const readThread = startReadThread(donorPrimary, dbName, kCollName, donorDoc.blockTimestamp); const writeThread = startWriteThread(donorPrimary, dbName, kCollName); - assert.soon(() => TenantMigrationUtil.getNumBlockedReads(donorPrimary, tenantId) == 1); - assert.soon(() => TenantMigrationUtil.getNumBlockedWrites(donorPrimary, tenantId) == 1); + assert.soon(() => getNumBlockedReads(donorPrimary, tenantId) == 1); + assert.soon(() => getNumBlockedWrites(donorPrimary, tenantId) == 1); // Cannot delete the donor state doc since it has not been marked as garbage collectable. assert.commandFailedWithCode(donorsColl.remove({}), ErrorCodes.IllegalOperation); @@ -222,4 +224,3 @@ const kCollName = "testColl"; teardown(); })(); -})(); diff --git a/jstests/replsets/tenant_migration_donor_wont_retry_recipientsyncdata_on_non_retriable_interruption_errors.js b/jstests/replsets/tenant_migration_donor_wont_retry_recipientsyncdata_on_non_retriable_interruption_errors.js index b9790aff744..0aa3d4758e4 100644 --- a/jstests/replsets/tenant_migration_donor_wont_retry_recipientsyncdata_on_non_retriable_interruption_errors.js +++ b/jstests/replsets/tenant_migration_donor_wont_retry_recipientsyncdata_on_non_retriable_interruption_errors.js @@ -12,18 +12,15 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {runMigrationAsync} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load("jstests/replsets/rslib.js"); // 'createRstArgs' const kTenantId = ObjectId().str; -const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); - const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()}); const donorRst = tenantMigrationTest.getDonorRst(); @@ -43,11 +40,9 @@ const migrationOpts = { tenantId: kTenantId, recipientConnString: tenantMigrationTest.getRecipientConnString(), }; -const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst); -const runMigrationThread = new Thread(TenantMigrationUtil.runMigrationAsync, - migrationOpts, - donorRstArgs, - {retryOnRetryableErrors: true}); +const donorRstArgs = createRstArgs(donorRst); +const runMigrationThread = + new Thread(runMigrationAsync, migrationOpts, donorRstArgs, {retryOnRetryableErrors: true}); runMigrationThread.start(); TenantMigrationTest.assertAborted(runMigrationThread.returnData()); @@ -56,4 +51,3 @@ tenantMigrationTest.waitForDonorNodesToReachState( assert.commandWorked(tenantMigrationTest.forgetMigration(migrationOpts.migrationIdString)); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_drop_collection.js b/jstests/replsets/tenant_migration_drop_collection.js index 74529b9107c..007fd2f9497 100644 --- a/jstests/replsets/tenant_migration_drop_collection.js +++ b/jstests/replsets/tenant_migration_drop_collection.js @@ -15,22 +15,24 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + makeX509OptionsForTest, + runMigrationAsync +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); load('jstests/replsets/libs/two_phase_drops.js'); +load("jstests/replsets/rslib.js"); // 'createRstArgs' function runDropTest({failPointName, failPointData, expectedLog, createNew}) { // Configure batch size for recipient clone. const recipientRst = new ReplSetTest({ nodes: 1, name: "recipient", - nodeOptions: Object.assign(TenantMigrationUtil.makeX509OptionsForTest().recipient, + nodeOptions: Object.assign(makeX509OptionsForTest().recipient, {setParameter: {collectionClonerBatchSize: 1}}) }); @@ -61,15 +63,14 @@ function runDropTest({failPointName, failPointData, expectedLog, createNew}) { recipientConnString: tenantMigrationTest.getRecipientConnString(), tenantId: tenantId, }; - const donorRstArgs = TenantMigrationUtil.createRstArgs(tenantMigrationTest.getDonorRst()); + const donorRstArgs = createRstArgs(tenantMigrationTest.getDonorRst()); // Set failpoint for recipient. const failPoint = configureFailPoint(recipientPrimary, failPointName, failPointData); // Start migration and wait for failpoint. jsTestLog("Waiting to hit recipient failpoint"); - const migrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); + const migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); migrationThread.start(); failPoint.wait(); @@ -196,4 +197,3 @@ runDropTest({ '{code: 5289701, attr: { namespace: nss, uuid: (x)=>(x.uuid.$uuid === uuid), tenantId: tenantId}}', createNew: true }); -})(); diff --git a/jstests/replsets/tenant_migration_drop_state_doc_collection.js b/jstests/replsets/tenant_migration_drop_state_doc_collection.js index 378a1c6a289..505d2c4e2a7 100644 --- a/jstests/replsets/tenant_migration_drop_state_doc_collection.js +++ b/jstests/replsets/tenant_migration_drop_state_doc_collection.js @@ -10,13 +10,9 @@ * ] */ -(function() { -"use strict"; - +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); const kMigrationFpNames = [ "pauseTenantMigrationAfterPersistingInitialDonorStateDoc", @@ -209,4 +205,3 @@ kMigrationFpNames.forEach(fpName => { }); tenantMigrationTest.stop(); }); -})(); diff --git a/jstests/replsets/tenant_migration_ensure_migration_outcome_visibility_for_blocked_writes.js b/jstests/replsets/tenant_migration_ensure_migration_outcome_visibility_for_blocked_writes.js index df689030730..4eb0c9378ee 100644 --- a/jstests/replsets/tenant_migration_ensure_migration_outcome_visibility_for_blocked_writes.js +++ b/jstests/replsets/tenant_migration_ensure_migration_outcome_visibility_for_blocked_writes.js @@ -10,14 +10,17 @@ * serverless, * ] */ -(function() { -'use strict'; + +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + makeX509OptionsForTest, + runMigrationAsync +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load("jstests/replsets/rslib.js"); // 'createRstArgs' const kGarbageCollectionParams = { // Set the delay before a donor state doc is garbage collected to be short to speed up the test. @@ -32,8 +35,8 @@ const kTenantDefinedDbName = "0"; const donorRst = new ReplSetTest({ nodes: 1, name: 'donor', - nodeOptions: Object.assign(TenantMigrationUtil.makeX509OptionsForTest().donor, - {setParameter: kGarbageCollectionParams}) + nodeOptions: + Object.assign(makeX509OptionsForTest().donor, {setParameter: kGarbageCollectionParams}) }); function insertDocument(primaryHost, dbName, collName) { @@ -64,7 +67,7 @@ function insertDocument(primaryHost, dbName, collName) { recipientConnString: tenantMigrationTest.getRecipientConnString(), tenantId, }; - const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst); + const donorRstArgs = createRstArgs(donorRst); const dbName = tenantMigrationTest.tenantDB(tenantId, kTenantDefinedDbName); const primary = donorRst.getPrimary(); @@ -76,8 +79,7 @@ function insertDocument(primaryHost, dbName, collName) { assert.commandWorked(primaryDB.runCommand({create: kCollName})); const blockFp = configureFailPoint(primaryDB, "pauseTenantMigrationBeforeLeavingBlockingState"); - const migrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); + const migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); migrationThread.start(); blockFp.wait(); @@ -121,7 +123,7 @@ function insertDocument(primaryHost, dbName, collName) { recipientConnString: tenantMigrationTest.getRecipientConnString(), tenantId, }; - const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst); + const donorRstArgs = createRstArgs(donorRst); const dbName = tenantMigrationTest.tenantDB(tenantId, kTenantDefinedDbName); const primary = donorRst.getPrimary(); @@ -134,8 +136,7 @@ function insertDocument(primaryHost, dbName, collName) { const abortFp = configureFailPoint(primaryDB, "abortTenantMigrationBeforeLeavingBlockingState"); const blockFp = configureFailPoint(primaryDB, "pauseTenantMigrationBeforeLeavingBlockingState"); - const migrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); + const migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); migrationThread.start(); blockFp.wait(); @@ -162,4 +163,3 @@ function insertDocument(primaryHost, dbName, collName) { tenantMigrationTest.stop(); donorRst.stopSet(); })(); -})(); diff --git a/jstests/replsets/tenant_migration_external_cluster_validation.js b/jstests/replsets/tenant_migration_external_cluster_validation.js index 8b9df026a64..c9d116ffd61 100644 --- a/jstests/replsets/tenant_migration_external_cluster_validation.js +++ b/jstests/replsets/tenant_migration_external_cluster_validation.js @@ -11,12 +11,11 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {makeX509OptionsForTest} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); // Multiple users cannot be authenticated on one connection within a session. TestData.disableImplicitSessions = true; @@ -52,7 +51,7 @@ const kDbName = kTenantId + "_" + "testDb"; const kCollName = "testColl"; -const x509Options = TenantMigrationUtil.makeX509OptionsForTest(); +const x509Options = makeX509OptionsForTest(); const donorRst = new ReplSetTest({ nodes: 2, name: "donor", @@ -174,4 +173,3 @@ recipientSecondaryTestDB.logout(); tenantMigrationTest.stop(); donorRst.stopSet(); recipientRst.stopSet(); -})(); diff --git a/jstests/replsets/tenant_migration_external_keys_ttl.js b/jstests/replsets/tenant_migration_external_keys_ttl.js index 0006d9e63f5..246c3af0197 100644 --- a/jstests/replsets/tenant_migration_external_keys_ttl.js +++ b/jstests/replsets/tenant_migration_external_keys_ttl.js @@ -14,13 +14,19 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + forgetMigrationAsync, + getExternalKeys, + isShardMergeEnabled, + kExternalKeysNs, + makeX509OptionsForTest +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); load("jstests/libs/parallelTester.js"); +load("jstests/replsets/rslib.js"); // `createRstArgs` const kExternalKeysTTLIndexName = "ExternalKeysTTLIndex"; const kTenantIdPrefix = "testTenantId"; @@ -35,7 +41,7 @@ let makeTenantId = function() { function waitForExternalKeysTTLIndex(conn) { assert.soon(() => { - const indexSpecs = conn.getCollection(TenantMigrationUtil.kExternalKeysNs).getIndexSpecs(); + const indexSpecs = conn.getCollection(kExternalKeysNs).getIndexSpecs(); const hasIndex = indexSpecs.some(indexSpec => { return indexSpec.name === kExternalKeysTTLIndexName && indexSpec.key.ttlExpiresAt === 1 && indexSpec.expireAfterSeconds === 0; @@ -51,15 +57,14 @@ function waitForExternalKeysTTLIndex(conn) { function waitForExternalKeysToBeDeleted(conn, migrationId) { assert.soonNoExcept(() => { - const externalKeys = TenantMigrationUtil.getExternalKeys(conn, migrationId); + const externalKeys = getExternalKeys(conn, migrationId); assert.eq(0, externalKeys.length, tojson(externalKeys)); return true; }); } function verifyExternalKeys(conn, {migrationId, expectTTLValue}) { - const externalKeys = - conn.getCollection(TenantMigrationUtil.kExternalKeysNs).find({migrationId}).toArray(); + const externalKeys = conn.getCollection(kExternalKeysNs).find({migrationId}).toArray(); assert.gt(externalKeys.length, 0); externalKeys.forEach(key => { @@ -118,7 +123,7 @@ function makeTestParams() { (() => { jsTestLog("Basic case with multiple migrations"); const {tmt, teardown} = setup(); - if (TenantMigrationUtil.isShardMergeEnabled(tmt.getDonorPrimary().getDB("admin"))) { + if (isShardMergeEnabled(tmt.getDonorPrimary().getDB("admin"))) { // This test runs multiple concurrent migrations, which shard merge can't handle. jsTestLog( "Skip: featureFlagShardMerge is enabled and this test runs multiple concurrent migrations, which shard merge can't handle."); @@ -216,7 +221,7 @@ function makeTestParams() { (() => { function setup() { - const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); + const migrationX509Options = makeX509OptionsForTest(); const donorRst = new ReplSetTest({ nodes: 3, name: "donorRst", @@ -331,10 +336,8 @@ function makeTestParams() { const fp = configureFailPoint( donorPrimary, "pauseTenantMigrationBeforeMarkingExternalKeysGarbageCollectable"); - const forgetMigrationThread = new Thread(TenantMigrationUtil.forgetMigrationAsync, - migrationOpts.migrationIdString, - TenantMigrationUtil.createRstArgs(donorRst), - true); + const forgetMigrationThread = new Thread( + forgetMigrationAsync, migrationOpts.migrationIdString, createRstArgs(donorRst), true); forgetMigrationThread.start(); fp.wait(); @@ -369,10 +372,8 @@ function makeTestParams() { const fp = configureFailPoint( recipientPrimary, "pauseTenantMigrationBeforeMarkingExternalKeysGarbageCollectable"); - const forgetMigrationThread = new Thread(TenantMigrationUtil.forgetMigrationAsync, - migrationOpts.migrationIdString, - TenantMigrationUtil.createRstArgs(donorRst), - true); + const forgetMigrationThread = new Thread( + forgetMigrationAsync, migrationOpts.migrationIdString, createRstArgs(donorRst), true); forgetMigrationThread.start(); fp.wait(); @@ -411,10 +412,8 @@ function makeTestParams() { const fp = configureFailPoint( donorPrimary, "pauseTenantMigrationDonorBeforeMarkingStateGarbageCollectable"); - const forgetMigrationThread = new Thread(TenantMigrationUtil.forgetMigrationAsync, - migrationOpts.migrationIdString, - TenantMigrationUtil.createRstArgs(donorRst), - true); + const forgetMigrationThread = new Thread( + forgetMigrationAsync, migrationOpts.migrationIdString, createRstArgs(donorRst), true); forgetMigrationThread.start(); fp.wait(); @@ -457,10 +456,8 @@ function makeTestParams() { const fp = configureFailPoint( recipientPrimary, "fpAfterReceivingRecipientForgetMigration", {action: "hang"}); - const forgetMigrationThread = new Thread(TenantMigrationUtil.forgetMigrationAsync, - migrationOpts.migrationIdString, - TenantMigrationUtil.createRstArgs(donorRst), - true); + const forgetMigrationThread = new Thread( + forgetMigrationAsync, migrationOpts.migrationIdString, createRstArgs(donorRst), true); forgetMigrationThread.start(); fp.wait(); @@ -482,4 +479,3 @@ function makeTestParams() { teardown(); } })(); -})(); diff --git a/jstests/replsets/tenant_migration_fetch_committed_transactions.js b/jstests/replsets/tenant_migration_fetch_committed_transactions.js index 77040de41ad..b4d7b42de23 100644 --- a/jstests/replsets/tenant_migration_fetch_committed_transactions.js +++ b/jstests/replsets/tenant_migration_fetch_committed_transactions.js @@ -14,12 +14,8 @@ * ] */ -(function() { -"use strict"; - +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/core/txns/libs/prepare_helpers.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); load("jstests/replsets/rslib.js"); load("jstests/libs/uuid_util.js"); @@ -139,4 +135,3 @@ TenantMigrationTest.assertCommitted(tenantMigrationTest.waitForMigrationToComple validateTransactionEntryonRecipient(sessionIdBeforeMigration); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_fetch_committed_transactions_retry.js b/jstests/replsets/tenant_migration_fetch_committed_transactions_retry.js index 6f2f8a6a4c4..2e5dce38cf7 100644 --- a/jstests/replsets/tenant_migration_fetch_committed_transactions_retry.js +++ b/jstests/replsets/tenant_migration_fetch_committed_transactions_retry.js @@ -18,12 +18,9 @@ * ] */ -(function() { -"use strict"; - +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/aggregation/extras/utils.js"); load("jstests/libs/fail_point_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); load("jstests/libs/uuid_util.js"); let tenantMigrationTest = new TenantMigrationTest({name: jsTestName(), sharedOptions: {nodes: 1}}); @@ -274,4 +271,3 @@ const assertTransactionEntries = (donorTxnEntries, recipientTxnEntries) => { tenantMigrationTest.stop(); })(); -})(); diff --git a/jstests/replsets/tenant_migration_fetch_committed_transactions_shard_merge.js b/jstests/replsets/tenant_migration_fetch_committed_transactions_shard_merge.js index c99f57a789b..9a0a9fa8dd4 100644 --- a/jstests/replsets/tenant_migration_fetch_committed_transactions_shard_merge.js +++ b/jstests/replsets/tenant_migration_fetch_committed_transactions_shard_merge.js @@ -13,12 +13,12 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + isShardMergeEnabled, +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/core/txns/libs/prepare_helpers.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); load("jstests/replsets/rslib.js"); load("jstests/libs/uuid_util.js"); @@ -39,10 +39,10 @@ const recipientPrimary = tenantMigrationTest.getRecipientPrimary(); // suites will execute this test without featureFlagShardMerge enabled (despite the // presence of the featureFlagShardMerge tag above), which means the test will attempt // to run a multi-tenant migration and fail. -if (!TenantMigrationUtil.isShardMergeEnabled(donorPrimary.getDB("admin"))) { +if (!isShardMergeEnabled(donorPrimary.getDB("admin"))) { tenantMigrationTest.stop(); jsTestLog("Skipping Shard Merge-specific test"); - return; + quit(); } function validateTransactionEntryonRecipient(sessionId) { @@ -153,4 +153,3 @@ validateTransactionEntryonRecipient(sessionIdBeforeMigration); validateTransactionEntryonRecipient(sessionIdForOtherTenant); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_filters_tenant_id.js b/jstests/replsets/tenant_migration_filters_tenant_id.js index a9e48122006..591b7d0bbcf 100644 --- a/jstests/replsets/tenant_migration_filters_tenant_id.js +++ b/jstests/replsets/tenant_migration_filters_tenant_id.js @@ -11,12 +11,12 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + isNamespaceForTenant, +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); const tenantIdPrefix = "tenantId"; const baseDBName = "testDB"; @@ -32,7 +32,7 @@ const runTest = (baseTenantId, dbName, shouldMatch) => { const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()}); - assert.eq(shouldMatch, TenantMigrationUtil.isNamespaceForTenant(baseTenantId, dbName)); + assert.eq(shouldMatch, isNamespaceForTenant(baseTenantId, dbName)); tenantMigrationTest.insertDonorDB(dbName, collName); // Run a migration with the base tenant ID. @@ -66,4 +66,3 @@ for (const {makeTenantId, shouldMatch} of testCases) { const tenantId = makeTenantId(baseTenantId); runTest(baseTenantId, `${tenantId}_${baseDBName}`, shouldMatch); } -})(); diff --git a/jstests/replsets/tenant_migration_find_and_modify_retry.js b/jstests/replsets/tenant_migration_find_and_modify_retry.js index 91d408f59ab..0c6dcdd81a2 100644 --- a/jstests/replsets/tenant_migration_find_and_modify_retry.js +++ b/jstests/replsets/tenant_migration_find_and_modify_retry.js @@ -14,11 +14,7 @@ * ] */ -(function() { -"use strict"; - -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/libs/uuid_util.js"); load("jstests/libs/fail_point_util.js"); // For configureFailPoint(). @@ -99,4 +95,3 @@ jsTestLog("Retry findAndModify on recipient: " + tojson(res)); assert.eq(2, res.value.y); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_ignore_create_index_on_nonempty_collection.js b/jstests/replsets/tenant_migration_ignore_create_index_on_nonempty_collection.js index c3a942ee6b9..92f8fa54091 100644 --- a/jstests/replsets/tenant_migration_ignore_create_index_on_nonempty_collection.js +++ b/jstests/replsets/tenant_migration_ignore_create_index_on_nonempty_collection.js @@ -13,10 +13,7 @@ * ] */ -(function() { -"use strict"; - -load("jstests/replsets/libs/tenant_migration_test.js"); +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/libs/uuid_util.js"); load("jstests/libs/fail_point_util.js"); // For configureFailPoint(). @@ -58,4 +55,3 @@ hangAfterRetrievingStartOpTime.off(); TenantMigrationTest.assertCommitted(tenantMigrationTest.waitForMigrationToComplete(migrationOpts)); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_index_oplog_entries.js b/jstests/replsets/tenant_migration_index_oplog_entries.js index 0d0961ddd84..3a1d5af954d 100644 --- a/jstests/replsets/tenant_migration_index_oplog_entries.js +++ b/jstests/replsets/tenant_migration_index_oplog_entries.js @@ -13,7 +13,6 @@ "use strict"; load("jstests/libs/fail_point_util.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); const kDbName = "testDb"; const kCollName = "testColl"; diff --git a/jstests/replsets/tenant_migration_invalid_inputs.js b/jstests/replsets/tenant_migration_invalid_inputs.js index ef2406522a8..c6ba021d761 100644 --- a/jstests/replsets/tenant_migration_invalid_inputs.js +++ b/jstests/replsets/tenant_migration_invalid_inputs.js @@ -14,11 +14,11 @@ * ] */ -(function() { -"use strict"; - -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + donorStartMigrationWithProtocol, + makeMigrationCertificatesForTest +} from "jstests/replsets/libs/tenant_migration_util.js"; const tenantMigrationTest = new TenantMigrationTest({name: jsTestName(), enableRecipientTesting: false}); @@ -30,103 +30,97 @@ const tenantId = "testTenantId"; const readPreference = { mode: 'primary' }; -const migrationCertificates = TenantMigrationUtil.makeMigrationCertificatesForTest(); +const migrationCertificates = makeMigrationCertificatesForTest(); jsTestLog("Testing 'donorStartMigration' command provided with invalid options."); // Test missing tenantId field for protocol 'multitenant migrations'. assert.commandFailedWithCode( - donorPrimary.adminCommand( - TenantMigrationUtil.donorStartMigrationWithProtocol({ - donorStartMigration: 1, - migrationId: UUID(), - recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL(), - readPreference, - donorCertificateForRecipient: migrationCertificates.donorCertificateForRecipient, - recipientCertificateForDonor: migrationCertificates.recipientCertificateForDonor, - }, - donorPrimary.getDB("admin"))), + donorPrimary.adminCommand(donorStartMigrationWithProtocol({ + donorStartMigration: 1, + migrationId: UUID(), + recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL(), + readPreference, + donorCertificateForRecipient: migrationCertificates.donorCertificateForRecipient, + recipientCertificateForDonor: migrationCertificates.recipientCertificateForDonor, + }, + donorPrimary.getDB("admin"))), ErrorCodes.InvalidOptions); // Test empty tenantId and unsupported database prefixes. const unsupportedtenantIds = ['', 'admin', 'local', 'config']; unsupportedtenantIds.forEach((invalidTenantId) => { assert.commandFailedWithCode( - donorPrimary.adminCommand( - TenantMigrationUtil.donorStartMigrationWithProtocol({ - donorStartMigration: 1, - migrationId: UUID(), - recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL(), - tenantId: invalidTenantId, - readPreference, - donorCertificateForRecipient: migrationCertificates.donorCertificateForRecipient, - recipientCertificateForDonor: migrationCertificates.recipientCertificateForDonor, - }, - donorPrimary.getDB("admin"))), - [ErrorCodes.InvalidOptions, ErrorCodes.BadValue]); -}); - -// Test migrating a tenant to the donor itself. -assert.commandFailedWithCode( - donorPrimary.adminCommand( - TenantMigrationUtil.donorStartMigrationWithProtocol({ + donorPrimary.adminCommand(donorStartMigrationWithProtocol({ donorStartMigration: 1, migrationId: UUID(), - recipientConnectionString: tenantMigrationTest.getDonorRst().getURL(), - tenantId, + recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL(), + tenantId: invalidTenantId, readPreference, donorCertificateForRecipient: migrationCertificates.donorCertificateForRecipient, recipientCertificateForDonor: migrationCertificates.recipientCertificateForDonor, }, - donorPrimary.getDB("admin"))), + donorPrimary.getDB("admin"))), + [ErrorCodes.InvalidOptions, ErrorCodes.BadValue]); +}); + +// Test migrating a tenant to the donor itself. +assert.commandFailedWithCode( + donorPrimary.adminCommand(donorStartMigrationWithProtocol({ + donorStartMigration: 1, + migrationId: UUID(), + recipientConnectionString: tenantMigrationTest.getDonorRst().getURL(), + tenantId, + readPreference, + donorCertificateForRecipient: migrationCertificates.donorCertificateForRecipient, + recipientCertificateForDonor: migrationCertificates.recipientCertificateForDonor, + }, + donorPrimary.getDB("admin"))), ErrorCodes.BadValue); // Test migrating a tenant to a recipient that shares one or more hosts with the donor. assert.commandFailedWithCode( - donorPrimary.adminCommand( - TenantMigrationUtil.donorStartMigrationWithProtocol({ - donorStartMigration: 1, - migrationId: UUID(), - recipientConnectionString: - tenantMigrationTest.getRecipientRst().getURL() + "," + donorPrimary.host, - tenantId, - readPreference, - donorCertificateForRecipient: migrationCertificates.donorCertificateForRecipient, - recipientCertificateForDonor: migrationCertificates.recipientCertificateForDonor, - }, - donorPrimary.getDB("admin"))), + donorPrimary.adminCommand(donorStartMigrationWithProtocol({ + donorStartMigration: 1, + migrationId: UUID(), + recipientConnectionString: + tenantMigrationTest.getRecipientRst().getURL() + "," + donorPrimary.host, + tenantId, + readPreference, + donorCertificateForRecipient: migrationCertificates.donorCertificateForRecipient, + recipientCertificateForDonor: migrationCertificates.recipientCertificateForDonor, + }, + donorPrimary.getDB("admin"))), ErrorCodes.BadValue); // Test setting tenantIds field for protocol 'multitenant migrations'. assert.commandFailedWithCode( - donorPrimary.adminCommand( - TenantMigrationUtil.donorStartMigrationWithProtocol({ - donorStartMigration: 1, - migrationId: UUID(), - recipientConnectionString: - tenantMigrationTest.getRecipientRst().getURL() + "," + donorPrimary.host, - tenantId, - tenantIds: [ObjectId(), ObjectId()], - readPreference, - donorCertificateForRecipient: migrationCertificates.donorCertificateForRecipient, - recipientCertificateForDonor: migrationCertificates.recipientCertificateForDonor, - }, - donorPrimary.getDB("admin"))), + donorPrimary.adminCommand(donorStartMigrationWithProtocol({ + donorStartMigration: 1, + migrationId: UUID(), + recipientConnectionString: + tenantMigrationTest.getRecipientRst().getURL() + "," + donorPrimary.host, + tenantId, + tenantIds: [ObjectId(), ObjectId()], + readPreference, + donorCertificateForRecipient: migrationCertificates.donorCertificateForRecipient, + recipientCertificateForDonor: migrationCertificates.recipientCertificateForDonor, + }, + donorPrimary.getDB("admin"))), ErrorCodes.BadValue); // Test migrating a tenant to a standalone recipient. assert.commandFailedWithCode( - donorPrimary.adminCommand( - TenantMigrationUtil.donorStartMigrationWithProtocol({ - donorStartMigration: 1, - migrationId: UUID(), - recipientConnectionString: recipientPrimary.host, - tenantId, - readPreference, - donorCertificateForRecipient: migrationCertificates.donorCertificateForRecipient, - recipientCertificateForDonor: migrationCertificates.recipientCertificateForDonor, - }, - donorPrimary.getDB("admin"))), + donorPrimary.adminCommand(donorStartMigrationWithProtocol({ + donorStartMigration: 1, + migrationId: UUID(), + recipientConnectionString: recipientPrimary.host, + tenantId, + readPreference, + donorCertificateForRecipient: migrationCertificates.donorCertificateForRecipient, + recipientCertificateForDonor: migrationCertificates.recipientCertificateForDonor, + }, + donorPrimary.getDB("admin"))), ErrorCodes.BadValue); jsTestLog("Testing 'recipientSyncData' command provided with invalid options."); @@ -221,4 +215,3 @@ nullTimestamps.forEach((nullTs) => { }); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_large_txn.js b/jstests/replsets/tenant_migration_large_txn.js index 8cad28dc9fa..689ed9f5fc8 100644 --- a/jstests/replsets/tenant_migration_large_txn.js +++ b/jstests/replsets/tenant_migration_large_txn.js @@ -14,14 +14,15 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + runMigrationAsync, +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load('jstests/replsets/rslib.js'); // 'createRstArgs' const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()}); @@ -61,13 +62,12 @@ const migrationOpts = { recipientConnString: tenantMigrationTest.getRecipientConnString(), tenantId: kTenantId, }; -const donorRstArgs = TenantMigrationUtil.createRstArgs(tenantMigrationTest.getDonorRst()); +const donorRstArgs = createRstArgs(tenantMigrationTest.getDonorRst()); // Start a migration, and pause it after the donor has majority-committed the initial state doc. const dataSyncFp = configureFailPoint(donorPrimary, "pauseTenantMigrationBeforeLeavingDataSyncState"); -const migrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); +const migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); migrationThread.start(); dataSyncFp.wait(); @@ -96,4 +96,3 @@ txnThread.join(); assert.commandWorked(tenantMigrationTest.forgetMigration(migrationOpts.migrationIdString)); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_logs.js b/jstests/replsets/tenant_migration_logs.js index 51dde90ee75..1e399d5b37f 100644 --- a/jstests/replsets/tenant_migration_logs.js +++ b/jstests/replsets/tenant_migration_logs.js @@ -10,10 +10,7 @@ * ] */ -(function() { -"use strict"; - -load("jstests/replsets/libs/tenant_migration_test.js"); +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/libs/uuid_util.js"); function assertNoCertificateOrPrivateKeyLogsForCmd(conn, cmdName) { @@ -59,4 +56,3 @@ const recipientPrimary = tenantMigrationTest.getRecipientPrimary(); })(); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_metrics_output.js b/jstests/replsets/tenant_migration_metrics_output.js index 6a117ac64a3..49b763ec058 100644 --- a/jstests/replsets/tenant_migration_metrics_output.js +++ b/jstests/replsets/tenant_migration_metrics_output.js @@ -10,13 +10,13 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + makeX509OptionsForTest, +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/ftdc.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); // Verify that the server status response has the fields that we expect. function verifyServerStatus(conn) { @@ -36,7 +36,7 @@ const testPath = MongoRunner.toRealPath("ftdc_dir_repl_node"); const donorRst = new ReplSetTest({ nodes: 1, name: "donorRst", - nodeOptions: Object.assign(TenantMigrationUtil.makeX509OptionsForTest().donor, + nodeOptions: Object.assign(makeX509OptionsForTest().donor, {setParameter: {diagnosticDataCollectionDirectoryPath: testPath}}) }); @@ -61,4 +61,3 @@ verifyFTDCOutput(tenantMigrationTest.getDonorPrimary()); tenantMigrationTest.stop(); donorRst.stopSet(); -})(); diff --git a/jstests/replsets/tenant_migration_multi_writes.js b/jstests/replsets/tenant_migration_multi_writes.js index 79b20c1a1f8..534ba4d8228 100644 --- a/jstests/replsets/tenant_migration_multi_writes.js +++ b/jstests/replsets/tenant_migration_multi_writes.js @@ -16,19 +16,19 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + makeX509OptionsForTest, +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); const donorRst = new ReplSetTest({ nodes: [{}, {rsConfig: {priority: 0}}, {rsConfig: {priority: 0}}], name: "TenantMigrationTest_donor", - nodeOptions: Object.assign(TenantMigrationUtil.makeX509OptionsForTest().donor, { + nodeOptions: Object.assign(makeX509OptionsForTest().donor, { setParameter: { // Set the delay before a donor state doc is garbage collected to be short to speed up // the test. @@ -156,4 +156,3 @@ readWriteConcerns.forEach(concerns => { tenantMigrationTest.stop(); donorRst.stopSet(); -})(); diff --git a/jstests/replsets/tenant_migration_multikey_index.js b/jstests/replsets/tenant_migration_multikey_index.js index d639cb62305..14e6ff23bd0 100644 --- a/jstests/replsets/tenant_migration_multikey_index.js +++ b/jstests/replsets/tenant_migration_multikey_index.js @@ -11,14 +11,14 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + makeX509OptionsForTest, +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/analyze_plan.js"); load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); const getQueryExplainIndexScanStage = function(coll) { const explain = coll.find().hint({"a.b": 1, "a.c": 1}).explain(); @@ -35,7 +35,7 @@ const verifyMultiKeyIndex = function(coll, isMultiKey, multiKeyPath) { const recipientRst = new ReplSetTest({ nodes: 2, name: jsTestName() + "_recipient", - nodeOptions: Object.assign(TenantMigrationUtil.makeX509OptionsForTest().recipient, { + nodeOptions: Object.assign(makeX509OptionsForTest().recipient, { setParameter: { // Allow reads on recipient before migration completes for testing. 'failpoint.tenantMigrationRecipientNotRejectReads': tojson({mode: 'alwaysOn'}), @@ -132,4 +132,3 @@ verifyMultiKeyIndex(recipientColl2, true, {"a.b": ["a", "a.b"], "a.c": ["a"]}); tenantMigrationTest.stop(); recipientRst.stopSet(); -})(); diff --git a/jstests/replsets/tenant_migration_network_error_via_rollback.js b/jstests/replsets/tenant_migration_network_error_via_rollback.js index b1ca2c5e166..63e27ae506c 100644 --- a/jstests/replsets/tenant_migration_network_error_via_rollback.js +++ b/jstests/replsets/tenant_migration_network_error_via_rollback.js @@ -17,17 +17,17 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + makeX509OptionsForTest, +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); // for 'extractUUIDFromObject' -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); load("jstests/replsets/rslib.js"); // for 'stopServerReplication' function runTest({failPointName, failPointData = {}, batchSize = 10 * 1000}) { - const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); + const migrationX509Options = makeX509OptionsForTest(); const donorRst = new ReplSetTest({ name: "recipientRst", @@ -295,4 +295,3 @@ switch (caseNum) { // Unreachable. assert(false); } -})(); diff --git a/jstests/replsets/tenant_migration_no_failover.js b/jstests/replsets/tenant_migration_no_failover.js index e074d68a397..b561b903e70 100644 --- a/jstests/replsets/tenant_migration_no_failover.js +++ b/jstests/replsets/tenant_migration_no_failover.js @@ -10,12 +10,9 @@ * ] */ -(function() { -"use strict"; - +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()}); const tenantId = ObjectId().str; @@ -47,4 +44,3 @@ for (const db of [...tenantDBs, ...nonTenantDBs]) { } tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_on_clustered_collection.js b/jstests/replsets/tenant_migration_on_clustered_collection.js index 6e31f1f6a89..b9d827de0fb 100644 --- a/jstests/replsets/tenant_migration_on_clustered_collection.js +++ b/jstests/replsets/tenant_migration_on_clustered_collection.js @@ -15,14 +15,15 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + runMigrationAsync, +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/clustered_collections/clustered_collection_util.js"); // ClusteredCollectionUtil load("jstests/libs/parallelTester.js"); // Thread() load("jstests/libs/uuid_util.js"); // extractUUIDFromObject() -load("jstests/replsets/libs/tenant_migration_test.js"); // TenantMigrationTest -load("jstests/replsets/libs/tenant_migration_util.js"); // TenantMigrationUtil +load('jstests/replsets/rslib.js'); // 'createRstArgs' const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()}); @@ -62,9 +63,8 @@ const runTenantMigration = () => { recipientConnString: tenantMigrationTest.getRecipientConnString(), tenantId: kTenantId, }; - const donorRstArgs = TenantMigrationUtil.createRstArgs(tenantMigrationTest.getDonorRst()); - const migrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); + const donorRstArgs = createRstArgs(tenantMigrationTest.getDonorRst()); + const migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); migrationThread.start(); TenantMigrationTest.assertCommitted(migrationThread.returnData()); @@ -98,4 +98,3 @@ runTenantMigration(); validateMigrationResults(); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_oplog_view.js b/jstests/replsets/tenant_migration_oplog_view.js index 7738ebee2ef..764cf86494e 100644 --- a/jstests/replsets/tenant_migration_oplog_view.js +++ b/jstests/replsets/tenant_migration_oplog_view.js @@ -10,10 +10,8 @@ * serverless, * ] */ -(function() { -"use strict"; -load("jstests/replsets/libs/tenant_migration_test.js"); +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; const kGarbageCollectionDelayMS = 5 * 1000; const donorRst = new ReplSetTest({ @@ -109,4 +107,3 @@ const collection = session.getDatabase(dbName)[collName]; donorRst.stopSet(); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_read_your_own_writes.js b/jstests/replsets/tenant_migration_read_your_own_writes.js index 39c45a212fe..2c6b4837740 100644 --- a/jstests/replsets/tenant_migration_read_your_own_writes.js +++ b/jstests/replsets/tenant_migration_read_your_own_writes.js @@ -12,11 +12,7 @@ * ] */ -(function() { -"use strict"; - -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/libs/uuid_util.js"); load("jstests/libs/fail_point_util.js"); // For configureFailPoint(). @@ -119,4 +115,3 @@ tenantMigrationTest.getDonorRst().nodes.forEach( {configureFailPoint: "tenantMigrationDonorAllowsNonTimestampedReads", mode: "alwaysOn"}))); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_recipient_aborts_merge_on_donor_failure.js b/jstests/replsets/tenant_migration_recipient_aborts_merge_on_donor_failure.js index c6c1bbbc591..f84056679a6 100644 --- a/jstests/replsets/tenant_migration_recipient_aborts_merge_on_donor_failure.js +++ b/jstests/replsets/tenant_migration_recipient_aborts_merge_on_donor_failure.js @@ -11,13 +11,11 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {isShardMergeEnabled} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); (() => { const tenantMigrationTest = @@ -25,7 +23,7 @@ load("jstests/replsets/libs/tenant_migration_util.js"); const recipientPrimary = tenantMigrationTest.getRecipientPrimary(); - if (!TenantMigrationUtil.isShardMergeEnabled(recipientPrimary.getDB("admin"))) { + if (!isShardMergeEnabled(recipientPrimary.getDB("admin"))) { tenantMigrationTest.stop(); jsTestLog("Skipping Shard Merge-specific test"); return; @@ -78,4 +76,3 @@ load("jstests/replsets/libs/tenant_migration_util.js"); tenantMigrationTest.stop(); })(); -})(); diff --git a/jstests/replsets/tenant_migration_recipient_access_blocker_rollback.js b/jstests/replsets/tenant_migration_recipient_access_blocker_rollback.js index f0d74342f6f..5cc3a9dd7c5 100644 --- a/jstests/replsets/tenant_migration_recipient_access_blocker_rollback.js +++ b/jstests/replsets/tenant_migration_recipient_access_blocker_rollback.js @@ -10,16 +10,19 @@ * serverless, * ] */ -(function() { -"use strict"; + +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + getCertificateAndPrivateKey, + makeX509OptionsForTest +} from "jstests/replsets/libs/tenant_migration_util.js"; + load("jstests/libs/uuid_util.js"); // For extractUUIDFromObject(). load("jstests/libs/fail_point_util.js"); // For configureFailPoint(). load("jstests/libs/write_concern_util.js"); // for 'stopReplicationOnSecondaries' load("jstests/libs/parallelTester.js"); // For Thread() -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); -const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); +const migrationX509Options = makeX509OptionsForTest(); const recipientRst = new ReplSetTest({ name: "recipRst", @@ -118,8 +121,8 @@ function runRollbackAfterLoneRecipientForgetMigrationCommand(tenantId) { const kMigrationId = UUID(); const kTenantId = tenantId; const kReadPreference = {mode: "primary"}; - const recipientCertificateForDonor = TenantMigrationUtil.getCertificateAndPrivateKey( - "jstests/libs/tenant_migration_recipient.pem"); + const recipientCertificateForDonor = + getCertificateAndPrivateKey("jstests/libs/tenant_migration_recipient.pem"); const dbName = tenantMigrationTest.tenantDB(kTenantId, "testDB"); const collName = "testColl"; @@ -218,4 +221,3 @@ runRollbackAfterMigrationCommitted(ObjectId().str); runRollbackAfterLoneRecipientForgetMigrationCommand(ObjectId().str); recipientRst.stopSet(); -})(); diff --git a/jstests/replsets/tenant_migration_recipient_current_op.js b/jstests/replsets/tenant_migration_recipient_current_op.js index 581014be9e9..df00c781e1f 100644 --- a/jstests/replsets/tenant_migration_recipient_current_op.js +++ b/jstests/replsets/tenant_migration_recipient_current_op.js @@ -17,14 +17,13 @@ * ] */ -(function() { +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {forgetMigrationAsync} from "jstests/replsets/libs/tenant_migration_util.js"; -"use strict"; load("jstests/libs/uuid_util.js"); // For extractUUIDFromObject(). load("jstests/libs/fail_point_util.js"); // For configureFailPoint(). load("jstests/libs/parallelTester.js"); // For the Thread(). -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load('jstests/replsets/rslib.js'); // 'createRstArgs' const tenantMigrationTest = new TenantMigrationTest({ name: jsTestName(), @@ -276,11 +275,10 @@ assert.commandWorked( } jsTestLog("Issuing a forget migration command."); -const forgetMigrationThread = - new Thread(TenantMigrationUtil.forgetMigrationAsync, - migrationOpts.migrationIdString, - TenantMigrationUtil.createRstArgs(tenantMigrationTest.getDonorRst()), - true /* retryOnRetryableErrors */); +const forgetMigrationThread = new Thread(forgetMigrationAsync, + migrationOpts.migrationIdString, + createRstArgs(tenantMigrationTest.getDonorRst()), + true /* retryOnRetryableErrors */); forgetMigrationThread.start(); { @@ -340,4 +338,3 @@ forgetMigrationThread.start(); } tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_recipient_directly_deletes_its_state_doc.js b/jstests/replsets/tenant_migration_recipient_directly_deletes_its_state_doc.js index cc5bda3efaf..6f6e7e360a2 100644 --- a/jstests/replsets/tenant_migration_recipient_directly_deletes_its_state_doc.js +++ b/jstests/replsets/tenant_migration_recipient_directly_deletes_its_state_doc.js @@ -14,12 +14,9 @@ * ] */ -(function() { -"use strict"; - +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); (() => { jsTest.log("Test case where the TTL monitor deletes the state doc first"); @@ -130,4 +127,3 @@ load("jstests/replsets/libs/tenant_migration_test.js"); tmt.stop(); })(); -})(); diff --git a/jstests/replsets/tenant_migration_recipient_does_not_change_sync_source_after_step_down.js b/jstests/replsets/tenant_migration_recipient_does_not_change_sync_source_after_step_down.js index b6039175c44..5ccc64e3957 100644 --- a/jstests/replsets/tenant_migration_recipient_does_not_change_sync_source_after_step_down.js +++ b/jstests/replsets/tenant_migration_recipient_does_not_change_sync_source_after_step_down.js @@ -15,13 +15,11 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {makeX509OptionsForTest} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); // Verify the recipient's current sync source is the expected one. const verifySyncSource = function(conn, migrationId, expectedSyncSource) { @@ -36,7 +34,7 @@ const batchSize = 2; const recipientRst = new ReplSetTest({ nodes: 2, name: jsTestName() + "_recipient", - nodeOptions: Object.assign(TenantMigrationUtil.makeX509OptionsForTest().recipient, { + nodeOptions: Object.assign(makeX509OptionsForTest().recipient, { setParameter: { // Use a batch size of 2 so that collection cloner requires more than a single // batch to complete. @@ -119,4 +117,3 @@ verifySyncSource(recipientPrimary, migrationId, donorPrimary.host); tenantMigrationTest.stop(); recipientRst.stopSet(); -})(); diff --git a/jstests/replsets/tenant_migration_recipient_failover_before_creating_oplog_buffer.js b/jstests/replsets/tenant_migration_recipient_failover_before_creating_oplog_buffer.js index 8999d7b0513..da8e9757b23 100644 --- a/jstests/replsets/tenant_migration_recipient_failover_before_creating_oplog_buffer.js +++ b/jstests/replsets/tenant_migration_recipient_failover_before_creating_oplog_buffer.js @@ -12,13 +12,9 @@ * ] */ -(function() { - -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/libs/uuid_util.js"); // For extractUUIDFromObject(). load("jstests/libs/fail_point_util.js"); // For configureFailPoint(). -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); const tenantMigrationTest = new TenantMigrationTest({name: jsTestName(), sharedOptions: {nodes: 2}}); @@ -56,4 +52,3 @@ jsTestLog("Waiting for migration to complete."); TenantMigrationTest.assertCommitted(tenantMigrationTest.waitForMigrationToComplete(migrationOpts)); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_recipient_fetches_retryable_writes_entry_after_committed_snapshot.js b/jstests/replsets/tenant_migration_recipient_fetches_retryable_writes_entry_after_committed_snapshot.js index 7d5745bd566..cd57e11b98c 100644 --- a/jstests/replsets/tenant_migration_recipient_fetches_retryable_writes_entry_after_committed_snapshot.js +++ b/jstests/replsets/tenant_migration_recipient_fetches_retryable_writes_entry_after_committed_snapshot.js @@ -15,9 +15,12 @@ * ] */ -(function() { -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + isShardMergeEnabled, + makeX509OptionsForTest +} from "jstests/replsets/libs/tenant_migration_util.js"; + load("jstests/libs/fail_point_util.js"); // For configureFailPoint(). load("jstests/libs/uuid_util.js"); // For extractUUIDFromObject(). load("jstests/libs/write_concern_util.js"); @@ -60,7 +63,7 @@ const donorRst = new ReplSetTest({ // stopReplProducerOnDocument failpoint. Also disable primary catchup because some replicated // retryable write statements are intentionally not being made majority committed. settings: {chainingAllowed: false, catchUpTimeoutMillis: 0}, - nodeOptions: Object.assign(TenantMigrationUtil.makeX509OptionsForTest().donor, { + nodeOptions: Object.assign(makeX509OptionsForTest().donor, { setParameter: { tenantMigrationExcludeDonorHostTimeoutMS: 30 * 1000, // Allow non-timestamped reads on donor after migration completes for testing. @@ -74,12 +77,12 @@ const donorPrimary = donorRst.getPrimary(); const tenantMigrationTest = new TenantMigrationTest({name: jsTestName(), donorRst: donorRst}); -if (TenantMigrationUtil.isShardMergeEnabled(donorPrimary.getDB("admin"))) { +if (isShardMergeEnabled(donorPrimary.getDB("admin"))) { jsTestLog( "Skip: incompatible with featureFlagShardMerge. Only 'primary' read preference is supported."); donorRst.stopSet(); tenantMigrationTest.stop(); - return; + quit(); } const recipientPrimary = tenantMigrationTest.getRecipientPrimary(); @@ -243,4 +246,3 @@ assert.eq(docAfterMigration.counter, counterTotal); donorRst.stopSet(); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_recipient_fetches_retryable_writes_oplog_entries.js b/jstests/replsets/tenant_migration_recipient_fetches_retryable_writes_oplog_entries.js index 52a25a277f9..84d5cc55bc3 100644 --- a/jstests/replsets/tenant_migration_recipient_fetches_retryable_writes_oplog_entries.js +++ b/jstests/replsets/tenant_migration_recipient_fetches_retryable_writes_oplog_entries.js @@ -10,10 +10,10 @@ * serverless, * ] */ -(function() { -"use strict"; -load("jstests/replsets/libs/tenant_migration_test.js"); +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {isShardMergeEnabled} from "jstests/replsets/libs/tenant_migration_util.js"; + load("jstests/libs/uuid_util.js"); // For extractUUIDFromObject(). load("jstests/libs/fail_point_util.js"); // For configureFailPoint(). load("jstests/libs/parallelTester.js"); // For Thread. @@ -64,8 +64,7 @@ function runTest({storeFindAndModifyImagesInSideCollection = false}) { const secondTenantSession = rsConn.startSession({retryWrites: true}); const secondTenantCollection = secondTenantSession.getDatabase(kDbName2)[kCollName]; - const isShardMergeEnabled = - TenantMigrationUtil.isShardMergeEnabled(donorRst.getPrimary().getDB("adminDB")); + const isShardMergeEnabledOnDonor = isShardMergeEnabled(donorRst.getPrimary().getDB("adminDB")); jsTestLog("Run retryable writes prior to the migration"); @@ -172,7 +171,7 @@ function runTest({storeFindAndModifyImagesInSideCollection = false}) { // Only for shardMerge we expect to have the other tenantId. Otherwise only for the provided // tenantId. - assert.eq(isShardMergeEnabled ? 1 : 0, + assert.eq(isShardMergeEnabledOnDonor ? 1 : 0, recipientOplogBuffer.find({"entry.o._id": "retryableWrite1"}).itcount()); // Ensure the retryable write oplog entries that should not be in `kOplogBufferNS` are in fact @@ -194,4 +193,3 @@ function runTest({storeFindAndModifyImagesInSideCollection = false}) { runTest({storeFindAndModifyImagesInSideCollection: false}); runTest({storeFindAndModifyImagesInSideCollection: true}); -})(); diff --git a/jstests/replsets/tenant_migration_recipient_fetches_synthetic_find_and_modify_oplog_entries.js b/jstests/replsets/tenant_migration_recipient_fetches_synthetic_find_and_modify_oplog_entries.js index 94d751e8811..3a206b498a3 100644 --- a/jstests/replsets/tenant_migration_recipient_fetches_synthetic_find_and_modify_oplog_entries.js +++ b/jstests/replsets/tenant_migration_recipient_fetches_synthetic_find_and_modify_oplog_entries.js @@ -11,10 +11,8 @@ * serverless, * ] */ -(function() { -"use strict"; -load("jstests/replsets/libs/tenant_migration_test.js"); +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/libs/uuid_util.js"); // For extractUUIDFromObject(). load("jstests/libs/fail_point_util.js"); // For configureFailPoint(). load("jstests/libs/parallelTester.js"); // For Thread. @@ -106,4 +104,3 @@ assert.eq(0, bsonWoCompare(cmdResponse, retryResponse), retryResponse); assert.commandWorked(tenantMigrationTest.forgetMigration(migrationOpts.migrationIdString)); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_recipient_forget_migration.js b/jstests/replsets/tenant_migration_recipient_forget_migration.js index c26f96301bd..145d837c63a 100644 --- a/jstests/replsets/tenant_migration_recipient_forget_migration.js +++ b/jstests/replsets/tenant_migration_recipient_forget_migration.js @@ -10,14 +10,16 @@ * ] */ -(function() { +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + forgetMigrationAsync, + isShardMergeEnabled +} from "jstests/replsets/libs/tenant_migration_util.js"; -"use strict"; load("jstests/libs/uuid_util.js"); // For extractUUIDFromObject(). load("jstests/libs/fail_point_util.js"); // For configureFailPoint(). load("jstests/libs/parallelTester.js"); // For Thread(), used for async forgetMigration. -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load('jstests/replsets/rslib.js'); // 'createRstArgs' const tenantMigrationTest = new TenantMigrationTest({ name: jsTestName(), @@ -30,8 +32,8 @@ const kReadPreference = { mode: "primary" }; -const isShardMergeEnabled = - TenantMigrationUtil.isShardMergeEnabled(tenantMigrationTest.getDonorPrimary().getDB("admin")); +const isShardMergeEnabledOnDonorPrimary = + isShardMergeEnabled(tenantMigrationTest.getDonorPrimary().getDB("admin")); const oplogBufferCollectionName = (migrationIdString) => `repl.migration.oplog_${migrationIdString}`; @@ -40,7 +42,7 @@ const donatedFilesCollectionName = (migrationIdString) => `donatedFiles.${migrat const assertTempCollectionsExist = (conn, migrationIdString) => { const collections = conn.getDB("config").getCollectionNames(); assert(collections.includes(oplogBufferCollectionName(migrationIdString)), collections); - if (isShardMergeEnabled) { + if (isShardMergeEnabledOnDonorPrimary) { assert(collections.includes(donatedFilesCollectionName(migrationIdString)), collections); } }; @@ -48,7 +50,7 @@ const assertTempCollectionsExist = (conn, migrationIdString) => { const assertTempCollectionsDoNotExist = (conn, migrationIdString) => { const collections = conn.getDB("config").getCollectionNames(); assert(!collections.includes(oplogBufferCollectionName(migrationIdString)), collections); - if (isShardMergeEnabled) { + if (isShardMergeEnabledOnDonorPrimary) { assert(!collections.includes(donatedFilesCollectionName(migrationIdString)), collections); } }; @@ -71,11 +73,10 @@ const assertTempCollectionsDoNotExist = (conn, migrationIdString) => { {action: "hang"}); jsTestLog("Issuing a forget migration command."); - const forgetMigrationThread = - new Thread(TenantMigrationUtil.forgetMigrationAsync, - migrationOpts.migrationIdString, - TenantMigrationUtil.createRstArgs(tenantMigrationTest.getDonorRst()), - true /* retryOnRetryableErrors */); + const forgetMigrationThread = new Thread(forgetMigrationAsync, + migrationOpts.migrationIdString, + createRstArgs(tenantMigrationTest.getDonorRst()), + true /* retryOnRetryableErrors */); forgetMigrationThread.start(); fpBeforeDroppingTempCollections.wait(); @@ -114,11 +115,10 @@ const assertTempCollectionsDoNotExist = (conn, migrationIdString) => { {action: "hang"}); jsTestLog("Issuing a forget migration command."); - const forgetMigrationThread = - new Thread(TenantMigrationUtil.forgetMigrationAsync, - migrationOpts.migrationIdString, - TenantMigrationUtil.createRstArgs(tenantMigrationTest.getDonorRst()), - true /* retryOnRetryableErrors */); + const forgetMigrationThread = new Thread(forgetMigrationAsync, + migrationOpts.migrationIdString, + createRstArgs(tenantMigrationTest.getDonorRst()), + true /* retryOnRetryableErrors */); forgetMigrationThread.start(); fpBeforeDroppingTempCollections.wait(); @@ -142,4 +142,3 @@ const assertTempCollectionsDoNotExist = (conn, migrationIdString) => { })(); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_recipient_has_tenant_data.js b/jstests/replsets/tenant_migration_recipient_has_tenant_data.js index ef61d84540e..f04f662e20a 100644 --- a/jstests/replsets/tenant_migration_recipient_has_tenant_data.js +++ b/jstests/replsets/tenant_migration_recipient_has_tenant_data.js @@ -12,12 +12,11 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {makeX509OptionsForTest} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); const kGarbageCollectionParams = { // Set the delay before a donor state doc is garbage collected to be short to speed up @@ -31,8 +30,8 @@ const kGarbageCollectionParams = { const donorRst = new ReplSetTest({ nodes: 1, name: "donor", - nodeOptions: Object.assign(TenantMigrationUtil.makeX509OptionsForTest().donor, - {setParameter: kGarbageCollectionParams}) + nodeOptions: + Object.assign(makeX509OptionsForTest().donor, {setParameter: kGarbageCollectionParams}) }); donorRst.startSet(); @@ -74,4 +73,3 @@ TenantMigrationTest.assertAborted(tenantMigrationTest.runMigration(migrationOpts donorRst.stopSet(); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_recipient_initial_sync_cloning.js b/jstests/replsets/tenant_migration_recipient_initial_sync_cloning.js index 1f4f377f59c..d085b7645d3 100644 --- a/jstests/replsets/tenant_migration_recipient_initial_sync_cloning.js +++ b/jstests/replsets/tenant_migration_recipient_initial_sync_cloning.js @@ -14,15 +14,14 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {makeX509OptionsForTest} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); load('jstests/replsets/rslib.js'); // for waitForNewlyAddedRemovalForNodeToBeCommitted -const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); +const migrationX509Options = makeX509OptionsForTest(); const testDBName = 'testDB'; const testCollName = 'testColl'; @@ -201,4 +200,3 @@ runTestCase('tenantId4', "fpAfterWaitForRejectReadsBeforeTimestamp", true /* checkMtab */, restartNodeAndCheckStateWithoutOplogApplication); -})(); diff --git a/jstests/replsets/tenant_migration_recipient_initial_sync_recovery.js b/jstests/replsets/tenant_migration_recipient_initial_sync_recovery.js index 1012be2670c..a371023fc05 100644 --- a/jstests/replsets/tenant_migration_recipient_initial_sync_recovery.js +++ b/jstests/replsets/tenant_migration_recipient_initial_sync_recovery.js @@ -13,14 +13,15 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + getServerlessOperationLock, + ServerlessLockType +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); load("jstests/libs/write_concern_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -const {ServerlessLockType, getServerlessOperationLock} = TenantMigrationUtil; const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()}); @@ -110,4 +111,3 @@ if (recipientDoc && !recipientDoc.expireAt) { restartServerReplication(initialSyncNode); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_recipient_invalidates_in_memory_txns.js b/jstests/replsets/tenant_migration_recipient_invalidates_in_memory_txns.js index d06af9fb500..b1f4bfbc63d 100644 --- a/jstests/replsets/tenant_migration_recipient_invalidates_in_memory_txns.js +++ b/jstests/replsets/tenant_migration_recipient_invalidates_in_memory_txns.js @@ -23,10 +23,7 @@ * ] */ -(function() { -"use strict"; - -load("jstests/replsets/libs/tenant_migration_test.js"); +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/replsets/rslib.js"); load("jstests/libs/uuid_util.js"); @@ -114,4 +111,3 @@ const migrationOpts2 = { TenantMigrationTest.assertCommitted(tenantMigrationTest.runMigration(migrationOpts2)); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_recipient_resume_on_stepup_and_restart.js b/jstests/replsets/tenant_migration_recipient_resume_on_stepup_and_restart.js index 01d98b34097..0336593795b 100644 --- a/jstests/replsets/tenant_migration_recipient_resume_on_stepup_and_restart.js +++ b/jstests/replsets/tenant_migration_recipient_resume_on_stepup_and_restart.js @@ -13,14 +13,17 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + forgetMigrationAsync, + makeX509OptionsForTest, + runMigrationAsync, +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load('jstests/replsets/rslib.js'); // 'createRstArgs' const kMaxSleepTimeMS = 100; const kTenantId = "testTenantId"; @@ -32,7 +35,7 @@ const kGarbageCollectionDelayMS = 30 * 1000; // Set the TTL monitor to run at a smaller interval to speed up the test. const kTTLMonitorSleepSecs = 1; -const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); +const migrationX509Options = makeX509OptionsForTest(); /** * Runs the donorStartMigration command to start a migration, and interrupts the migration on the @@ -58,10 +61,9 @@ function testRecipientSyncDataInterrupt(interruptFunc, recipientRestarted) { tenantId: kTenantId, recipientConnString: tenantMigrationTest.getRecipientConnString(), }; - const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst); + const donorRstArgs = createRstArgs(donorRst); - const runMigrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); + const runMigrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); runMigrationThread.start(); // Wait for recipientSyncData command to start. @@ -129,11 +131,11 @@ function testRecipientForgetMigrationInterrupt(interruptFunc) { tenantId: kTenantId, recipientConnString: recipientRst.getURL(), }; - const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst); + const donorRstArgs = createRstArgs(donorRst); TenantMigrationTest.assertCommitted( tenantMigrationTest.runMigration(migrationOpts, {automaticForgetMigration: false})); - const forgetMigrationThread = new Thread(TenantMigrationUtil.forgetMigrationAsync, + const forgetMigrationThread = new Thread(forgetMigrationAsync, migrationOpts.migrationIdString, donorRstArgs, false /* retryOnRetryableErrors */); @@ -201,4 +203,3 @@ function testRecipientForgetMigrationInterrupt(interruptFunc) { recipientRst.getPrimary(); }); })(); -})(); diff --git a/jstests/replsets/tenant_migration_recipient_resumes_on_donor_failover.js b/jstests/replsets/tenant_migration_recipient_resumes_on_donor_failover.js index 019e6d8b89b..fa41dcc7afa 100644 --- a/jstests/replsets/tenant_migration_recipient_resumes_on_donor_failover.js +++ b/jstests/replsets/tenant_migration_recipient_resumes_on_donor_failover.js @@ -18,21 +18,19 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {makeX509OptionsForTest} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); load("jstests/libs/write_concern_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); load('jstests/replsets/rslib.js'); function runTest(failPoint) { const recipientRst = new ReplSetTest({ nodes: 2, name: jsTestName() + "_recipient", - nodeOptions: Object.assign(TenantMigrationUtil.makeX509OptionsForTest().recipient, { + nodeOptions: Object.assign(makeX509OptionsForTest().recipient, { setParameter: { // Use a batch size of 2 so that collection cloner requires more than a single batch // to complete. @@ -143,4 +141,3 @@ if (testEnabled) { // 'RecipientSyncData' cmd, indicating that the data is consistent. runTest('fpAfterDataConsistentMigrationRecipientInstance'); } -})(); diff --git a/jstests/replsets/tenant_migration_recipient_retry_forget_migration.js b/jstests/replsets/tenant_migration_recipient_retry_forget_migration.js index 4bc8302c8a3..af00f5b0ae7 100644 --- a/jstests/replsets/tenant_migration_recipient_retry_forget_migration.js +++ b/jstests/replsets/tenant_migration_recipient_retry_forget_migration.js @@ -10,21 +10,19 @@ * ] */ -(function() { +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {getCertificateAndPrivateKey} from "jstests/replsets/libs/tenant_migration_util.js"; -"use strict"; load("jstests/libs/fail_point_util.js"); // For configureFailPoint(). load("jstests/libs/parallelTester.js"); // For Thread() load("jstests/libs/uuid_util.js"); // For extractUUIDFromObject(). -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()}); const migrationId = UUID(); const tenantId = 'testTenantId'; const recipientCertificateForDonor = - TenantMigrationUtil.getCertificateAndPrivateKey("jstests/libs/tenant_migration_recipient.pem"); + getCertificateAndPrivateKey("jstests/libs/tenant_migration_recipient.pem"); const dbName = tenantMigrationTest.tenantDB(tenantId, "test"); const collName = "coll"; @@ -115,4 +113,3 @@ assert.eq(currOp.state, 3 /* kDone */, currOp); assert(currOp.hasOwnProperty("expireAt"), currOp); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_recipient_retryable_writes_failover.js b/jstests/replsets/tenant_migration_recipient_retryable_writes_failover.js index 9db0cb6a56b..816584bf075 100644 --- a/jstests/replsets/tenant_migration_recipient_retryable_writes_failover.js +++ b/jstests/replsets/tenant_migration_recipient_retryable_writes_failover.js @@ -12,12 +12,9 @@ * ] */ -(function() { - -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/libs/uuid_util.js"); // For extractUUIDFromObject(). load("jstests/libs/fail_point_util.js"); // For configureFailPoint(). -load("jstests/replsets/libs/tenant_migration_test.js"); const tenantMigrationTest = new TenantMigrationTest({name: jsTestName(), sharedOptions: {nodes: 2}}); @@ -111,4 +108,3 @@ jsTestLog("Waiting for migration to complete."); TenantMigrationTest.assertCommitted(tenantMigrationTest.waitForMigrationToComplete(migrationOpts)); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_recipient_rollback_recovery.js b/jstests/replsets/tenant_migration_recipient_rollback_recovery.js index 02a707d9443..5bdd59683b8 100644 --- a/jstests/replsets/tenant_migration_recipient_rollback_recovery.js +++ b/jstests/replsets/tenant_migration_recipient_rollback_recovery.js @@ -10,15 +10,19 @@ * serverless, * ] */ -(function() { -"use strict"; + +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + forgetMigrationAsync, + makeX509OptionsForTest, + runMigrationAsync, +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/replsets/libs/rollback_test.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load("jstests/replsets/rslib.js"); // 'createRstArgs' const kTenantId = "testTenantId"; @@ -29,7 +33,7 @@ const kMaxSleepTimeMS = 250; // state. const kGarbageCollectionDelayMS = 30 * 1000; -const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); +const migrationX509Options = makeX509OptionsForTest(); function makeMigrationOpts(tenantMigrationTest, migrationId, tenantId) { return { @@ -61,7 +65,7 @@ function testRollBack(setUpFunc, rollbackOpsFunc, steadyStateFunc) { donorRst.startSet(); donorRst.initiate(); - const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst); + const donorRstArgs = createRstArgs(donorRst); const recipientRst = new ReplSetTest({ name: "recipientRst", @@ -129,8 +133,7 @@ function testRollbackInitialState() { // Start the migration asynchronously and wait for the primary to insert the state doc. migrationOpts = makeMigrationOpts(tenantMigrationTest, migrationId, kTenantId + "-initial"); - migrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); + migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); migrationThread.start(); assert.soon(() => { return 1 === @@ -179,8 +182,7 @@ function testRollBackStateTransition(pauseFailPoint, setUpFailPoints, nextState, migrationOpts = makeMigrationOpts(tenantMigrationTest, migrationId, kTenantId + "-" + nextState); - migrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); + migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); migrationThread.start(); pauseFp.wait(); }; @@ -233,7 +235,7 @@ function testRollBackMarkingStateGarbageCollectable() { const recipientPrimary = tenantMigrationTest.getRecipientPrimary(); // Run donorForgetMigration and wait for the primary to do the write to mark the state doc // as garbage collectable. - forgetMigrationThread = new Thread(TenantMigrationUtil.forgetMigrationAsync, + forgetMigrationThread = new Thread(forgetMigrationAsync, migrationOpts.migrationIdString, donorRstArgs, false /* retryOnRetryableErrors */); @@ -270,11 +272,11 @@ function testRollBackRandom() { let setUpFunc = (tenantMigrationTest, donorRstArgs) => { migrationOpts = makeMigrationOpts(tenantMigrationTest, migrationId, kTenantId + "-random"); - migrationThread = new Thread((donorRstArgs, migrationOpts) => { - load("jstests/replsets/libs/tenant_migration_util.js"); - assert.commandWorked( - TenantMigrationUtil.runMigrationAsync(migrationOpts, donorRstArgs)); - assert.commandWorked(TenantMigrationUtil.forgetMigrationAsync( + migrationThread = new Thread(async (donorRstArgs, migrationOpts) => { + const {runMigrationAsync, forgetMigrationAsync} = + await import("jstests/replsets/libs/tenant_migration_util.js"); + assert.commandWorked(await runMigrationAsync(migrationOpts, donorRstArgs)); + assert.commandWorked(await forgetMigrationAsync( migrationOpts.migrationIdString, donorRstArgs, false /* retryOnRetryableErrors */)); }, donorRstArgs, migrationOpts); @@ -331,4 +333,3 @@ testRollBackMarkingStateGarbageCollectable(); jsTest.log("Test roll back random"); testRollBackRandom(); -}()); diff --git a/jstests/replsets/tenant_migration_recipient_shard_merge_learn_files.js b/jstests/replsets/tenant_migration_recipient_shard_merge_learn_files.js index 7215e7b1088..10ccacb62ad 100644 --- a/jstests/replsets/tenant_migration_recipient_shard_merge_learn_files.js +++ b/jstests/replsets/tenant_migration_recipient_shard_merge_learn_files.js @@ -11,13 +11,11 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {isShardMergeEnabled} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); const tenantMigrationTest = new TenantMigrationTest({name: jsTestName(), sharedOptions: {nodes: 3}}); @@ -28,10 +26,10 @@ const recipientPrimary = tenantMigrationTest.getRecipientPrimary(); // suites will execute this test without featureFlagShardMerge enabled (despite the // presence of the featureFlagShardMerge tag above), which means the test will attempt // to run a multi-tenant migration and fail. -if (!TenantMigrationUtil.isShardMergeEnabled(recipientPrimary.getDB("admin"))) { +if (!isShardMergeEnabled(recipientPrimary.getDB("admin"))) { tenantMigrationTest.stop(); jsTestLog("Skipping Shard Merge-specific test"); - return; + quit(); } jsTestLog( @@ -85,4 +83,3 @@ tenantMigrationTest.getRecipientRst().nodes.forEach(node => { }); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_recipient_shard_merge_oplog_catchup.js b/jstests/replsets/tenant_migration_recipient_shard_merge_oplog_catchup.js index 35623bff5f9..b9951427d87 100644 --- a/jstests/replsets/tenant_migration_recipient_shard_merge_oplog_catchup.js +++ b/jstests/replsets/tenant_migration_recipient_shard_merge_oplog_catchup.js @@ -11,13 +11,11 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {isShardMergeEnabled} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); const tenantMigrationTest = new TenantMigrationTest({name: jsTestName(), sharedOptions: {nodes: 3}}); @@ -27,10 +25,10 @@ const donorPrimary = tenantMigrationTest.getDonorPrimary(); // suites will execute this test without featureFlagShardMerge enabled (despite the // presence of the featureFlagShardMerge tag above), which means the test will attempt // to run a multi-tenant migration and fail. -if (!TenantMigrationUtil.isShardMergeEnabled(donorPrimary.getDB("admin"))) { +if (!isShardMergeEnabled(donorPrimary.getDB("admin"))) { tenantMigrationTest.stop(); jsTestLog("Skipping Shard Merge-specific test"); - return; + quit(); } // Insert some documents before migration start so that this collection gets cloned by file cloner. @@ -91,4 +89,3 @@ tenantMigrationTest.getRecipientRst().nodes.forEach(node => { }); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_recipient_shard_merge_ttl.js b/jstests/replsets/tenant_migration_recipient_shard_merge_ttl.js index 7dd50a1eeb8..579c16fd1cb 100644 --- a/jstests/replsets/tenant_migration_recipient_shard_merge_ttl.js +++ b/jstests/replsets/tenant_migration_recipient_shard_merge_ttl.js @@ -12,13 +12,13 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + isShardMergeEnabled, +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); const tenantMigrationTest = new TenantMigrationTest({name: jsTestName(), quickGarbageCollection: true}); @@ -29,10 +29,10 @@ const recipientPrimary = tenantMigrationTest.getRecipientPrimary(); // suites will execute this test without featureFlagShardMerge enabled (despite the // presence of the featureFlagShardMerge tag above), which means the test will attempt // to run a multi-tenant migration and fail. -if (!TenantMigrationUtil.isShardMergeEnabled(recipientPrimary.getDB("admin"))) { +if (!isShardMergeEnabled(recipientPrimary.getDB("admin"))) { tenantMigrationTest.stop(); jsTestLog("Skipping Shard Merge-specific test"); - return; + quit(); } const tenantId = ObjectId().str; @@ -104,4 +104,3 @@ assert.eq(documentCount, 0); hangTTLMonitorBetweenPasses.off(); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_recipient_startup_recovery.js b/jstests/replsets/tenant_migration_recipient_startup_recovery.js index fe8913939be..640a94d4a96 100644 --- a/jstests/replsets/tenant_migration_recipient_startup_recovery.js +++ b/jstests/replsets/tenant_migration_recipient_startup_recovery.js @@ -13,17 +13,16 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {makeX509OptionsForTest} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); const recipientRst = new ReplSetTest({ nodes: 1, name: 'recipient', - nodeOptions: Object.assign(TenantMigrationUtil.makeX509OptionsForTest().recipient, { + nodeOptions: Object.assign(makeX509OptionsForTest().recipient, { setParameter: {"failpoint.PrimaryOnlyServiceSkipRebuildingInstances": tojson({mode: "alwaysOn"})} }) @@ -108,4 +107,3 @@ if (recipientDoc) { tenantMigrationTest.stop(); recipientRst.stopSet(); -})(); diff --git a/jstests/replsets/tenant_migration_recipient_sync_data_timeout.js b/jstests/replsets/tenant_migration_recipient_sync_data_timeout.js index 6e37a8c48c0..e3f1fb55225 100644 --- a/jstests/replsets/tenant_migration_recipient_sync_data_timeout.js +++ b/jstests/replsets/tenant_migration_recipient_sync_data_timeout.js @@ -10,12 +10,9 @@ * ] */ -(function() { -"use strict"; - +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()}); @@ -37,4 +34,3 @@ TenantMigrationTest.assertCommitted(tenantMigrationTest.runMigration(migrationOp assert.commandWorked(tenantMigrationTest.forgetMigration(migrationOpts.migrationIdString)); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_recipient_sync_donor_timestamp.js b/jstests/replsets/tenant_migration_recipient_sync_donor_timestamp.js index 4a2a3dbfda9..72d9a71b293 100644 --- a/jstests/replsets/tenant_migration_recipient_sync_donor_timestamp.js +++ b/jstests/replsets/tenant_migration_recipient_sync_donor_timestamp.js @@ -14,13 +14,9 @@ * ] */ -(function() { - -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); // For extractUUIDFromObject() -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); // Make the batch size small so that we can pause before all the batches are applied. const tenantMigrationTest = new TenantMigrationTest( @@ -96,4 +92,3 @@ jsTestLog("Waiting for migration to complete."); TenantMigrationTest.assertCommitted(tenantMigrationTest.waitForMigrationToComplete(migrationOpts)); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_recipient_ttl.js b/jstests/replsets/tenant_migration_recipient_ttl.js index 8945eaafa97..dd776653a05 100644 --- a/jstests/replsets/tenant_migration_recipient_ttl.js +++ b/jstests/replsets/tenant_migration_recipient_ttl.js @@ -10,12 +10,8 @@ * ] */ -(function() { - -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/libs/uuid_util.js"); // For extractUUIDFromObject(). -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); const kGarbageCollectionParams = { // Set the delay to 20s so that we can see the `expireAt` set prior to the document vanishing. @@ -85,4 +81,3 @@ jsTestLog("Waiting for the state document to have been deleted."); tenantMigrationTest.waitForMigrationGarbageCollection(kMigrationId, kTenantId); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_recipient_vote_imported_files.js b/jstests/replsets/tenant_migration_recipient_vote_imported_files.js index 0cd364c998d..318837ab94d 100644 --- a/jstests/replsets/tenant_migration_recipient_vote_imported_files.js +++ b/jstests/replsets/tenant_migration_recipient_vote_imported_files.js @@ -11,14 +11,16 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + isShardMergeEnabled, + runMigrationAsync +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load('jstests/replsets/rslib.js'); // 'createRstArgs' const tenantMigrationTest = new TenantMigrationTest({ name: jsTestName(), @@ -31,10 +33,10 @@ const recipientPrimary = tenantMigrationTest.getRecipientPrimary(); // suites will execute this test without featureFlagShardMerge enabled (despite the // presence of the featureFlagShardMerge tag above), which means the test will attempt // to run a multi-tenant migration and fail. -if (!TenantMigrationUtil.isShardMergeEnabled(recipientPrimary.getDB("admin"))) { +if (!isShardMergeEnabled(recipientPrimary.getDB("admin"))) { tenantMigrationTest.stop(); jsTestLog("Skipping Shard Merge-specific test"); - return; + quit(); } const kTenantId = ObjectId(); @@ -69,7 +71,7 @@ const migrationOpts = { tenantIds: tojson([kTenantId]), }; -const donorRstArgs = TenantMigrationUtil.createRstArgs(tenantMigrationTest.getDonorRst()); +const donorRstArgs = createRstArgs(tenantMigrationTest.getDonorRst()); jsTestLog("Test that recipientVoteImportedFiles fails with no migration started"); voteShouldFail(migrationId); @@ -77,8 +79,7 @@ voteShouldFail(migrationId); jsTestLog("Start a migration and pause after cloning"); const fpAfterStartingOplogApplierMigrationRecipientInstance = configureFailPoint( recipientPrimary, "fpAfterStartingOplogApplierMigrationRecipientInstance", {action: "hang"}); -const migrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); +const migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); migrationThread.start(); jsTestLog("Wait for recipient to log 'Waiting for all nodes to call recipientVoteImportedFiles'"); @@ -103,4 +104,3 @@ tenantMigrationTest.waitForMigrationGarbageCollection(migrationId, kTenantId.str jsTestLog("Test that recipientVoteImportedFiles fails after migration is forgotten"); voteShouldFail(migrationId); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_resume_collection_cloner_after_recipient_failover.js b/jstests/replsets/tenant_migration_resume_collection_cloner_after_recipient_failover.js index 035cbacd900..1b1d1f9a674 100644 --- a/jstests/replsets/tenant_migration_resume_collection_cloner_after_recipient_failover.js +++ b/jstests/replsets/tenant_migration_resume_collection_cloner_after_recipient_failover.js @@ -11,20 +11,21 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + checkTenantDBHashes, + makeX509OptionsForTest, +} from "jstests/replsets/libs/tenant_migration_util.js"; -const tenantMigrationFailoverTest = function(isTimeSeries, createCollFn, docs) { - load("jstests/libs/fail_point_util.js"); - load("jstests/libs/uuid_util.js"); // for 'extractUUIDFromObject' - load("jstests/replsets/libs/tenant_migration_test.js"); - load("jstests/replsets/libs/tenant_migration_util.js"); +load("jstests/libs/fail_point_util.js"); +load("jstests/libs/uuid_util.js"); // for 'extractUUIDFromObject' +const tenantMigrationFailoverTest = function(isTimeSeries, createCollFn, docs) { const batchSize = 2; const recipientRst = new ReplSetTest({ nodes: 2, name: jsTestName() + "_recipient", - nodeOptions: Object.assign(TenantMigrationUtil.makeX509OptionsForTest().recipient, { + nodeOptions: Object.assign(makeX509OptionsForTest().recipient, { setParameter: { // Use a batch size of 2 so that collection cloner requires more than a single // batch to complete. @@ -101,7 +102,7 @@ const tenantMigrationFailoverTest = function(isTimeSeries, createCollFn, docs) { recipientColl = newRecipientPrimary.getDB(dbName).getCollection(collName); assert.eq(docs.length, recipientColl.find().itcount()); assert.docEq(docs, recipientColl.find().sort({_id: 1}).toArray()); - TenantMigrationUtil.checkTenantDBHashes({ + checkTenantDBHashes({ donorRst: tenantMigrationTest.getDonorRst(), recipientRst: tenantMigrationTest.getRecipientRst(), tenantId @@ -128,4 +129,3 @@ jsTestLog("Running tenant migration test for regular collection"); tenantMigrationFailoverTest(false, (db, collName) => db.createCollection(collName), [{_id: 0}, {_id: "string"}, {_id: UUID()}, {_id: new Date()}]); -})(); diff --git a/jstests/replsets/tenant_migration_resume_collection_cloner_after_recipient_failover_with_dropped_views.js b/jstests/replsets/tenant_migration_resume_collection_cloner_after_recipient_failover_with_dropped_views.js index de499f06f34..e2b3d9618ef 100644 --- a/jstests/replsets/tenant_migration_resume_collection_cloner_after_recipient_failover_with_dropped_views.js +++ b/jstests/replsets/tenant_migration_resume_collection_cloner_after_recipient_failover_with_dropped_views.js @@ -11,19 +11,17 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {makeX509OptionsForTest} from "jstests/replsets/libs/tenant_migration_util.js"; -const tenantMigrationFailoverTest = function(isTimeSeries, createCollFn) { - load("jstests/libs/fail_point_util.js"); - load("jstests/libs/uuid_util.js"); // for 'extractUUIDFromObject' - load("jstests/replsets/libs/tenant_migration_test.js"); - load("jstests/replsets/libs/tenant_migration_util.js"); +load("jstests/libs/fail_point_util.js"); +load("jstests/libs/uuid_util.js"); // for 'extractUUIDFromObject' +const tenantMigrationFailoverTest = function(isTimeSeries, createCollFn) { const recipientRst = new ReplSetTest({ nodes: 2, name: jsTestName() + "_recipient", - nodeOptions: Object.assign(TenantMigrationUtil.makeX509OptionsForTest().recipient, { + nodeOptions: Object.assign(makeX509OptionsForTest().recipient, { setParameter: { // Allow reads on recipient before migration completes for testing. 'failpoint.tenantMigrationRecipientNotRejectReads': tojson({mode: 'alwaysOn'}), @@ -132,4 +130,3 @@ tenantMigrationFailoverTest(true, jsTestLog("Running tenant migration test for regular view"); tenantMigrationFailoverTest(false, (db, collName) => db.createView(collName, "sourceCollection", [])); -})(); diff --git a/jstests/replsets/tenant_migration_resume_collection_cloner_after_rename.js b/jstests/replsets/tenant_migration_resume_collection_cloner_after_rename.js index d97e6986a1a..275d1706f03 100644 --- a/jstests/replsets/tenant_migration_resume_collection_cloner_after_rename.js +++ b/jstests/replsets/tenant_migration_resume_collection_cloner_after_rename.js @@ -11,19 +11,22 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + checkTenantDBHashes, + makeX509OptionsForTest, + runMigrationAsync +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); // for 'extractUUIDFromObject' load("jstests/libs/parallelTester.js"); // for 'Thread' -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load('jstests/replsets/rslib.js'); // 'createRstArgs' const recipientRst = new ReplSetTest({ nodes: 2, name: jsTestName() + "_recipient", - nodeOptions: Object.assign(TenantMigrationUtil.makeX509OptionsForTest().recipient, { + nodeOptions: Object.assign(makeX509OptionsForTest().recipient, { setParameter: { // Use a batch size of 2 so that collection cloner requires more than a single batch to // complete. @@ -67,9 +70,8 @@ const hangDuringCollectionClone = {nss: recipientColl.getFullName()}); // Start a migration and wait for recipient to hang after cloning 2 documents. -const donorRstArgs = TenantMigrationUtil.createRstArgs(tenantMigrationTest.getDonorRst()); -const migrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); +const donorRstArgs = createRstArgs(tenantMigrationTest.getDonorRst()); +const migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); migrationThread.start(); hangDuringCollectionClone.wait(); assert.soon(() => recipientColl.find().itcount() === 2); @@ -111,7 +113,7 @@ TenantMigrationTest.assertCommitted(migrationThread.returnData()); recipientColl = newRecipientPrimary.getDB(dbName).getCollection(collNameRenamed); assert.eq(4, recipientColl.find().itcount()); assert.eq(recipientColl.find().sort({_id: 1}).toArray(), docs); -TenantMigrationUtil.checkTenantDBHashes({ +checkTenantDBHashes({ donorRst: tenantMigrationTest.getDonorRst(), recipientRst: tenantMigrationTest.getRecipientRst(), tenantId @@ -119,4 +121,3 @@ TenantMigrationUtil.checkTenantDBHashes({ tenantMigrationTest.stop(); recipientRst.stopSet(); -})(); diff --git a/jstests/replsets/tenant_migration_resume_oplog_application.js b/jstests/replsets/tenant_migration_resume_oplog_application.js index 9d6661753ab..8571519c536 100644 --- a/jstests/replsets/tenant_migration_resume_oplog_application.js +++ b/jstests/replsets/tenant_migration_resume_oplog_application.js @@ -11,22 +11,25 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + checkTenantDBHashes, + makeX509OptionsForTest, + runMigrationAsync, +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); // for 'extractUUIDFromObject' load("jstests/libs/parallelTester.js"); // for 'Thread' load("jstests/libs/write_concern_util.js"); // for 'stopReplicationOnSecondaries' load("jstests/aggregation/extras/utils.js"); // For assertArrayEq. -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load('jstests/replsets/rslib.js'); // For 'createRstArgs' const recipientRst = new ReplSetTest({ nodes: 3, name: jsTestName() + "_recipient", // Use a batch size of 2 so that we can hang in the middle of tenant oplog application. - nodeOptions: Object.assign(TenantMigrationUtil.makeX509OptionsForTest().recipient, + nodeOptions: Object.assign(makeX509OptionsForTest().recipient, {setParameter: {tenantApplierBatchSizeOps: 2}}) }); @@ -65,9 +68,8 @@ let waitAfterDatabaseClone = configureFailPoint( let waitInOplogApplier = configureFailPoint(recipientPrimary, "hangInTenantOplogApplication"); // Start a migration and wait for recipient to hang in the tenant database cloner. -const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst); -const migrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); +const donorRstArgs = createRstArgs(donorRst); +const migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); migrationThread.start(); waitAfterDatabaseClone.wait(); @@ -107,11 +109,10 @@ resultsArr = appliedNoOps.toArray(); assert.eq(3, appliedNoOps.count(), appliedNoOps); assert.eq(docsToApply[2], resultsArr[2].o2.o, resultsArr); -TenantMigrationUtil.checkTenantDBHashes({ +checkTenantDBHashes({ donorRst: tenantMigrationTest.getDonorRst(), recipientRst: tenantMigrationTest.getRecipientRst(), tenantId }); tenantMigrationTest.stop(); recipientRst.stopSet(); -})(); diff --git a/jstests/replsets/tenant_migration_retry_session_migration.js b/jstests/replsets/tenant_migration_retry_session_migration.js index 7d75a0d506a..aa322f4ef63 100644 --- a/jstests/replsets/tenant_migration_retry_session_migration.js +++ b/jstests/replsets/tenant_migration_retry_session_migration.js @@ -15,11 +15,9 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {checkTenantDBHashes} from "jstests/replsets/libs/tenant_migration_util.js"; -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); load("jstests/replsets/rslib.js"); load("jstests/libs/uuid_util.js"); @@ -156,11 +154,10 @@ assert.commandWorked(recipientPrimary.getDB(kDbName).runCommand({ // The dbhash between the donor and the recipient should still match after retrying // commitTransaction and the retryable writes because they should be noop. -TenantMigrationUtil.checkTenantDBHashes({ +checkTenantDBHashes({ donorRst: tenantMigrationTest.getDonorRst(), recipientRst: tenantMigrationTest.getRecipientRst(), tenantId: kTenantId }); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_retryable_write_retry.js b/jstests/replsets/tenant_migration_retryable_write_retry.js index a895fd9e788..6c913e94cb0 100644 --- a/jstests/replsets/tenant_migration_retryable_write_retry.js +++ b/jstests/replsets/tenant_migration_retryable_write_retry.js @@ -15,15 +15,15 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + makeX509OptionsForTest, +} from "jstests/replsets/libs/tenant_migration_util.js"; -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); load("jstests/libs/fail_point_util.js"); // For configureFailPoint(). load("jstests/libs/uuid_util.js"); // For extractUUIDFromObject(). -const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); +const migrationX509Options = makeX509OptionsForTest(); const donorRst = new ReplSetTest({ nodes: 1, @@ -327,4 +327,3 @@ assert.commandWorked(tenantMigrationTest.forgetMigration(migrationOpts.migration donorRst.stopSet(); recipientRst.stopSet(); -})(); diff --git a/jstests/replsets/tenant_migration_retryable_write_retry_on_recipient.js b/jstests/replsets/tenant_migration_retryable_write_retry_on_recipient.js index c18c8dfd0dd..8fb9b8fcb07 100644 --- a/jstests/replsets/tenant_migration_retryable_write_retry_on_recipient.js +++ b/jstests/replsets/tenant_migration_retryable_write_retry_on_recipient.js @@ -11,14 +11,16 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + isShardMergeEnabled, + runMigrationAsync +} from "jstests/replsets/libs/tenant_migration_util.js"; -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); // for 'Thread' load("jstests/libs/uuid_util.js"); +load("jstests/replsets/rslib.js"); // 'createRstArgs' const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()}); @@ -36,10 +38,10 @@ const recipientDb = recipientPrimary.getDB(kDbName); // wrongly restarts the Shard Merge protocol. It copies and imports donor files again, and // eventually hits an invariant in TenantFileImporterService, which doesn't support restart. // Once we fix Shard Merge to not resume on stepup, this test will work as-is. -if (TenantMigrationUtil.isShardMergeEnabled(donorPrimary.getDB("adminDB"))) { +if (isShardMergeEnabled(donorPrimary.getDB("adminDB"))) { jsTestLog("Skip: featureFlagShardMerge enabled, but shard merge does not survive stepup"); tenantMigrationTest.stop(); - return; + quit(); } jsTestLog("Run a migration to the end of cloning"); @@ -164,9 +166,8 @@ assert.commandWorked( assert.commandWorked( donorDb.runCommand(beforeWrites.retryableFindAndModifyUpdateWithPreImageCommand)); -const donorRstArgs = TenantMigrationUtil.createRstArgs(tenantMigrationTest.getDonorRst()); -const migrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); +const donorRstArgs = createRstArgs(tenantMigrationTest.getDonorRst()); +const migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); migrationThread.start(); waitBeforeFetchingTransactions.wait(); @@ -295,4 +296,3 @@ testRecipientRetryableWrites(recipient2Db, duringWrites); tenantMigrationTest2.stop(); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_shard_merge_import_write_conflict_retry.js b/jstests/replsets/tenant_migration_shard_merge_import_write_conflict_retry.js index 5b7a8c5b064..2849b2e5109 100644 --- a/jstests/replsets/tenant_migration_shard_merge_import_write_conflict_retry.js +++ b/jstests/replsets/tenant_migration_shard_merge_import_write_conflict_retry.js @@ -14,11 +14,11 @@ * serverless, * ] */ -(function() { -"use strict"; + +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {isShardMergeEnabled} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); load("jstests/libs/fail_point_util.js"); const migrationId = UUID(); @@ -26,10 +26,10 @@ const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()}); const donorPrimary = tenantMigrationTest.getDonorPrimary(); const recipientPrimary = tenantMigrationTest.getRecipientPrimary(); -if (!TenantMigrationUtil.isShardMergeEnabled(recipientPrimary.getDB("admin"))) { +if (!isShardMergeEnabled(recipientPrimary.getDB("admin"))) { tenantMigrationTest.stop(); jsTestLog("Skipping Shard Merge-specific test"); - return; + quit(); } const kDataDir = @@ -87,4 +87,3 @@ tenantMigrationTest.getRecipientRst().nodes.forEach(node => { }); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_shard_merge_invalid_inputs.js b/jstests/replsets/tenant_migration_shard_merge_invalid_inputs.js index d8342a24b10..6294e154480 100644 --- a/jstests/replsets/tenant_migration_shard_merge_invalid_inputs.js +++ b/jstests/replsets/tenant_migration_shard_merge_invalid_inputs.js @@ -14,11 +14,11 @@ * ] */ -(function() { -"use strict"; - -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + isShardMergeEnabled, + makeMigrationCertificatesForTest, +} from "jstests/replsets/libs/tenant_migration_util.js"; const tenantMigrationTest = new TenantMigrationTest({name: jsTestName(), enableRecipientTesting: false}); @@ -29,10 +29,10 @@ const donorPrimary = tenantMigrationTest.getDonorPrimary(); // suites will execute this test without featureFlagShardMerge enabled (despite the // presence of the featureFlagShardMerge tag above), which means the test will attempt // to run a multi-tenant migration and fail. -if (!TenantMigrationUtil.isShardMergeEnabled(donorPrimary.getDB("admin"))) { +if (!isShardMergeEnabled(donorPrimary.getDB("admin"))) { tenantMigrationTest.stop(); jsTestLog("Skipping Shard Merge-specific test"); - return; + quit(); } const recipientPrimary = tenantMigrationTest.getRecipientPrimary(); @@ -41,7 +41,7 @@ const tenantId = "testTenantId"; const readPreference = { mode: 'primary' }; -const migrationCertificates = TenantMigrationUtil.makeMigrationCertificatesForTest(); +const migrationCertificates = makeMigrationCertificatesForTest(); jsTestLog("Testing 'donorStartMigration' command provided with invalid options."); @@ -198,4 +198,3 @@ assert.commandFailedWithCode(recipientPrimary.adminCommand({ }), ErrorCodes.InvalidOptions); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_shard_merge_read_preference.js b/jstests/replsets/tenant_migration_shard_merge_read_preference.js index d2768626210..dbfd63ae0a8 100644 --- a/jstests/replsets/tenant_migration_shard_merge_read_preference.js +++ b/jstests/replsets/tenant_migration_shard_merge_read_preference.js @@ -12,21 +12,22 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + isShardMergeEnabled, +} from "jstests/replsets/libs/tenant_migration_util.js"; + load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); const tenantMigrationTest = new TenantMigrationTest({name: jsTestName(), enableRecipientTesting: false}); const donorPrimary = tenantMigrationTest.getDonorPrimary(); -if (!TenantMigrationUtil.isShardMergeEnabled(donorPrimary.getDB("admin"))) { +if (!isShardMergeEnabled(donorPrimary.getDB("admin"))) { tenantMigrationTest.stop(); jsTestLog("Skipping Shard Merge-specific test"); - return; + quit(); } const failingMigrationOpts = { @@ -45,4 +46,3 @@ const succeessfulMigrationOpts = { assert.commandWorked(tenantMigrationTest.startMigration(succeessfulMigrationOpts)); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_shard_merge_recipient_current_op.js b/jstests/replsets/tenant_migration_shard_merge_recipient_current_op.js index f8aba60ba46..c5021286ed2 100644 --- a/jstests/replsets/tenant_migration_shard_merge_recipient_current_op.js +++ b/jstests/replsets/tenant_migration_shard_merge_recipient_current_op.js @@ -14,14 +14,16 @@ * ] */ -(function() { +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + forgetMigrationAsync, + isShardMergeEnabled, +} from "jstests/replsets/libs/tenant_migration_util.js"; -"use strict"; load("jstests/libs/uuid_util.js"); // For extractUUIDFromObject(). load("jstests/libs/fail_point_util.js"); // For configureFailPoint(). load("jstests/libs/parallelTester.js"); // For the Thread(). -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +load('jstests/replsets/rslib.js'); // For 'createRstArgs' const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()}); @@ -29,11 +31,10 @@ const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()}); // suites will execute this test without featureFlagShardMerge enabled (despite the // presence of the featureFlagShardMerge tag above), which means the test will attempt // to run a multi-tenant migration and fail. -if (!TenantMigrationUtil.isShardMergeEnabled( - tenantMigrationTest.getDonorPrimary().getDB("admin"))) { +if (!isShardMergeEnabled(tenantMigrationTest.getDonorPrimary().getDB("admin"))) { tenantMigrationTest.stop(); jsTestLog("Skipping Shard Merge-specific test"); - return; + quit(); } const kMigrationId = UUID(); @@ -209,11 +210,10 @@ const fpBeforePersistingRejectReadsBeforeTimestamp = configureFailPoint( } jsTestLog("Issuing a forget migration command."); -const forgetMigrationThread = - new Thread(TenantMigrationUtil.forgetMigrationAsync, - migrationOpts.migrationIdString, - TenantMigrationUtil.createRstArgs(tenantMigrationTest.getDonorRst()), - true /* retryOnRetryableErrors */); +const forgetMigrationThread = new Thread(forgetMigrationAsync, + migrationOpts.migrationIdString, + createRstArgs(tenantMigrationTest.getDonorRst()), + true /* retryOnRetryableErrors */); forgetMigrationThread.start(); { @@ -246,4 +246,3 @@ forgetMigrationThread.start(); } tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_shard_merge_recipient_fetches_synthetic_find_and_modify_entries.js b/jstests/replsets/tenant_migration_shard_merge_recipient_fetches_synthetic_find_and_modify_entries.js index b11b7209c47..a44b25e0d62 100644 --- a/jstests/replsets/tenant_migration_shard_merge_recipient_fetches_synthetic_find_and_modify_entries.js +++ b/jstests/replsets/tenant_migration_shard_merge_recipient_fetches_synthetic_find_and_modify_entries.js @@ -13,10 +13,10 @@ * serverless, * ] */ -(function() { -"use strict"; -load("jstests/replsets/libs/tenant_migration_test.js"); +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {isShardMergeEnabled} from "jstests/replsets/libs/tenant_migration_util.js"; + load("jstests/libs/uuid_util.js"); // For extractUUIDFromObject(). load("jstests/libs/fail_point_util.js"); // For configureFailPoint(). load("jstests/libs/parallelTester.js"); // For Thread. @@ -34,10 +34,10 @@ const recipientPrimary = tenantMigrationTest.getRecipientPrimary(); // suites will execute this test without featureFlagShardMerge enabled (despite the // presence of the featureFlagShardMerge tag above), which means the test will attempt // to run a multi-tenant migration and fail. -if (!TenantMigrationUtil.isShardMergeEnabled(donorPrimary.getDB("admin"))) { +if (!isShardMergeEnabled(donorPrimary.getDB("admin"))) { tenantMigrationTest.stop(); jsTestLog("Skipping Shard Merge-specific test"); - return; + quit(); } const tenantCollection = donorPrimary.getDB(kDbName)[kCollName]; @@ -121,4 +121,3 @@ assert.eq(0, bsonWoCompare(cmdResponse2, retryResponse2), retryResponse2); assert.commandWorked(tenantMigrationTest.forgetMigration(migrationOpts.migrationIdString)); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_ssl_configuration.js b/jstests/replsets/tenant_migration_ssl_configuration.js index 406979b8776..de4032102cc 100644 --- a/jstests/replsets/tenant_migration_ssl_configuration.js +++ b/jstests/replsets/tenant_migration_ssl_configuration.js @@ -12,22 +12,26 @@ * ] */ -(function() { -"use strict"; - -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + donorStartMigrationWithProtocol, + getCertificateAndPrivateKey, + isMigrationCompleted, + makeMigrationCertificatesForTest, + makeX509OptionsForTest, + runTenantMigrationCommand +} from "jstests/replsets/libs/tenant_migration_util.js"; const kTenantId = ObjectId().str; const kReadPreference = { mode: "primary" }; -const kValidMigrationCertificates = TenantMigrationUtil.makeMigrationCertificatesForTest(); +const kValidMigrationCertificates = makeMigrationCertificatesForTest(); const kExpiredMigrationCertificates = { - donorCertificateForRecipient: TenantMigrationUtil.getCertificateAndPrivateKey( - "jstests/libs/tenant_migration_donor_expired.pem"), - recipientCertificateForDonor: TenantMigrationUtil.getCertificateAndPrivateKey( - "jstests/libs/tenant_migration_recipient_expired.pem") + donorCertificateForRecipient: + getCertificateAndPrivateKey("jstests/libs/tenant_migration_donor_expired.pem"), + recipientCertificateForDonor: + getCertificateAndPrivateKey("jstests/libs/tenant_migration_recipient_expired.pem") }; (() => { @@ -41,33 +45,29 @@ const kExpiredMigrationCertificates = { jsTest.log("Test that donorStartMigration requires 'donorCertificateForRecipient' when " + "tenantMigrationDisableX509Auth=false"); assert.commandFailedWithCode( - donorPrimary.adminCommand( - TenantMigrationUtil.donorStartMigrationWithProtocol({ - donorStartMigration: 1, - migrationId: UUID(), - recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL(), - tenantId: kTenantId, - readPreference: kReadPreference, - recipientCertificateForDonor: - kValidMigrationCertificates.recipientCertificateForDonor, - }, - donorPrimary.getDB("admin"))), + donorPrimary.adminCommand(donorStartMigrationWithProtocol({ + donorStartMigration: 1, + migrationId: UUID(), + recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL(), + tenantId: kTenantId, + readPreference: kReadPreference, + recipientCertificateForDonor: kValidMigrationCertificates.recipientCertificateForDonor, + }, + donorPrimary.getDB("admin"))), ErrorCodes.InvalidOptions); jsTest.log("Test that donorStartMigration requires 'recipientCertificateForDonor' when " + "tenantMigrationDisableX509Auth=false"); assert.commandFailedWithCode( - donorPrimary.adminCommand( - TenantMigrationUtil.donorStartMigrationWithProtocol({ - donorStartMigration: 1, - migrationId: UUID(), - recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL(), - tenantId: kTenantId, - readPreference: kReadPreference, - donorCertificateForRecipient: - kValidMigrationCertificates.donorCertificateForRecipient, - }, - donorPrimary.getDB("admin"))), + donorPrimary.adminCommand(donorStartMigrationWithProtocol({ + donorStartMigration: 1, + migrationId: UUID(), + recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL(), + tenantId: kTenantId, + readPreference: kReadPreference, + donorCertificateForRecipient: kValidMigrationCertificates.donorCertificateForRecipient, + }, + donorPrimary.getDB("admin"))), ErrorCodes.InvalidOptions); jsTest.log("Test that recipientSyncData requires 'recipientCertificateForDonor' when " + @@ -108,19 +108,16 @@ const kExpiredMigrationCertificates = { const donorPrimary = tenantMigrationTest.getDonorPrimary(); assert.commandFailedWithCode( - donorPrimary.adminCommand( - TenantMigrationUtil.donorStartMigrationWithProtocol({ - donorStartMigration: 1, - migrationId: UUID(), - recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL(), - tenantId: kTenantId, - readPreference: kReadPreference, - donorCertificateForRecipient: - kValidMigrationCertificates.donorCertificateForRecipient, - recipientCertificateForDonor: - kValidMigrationCertificates.recipientCertificateForDonor, - }, - donorPrimary.getDB("admin"))), + donorPrimary.adminCommand(donorStartMigrationWithProtocol({ + donorStartMigration: 1, + migrationId: UUID(), + recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL(), + tenantId: kTenantId, + readPreference: kReadPreference, + donorCertificateForRecipient: kValidMigrationCertificates.donorCertificateForRecipient, + recipientCertificateForDonor: kValidMigrationCertificates.recipientCertificateForDonor, + }, + donorPrimary.getDB("admin"))), ErrorCodes.IllegalOperation); donorRst.stopSet(); @@ -156,7 +153,7 @@ const kExpiredMigrationCertificates = { (() => { jsTest.log("Test that recipientSyncData doesn't require 'recipientCertificateForDonor' when " + "tenantMigrationDisableX509Auth=true"); - const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); + const migrationX509Options = makeX509OptionsForTest(); const recipientRst = new ReplSetTest({ nodes: 1, name: "recipient", @@ -187,7 +184,7 @@ const kExpiredMigrationCertificates = { jsTest.log( "Test that recipientForgetMigration doesn't require 'recipientCertificateForDonor' when " + "tenantMigrationDisableX509Auth=true"); - const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); + const migrationX509Options = makeX509OptionsForTest(); const recipientRst = new ReplSetTest({ nodes: 1, name: "recipient", @@ -217,7 +214,7 @@ const kExpiredMigrationCertificates = { (() => { jsTest.log("Test that donorStartMigration doesn't require certificate fields when " + "tenantMigrationDisableX509Auth=true"); - const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); + const migrationX509Options = makeX509OptionsForTest(); const donorRst = new ReplSetTest({ nodes: 1, name: "donor", @@ -248,10 +245,10 @@ const kExpiredMigrationCertificates = { tenantId: kTenantId, readPreference: kReadPreference }; - const stateRes = assert.commandWorked(TenantMigrationUtil.runTenantMigrationCommand( + const stateRes = assert.commandWorked(runTenantMigrationCommand( donorStartMigrationCmdObj, donorRst, - {retryOnRetryableErrors: false, shouldStopFunc: TenantMigrationUtil.isMigrationCompleted})); + {retryOnRetryableErrors: false, shouldStopFunc: isMigrationCompleted})); assert.eq(stateRes.state, TenantMigrationTest.DonorState.kCommitted); assert.commandWorked( donorRst.getPrimary().adminCommand({donorForgetMigration: 1, migrationId: migrationId})); @@ -293,10 +290,10 @@ const kExpiredMigrationCertificates = { readPreference: kReadPreference }; - const stateRes = assert.commandWorked(TenantMigrationUtil.runTenantMigrationCommand( + const stateRes = assert.commandWorked(runTenantMigrationCommand( donorStartMigrationCmdObj, donorRst, - {retryOnRetryableErrors: false, shouldStopFunc: TenantMigrationUtil.isMigrationCompleted})); + {retryOnRetryableErrors: false, shouldStopFunc: isMigrationCompleted})); assert.eq(stateRes.state, TenantMigrationTest.DonorState.kCommitted); donorRst.stopSet(); @@ -307,7 +304,7 @@ const kExpiredMigrationCertificates = { (() => { jsTest.log( "Test that input certificate fields are not used when tenantMigrationDisableX509Auth=true"); - const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); + const migrationX509Options = makeX509OptionsForTest(); const donorRst = new ReplSetTest({ nodes: 1, name: "donor", @@ -339,14 +336,13 @@ const kExpiredMigrationCertificates = { donorCertificateForRecipient: kExpiredMigrationCertificates.donorCertificateForRecipient, recipientCertificateForDonor: kExpiredMigrationCertificates.recipientCertificateForDonor, }; - const stateRes = assert.commandWorked(TenantMigrationUtil.runTenantMigrationCommand( + const stateRes = assert.commandWorked(runTenantMigrationCommand( donorStartMigrationCmdObj, donorRst, - {retryOnRetryableErrors: false, shouldStopFunc: TenantMigrationUtil.isMigrationCompleted})); + {retryOnRetryableErrors: false, shouldStopFunc: isMigrationCompleted})); assert.eq(stateRes.state, TenantMigrationTest.DonorState.kCommitted); donorRst.stopSet(); recipientRst.stopSet(); tenantMigrationTest.stop(); })(); -})(); diff --git a/jstests/replsets/tenant_migration_stepup_recovery_after_abort.js b/jstests/replsets/tenant_migration_stepup_recovery_after_abort.js index 9603b611a5c..ca708b301d5 100644 --- a/jstests/replsets/tenant_migration_stepup_recovery_after_abort.js +++ b/jstests/replsets/tenant_migration_stepup_recovery_after_abort.js @@ -10,12 +10,11 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {makeX509OptionsForTest} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); // Set the delay before a state doc is garbage collected to be short to speed up the test. const kGarbageCollectionParams = { @@ -26,8 +25,8 @@ const kGarbageCollectionParams = { const donorRst = new ReplSetTest({ nodes: 3, name: "donor", - nodeOptions: Object.assign(TenantMigrationUtil.makeX509OptionsForTest().donor, - {setParameter: kGarbageCollectionParams}) + nodeOptions: + Object.assign(makeX509OptionsForTest().donor, {setParameter: kGarbageCollectionParams}) }); donorRst.startSet(); @@ -67,4 +66,3 @@ tenantMigrationTest.waitForMigrationGarbageCollection(migrationId, tenantId); donorRst.stopSet(); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_sync_source_too_stale.js b/jstests/replsets/tenant_migration_sync_source_too_stale.js index 47376d19f66..50b2b0f0b5a 100644 --- a/jstests/replsets/tenant_migration_sync_source_too_stale.js +++ b/jstests/replsets/tenant_migration_sync_source_too_stale.js @@ -23,20 +23,19 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {makeX509OptionsForTest} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); load("jstests/libs/write_concern_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); load('jstests/replsets/rslib.js'); const donorRst = new ReplSetTest({ name: `${jsTestName()}_donor`, nodes: 3, settings: {chainingAllowed: false}, - nodeOptions: Object.assign(TenantMigrationUtil.makeX509OptionsForTest().donor, { + nodeOptions: Object.assign(makeX509OptionsForTest().donor, { setParameter: { // Allow non-timestamped reads on donor after migration completes for testing. 'failpoint.tenantMigrationDonorAllowsNonTimestampedReads': tojson({mode: 'alwaysOn'}), @@ -168,4 +167,3 @@ TenantMigrationTest.assertCommitted(tenantMigrationTest.waitForMigrationToComple donorRst.stopSet(); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_test_max_bson_limit.js b/jstests/replsets/tenant_migration_test_max_bson_limit.js index 6c831d650f3..97115f3c764 100644 --- a/jstests/replsets/tenant_migration_test_max_bson_limit.js +++ b/jstests/replsets/tenant_migration_test_max_bson_limit.js @@ -9,14 +9,11 @@ * serverless, * ] */ -(function() { -'use strict'; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); const kCollName = "testColl"; const kTenantDefinedDbName = "0"; @@ -90,4 +87,3 @@ assert.lte(Object.bsonsize(bulkWriteRes), assert.commandWorked(primaryDB.hello()).maxBsonObjectSize); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_timeseries_collections.js b/jstests/replsets/tenant_migration_timeseries_collections.js index 8499bf857e6..3474a6405a6 100644 --- a/jstests/replsets/tenant_migration_timeseries_collections.js +++ b/jstests/replsets/tenant_migration_timeseries_collections.js @@ -10,11 +10,8 @@ * ] */ -(function() { -"use strict"; - +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()}); @@ -52,4 +49,3 @@ tenantMigrationTest.getRecipientRst().nodes.forEach(node => { }); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_timeseries_retryable_write_oplog_cloning.js b/jstests/replsets/tenant_migration_timeseries_retryable_write_oplog_cloning.js index 3715b23efca..96a04e013b2 100644 --- a/jstests/replsets/tenant_migration_timeseries_retryable_write_oplog_cloning.js +++ b/jstests/replsets/tenant_migration_timeseries_retryable_write_oplog_cloning.js @@ -14,15 +14,13 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {makeX509OptionsForTest} from "jstests/replsets/libs/tenant_migration_util.js"; -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); load("jstests/libs/uuid_util.js"); function testOplogCloning(ordered) { - const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); + const migrationX509Options = makeX509OptionsForTest(); const kGarbageCollectionParams = { // Set the delay before a donor state doc is garbage collected to be short to speed up // the test. @@ -282,4 +280,3 @@ function testOplogCloning(ordered) { testOplogCloning(true); testOplogCloning(false); -})(); diff --git a/jstests/replsets/tenant_migration_timeseries_retryable_write_retry_on_recipient.js b/jstests/replsets/tenant_migration_timeseries_retryable_write_retry_on_recipient.js index 410269bd268..e9725f537ec 100644 --- a/jstests/replsets/tenant_migration_timeseries_retryable_write_retry_on_recipient.js +++ b/jstests/replsets/tenant_migration_timeseries_retryable_write_retry_on_recipient.js @@ -16,14 +16,13 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {runMigrationAsync} from "jstests/replsets/libs/tenant_migration_util.js"; -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); // for 'Thread' load("jstests/libs/uuid_util.js"); +load("jstests/replsets/rslib.js"); // 'createRstArgs' function testRetryOnRecipient(ordered) { const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()}); @@ -93,9 +92,8 @@ function testRetryOnRecipient(ordered) { jsTestLog("Run retryable writes before the migration"); assert.commandWorked(donorDb.runCommand(beforeWrites.retryableInsertCommand)); - const donorRstArgs = TenantMigrationUtil.createRstArgs(tenantMigrationTest.getDonorRst()); - const migrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); + const donorRstArgs = createRstArgs(tenantMigrationTest.getDonorRst()); + const migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); migrationThread.start(); pauseTenantMigrationBeforeLeavingDataSyncState.wait(); @@ -165,4 +163,3 @@ function testRetryOnRecipient(ordered) { testRetryOnRecipient(true); testRetryOnRecipient(false); -})(); diff --git a/jstests/replsets/tenant_migration_transaction_boundary.js b/jstests/replsets/tenant_migration_transaction_boundary.js index 6e92e801849..c8bdbfdc0a3 100644 --- a/jstests/replsets/tenant_migration_transaction_boundary.js +++ b/jstests/replsets/tenant_migration_transaction_boundary.js @@ -21,11 +21,7 @@ * ] */ -(function() { -"use strict"; - -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/replsets/rslib.js"); load("jstests/libs/uuid_util.js"); @@ -85,4 +81,3 @@ TenantMigrationTest.assertCommitted(tenantMigrationTest.waitForMigrationToComple assert.eq(recipientPrimary.getCollection(tenantNS).countDocuments({}), 3); assert.eq(recipientPrimary.getCollection(tenantNS).count(), 3); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_v1_id_index.js b/jstests/replsets/tenant_migration_v1_id_index.js index 8ab9aa227da..6203be453fa 100644 --- a/jstests/replsets/tenant_migration_v1_id_index.js +++ b/jstests/replsets/tenant_migration_v1_id_index.js @@ -11,11 +11,8 @@ * ] */ -(function() { -"use strict"; - +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()}); @@ -62,4 +59,3 @@ TenantMigrationTest.assertCommitted(tenantMigrationTest.waitForMigrationToComple assert.commandWorked(tenantMigrationTest.forgetMigration(migrationOpts.migrationIdString)); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migration_x509.js b/jstests/replsets/tenant_migration_x509.js index 5344ef04e40..e0bce5e192d 100644 --- a/jstests/replsets/tenant_migration_x509.js +++ b/jstests/replsets/tenant_migration_x509.js @@ -11,11 +11,9 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {getCertificateAndPrivateKey} from "jstests/replsets/libs/tenant_migration_util.js"; -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); load("jstests/libs/uuid_util.js"); function makeTestNs(tenantId) { @@ -33,9 +31,9 @@ function setup() { } const kDonorCertificateAndPrivateKey = - TenantMigrationUtil.getCertificateAndPrivateKey("jstests/libs/tenant_migration_donor.pem"); + getCertificateAndPrivateKey("jstests/libs/tenant_migration_donor.pem"); const kRecipientCertificateAndPrivateKey = - TenantMigrationUtil.getCertificateAndPrivateKey("jstests/libs/tenant_migration_recipient.pem"); + getCertificateAndPrivateKey("jstests/libs/tenant_migration_recipient.pem"); (() => { jsTest.log("Test valid donor and recipient certificates"); @@ -185,8 +183,8 @@ const kRecipientCertificateAndPrivateKey = const migrationOpts = { migrationIdString: extractUUIDFromObject(migrationId), tenantId: tenantId, - donorCertificateForRecipient: TenantMigrationUtil.getCertificateAndPrivateKey( - "jstests/libs/tenant_migration_donor_expired.pem"), + donorCertificateForRecipient: + getCertificateAndPrivateKey("jstests/libs/tenant_migration_donor_expired.pem"), recipientCertificateForDonor: kRecipientCertificateAndPrivateKey, }; const {dbName, collName} = makeTestNs(tenantId); @@ -304,8 +302,8 @@ const kRecipientCertificateAndPrivateKey = migrationIdString: extractUUIDFromObject(migrationId), tenantId: tenantId, donorCertificateForRecipient: kDonorCertificateAndPrivateKey, - recipientCertificateForDonor: TenantMigrationUtil.getCertificateAndPrivateKey( - "jstests/libs/tenant_migration_recipient_expired.pem"), + recipientCertificateForDonor: + getCertificateAndPrivateKey("jstests/libs/tenant_migration_recipient_expired.pem"), }; const {dbName, collName} = makeTestNs(tenantId); @@ -343,7 +341,7 @@ const kRecipientCertificateAndPrivateKey = if (!TestData.auth) { jsTestLog("Skipping testing authorization since auth is not enabled"); - return; + quit(); } (() => { @@ -354,7 +352,7 @@ if (!TestData.auth) { const migrationOpts = { migrationIdString: extractUUIDFromObject(migrationId), tenantId: tenantId, - donorCertificateForRecipient: TenantMigrationUtil.getCertificateAndPrivateKey( + donorCertificateForRecipient: getCertificateAndPrivateKey( "jstests/libs/tenant_migration_donor_insufficient_privileges.pem"), recipientCertificateForDonor: kRecipientCertificateAndPrivateKey, }; @@ -377,7 +375,7 @@ if (!TestData.auth) { migrationIdString: extractUUIDFromObject(migrationId), tenantId: tenantId, donorCertificateForRecipient: kDonorCertificateAndPrivateKey, - recipientCertificateForDonor: TenantMigrationUtil.getCertificateAndPrivateKey( + recipientCertificateForDonor: getCertificateAndPrivateKey( "jstests/libs/tenant_migration_recipient_insufficient_privileges.pem"), }; const {dbName, collName} = makeTestNs(tenantId); @@ -389,4 +387,3 @@ if (!TestData.auth) { tenantId, dbName, collName, false /* migrationCommitted */); teardown(); })(); -})(); diff --git a/jstests/replsets/tenant_migrations_back_to_back.js b/jstests/replsets/tenant_migrations_back_to_back.js index cab9b9b70da..b5dbba6b9f9 100644 --- a/jstests/replsets/tenant_migrations_back_to_back.js +++ b/jstests/replsets/tenant_migrations_back_to_back.js @@ -13,15 +13,13 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import {runMigrationAsync} from "jstests/replsets/libs/tenant_migration_util.js"; -load("jstests/replsets/libs/tenant_migration_test.js"); -load("jstests/replsets/libs/tenant_migration_util.js"); load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); // for 'Thread' load("jstests/libs/uuid_util.js"); -load("jstests/replsets/rslib.js"); // for 'getLastOpTime' +load("jstests/replsets/rslib.js"); // for 'getLastOpTime', 'createRstArgs' const kTenantId = ObjectId().str; const tenantMigrationTest = @@ -46,9 +44,8 @@ const preMigrationTimestamp = getLastOpTime(donorPrimary).ts; let waitForRejectReadsBeforeTsFp = configureFailPoint( recipientPrimary, "fpAfterWaitForRejectReadsBeforeTimestamp", {action: "hang"}); -const donorRstArgs = TenantMigrationUtil.createRstArgs(tenantMigrationTest.getDonorRst()); -const migrationThread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs); +const donorRstArgs = createRstArgs(tenantMigrationTest.getDonorRst()); +const migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs); migrationThread.start(); waitForRejectReadsBeforeTsFp.wait(); @@ -80,7 +77,7 @@ jsTestLog("Running a back-to-back migration"); const tenantMigrationTest2 = new TenantMigrationTest( {name: jsTestName() + "2", donorRst: tenantMigrationTest.getRecipientRst()}); const donor2Primary = tenantMigrationTest2.getDonorPrimary(); -const donor2RstArgs = TenantMigrationUtil.createRstArgs(tenantMigrationTest2.getDonorRst()); +const donor2RstArgs = createRstArgs(tenantMigrationTest2.getDonorRst()); const migration2Id = UUID(); const migrationOpts2 = { migrationIdString: extractUUIDFromObject(migration2Id), @@ -92,8 +89,7 @@ const newDonorRst = recipientRst; let waitAfterCreatingMtab = configureFailPoint(donor2Primary, "pauseTenantMigrationBeforeLeavingBlockingState"); -const migration2Thread = - new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts2, donor2RstArgs); +const migration2Thread = new Thread(runMigrationAsync, migrationOpts2, donor2RstArgs); migration2Thread.start(); // At this point, 'donor2Primary' should have both a recipient and donor access blocker. The donor // access blocker has entered the blocking state, and the recipient access blocker should @@ -158,4 +154,3 @@ TenantMigrationTest.assertCommitted(migration2Thread.returnData()); tenantMigrationTest2.stop(); tenantMigrationTest.stop(); -})(); diff --git a/jstests/replsets/tenant_migrations_noop_writes.js b/jstests/replsets/tenant_migrations_noop_writes.js index 6101c339f16..3cfd8445423 100644 --- a/jstests/replsets/tenant_migrations_noop_writes.js +++ b/jstests/replsets/tenant_migrations_noop_writes.js @@ -11,19 +11,21 @@ * ] */ -(function() { -"use strict"; +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; +import { + getTenantMigrationAccessBlocker, + makeX509OptionsForTest +} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); load("jstests/libs/write_concern_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); load('jstests/libs/parallel_shell_helpers.js'); // During "shard merge" tenant migrations, writes to internal DBs are still allowed. const kUnrelatedDbName = "admin"; const collName = "foo"; -const migrationX509Options = TenantMigrationUtil.makeX509OptionsForTest(); +const migrationX509Options = makeX509OptionsForTest(); let makeTenantId = function() { return ObjectId().str; @@ -49,8 +51,7 @@ function advanceClusterTime(conn, dbName, collName) { } function getBlockTimestamp(conn, tenantId) { - const mtabServerStatus = - TenantMigrationUtil.getTenantMigrationAccessBlocker({donorNode: conn, tenantId}).donor; + const mtabServerStatus = getTenantMigrationAccessBlocker({donorNode: conn, tenantId}).donor; assert(mtabServerStatus.blockTimestamp, tojson(mtabServerStatus)); return mtabServerStatus.blockTimestamp; } @@ -232,4 +233,3 @@ function setup() { awaitReadOnDonor(); teardown(); } -})(); diff --git a/jstests/replsets/tenant_migrations_transaction_with_create_collection.js b/jstests/replsets/tenant_migrations_transaction_with_create_collection.js index d3a6e5b9ce2..be97a065689 100644 --- a/jstests/replsets/tenant_migrations_transaction_with_create_collection.js +++ b/jstests/replsets/tenant_migrations_transaction_with_create_collection.js @@ -11,13 +11,10 @@ * ] */ -(function() { -"use strict"; - +import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; load("jstests/aggregation/extras/utils.js"); load("jstests/libs/fail_point_util.js"); load("jstests/libs/uuid_util.js"); -load("jstests/replsets/libs/tenant_migration_test.js"); const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()}); @@ -73,4 +70,3 @@ assertArrayEq({ }); tenantMigrationTest.stop(); -})(); |