summaryrefslogtreecommitdiff
path: root/jstests/replsets/tenant_migration_recipient_shard_merge_learn_files.js
blob: 834c28a730944799214c0bb18b5b541641ba51df (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
 * Tests that recipient is able to learn files to be imported from donor for shard merge protocol.
 *
 * @tags: [
 *   incompatible_with_eft,
 *   incompatible_with_macos,
 *   incompatible_with_windows_tls,
 *   requires_majority_read_concern,
 *   requires_persistence,
 *   serverless,
 *   featureFlagShardMerge,
 * ]
 */

(function() {
"use strict";

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}});

const recipientPrimary = tenantMigrationTest.getRecipientPrimary();

if (!TenantMigrationUtil.isShardMergeEnabled(recipientPrimary.getDB("admin"))) {
    tenantMigrationTest.stop();
    jsTestLog("Skipping Shard Merge-specific test");
    return;
}

jsTestLog(
    "Test that recipient state is correctly set to 'learned filenames' after creating the backup cursor");
const tenantId = "testTenantId";
const tenantDB = tenantMigrationTest.tenantDB(tenantId, "DB");
const collName = "testColl";

const donorRst = tenantMigrationTest.getDonorRst();
const donorPrimary = tenantMigrationTest.getDonorPrimary();
const donorSecondary = donorRst.getSecondary();

// Do a majority write.
tenantMigrationTest.insertDonorDB(tenantDB, collName);

// Ensure our new collections appear in the backup cursor's checkpoint.
assert.commandWorked(donorPrimary.adminCommand({fsync: 1}));

const failpoint = "fpAfterStartingOplogApplierMigrationRecipientInstance";
const waitInFailPoint = configureFailPoint(recipientPrimary, failpoint, {action: "hang"});

// In order to prevent the copying of "testTenantId" databases via logical cloning from donor to
// recipient, start migration on a tenant id which is non-existent on the donor.
const migrationUuid = UUID();
const kDummyTenantId = "nonExistentTenantId";
const migrationOpts = {
    migrationIdString: extractUUIDFromObject(migrationUuid),
    tenantId: kDummyTenantId,
    readPreference: {mode: 'primary'}
};

jsTestLog(`Starting the tenant migration to wait in failpoint: ${failpoint}`);
assert.commandWorked(tenantMigrationTest.startMigration(migrationOpts));

waitInFailPoint.wait();

tenantMigrationTest.assertRecipientNodesInExpectedState(
    tenantMigrationTest.getRecipientRst().nodes,
    migrationUuid,
    kDummyTenantId,
    TenantMigrationTest.RecipientState.kCopiedFiles,
    TenantMigrationTest.RecipientAccessState.kReject);

waitInFailPoint.off();

TenantMigrationTest.assertCommitted(tenantMigrationTest.waitForMigrationToComplete(migrationOpts));

const donorPrimaryCountDocumentsResult = donorPrimary.getDB(tenantDB)[collName].countDocuments({});
const donorPrimaryCountResult = donorPrimary.getDB(tenantDB)[collName].count();

tenantMigrationTest.getRecipientRst().nodes.forEach(node => {
    // Use "countDocuments" to check actual docs, "count" to check sizeStorer data.
    assert.eq(donorPrimaryCountDocumentsResult,
              node.getDB(tenantDB)[collName].countDocuments({}),
              "countDocuments");
    assert.eq(donorPrimaryCountResult, node.getDB(tenantDB)[collName].count(), "count");
});

tenantMigrationTest.stop();
})();