diff options
author | Cheahuychou Mao <mao.cheahuychou@gmail.com> | 2020-09-28 07:07:11 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-09-28 21:10:54 +0000 |
commit | 4085db0d66c107cc6b475e3d4cc7e7a17d71ba93 (patch) | |
tree | 0f454484e3ca9aecf6856957eefcc1f7755327bc /jstests/replsets/libs/tenant_migration_util.js | |
parent | 1075a48476d8bff9e57a39b40d599e62f8c427f9 (diff) | |
download | mongo-4085db0d66c107cc6b475e3d4cc7e7a17d71ba93.tar.gz |
SERVER-51169 Add a helper function to tenant_migration_util.js for running donorStartMigration and retry on NotPrimary errors
Diffstat (limited to 'jstests/replsets/libs/tenant_migration_util.js')
-rw-r--r-- | jstests/replsets/libs/tenant_migration_util.js | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/jstests/replsets/libs/tenant_migration_util.js b/jstests/replsets/libs/tenant_migration_util.js index 0a747da6237..a2313a56041 100644 --- a/jstests/replsets/libs/tenant_migration_util.js +++ b/jstests/replsets/libs/tenant_migration_util.js @@ -62,6 +62,56 @@ var TenantMigrationUtil = (function() { } /** + * Runs the donorStartMigration command with the given migration options every 'intervalMS' + * until the migration commits or aborts, or until the command fails with error other than + * NotPrimary errors. Returns the last command response. + */ + function startMigrationRetryOnNotPrimaryErrors(donorRstArgs, migrationOpts, intervalMS = 100) { + const cmdObj = { + donorStartMigration: 1, + migrationId: UUID(migrationOpts.migrationIdString), + recipientConnectionString: migrationOpts.recipientConnString, + databasePrefix: migrationOpts.dbPrefix, + readPreference: migrationOpts.readPreference + }; + + const donorRst = new ReplSetTest({rstArgs: donorRstArgs}); + let primary = donorRst.getPrimary(); + + while (true) { + const res = primary.adminCommand(cmdObj); + if (!res.ok) { + if (!ErrorCodes.isNotPrimaryError(res.code)) { + return res; + } + primary = donorRst.getPrimary(); + } else if (res.state == "committed" || res.state == "aborted") { + return res; + } + sleep(intervalMS); + } + } + + /** + * Runs the donorForgetMigration command with the given migrationId until the command succeeds + * or fails with error other than NotPrimary errors. Returns the last command response. + */ + function forgetMigrationRetryOnNotPrimaryErrors(donorRstArgs, migrationIdString) { + const cmdObj = {donorForgetMigration: 1, migrationId: UUID(migrationIdString)}; + + const donorRst = new ReplSetTest({rstArgs: donorRstArgs}); + let primary = donorRst.getPrimary(); + + while (true) { + const res = primary.adminCommand(cmdObj); + if (res.ok || !ErrorCodes.isNotPrimaryError(res.code)) { + return res; + } + primary = donorRst.getPrimary(); + } + } + + /** * Asserts that the migration 'migrationId' and 'dbPrefix' eventually goes to state "committed" * on all the given nodes. */ @@ -96,6 +146,8 @@ var TenantMigrationUtil = (function() { accessState, startMigration, forgetMigration, + startMigrationRetryOnNotPrimaryErrors, + forgetMigrationRetryOnNotPrimaryErrors, assertMigrationCommitted, waitForMigrationToCommit, waitForMigrationGarbageCollection |