diff options
author | Christopher Caplinger <christopher.caplinger@mongodb.com> | 2023-05-10 16:42:25 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-05-10 18:42:18 +0000 |
commit | a56988182b4d976f017628f29a2a25e19023be55 (patch) | |
tree | ce5555a44061080e38f70e5b5b91c006e4877800 /jstests/replsets | |
parent | 2d19cbb4e585885e0581e89d68df1e52040a80f8 (diff) | |
download | mongo-a56988182b4d976f017628f29a2a25e19023be55.tar.gz |
SERVER-74353: Tenant Migration test utils handle shard merge
Diffstat (limited to 'jstests/replsets')
26 files changed, 310 insertions, 363 deletions
diff --git a/jstests/replsets/libs/tenant_migration_test.js b/jstests/replsets/libs/tenant_migration_test.js index 270c443c8a1..6c06817f715 100644 --- a/jstests/replsets/libs/tenant_migration_test.js +++ b/jstests/replsets/libs/tenant_migration_test.js @@ -10,12 +10,15 @@ import { createTenantMigrationRecipientRoleIfNotExist, createTenantMigrationDonorRoleIfNotExist, runTenantMigrationCommand, + runDonorStartMigrationCommand, isMigrationCompleted, checkTenantDBHashes, getExternalKeys, isShardMergeEnabled, isNamespaceForTenant, getTenantMigrationAccessBlocker, + kProtocolShardMerge, + kProtocolMultitenantMigrations, } from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/aggregation/extras/utils.js"); @@ -67,6 +70,9 @@ export class TenantMigrationTest { * Make a new TenantMigrationTest * * @param {string} [name] the name of the replica sets + * @param {string} [protocol] the migration protocol to use, either "multitenant migrations" or + * "shard merge". If no value is provided, will default to "shard merge" if the shard merge + * feature flag is enabled, otherwise will be set to "multitenant migrations" * @param {boolean} [enableRecipientTesting] whether recipient would actually migrate tenant * data * @param {Object} [donorRst] the ReplSetTest instance to adopt for the donor @@ -83,6 +89,7 @@ export class TenantMigrationTest { */ constructor({ name = "TenantMigrationTest", + protocol = "", enableRecipientTesting = true, donorRst, recipientRst, @@ -132,7 +139,8 @@ export class TenantMigrationTest { tojson({mode: 'alwaysOn'}); } - let nodeOptions = isDonor ? migrationX509Options.donor : migrationX509Options.recipient; + const nodeOptions = + isDonor ? migrationX509Options.donor : migrationX509Options.recipient; nodeOptions["setParameter"] = setParameterOpts; const rstName = `${name}_${(isDonor ? "donor" : "recipient")}`; @@ -151,6 +159,19 @@ export class TenantMigrationTest { this._recipientRst = this._recipientPassedIn ? recipientRst : performSetUp(false /* isDonor */); + // 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 (protocol === "" && isShardMergeEnabled(this.getDonorPrimary().getDB("admin"))) { + this.protocol = kProtocolShardMerge; + } else if (protocol === "") { + this.protocol = kProtocolMultitenantMigrations; + } + + this.configRecipientsNs = this.protocol === kProtocolShardMerge + ? TenantMigrationTest.kConfigShardMergeRecipientsNS + : TenantMigrationTest.kConfigRecipientsNS; + this._donorRst.asCluster(this._donorRst.nodes, () => { this._donorRst.getPrimary(); this._donorRst.awaitReplication(); @@ -228,12 +249,8 @@ export class TenantMigrationTest { * * Returns the result of the 'donorStartMigration' command. */ - startMigration(migrationOpts, - {retryOnRetryableErrors = false, enableDonorStartMigrationFsync = false} = {}) { - return this.runDonorStartMigration(migrationOpts, { - retryOnRetryableErrors, - enableDonorStartMigrationFsync, - }); + startMigration(migrationOpts, {retryOnRetryableErrors = false} = {}) { + return this.runDonorStartMigration(migrationOpts, {retryOnRetryableErrors}); } /** @@ -291,11 +308,9 @@ export class TenantMigrationTest { const { waitForMigrationToComplete = false, retryOnRetryableErrors = false, - enableDonorStartMigrationFsync = false, } = opts; - const cmdObj = { - donorStartMigration: 1, + const migrationOpts = { migrationId: UUID(migrationIdString), tenantId, tenantIds, @@ -306,8 +321,7 @@ export class TenantMigrationTest { protocol }; - const stateRes = runTenantMigrationCommand(cmdObj, this.getDonorRst(), { - enableDonorStartMigrationFsync, + const stateRes = runDonorStartMigrationCommand(migrationOpts, this.getDonorRst(), { retryOnRetryableErrors, shouldStopFunc: stateRes => (!waitForMigrationToComplete || isMigrationCompleted(stateRes)) @@ -344,27 +358,21 @@ export class TenantMigrationTest { donorPrimary.getCollection(TenantMigrationTest.kConfigDonorsNS).findOne({ _id: UUID(migrationIdString) }); + const recipientStateDoc = - recipientPrimary.getCollection(TenantMigrationTest.kConfigRecipientsNS).findOne({ + recipientPrimary.getCollection(this.configRecipientsNs).findOne({ _id: UUID(migrationIdString) }); - const shardMergeRecipientStateDoc = - recipientPrimary.getCollection(TenantMigrationTest.kConfigShardMergeRecipientsNS) - .findOne({_id: UUID(migrationIdString)}); - if (donorStateDoc) { assert(donorStateDoc.expireAt); } if (recipientStateDoc) { assert(recipientStateDoc.expireAt); } - if (shardMergeRecipientStateDoc) { - assert(shardMergeRecipientStateDoc.expireAt); - } const configDBCollections = recipientPrimary.getDB('config').getCollectionNames(); - assert(!configDBCollections.includes('repl.migration.oplog_' + migrationIdString), + assert(!configDBCollections.includes(`repl.migration.oplog_${migrationIdString}`), configDBCollections); this.getDonorRst().asCluster(donorPrimary, () => { @@ -425,12 +433,7 @@ export class TenantMigrationTest { }); recipientNodes.forEach(node => { - const configRecipientsColl = - node.getCollection(TenantMigrationTest.kConfigRecipientsNS); - assert.soon(() => 0 === configRecipientsColl.count({_id: migrationId}), tojson(node)); - - const configShardMergeRecipientsColl = - node.getCollection(TenantMigrationTest.kConfigShardMergeRecipientsNS); + const configRecipientsColl = node.getCollection(this.configRecipientsNs); assert.soon(() => 0 === configRecipientsColl.count({_id: migrationId}), tojson(node)); let mtab; @@ -544,13 +547,8 @@ export class TenantMigrationTest { expectedAccessState, }) { const configRecipientsColl = - this.getRecipientPrimary().getCollection("config.tenantMigrationRecipients"); - let configDoc = configRecipientsColl.findOne({_id: migrationId}); - if (!configDoc) { - configDoc = this.getRecipientPrimary() - .getCollection(TenantMigrationTest.kConfigShardMergeRecipientsNS) - .findOne({_id: migrationId}); - } + this.getRecipientPrimary().getCollection(this.configRecipientsNs); + const configDoc = configRecipientsColl.findOne({_id: migrationId}); const mtab = this.getTenantMigrationAccessBlocker({recipientNode: node, tenantId}); diff --git a/jstests/replsets/libs/tenant_migration_util.js b/jstests/replsets/libs/tenant_migration_util.js index 611ca24fb66..3b1ae935225 100644 --- a/jstests/replsets/libs/tenant_migration_util.js +++ b/jstests/replsets/libs/tenant_migration_util.js @@ -2,6 +2,8 @@ * Utilities for testing tenant migrations. */ export const kExternalKeysNs = "config.external_validation_keys"; +export const kProtocolShardMerge = "shard merge"; +export const kProtocolMultitenantMigrations = "multitenant migrations"; /** * Returns true if feature flag 'featureFlagShardMerge' is enabled, false otherwise. @@ -29,35 +31,6 @@ function shouldUseMergeTenantIds(db) { } /** - * 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)]; - } - - 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 the external keys for the given migration id. */ export function getExternalKeys(conn, migrationId) { @@ -138,35 +111,31 @@ export function isMigrationCompleted(res) { * fixture. */ export async function runMigrationAsync(migrationOpts, donorRstArgs, opts = {}) { - const {isMigrationCompleted, makeMigrationCertificatesForTest, runTenantMigrationCommand} = + const {isMigrationCompleted, makeMigrationCertificatesForTest, runDonorStartMigrationCommand} = await import("jstests/replsets/libs/tenant_migration_util.js"); load("jstests/replsets/rslib.js"); // createRst 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, - }; - return runTenantMigrationCommand(cmdObj, donorRst, { - retryOnRetryableErrors, - enableDonorStartMigrationFsync, - shouldStopFunc: isMigrationCompleted - }); + return runDonorStartMigrationCommand( + { + 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, + }, + donorRst, + {retryOnRetryableErrors, shouldStopFunc: isMigrationCompleted}); } /** @@ -216,6 +185,36 @@ export async function tryAbortMigrationAsync( } /** + * Runs the donorStartMigration command against the primary of the provided replica set. Will + * automatically assign the correct 'protocol' and 'tenantId'/'tenantIds' based on the provided + * 'protocol' and/or currently enabled feature flags. + */ +export function runDonorStartMigrationCommand(migrationOpts, rst, { + retryOnRetryableErrors = false, + shouldStopFunc = () => true, +} = {}) { + // 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. + const db = rst.getPrimary().getDB("admin"); + const cmd = Object.assign({donorStartMigration: 1}, migrationOpts); + if (cmd["protocol"] === undefined && isShardMergeEnabled(db)) { + if (shouldUseMergeTenantIds(db)) { + cmd.tenantIds = cmd.tenantIds || [ObjectId(cmd.tenantId)]; + } + + delete cmd.tenantId; + cmd.protocol = kProtocolShardMerge; + } else if (cmd["protocol"] == kProtocolShardMerge) { + delete cmd.tenantId; + } else { + delete cmd.tenantIds; + } + + return runTenantMigrationCommand(cmd, rst, {retryOnRetryableErrors, shouldStopFunc}); +} + +/** * 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. @@ -223,52 +222,37 @@ export async function tryAbortMigrationAsync( 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 primary.adminCommand(localCmdObj); - }; - } - 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. + // "ok: 1". And, admin commands(like, donorStartMigration) doesn't generate + // writeConcernErros or WriteErrors. So, it's safe to wrap the command invocation with + // assert.commandWorked() here. However, in few scenarios, like + // Mongo.prototype.recordRerouteDueToTenantMigration(), it's not safe to wrap the + // command invocation with commandWorked() as retrying on retryable writeConcernErrors + // can cause the retry attempt to fail with writeErrors. res = undefined; // In some tests we expects the command to fail due to a network error. We want to // catch the error OR the unhandled exception here and return the error to the // caller to assert on the result. Otherwise if this is not a network exception // it will be caught in the outter catch and either be retried or thrown. - res = executeNoThrowNetworkError(() => run()); + res = executeNoThrowNetworkError(() => primary.adminCommand(cmdObj)); assert.commandWorked(res); return shouldStopFunc(res); } catch (e) { if (retryOnRetryableErrors && isRetryableError(e)) { jsTestLog(`Retryable error running runTenantMigrationCommand. Command: ${ - tojson(localCmdObj)}, Error: ${tojson(e)}`); + tojson(cmdObj)}, Error: ${tojson(e)}`); primary = rst.getPrimary(); return false; } jsTestLog(`Error running runTenantMigrationCommand. Command: ${ - tojson(localCmdObj)}, Error: ${tojson(e)}`); + tojson(cmdObj)}, Error: ${tojson(e)}`); // 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. diff --git a/jstests/replsets/shard_merge_invalid_options.js b/jstests/replsets/shard_merge_invalid_options.js index d461cbc16d1..93e5c2daf96 100644 --- a/jstests/replsets/shard_merge_invalid_options.js +++ b/jstests/replsets/shard_merge_invalid_options.js @@ -8,8 +8,10 @@ import { isShardMergeEnabled, - makeMigrationCertificatesForTest + kProtocolShardMerge, + makeMigrationCertificatesForTest, } from "jstests/replsets/libs/tenant_migration_util.js"; + load("jstests/libs/fail_point_util.js"); function runTest(nodeOptions) { @@ -47,7 +49,7 @@ function runTest(nodeOptions) { assert.commandFailedWithCode( adminDB.runCommand({ donorStartMigration: 1, - protocol: "shard merge", + protocol: kProtocolShardMerge, migrationId: UUID(), recipientConnectionString: kDummyConnStr, readPreference: readPreference, @@ -63,7 +65,7 @@ function runTest(nodeOptions) { assert.commandFailedWithCode( adminDB.runCommand({ donorStartMigration: 1, - protocol: "shard merge", + protocol: kProtocolShardMerge, migrationId: UUID(), recipientConnectionString: kDummyConnStr, readPreference: readPreference, @@ -78,7 +80,7 @@ function runTest(nodeOptions) { assert.commandFailedWithCode( adminDB.runCommand({ donorStartMigration: 1, - protocol: "shard merge", + protocol: kProtocolShardMerge, migrationId: UUID(), recipientConnectionString: kDummyConnStr, readPreference: readPreference, @@ -96,7 +98,7 @@ function runTest(nodeOptions) { assert.commandFailedWithCode( adminDB.runCommand({ donorStartMigration: 1, - protocol: "shard merge", + protocol: kProtocolShardMerge, migrationId: UUID(), recipientConnectionString: kDummyConnStr, readPreference: readPreference, @@ -113,7 +115,7 @@ function runTest(nodeOptions) { assert.commandFailedWithCode( adminDB.runCommand({ donorStartMigration: 1, - protocol: "shard merge", + protocol: kProtocolShardMerge, migrationId: UUID(), recipientConnectionString: kDummyConnStr, readPreference: readPreference, @@ -129,7 +131,7 @@ function runTest(nodeOptions) { assert.commandFailedWithCode( adminDB.runCommand({ donorStartMigration: 1, - protocol: "shard merge", + protocol: kProtocolShardMerge, migrationId: UUID(), recipientConnectionString: kDummyConnStr, readPreference: readPreference, @@ -145,7 +147,7 @@ function runTest(nodeOptions) { assert.commandFailedWithCode( adminDB.runCommand({ recipientSyncData: 1, - protocol: "shard merge", + protocol: kProtocolShardMerge, migrationId: UUID(), tenantIds: [ObjectId()], donorConnectionString: kDummyConnStr, diff --git a/jstests/replsets/tenant_migration_abort_forget_retry.js b/jstests/replsets/tenant_migration_abort_forget_retry.js index 53f8d16d097..4f3eb5e6381 100644 --- a/jstests/replsets/tenant_migration_abort_forget_retry.js +++ b/jstests/replsets/tenant_migration_abort_forget_retry.js @@ -14,10 +14,7 @@ */ import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; -import { - runTenantMigrationCommand, - tryAbortMigrationAsync -} from "jstests/replsets/libs/tenant_migration_util.js"; +import {tryAbortMigrationAsync} from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); load("jstests/libs/parallelTester.js"); @@ -81,7 +78,7 @@ const tenantMigrationTest = const tryAbortThread = new Thread(tryAbortMigrationAsync, {migrationIdString: migrationId1, tenantId: tenantId}, donorRstArgs, - runTenantMigrationCommand); + true /* retryOnRetryableErrors */); tryAbortThread.start(); // Wait for donorAbortMigration command to start. 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 91cfc8d80e4..0f42f344d64 100644 --- a/jstests/replsets/tenant_migration_advance_stable_ts_after_clone.js +++ b/jstests/replsets/tenant_migration_advance_stable_ts_after_clone.js @@ -83,7 +83,7 @@ const hangBeforeAdvanceStableTsFp = configureFailPoint(recipientPrimary, "fpBeforeAdvancingStableTimestamp", {action: "hang"}); // Start the migration. -assert.commandWorked(tmt.startMigration(migrationOpts, {enableDonorStartMigrationFsync: true})); +assert.commandWorked(tmt.startMigration(migrationOpts)); // The recipient's stable timestamp should be less than the timestamp it receives from the donor to // use as the startApplyingDonorOpTime, so the recipient should advance its stable timestamp. Wait diff --git a/jstests/replsets/tenant_migration_collection_ttl.js b/jstests/replsets/tenant_migration_collection_ttl.js index 105fa1d3108..e48e75d767f 100644 --- a/jstests/replsets/tenant_migration_collection_ttl.js +++ b/jstests/replsets/tenant_migration_collection_ttl.js @@ -191,8 +191,7 @@ function assertTTLDeleteExpiredDocs(dbName, node) { let blockFp = configureFailPoint(donorPrimary, "pauseTenantMigrationBeforeLeavingBlockingState"); - assert.commandWorked( - tenantMigrationTest.startMigration(migrationOpts, {enableDonorStartMigrationFsync: true})); + assert.commandWorked(tenantMigrationTest.startMigration(migrationOpts)); blockFp.wait(); // At a very slow machine, there is a chance that a TTL cycle happened at the donor diff --git a/jstests/replsets/tenant_migration_commit_transaction_retry.js b/jstests/replsets/tenant_migration_commit_transaction_retry.js index f2f0d946584..fbf004a15bd 100644 --- a/jstests/replsets/tenant_migration_commit_transaction_retry.js +++ b/jstests/replsets/tenant_migration_commit_transaction_retry.js @@ -113,8 +113,7 @@ const migrationOpts2 = { migrationIdString: extractUUIDFromObject(migrationId2), tenantId: kTenantId, }; -TenantMigrationTest.assertCommitted( - tenantMigrationTest2.runMigration(migrationOpts2, {enableDonorStartMigrationFsync: true})); +TenantMigrationTest.assertCommitted(tenantMigrationTest2.runMigration(migrationOpts2)); const recipientPrimary2 = tenantMigrationTest2.getRecipientPrimary(); const recipientTxnEntries2 = recipientPrimary2.getDB("config")["transactions"].find().toArray(); jsTestLog(`Recipient2 config.transactions: ${tojson(recipientTxnEntries2)}`); 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 7cbe5af8db9..912cc114cc6 100644 --- a/jstests/replsets/tenant_migration_concurrent_writes_on_donor_aborted.js +++ b/jstests/replsets/tenant_migration_concurrent_writes_on_donor_aborted.js @@ -134,7 +134,6 @@ let abortFp = configureFailPoint(donorPrimary, "abortTenantMigrationBeforeLeavin TenantMigrationTest.assertAborted(tenantMigrationTest.runMigration(migrationOpts, { retryOnRetryableErrors: false, automaticForgetMigration: false, - enableDonorStartMigrationFsync: true })); // Allow the migration to complete and abort. 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 dd2b09321bc..4238481c3ce 100644 --- a/jstests/replsets/tenant_migration_concurrent_writes_on_donor_blocking.js +++ b/jstests/replsets/tenant_migration_concurrent_writes_on_donor_blocking.js @@ -155,8 +155,7 @@ function runTestsAfterMigrationCommitted() { setupTestsBeforeMigration(); -assert.commandWorked( - tenantMigrationTest.startMigration(migrationOpts, {enableDonorStartMigrationFsync: true})); +assert.commandWorked(tenantMigrationTest.startMigration(migrationOpts)); // Run the command after the migration enters the blocking state. let blockFp = configureFailPoint(donorPrimary, "pauseTenantMigrationBeforeLeavingBlockingState"); 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 2dc3e2546b9..0092c26e747 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 @@ -67,8 +67,7 @@ function testRejectBlockedWritesAfterMigrationAborted(testCase, testOpts) { new Thread(resumeMigrationAfterBlockingWrite, testOpts.primaryHost, tenantId, 1); // Run the command after the migration enters the blocking state. - assert.commandWorked( - tenantMigrationTest.startMigration(migrationOpts, {enableDonorStartMigrationFsync: true})); + assert.commandWorked(tenantMigrationTest.startMigration(migrationOpts)); resumeMigrationThread.start(); blockingFp.wait(); 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 17da4d0a93e..965fc49bc91 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 @@ -66,8 +66,7 @@ function testRejectBlockedWritesAfterMigrationCommitted(testCase, testOpts) { // Run the command after the migration enters the blocking state. resumeMigrationThread.start(); - assert.commandWorked( - tenantMigrationTest.startMigration(migrationOpts, {enableDonorStartMigrationFsync: true})); + assert.commandWorked(tenantMigrationTest.startMigration(migrationOpts)); blockingFp.wait(); // The migration should unpause and commit after the write is blocked. Verify that the write is 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 f77889c42c9..bcad804c789 100644 --- a/jstests/replsets/tenant_migration_concurrent_writes_on_donor_committed.js +++ b/jstests/replsets/tenant_migration_concurrent_writes_on_donor_committed.js @@ -122,7 +122,6 @@ setupTestsBeforeMigration(); TenantMigrationTest.assertCommitted(tenantMigrationTest.runMigration(migrationOpts, { retryOnRetryableErrors: false, automaticForgetMigration: false, - enableDonorStartMigrationFsync: true })); // run the tests after the migration has committed. diff --git a/jstests/replsets/tenant_migration_external_cluster_validation.js b/jstests/replsets/tenant_migration_external_cluster_validation.js index 378d6cc8c9c..69d30ac40f1 100644 --- a/jstests/replsets/tenant_migration_external_cluster_validation.js +++ b/jstests/replsets/tenant_migration_external_cluster_validation.js @@ -93,8 +93,6 @@ const recipientPrimaryTestDB = recipientPrimary.getDB(kDbName); const donorSecondaryTestDB = donorRst.getSecondary().getDB(kDbName); const recipientSecondaryTestDB = recipientRst.getSecondary().getDB(kDbName); -const tenantMigrationTest = new TenantMigrationTest({name: jsTestName(), donorRst, recipientRst}); - createUsers(donorRst); createUsers(recipientRst); @@ -137,6 +135,7 @@ recipientSecondaryTestDB.logout(); assert.eq(1, donorAdminDB.auth(kAdminUser.name, kAdminUser.pwd)); assert.eq(1, recipientAdminDB.auth(kAdminUser.name, kAdminUser.pwd)); +const tenantMigrationTest = new TenantMigrationTest({name: jsTestName(), donorRst, recipientRst}); const migrationId = UUID(); const migrationOpts = { migrationIdString: extractUUIDFromObject(migrationId), diff --git a/jstests/replsets/tenant_migration_invalid_inputs.js b/jstests/replsets/tenant_migration_invalid_inputs.js index 7f97f8212f5..5ffe59fa7c9 100644 --- a/jstests/replsets/tenant_migration_invalid_inputs.js +++ b/jstests/replsets/tenant_migration_invalid_inputs.js @@ -15,10 +15,7 @@ */ import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; -import { - donorStartMigrationWithProtocol, - makeMigrationCertificatesForTest -} from "jstests/replsets/libs/tenant_migration_util.js"; +import {makeMigrationCertificatesForTest} from "jstests/replsets/libs/tenant_migration_util.js"; const tenantMigrationTest = new TenantMigrationTest({name: jsTestName(), enableRecipientTesting: false}); @@ -35,93 +32,81 @@ const migrationCertificates = makeMigrationCertificatesForTest(); jsTestLog("Testing 'donorStartMigration' command provided with invalid options."); // Test missing tenantId field for protocol 'multitenant migrations'. -assert.commandFailedWithCode( - donorPrimary.adminCommand(donorStartMigrationWithProtocol({ - donorStartMigration: 1, - migrationId: UUID(), - recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL(), - readPreference, - donorCertificateForRecipient: migrationCertificates.donorCertificateForRecipient, - recipientCertificateForDonor: migrationCertificates.recipientCertificateForDonor, - }, - donorPrimary.getDB("admin"))), - ErrorCodes.InvalidOptions); +assert.commandFailedWithCode(donorPrimary.adminCommand({ + donorStartMigration: 1, + migrationId: UUID(), + recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL(), + readPreference, + donorCertificateForRecipient: migrationCertificates.donorCertificateForRecipient, + recipientCertificateForDonor: migrationCertificates.recipientCertificateForDonor, +}), + ErrorCodes.InvalidOptions); // Test empty tenantId and unsupported database prefixes. const unsupportedtenantIds = ['', 'admin', 'local', 'config']; unsupportedtenantIds.forEach((invalidTenantId) => { - assert.commandFailedWithCode( - donorPrimary.adminCommand(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(donorStartMigrationWithProtocol({ + assert.commandFailedWithCode(donorPrimary.adminCommand({ 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"))), - ErrorCodes.BadValue); + }), + [ErrorCodes.InvalidOptions, ErrorCodes.BadValue]); +}); + +// Test migrating a tenant to the donor itself. +assert.commandFailedWithCode(donorPrimary.adminCommand({ + donorStartMigration: 1, + migrationId: UUID(), + recipientConnectionString: tenantMigrationTest.getDonorRst().getURL(), + tenantId, + readPreference, + donorCertificateForRecipient: migrationCertificates.donorCertificateForRecipient, + recipientCertificateForDonor: migrationCertificates.recipientCertificateForDonor, +}), + ErrorCodes.BadValue); // Test migrating a tenant to a recipient that shares one or more hosts with the donor. -assert.commandFailedWithCode( - 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); +assert.commandFailedWithCode(donorPrimary.adminCommand({ + donorStartMigration: 1, + migrationId: UUID(), + recipientConnectionString: + tenantMigrationTest.getRecipientRst().getURL() + "," + donorPrimary.host, + tenantId, + readPreference, + donorCertificateForRecipient: migrationCertificates.donorCertificateForRecipient, + recipientCertificateForDonor: migrationCertificates.recipientCertificateForDonor, +}), + ErrorCodes.BadValue); // Test setting tenantIds field for protocol 'multitenant migrations'. -assert.commandFailedWithCode( - 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); +assert.commandFailedWithCode(donorPrimary.adminCommand({ + donorStartMigration: 1, + migrationId: UUID(), + recipientConnectionString: + tenantMigrationTest.getRecipientRst().getURL() + "," + donorPrimary.host, + tenantId, + tenantIds: [ObjectId(), ObjectId()], + readPreference, + donorCertificateForRecipient: migrationCertificates.donorCertificateForRecipient, + recipientCertificateForDonor: migrationCertificates.recipientCertificateForDonor, +}), + ErrorCodes.BadValue); // Test migrating a tenant to a standalone recipient. -assert.commandFailedWithCode( - donorPrimary.adminCommand(donorStartMigrationWithProtocol({ - donorStartMigration: 1, - migrationId: UUID(), - recipientConnectionString: recipientPrimary.host, - tenantId, - readPreference, - donorCertificateForRecipient: migrationCertificates.donorCertificateForRecipient, - recipientCertificateForDonor: migrationCertificates.recipientCertificateForDonor, - }, - donorPrimary.getDB("admin"))), - ErrorCodes.BadValue); +assert.commandFailedWithCode(donorPrimary.adminCommand({ + donorStartMigration: 1, + migrationId: UUID(), + recipientConnectionString: recipientPrimary.host, + tenantId, + readPreference, + donorCertificateForRecipient: migrationCertificates.donorCertificateForRecipient, + recipientCertificateForDonor: migrationCertificates.recipientCertificateForDonor, +}), + ErrorCodes.BadValue); jsTestLog("Testing 'recipientSyncData' command provided with invalid options."); diff --git a/jstests/replsets/tenant_migration_multikey_index.js b/jstests/replsets/tenant_migration_multikey_index.js index 925547bc1f1..964b26931b3 100644 --- a/jstests/replsets/tenant_migration_multikey_index.js +++ b/jstests/replsets/tenant_migration_multikey_index.js @@ -91,8 +91,7 @@ const fpBeforeFulfillingDataConsistentPromise = configureFailPoint( recipientPrimary, "fpBeforeFulfillingDataConsistentPromise", {action: "hang"}); jsTestLog("Starting the tenant migration"); -assert.commandWorked( - tenantMigrationTest.startMigration(migrationOpts, {enableDonorStartMigrationFsync: true})); +assert.commandWorked(tenantMigrationTest.startMigration(migrationOpts)); fpBeforeFulfillingDataConsistentPromise.wait(); diff --git a/jstests/replsets/tenant_migration_no_failover.js b/jstests/replsets/tenant_migration_no_failover.js index 26f4a678194..e808c9a3c7b 100644 --- a/jstests/replsets/tenant_migration_no_failover.js +++ b/jstests/replsets/tenant_migration_no_failover.js @@ -35,8 +35,7 @@ const migrationOpts = { tenantId, }; -TenantMigrationTest.assertCommitted( - tenantMigrationTest.runMigration(migrationOpts, {enableDonorStartMigrationFsync: true})); +TenantMigrationTest.assertCommitted(tenantMigrationTest.runMigration(migrationOpts)); for (const db of [...tenantDBs, ...nonTenantDBs]) { for (const coll of collNames) { diff --git a/jstests/replsets/tenant_migration_recipient_current_op.js b/jstests/replsets/tenant_migration_recipient_current_op.js index 967b9ec9581..72161e77b29 100644 --- a/jstests/replsets/tenant_migration_recipient_current_op.js +++ b/jstests/replsets/tenant_migration_recipient_current_op.js @@ -133,8 +133,7 @@ const fpAfterForgetMigration = configureFailPoint( jsTestLog("Starting tenant migration with migrationId: " + kMigrationId + ", tenantId: " + kTenantId); -assert.commandWorked( - tenantMigrationTest.startMigration(migrationOpts, {enableDonorStartMigrationFsync: true})); +assert.commandWorked(tenantMigrationTest.startMigration(migrationOpts)); { // Wait until a current operation corresponding to "tenant recipient migration" with state diff --git a/jstests/replsets/tenant_migration_recipient_has_tenant_data.js b/jstests/replsets/tenant_migration_recipient_has_tenant_data.js index 5a7f5778404..bc3a9eea3cb 100644 --- a/jstests/replsets/tenant_migration_recipient_has_tenant_data.js +++ b/jstests/replsets/tenant_migration_recipient_has_tenant_data.js @@ -58,8 +58,7 @@ const migrationOpts = { tenantId: kTenantId, }; -TenantMigrationTest.assertCommitted( - tenantMigrationTest.runMigration(migrationOpts, {enableDonorStartMigrationFsync: true})); +TenantMigrationTest.assertCommitted(tenantMigrationTest.runMigration(migrationOpts)); tenantMigrationTest.waitForMigrationGarbageCollection(migrationId, kTenantId); jsTest.log( 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 b1e8ab7d6c6..e06cf1c95ae 100644 --- a/jstests/replsets/tenant_migration_recipient_shard_merge_learn_files.js +++ b/jstests/replsets/tenant_migration_recipient_shard_merge_learn_files.js @@ -54,8 +54,7 @@ const migrationOpts = { }; jsTestLog(`Starting the tenant migration to wait in failpoint: ${failpoint}`); -assert.commandWorked( - tenantMigrationTest.startMigration(migrationOpts, {enableDonorStartMigrationFsync: true})); +assert.commandWorked(tenantMigrationTest.startMigration(migrationOpts)); waitInFailPoint.wait(); diff --git a/jstests/replsets/tenant_migration_shard_merge_conflicting_recipient_sync_data_cmds.js b/jstests/replsets/tenant_migration_shard_merge_conflicting_recipient_sync_data_cmds.js index 2a5a88e1026..6a866d608b5 100644 --- a/jstests/replsets/tenant_migration_shard_merge_conflicting_recipient_sync_data_cmds.js +++ b/jstests/replsets/tenant_migration_shard_merge_conflicting_recipient_sync_data_cmds.js @@ -15,6 +15,7 @@ import { getCertificateAndPrivateKey, isShardMergeEnabled, + kProtocolShardMerge, makeX509OptionsForTest, } from "jstests/replsets/libs/tenant_migration_util.js"; @@ -51,13 +52,15 @@ TestData.stopFailPointErrorCode = 4880402; /** * Runs recipientSyncData on the given host and returns the response. */ -function runRecipientSyncDataCmd(primaryHost, { - migrationIdString, - tenantIds, - donorConnectionString, - readPreference, - recipientCertificateForDonor -}) { +function runRecipientSyncDataCmd(primaryHost, + { + migrationIdString, + tenantIds, + donorConnectionString, + readPreference, + recipientCertificateForDonor + }, + protocol) { jsTestLog("Starting a recipientSyncDataCmd for migrationId: " + migrationIdString + " tenantIds: '" + tenantIds + "'"); const primary = new Mongo(primaryHost); @@ -66,7 +69,7 @@ function runRecipientSyncDataCmd(primaryHost, { migrationId: UUID(migrationIdString), donorConnectionString: donorConnectionString, tenantIds: eval(tenantIds), - protocol: "shard merge", + protocol, readPreference: readPreference, startMigrationDonorTimestamp: Timestamp(1, 1), recipientCertificateForDonor: recipientCertificateForDonor @@ -113,9 +116,9 @@ function testConcurrentConflictingMigration(migrationOpts0, migrationOpts1) { // Start the conflicting recipientSyncData cmds. const recipientSyncDataThread0 = - new Thread(runRecipientSyncDataCmd, primary.host, migrationOpts0); + new Thread(runRecipientSyncDataCmd, primary.host, migrationOpts0, kProtocolShardMerge); const recipientSyncDataThread1 = - new Thread(runRecipientSyncDataCmd, primary.host, migrationOpts1); + new Thread(runRecipientSyncDataCmd, primary.host, migrationOpts1, kProtocolShardMerge); recipientSyncDataThread0.start(); recipientSyncDataThread1.start(); 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 9de3bfebe90..eb7048ef3c2 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 @@ -66,8 +66,7 @@ const migrationOpts = { migrationIdString: extractUUIDFromObject(migrationId), tenantIds: [tenantId] }; -TenantMigrationTest.assertCommitted( - tenantMigrationTest.runMigration(migrationOpts, {enableDonorStartMigrationFsync: true})); +TenantMigrationTest.assertCommitted(tenantMigrationTest.runMigration(migrationOpts)); tenantMigrationTest.getRecipientRst().nodes.forEach(node => { for (let collectionName of ["myCollection", "myCappedCollection"]) { diff --git a/jstests/replsets/tenant_migration_shard_merge_invalid_inputs.js b/jstests/replsets/tenant_migration_shard_merge_invalid_inputs.js index 81bae99e494..dbf69f06cc3 100644 --- a/jstests/replsets/tenant_migration_shard_merge_invalid_inputs.js +++ b/jstests/replsets/tenant_migration_shard_merge_invalid_inputs.js @@ -17,6 +17,7 @@ import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; import { isShardMergeEnabled, + kProtocolShardMerge, makeMigrationCertificatesForTest, } from "jstests/replsets/libs/tenant_migration_util.js"; @@ -51,7 +52,7 @@ unsupportedtenantIds.forEach((invalidTenantId) => { const cmd = { donorStartMigration: 1, migrationId: UUID(), - protocol: 'shard merge', + protocol: kProtocolShardMerge, tenantId: invalidTenantId, recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL(), readPreference, @@ -66,7 +67,7 @@ unsupportedtenantIds.forEach((invalidTenantId) => { assert.commandFailedWithCode(donorPrimary.adminCommand({ donorStartMigration: 1, migrationId: UUID(), - protocol: 'shard merge', + protocol: kProtocolShardMerge, recipientConnectionString: tenantMigrationTest.getDonorRst().getURL(), readPreference, donorCertificateForRecipient: migrationCertificates.donorCertificateForRecipient, @@ -78,7 +79,7 @@ assert.commandFailedWithCode(donorPrimary.adminCommand({ assert.commandFailedWithCode(donorPrimary.adminCommand({ donorStartMigration: 1, migrationId: UUID(), - protocol: 'shard merge', + protocol: kProtocolShardMerge, recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL() + "," + donorPrimary.host, readPreference, @@ -91,7 +92,7 @@ assert.commandFailedWithCode(donorPrimary.adminCommand({ assert.commandFailedWithCode(donorPrimary.adminCommand({ donorStartMigration: 1, migrationId: UUID(), - protocol: 'shard merge', + protocol: kProtocolShardMerge, recipientConnectionString: recipientPrimary.host, readPreference, donorCertificateForRecipient: migrationCertificates.donorCertificateForRecipient, @@ -109,7 +110,7 @@ unsupportedtenantIds.forEach((invalidTenantId) => { donorConnectionString: tenantMigrationTest.getDonorRst().getURL(), tenantId: invalidTenantId, tenantIds: [ObjectId()], - protocol: 'shard merge', + protocol: kProtocolShardMerge, startMigrationDonorTimestamp: Timestamp(1, 1), readPreference, recipientCertificateForDonor: migrationCertificates.recipientCertificateForDonor, @@ -121,7 +122,7 @@ unsupportedtenantIds.forEach((invalidTenantId) => { assert.commandFailedWithCode(recipientPrimary.adminCommand({ recipientSyncData: 1, migrationId: UUID(), - protocol: 'shard merge', + protocol: kProtocolShardMerge, tenantIds: [ObjectId()], donorConnectionString: tenantMigrationTest.getRecipientRst().getURL(), startMigrationDonorTimestamp: Timestamp(1, 1), @@ -134,7 +135,7 @@ assert.commandFailedWithCode(recipientPrimary.adminCommand({ assert.commandFailedWithCode(recipientPrimary.adminCommand({ recipientSyncData: 1, migrationId: UUID(), - protocol: 'shard merge', + protocol: kProtocolShardMerge, tenantIds: [ObjectId()], donorConnectionString: `${tenantMigrationTest.getDonorRst().getURL()},${recipientPrimary.host}`, startMigrationDonorTimestamp: Timestamp(1, 1), @@ -147,7 +148,7 @@ assert.commandFailedWithCode(recipientPrimary.adminCommand({ assert.commandFailedWithCode(recipientPrimary.adminCommand({ recipientSyncData: 1, migrationId: UUID(), - protocol: 'shard merge', + protocol: kProtocolShardMerge, tenantIds: [ObjectId()], donorConnectionString: recipientPrimary.host, startMigrationDonorTimestamp: Timestamp(1, 1), @@ -162,7 +163,7 @@ nullTimestamps.forEach((nullTs) => { assert.commandFailedWithCode(donorPrimary.adminCommand({ recipientSyncData: 1, migrationId: UUID(), - protocol: 'shard merge', + protocol: kProtocolShardMerge, tenantIds: [ObjectId()], donorConnectionString: tenantMigrationTest.getDonorRst().getURL(), startMigrationDonorTimestamp: Timestamp(1, 1), @@ -177,7 +178,7 @@ nullTimestamps.forEach((nullTs) => { assert.commandFailedWithCode(recipientPrimary.adminCommand({ recipientSyncData: 1, migrationId: UUID(), - protocol: 'shard merge', + protocol: kProtocolShardMerge, donorConnectionString: tenantMigrationTest.getDonorRst().getURL(), startMigrationDonorTimestamp: Timestamp(1, 1), readPreference, @@ -189,7 +190,7 @@ assert.commandFailedWithCode(recipientPrimary.adminCommand({ assert.commandFailedWithCode(recipientPrimary.adminCommand({ recipientSyncData: 1, migrationId: UUID(), - protocol: 'shard merge', + protocol: kProtocolShardMerge, tenantIds: [], donorConnectionString: tenantMigrationTest.getDonorRst().getURL(), startMigrationDonorTimestamp: Timestamp(1, 1), @@ -201,7 +202,7 @@ assert.commandFailedWithCode(recipientPrimary.adminCommand({ // The decision field must be set for recipientForgetMigration with shard merge assert.commandFailedWithCode(recipientPrimary.adminCommand({ recipientForgetMigration: 1, - protocol: "shard merge", + protocol: kProtocolShardMerge, migrationId: UUID(), tenantIds: [ObjectId()], donorConnectionString: tenantMigrationTest.getDonorRst().getURL(), diff --git a/jstests/replsets/tenant_migration_shard_merge_recipient_access_blocker_rollback.js b/jstests/replsets/tenant_migration_shard_merge_recipient_access_blocker_rollback.js index 6da482857eb..0d0f5cd04cb 100644 --- a/jstests/replsets/tenant_migration_shard_merge_recipient_access_blocker_rollback.js +++ b/jstests/replsets/tenant_migration_shard_merge_recipient_access_blocker_rollback.js @@ -16,7 +16,8 @@ import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.j import { getCertificateAndPrivateKey, isShardMergeEnabled, - makeX509OptionsForTest + kProtocolShardMerge, + makeX509OptionsForTest, } from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/uuid_util.js"); // For extractUUIDFromObject(). @@ -64,7 +65,7 @@ function runRollbackAfterMigrationCommitted() { const migrationOpts = { migrationIdString: extractUUIDFromObject(kMigrationId), tenantIds: [kTenantId], - protocol: "shard merge", + protocol: kProtocolShardMerge, readPreference: kReadPreference }; @@ -156,20 +157,22 @@ function runRollbackAfterLoneRecipientForgetMigrationCommand() { const fpNewPrimary = configureFailPoint(newPrimary, "pauseBeforeRunTenantMigrationRecipientInstance"); - function runRecipientForgetMigration(host, { - migrationIdString, - donorConnectionString, - tenantIds, - readPreference, - recipientCertificateForDonor - }) { + function runRecipientForgetMigration(host, + { + migrationIdString, + donorConnectionString, + tenantIds, + readPreference, + recipientCertificateForDonor + }, + protocol) { const db = new Mongo(host); return db.adminCommand({ recipientForgetMigration: 1, migrationId: UUID(migrationIdString), donorConnectionString, tenantIds: eval(tenantIds), - protocol: "shard merge", + protocol, decision: "committed", readPreference, recipientCertificateForDonor @@ -177,13 +180,16 @@ function runRollbackAfterLoneRecipientForgetMigrationCommand() { } const recipientForgetMigrationThread = - new Thread(runRecipientForgetMigration, originalPrimary.host, { - migrationIdString: extractUUIDFromObject(kMigrationId), - donorConnectionString: tenantMigrationTest.getDonorRst().getURL(), - tenantIds: tojson([kTenantId]), - readPreference: kReadPreference, - recipientCertificateForDonor - }); + new Thread(runRecipientForgetMigration, + originalPrimary.host, + { + migrationIdString: extractUUIDFromObject(kMigrationId), + donorConnectionString: tenantMigrationTest.getDonorRst().getURL(), + tenantIds: tojson([kTenantId]), + readPreference: kReadPreference, + recipientCertificateForDonor + }, + kProtocolShardMerge); // Run a delayed/retried recipientForgetMigration command after the state doc has been deleted. recipientForgetMigrationThread.start(); diff --git a/jstests/replsets/tenant_migration_shard_merge_recipient_retry_forget_migration.js b/jstests/replsets/tenant_migration_shard_merge_recipient_retry_forget_migration.js index 1dcbacef5b8..cfd593ee696 100644 --- a/jstests/replsets/tenant_migration_shard_merge_recipient_retry_forget_migration.js +++ b/jstests/replsets/tenant_migration_shard_merge_recipient_retry_forget_migration.js @@ -15,7 +15,8 @@ import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; import { getCertificateAndPrivateKey, - isShardMergeEnabled + isShardMergeEnabled, + kProtocolShardMerge, } from "jstests/replsets/libs/tenant_migration_util.js"; load("jstests/libs/fail_point_util.js"); // For configureFailPoint(). @@ -48,20 +49,17 @@ const collName = "coll"; // the state doc has been garbage collected. assert.commandWorked(recipientPrimary.getDB(dbName)[collName].insert({_id: 1})); -function runRecipientForgetMigration(host, { - migrationIdString, - donorConnectionString, - tenantIds, - readPreference, - recipientCertificateForDonor -}) { +function runRecipientForgetMigration( + host, + {migrationIdString, donorConnectionString, tenantIds, recipientCertificateForDonor}, + protocol) { const db = new Mongo(host); return db.adminCommand({ recipientForgetMigration: 1, migrationId: UUID(migrationIdString), donorConnectionString, tenantIds: eval(tenantIds), - protocol: "shard merge", + protocol, decision: "committed", readPreference: {mode: "primary"}, recipientCertificateForDonor @@ -72,12 +70,15 @@ const fp = configureFailPoint( recipientPrimary, "fpBeforeMarkingStateDocAsGarbageCollectable", {action: "hang"}); const recipientForgetMigrationThread = - new Thread(runRecipientForgetMigration, recipientPrimary.host, { - migrationIdString: extractUUIDFromObject(migrationId), - donorConnectionString: tenantMigrationTest.getDonorRst().getURL(), - tenantIds: tojson([tenantId]), - recipientCertificateForDonor - }); + new Thread(runRecipientForgetMigration, + recipientPrimary.host, + { + migrationIdString: extractUUIDFromObject(migrationId), + donorConnectionString: tenantMigrationTest.getDonorRst().getURL(), + tenantIds: tojson([tenantId]), + recipientCertificateForDonor + }, + kProtocolShardMerge); // Run a delayed/retried recipientForgetMigration command after the state doc has been deleted. recipientForgetMigrationThread.start(); @@ -114,12 +115,15 @@ assert.eq(1, newRecipientPrimary.getDB(dbName)[collName].find().itcount()); // Test that we can retry the recipientForgetMigration on the new primary. newPrimaryFp.off(); -assert.commandWorked(runRecipientForgetMigration(newRecipientPrimary.host, { - migrationIdString: extractUUIDFromObject(migrationId), - donorConnectionString: tenantMigrationTest.getDonorRst().getURL(), - tenantIds: tojson([tenantId]), - recipientCertificateForDonor -})); +assert.commandWorked(runRecipientForgetMigration( + newRecipientPrimary.host, + { + migrationIdString: extractUUIDFromObject(migrationId), + donorConnectionString: tenantMigrationTest.getDonorRst().getURL(), + tenantIds: tojson([tenantId]), + recipientCertificateForDonor + }, + kProtocolShardMerge)); currOp = assert .commandWorked( diff --git a/jstests/replsets/tenant_migration_shard_merge_ssl_configuration.js b/jstests/replsets/tenant_migration_shard_merge_ssl_configuration.js index e52d7ad6af5..6b50b1361ca 100644 --- a/jstests/replsets/tenant_migration_shard_merge_ssl_configuration.js +++ b/jstests/replsets/tenant_migration_shard_merge_ssl_configuration.js @@ -15,15 +15,15 @@ import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js"; import { - donorStartMigrationWithProtocol, getCertificateAndPrivateKey, - isMigrationCompleted, isShardMergeEnabled, + kProtocolShardMerge, makeMigrationCertificatesForTest, makeX509OptionsForTest, - runTenantMigrationCommand, } from "jstests/replsets/libs/tenant_migration_util.js"; +load("jstests/libs/uuid_util.js"); + const standalone = MongoRunner.runMongod({}); const shardMergeFeatureFlagEnabled = isShardMergeEnabled(standalone.getDB("admin")); MongoRunner.stopMongod(standalone); @@ -64,7 +64,7 @@ const kExpiredMigrationCertificates = { migrationId: UUID(), recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL(), tenantIds: [kTenantId], - protocol: "shard merge", + protocol: kProtocolShardMerge, readPreference: kReadPreference, recipientCertificateForDonor: kValidMigrationCertificates.recipientCertificateForDonor, }), @@ -77,7 +77,7 @@ const kExpiredMigrationCertificates = { migrationId: UUID(), recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL(), tenantIds: [kTenantId], - protocol: "shard merge", + protocol: kProtocolShardMerge, readPreference: kReadPreference, donorCertificateForRecipient: kValidMigrationCertificates.donorCertificateForRecipient, }), @@ -90,7 +90,7 @@ const kExpiredMigrationCertificates = { migrationId: UUID(), donorConnectionString: tenantMigrationTest.getDonorRst().getURL(), tenantIds: [kTenantId], - protocol: "shard merge", + protocol: kProtocolShardMerge, startMigrationDonorTimestamp: Timestamp(1, 1), readPreference: kReadPreference }), @@ -103,7 +103,7 @@ const kExpiredMigrationCertificates = { migrationId: UUID(), donorConnectionString: tenantMigrationTest.getDonorRst().getURL(), tenantIds: [kTenantId], - protocol: "shard merge", + protocol: kProtocolShardMerge, decision: "aborted", readPreference: kReadPreference }), @@ -128,7 +128,7 @@ const kExpiredMigrationCertificates = { migrationId: UUID(), recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL(), tenantIds: [kTenantId], - protocol: "shard merge", + protocol: kProtocolShardMerge, readPreference: kReadPreference, donorCertificateForRecipient: kValidMigrationCertificates.donorCertificateForRecipient, recipientCertificateForDonor: kValidMigrationCertificates.recipientCertificateForDonor, @@ -155,7 +155,7 @@ const kExpiredMigrationCertificates = { migrationId: UUID(), donorConnectionString: tenantMigrationTest.getDonorRst().getURL(), tenantIds: [kTenantId], - protocol: "shard merge", + protocol: kProtocolShardMerge, readPreference: kReadPreference, startMigrationDonorTimestamp: Timestamp(1, 1), recipientCertificateForDonor: kValidMigrationCertificates.recipientCertificateForDonor, @@ -193,7 +193,7 @@ const kExpiredMigrationCertificates = { migrationId: UUID(), donorConnectionString: tenantMigrationTest.getDonorRst().getURL(), tenantIds: [kTenantId], - protocol: "shard merge", + protocol: kProtocolShardMerge, startMigrationDonorTimestamp: Timestamp(1, 1), readPreference: kReadPreference })); @@ -227,7 +227,7 @@ const kExpiredMigrationCertificates = { migrationId: UUID(), donorConnectionString: tenantMigrationTest.getDonorRst().getURL(), tenantIds: [kTenantId], - protocol: "shard merge", + protocol: kProtocolShardMerge, decision: "aborted", readPreference: kReadPreference })); @@ -267,16 +267,14 @@ const kExpiredMigrationCertificates = { const migrationId = UUID(); const donorStartMigrationCmdObj = { donorStartMigration: 1, - migrationId: migrationId, + migrationIdString: extractUUIDFromObject(migrationId), recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL(), tenantIds: [kTenantId], - protocol: "shard merge", + protocol: kProtocolShardMerge, readPreference: kReadPreference }; - const stateRes = assert.commandWorked(runTenantMigrationCommand( - donorStartMigrationCmdObj, - donorRst, - {retryOnRetryableErrors: false, shouldStopFunc: isMigrationCompleted})); + const stateRes = + assert.commandWorked(tenantMigrationTest.runMigration(donorStartMigrationCmdObj)); assert.eq(stateRes.state, TenantMigrationTest.DonorState.kCommitted); assert.commandWorked( donorRst.getPrimary().adminCommand({donorForgetMigration: 1, migrationId: migrationId})); @@ -314,17 +312,15 @@ const kExpiredMigrationCertificates = { const donorStartMigrationCmdObj = { donorStartMigration: 1, - migrationId: UUID(), + migrationIdString: extractUUIDFromObject(UUID()), recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL(), tenantIds: [kTenantId], - protocol: "shard merge", + protocol: kProtocolShardMerge, readPreference: kReadPreference }; - const stateRes = assert.commandWorked(runTenantMigrationCommand( - donorStartMigrationCmdObj, - donorRst, - {retryOnRetryableErrors: false, shouldStopFunc: isMigrationCompleted})); + const stateRes = + assert.commandWorked(tenantMigrationTest.runMigration(donorStartMigrationCmdObj)); assert.eq(stateRes.state, TenantMigrationTest.DonorState.kCommitted); donorRst.stopSet(); @@ -362,18 +358,16 @@ const kExpiredMigrationCertificates = { const donorStartMigrationCmdObj = { donorStartMigration: 1, - migrationId: UUID(), + migrationIdString: extractUUIDFromObject(UUID()), recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL(), tenantIds: [kTenantId], - protocol: "shard merge", + protocol: kProtocolShardMerge, readPreference: kReadPreference, donorCertificateForRecipient: kExpiredMigrationCertificates.donorCertificateForRecipient, recipientCertificateForDonor: kExpiredMigrationCertificates.recipientCertificateForDonor, }; - const stateRes = assert.commandWorked(runTenantMigrationCommand( - donorStartMigrationCmdObj, - donorRst, - {retryOnRetryableErrors: false, shouldStopFunc: isMigrationCompleted})); + const stateRes = + assert.commandWorked(tenantMigrationTest.runMigration(donorStartMigrationCmdObj)); assert.eq(stateRes.state, TenantMigrationTest.DonorState.kCommitted); donorRst.stopSet(); diff --git a/jstests/replsets/tenant_migration_ssl_configuration.js b/jstests/replsets/tenant_migration_ssl_configuration.js index 9e9d7b5e285..2ad965fff61 100644 --- a/jstests/replsets/tenant_migration_ssl_configuration.js +++ b/jstests/replsets/tenant_migration_ssl_configuration.js @@ -16,14 +16,13 @@ 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"; +load("jstests/libs/uuid_util.js"); + const kTenantId = ObjectId().str; const kReadPreference = { mode: "primary" @@ -46,31 +45,27 @@ const kExpiredMigrationCertificates = { jsTest.log("Test that donorStartMigration requires 'donorCertificateForRecipient' when " + "tenantMigrationDisableX509Auth=false"); - assert.commandFailedWithCode( - donorPrimary.adminCommand(donorStartMigrationWithProtocol({ - donorStartMigration: 1, - migrationId: UUID(), - recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL(), - tenantId: kTenantId, - readPreference: kReadPreference, - recipientCertificateForDonor: kValidMigrationCertificates.recipientCertificateForDonor, - }, - donorPrimary.getDB("admin"))), - ErrorCodes.InvalidOptions); + assert.commandFailedWithCode(donorPrimary.adminCommand({ + donorStartMigration: 1, + migrationId: UUID(), + recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL(), + tenantId: kTenantId, + readPreference: kReadPreference, + recipientCertificateForDonor: kValidMigrationCertificates.recipientCertificateForDonor, + }), + ErrorCodes.InvalidOptions); jsTest.log("Test that donorStartMigration requires 'recipientCertificateForDonor' when " + "tenantMigrationDisableX509Auth=false"); - assert.commandFailedWithCode( - donorPrimary.adminCommand(donorStartMigrationWithProtocol({ - donorStartMigration: 1, - migrationId: UUID(), - recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL(), - tenantId: kTenantId, - readPreference: kReadPreference, - donorCertificateForRecipient: kValidMigrationCertificates.donorCertificateForRecipient, - }, - donorPrimary.getDB("admin"))), - ErrorCodes.InvalidOptions); + assert.commandFailedWithCode(donorPrimary.adminCommand({ + donorStartMigration: 1, + migrationId: UUID(), + recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL(), + tenantId: kTenantId, + readPreference: kReadPreference, + donorCertificateForRecipient: kValidMigrationCertificates.donorCertificateForRecipient, + }), + ErrorCodes.InvalidOptions); jsTest.log("Test that recipientSyncData requires 'recipientCertificateForDonor' when " + "tenantMigrationDisableX509Auth=false"); @@ -109,18 +104,16 @@ const kExpiredMigrationCertificates = { const donorPrimary = tenantMigrationTest.getDonorPrimary(); - assert.commandFailedWithCode( - 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); + assert.commandFailedWithCode(donorPrimary.adminCommand({ + donorStartMigration: 1, + migrationId: UUID(), + recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL(), + tenantId: kTenantId, + readPreference: kReadPreference, + donorCertificateForRecipient: kValidMigrationCertificates.donorCertificateForRecipient, + recipientCertificateForDonor: kValidMigrationCertificates.recipientCertificateForDonor, + }), + ErrorCodes.IllegalOperation); donorRst.stopSet(); tenantMigrationTest.stop(); @@ -246,15 +239,13 @@ const kExpiredMigrationCertificates = { const migrationId = UUID(); const donorStartMigrationCmdObj = { donorStartMigration: 1, - migrationId: migrationId, + migrationIdString: extractUUIDFromObject(migrationId), recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL(), tenantId: kTenantId, readPreference: kReadPreference }; - const stateRes = assert.commandWorked(runTenantMigrationCommand( - donorStartMigrationCmdObj, - donorRst, - {retryOnRetryableErrors: false, shouldStopFunc: isMigrationCompleted})); + const stateRes = + assert.commandWorked(tenantMigrationTest.runMigration(donorStartMigrationCmdObj)); assert.eq(stateRes.state, TenantMigrationTest.DonorState.kCommitted); assert.commandWorked( donorRst.getPrimary().adminCommand({donorForgetMigration: 1, migrationId: migrationId})); @@ -292,16 +283,14 @@ const kExpiredMigrationCertificates = { const donorStartMigrationCmdObj = { donorStartMigration: 1, - migrationId: UUID(), + migrationIdString: extractUUIDFromObject(UUID()), recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL(), tenantId: kTenantId, readPreference: kReadPreference }; - const stateRes = assert.commandWorked(runTenantMigrationCommand( - donorStartMigrationCmdObj, - donorRst, - {retryOnRetryableErrors: false, shouldStopFunc: isMigrationCompleted})); + const stateRes = + assert.commandWorked(tenantMigrationTest.runMigration(donorStartMigrationCmdObj)); assert.eq(stateRes.state, TenantMigrationTest.DonorState.kCommitted); donorRst.stopSet(); @@ -339,17 +328,15 @@ const kExpiredMigrationCertificates = { const donorStartMigrationCmdObj = { donorStartMigration: 1, - migrationId: UUID(), + migrationIdString: extractUUIDFromObject(UUID()), recipientConnectionString: tenantMigrationTest.getRecipientRst().getURL(), tenantId: kTenantId, readPreference: kReadPreference, donorCertificateForRecipient: kExpiredMigrationCertificates.donorCertificateForRecipient, recipientCertificateForDonor: kExpiredMigrationCertificates.recipientCertificateForDonor, }; - const stateRes = assert.commandWorked(runTenantMigrationCommand( - donorStartMigrationCmdObj, - donorRst, - {retryOnRetryableErrors: false, shouldStopFunc: isMigrationCompleted})); + const stateRes = + assert.commandWorked(tenantMigrationTest.runMigration(donorStartMigrationCmdObj)); assert.eq(stateRes.state, TenantMigrationTest.DonorState.kCommitted); donorRst.stopSet(); |