summaryrefslogtreecommitdiff
path: root/jstests/replsets/tenant_migration_recipient_sync_source_reconnect_delayed_secondary.js
blob: e39e74df6b8d248ae084ce067523c37b622e8ec2 (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
/**
 * Tests that a migration will continuously retry sync source selection when there are no available
 * donor hosts. Also checks that a donor host is considered an uneligible sync source when it has a
 * majority OpTime earlier than the recipient's stored 'startApplyingDonorOpTime'.
 *
 * Tests that if the stale donor host advances its majority OpTime to 'startApplyingDonorOpTime'
 * or later, the recipient will successfully choose that donor as sync source and resume the
 * migration.
 *
 * @tags: [
 *   incompatible_with_eft,
 *   incompatible_with_macos,
 *   incompatible_with_shard_merge,
 *   incompatible_with_windows_tls,
 *   requires_majority_read_concern,
 *   requires_persistence,
 *   serverless,
 * ]
 */

(function() {
"use strict";

load("jstests/replsets/libs/tenant_migration_recipient_sync_source.js");

// After this setUp() call, we should have a migration with 'secondary' read preference. The
// recipient should be continuously retrying sync source selection, unable to choose
// 'delayedSecondary' because it is too stale and 'donorSecondary' because it is down.
const {
    tenantMigrationTest,
    migrationOpts,
    donorSecondary,
    delayedSecondary,
    hangAfterCreatingConnections
} = setUpMigrationSyncSourceTest();

if (!tenantMigrationTest) {
    // Feature flag was not enabled.
    return;
}

jsTestLog("Restarting replication on 'delayedSecondary'");
restartServerReplication(delayedSecondary);

// The recipient should eventually be able to connect to the lagged secondary, after the secondary
// has caught up and the exclude timeout has expired.
hangAfterCreatingConnections.wait();

const recipientPrimary = tenantMigrationTest.getRecipientPrimary();
const res = recipientPrimary.adminCommand({currentOp: true, desc: "tenant recipient migration"});
const currOp = res.inprog[0];
assert.eq(delayedSecondary.host,
          currOp.donorSyncSource,
          `the recipient should only be able to choose 'delayedSecondary' as sync source`);

hangAfterCreatingConnections.off();

TenantMigrationTest.assertCommitted(tenantMigrationTest.waitForMigrationToComplete(migrationOpts));
assert.commandWorked(tenantMigrationTest.forgetMigration(migrationOpts.migrationIdString));

// Remove 'donorSecondary' so that the test can complete properly.
const donorRst = tenantMigrationTest.getDonorRst();
donorRst.remove(donorSecondary);
donorRst.stopSet();
tenantMigrationTest.stop();
})();