summaryrefslogtreecommitdiff
path: root/jstests/replsets/tenant_migration_collection_rename.js
blob: fceec45c7d121876c721570afa3cf004870761df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
 * Tests that tenant migrations aborts without crashing when a donor collection is renamed.
 *
 * @tags: [
 *   incompatible_with_macos,
 *   # Shard merge uses backup cursor for copying files. Collection rename during file copy
 *   # shouldn't affect backup cursor. We expect the test coverage should be already provided by the
 *   # backup cursor.
 *   incompatible_with_shard_merge,
 *   incompatible_with_windows_tls,
 *   requires_fcv_52,
 *   requires_majority_read_concern,
 *   requires_persistence,
 *   serverless,
 * ]
 */

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/rslib.js");  // 'createRstArgs'

function insertData(collection) {
    // Enough for several batches.
    const bigStr = Array(1025).toString();  // 1KB of ','
    for (let i = 0; i < 1500; i++) {
        assert.commandWorked(collection.insert({bigStr: bigStr}));
    }
}

const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()});
const kTenantId = ObjectId().str;
const kDbName = tenantMigrationTest.tenantDB(kTenantId, "testDB");
const kCollectionName = "toBeRenamed";
const donorPrimary = tenantMigrationTest.getDonorPrimary();
const recipientPrimary = tenantMigrationTest.getRecipientPrimary();
const donorRstArgs = createRstArgs(tenantMigrationTest.getDonorRst());
const db = donorPrimary.getDB(kDbName);

jsTestLog("Populate collection");
insertData(db[kCollectionName]);

jsTestLog("Done populating collection");
const migrationId = UUID();
const migrationOpts = {
    migrationIdString: extractUUIDFromObject(migrationId),
    recipientConnString: tenantMigrationTest.getRecipientConnString(),
    tenantId: kTenantId,
};

const fpAfterBatch = configureFailPoint(
    recipientPrimary, "tenantMigrationHangCollectionClonerAfterHandlingBatchResponse");

jsTestLog("Start a migration and pause after first batch");
const migrationThread = new Thread(runMigrationAsync, migrationOpts, donorRstArgs);
migrationThread.start();

jsTestLog("Wait to reach failpoint");
fpAfterBatch.wait();

jsTestLog("Rename collection");
assert.commandWorked(db.adminCommand({
    renameCollection: db[kCollectionName].getFullName(),
    to: db[kCollectionName].getFullName() + "Renamed"
}));

jsTestLog("Let migration abort");
fpAfterBatch.off();
TenantMigrationTest.assertAborted(migrationThread.returnData(), ErrorCodes.DuplicateKey);
assert.commandWorked(tenantMigrationTest.forgetMigration(migrationOpts.migrationIdString));
tenantMigrationTest.stop();