summaryrefslogtreecommitdiff
path: root/jstests/serverless/shard_split_wait_for_block_timestamp.js
blob: 15cd8bc36a3e84f932f9e38397e8c781691ec2e4 (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
/*
 * Test that the shard split operation waits for recipient nodes to reach the blockOpTime by
 * pausing replication and observing the operation time out, then reenabling replication and
 * observing a successful split.
 *
 * @tags: [requires_fcv_62, serverless]
 */

import {
    assertMigrationState,
    findSplitOperation,
    ShardSplitTest
} from "jstests/serverless/libs/shard_split_test.js";

load("jstests/libs/fail_point_util.js");                         // for "configureFailPoint"
load("jstests/libs/write_concern_util.js");                      // for "stopServerReplication"
load("jstests/noPassthrough/libs/server_parameter_helpers.js");  // for "setParameter"

// Skip db hash check because secondary is left with a different config.
TestData.skipCheckDBHashes = true;

const test = new ShardSplitTest({
    quickGarbageCollection: true,
    nodeOptions: {
        setParameter:  // Timeout to test that the operation times out waiting for replication
            {shardSplitTimeoutMS: 2000}
    }
});
test.addRecipientNodes();

const donorPrimary = test.donor.getPrimary();
const tenantIds = [ObjectId(), ObjectId()];

// Stop replication on recipient nodes, and write a lot of data to the set
test.recipientNodes.forEach(node => stopServerReplication(node));
const largeString = 'X'.repeat(10000);
const bulk = donorPrimary.getDB("foo").bar.initializeUnorderedBulkOp();
for (let i = 0; i < 2000; i++) {
    bulk.insert({i, big: largeString});
}
assert.commandWorked(bulk.execute());

jsTestLog("Running commitShardSplit command");
const firstOperation = test.createSplitOperation(tenantIds);
assert.commandFailedWithCode(firstOperation.commit({retryOnRetryableErrors: false}),
                             ErrorCodes.TenantMigrationAborted);

firstOperation.forget();
test.cleanupSuccesfulAborted(firstOperation.migrationId, tenantIds);

jsTestLog("Restarting replication on recipient nodes, and running new split operation");
test.addRecipientNodes();
test.recipientNodes.forEach(node => restartServerReplication(node));
test.donor.awaitReplication();
test.donor.nodes.forEach(
    node => assert.commandWorked(setParameter(node, "shardSplitTimeoutMS", 60 * 1000)));

const secondOperation = test.createSplitOperation(tenantIds);
assert.isnull(findSplitOperation(donorPrimary, secondOperation.migrationId));
assert.commandWorked(secondOperation.commit());
assertMigrationState(donorPrimary, secondOperation.migrationId, "committed");

secondOperation.forget();

test.waitForGarbageCollection(secondOperation.migrationId, tenantIds);
test.stop();