summaryrefslogtreecommitdiff
path: root/jstests/serverless/shard_split_rejects_multiple_ops.js
blob: e4bf0f4fe2fec065f6b5d3e2aa8cece941473df1 (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
/**
 *
 * Tests that we can't run concurrent shard splits.
 * @tags: [requires_fcv_62, serverless]
 */

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

load("jstests/libs/fail_point_util.js");  // for "configureFailPoint"

const tenantIds = [ObjectId(), ObjectId()];

function commitShardSplitConcurrently() {
    const test = new ShardSplitTest({quickGarbageCollection: true});
    test.addRecipientNodes();

    const donorPrimary = test.donor.getPrimary();

    const fp = configureFailPoint(donorPrimary.getDB("admin"), "pauseShardSplitAfterBlocking");
    const fpAfterDecision =
        configureFailPoint(donorPrimary.getDB("admin"), "pauseShardSplitAfterDecision");

    const operation = test.createSplitOperation(tenantIds);
    const splitThread = operation.commitAsync();

    fp.wait();

    // fails because there is an ongoing shard split in blocking state.
    assert.commandFailedWithCode(donorPrimary.adminCommand({
        commitShardSplit: 1,
        migrationId: UUID(),
        tenantIds: [ObjectId(), ObjectId()],
        recipientTagName: test.recipientTagName,
        recipientSetName: test.recipientSetName
    }),
                                 117);  // ConflictingOperationInProgress

    fp.off();

    // blocks before processing any `forgetShardSplit` command.
    fpAfterDecision.wait();
    const forgetThread = operation.forgetAsync();

    // fails because the commitShardSplit hasn't be garbage collected yet.
    assert.commandFailedWithCode(donorPrimary.adminCommand({
        commitShardSplit: 1,
        migrationId: UUID(),
        tenantIds: [ObjectId(), ObjectId()],  // re use one tenantid
        recipientTagName: test.recipientTagName,
        recipientSetName: test.recipientSetName
    }),
                                 117);  // ConflictingOperationInProgress
    fpAfterDecision.off();
    assert.commandWorked(splitThread.returnData());
    assert.commandWorked(forgetThread.returnData());

    test.cleanupSuccesfulCommitted(operation.migrationId, tenantIds);

    // another split operation can start after garbage collection of the previous one.
    test.addRecipientNodes();
    assert.commandWorked(donorPrimary.adminCommand({
        commitShardSplit: 1,
        migrationId: UUID(),
        tenantIds: [ObjectId(), ObjectId()],
        recipientTagName: test.recipientTagName,
        recipientSetName: test.recipientSetName
    }));

    test.stop();
}

commitShardSplitConcurrently();