diff options
author | XueruiFa <xuerui.fa@mongodb.com> | 2020-09-29 21:45:09 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-10-14 23:18:32 +0000 |
commit | de77c7e53ee16d69b13fd605c60d913c446b47f0 (patch) | |
tree | 1f423c1f74e7d7e2ed38321e3d885e4518a3791d | |
parent | f3a8fe3692deb71d9f15bcf5da5b779acf9956d1 (diff) | |
download | mongo-de77c7e53ee16d69b13fd605c60d913c446b47f0.tar.gz |
SERVER-50528: Test a tenant migration end to end without failover
-rw-r--r-- | jstests/replsets/libs/tenant_migration_util.js | 18 | ||||
-rw-r--r-- | jstests/replsets/tenant_migration_no_failover.js | 107 |
2 files changed, 124 insertions, 1 deletions
diff --git a/jstests/replsets/libs/tenant_migration_util.js b/jstests/replsets/libs/tenant_migration_util.js index 96c6182053b..452088f1c9f 100644 --- a/jstests/replsets/libs/tenant_migration_util.js +++ b/jstests/replsets/libs/tenant_migration_util.js @@ -194,6 +194,20 @@ var TenantMigrationUtil = (function() { return node.adminCommand({serverStatus: 1}).tenantMigrationAccessBlocker[tenantId]; } + /** + * Crafts a tenant database name, given the tenantId. + */ + function tenantDB(tenantId, dbName) { + return `${tenantId}_${dbName}`; + } + + /** + * Crafts a database name that does not belong to the tenant, given the tenantId. + */ + function nonTenantDB(tenantId, dbName) { + return `non_${tenantId}_${dbName}`; + } + return { accessState, startMigration, @@ -204,6 +218,8 @@ var TenantMigrationUtil = (function() { waitForMigrationToCommit, waitForMigrationToAbort, waitForMigrationGarbageCollection, - getTenantMigrationAccessBlocker + getTenantMigrationAccessBlocker, + tenantDB, + nonTenantDB, }; })(); diff --git a/jstests/replsets/tenant_migration_no_failover.js b/jstests/replsets/tenant_migration_no_failover.js new file mode 100644 index 00000000000..48ce82b7d9d --- /dev/null +++ b/jstests/replsets/tenant_migration_no_failover.js @@ -0,0 +1,107 @@ +/** + * Tests a full tenant migration, assuming no failover. + * + * @tags: [requires_fcv_47, requires_majority_read_concern] + */ + +(function() { +"use strict"; + +load("jstests/libs/fail_point_util.js"); +load("jstests/libs/uuid_util.js"); +load("jstests/replsets/libs/tenant_migration_util.js"); + +const numDocs = 20; +const data = []; +for (let i = 0; i < numDocs; ++i) { + data.push({_id: i, x: i}); +} +const insertDonorDB = (primary, dbName, collName) => { + const db = primary.getDB(dbName); + const coll = db.getCollection(collName); + + assert.commandWorked(coll.insertMany(data)); +}; + +const verifyReceipientDB = (primary, dbName, collName, shouldMigrate) => { + const db = primary.getDB(dbName); + const coll = db.getCollection(collName); + + const findRes = coll.find(); + const numDocsFound = findRes.count(); + + if (!shouldMigrate) { + assert.eq(0, + numDocsFound, + `Find command on recipient collection ${collName} of DB ${ + dbName} should return 0 docs, instead has count of ${numDocsFound}`); + return; + } + + assert.eq(numDocs, + numDocsFound, + `Find command on recipient collection ${collName} of DB ${dbName} should return ${ + numDocs} docs, instead has count of ${numDocsFound}`); + + const docsReturned = findRes.sort({_id: 1}).toArray(); + assert(arrayEq(docsReturned, data), + () => (`${tojson(docsReturned)} is not equal to ${tojson(data)}`)); +}; + +const name = jsTestName(); +const donorRst = new ReplSetTest( + {name: `${name}_donor`, nodes: 1, nodeOptions: {setParameter: {enableTenantMigrations: true}}}); +const recipientRst = new ReplSetTest({ + name: `${name}_recipient`, + nodes: 1, + nodeOptions: {setParameter: {enableTenantMigrations: true}} +}); + +donorRst.startSet(); +donorRst.initiate(); + +recipientRst.startSet(); +recipientRst.initiate(); + +const tenantId = 'testTenantId'; + +const dbNames = ["db0", "db1", "db2"]; +const tenantDBs = dbNames.map(dbName => TenantMigrationUtil.tenantDB(tenantId, dbName)); +const nonTenantDBs = dbNames.map(dbName => TenantMigrationUtil.nonTenantDB(tenantId, dbName)); +const collNames = ["coll0", "coll1"]; + +const donorPrimary = donorRst.getPrimary(); +const recipientPrimary = recipientRst.getPrimary(); + +for (const db of [...tenantDBs, ...nonTenantDBs]) { + for (const coll of collNames) { + insertDonorDB(donorPrimary, db, coll); + } +} + +const migrationId = UUID(); +const migrationOpts = { + migrationIdString: extractUUIDFromObject(migrationId), + recipientConnString: recipientRst.getURL(), + tenantId, + readPreference: {mode: "primary"} +}; + +const res = + assert.commandWorked(TenantMigrationUtil.startMigration(donorPrimary.host, migrationOpts)); +assert.eq(res.state, "committed"); + +for (const coll of collNames) { + for (const db of tenantDBs) { + // TODO (SERVER-50528): Change shouldMigrate to true. + verifyReceipientDB(recipientPrimary, db, coll, false /* shouldMigrate */); + } + + for (const db of nonTenantDBs) { + verifyReceipientDB(recipientPrimary, db, coll, false /* shouldMigrate */); + } +} + +donorRst.stopSet(); +recipientRst.stopSet(); +})(); |