summaryrefslogtreecommitdiff
path: root/jstests/serverless/shard_split_abort_while_committing.js
blob: e3688236657f5abb999067a95dfe31a3b324841d (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
/*
 * Test that a well timed abortShardSplit command does not abort an already committed split.
 *
 * @tags: [requires_fcv_52, featureFlagShardSplit, serverless]
 */

load("jstests/libs/fail_point_util.js");
load("jstests/serverless/libs/basic_serverless_test.js");

const failpoints = ["pauseShardSplitAfterUpdatingToCommittedState"];

function testAbortAfterSplitIsAppliedStillsCommits(failpoint) {
    "use strict";

    const tenantIds = ["tenant1", "tenant2"];

    const test = new BasicServerlessTest({
        recipientTagName: "recipientNode",
        recipientSetName: "recipient",
        quickGarbageCollection: true
    });
    test.addRecipientNodes();

    const donorPrimary = test.getDonorPrimary();
    const operation = test.createSplitOperation(tenantIds);

    let blockFp = configureFailPoint(donorPrimary, failpoint);
    let splitThread = operation.commitAsync();
    blockFp.wait();

    // abortCmd expects to have the decisionPromise fullfilled which would be blocked by the
    // `failpoint` already blocking from returning the promise.
    let ranAbortFp = configureFailPoint(donorPrimary, "pauseShardSplitAfterReceivingAbortCmd");
    let abortThread = operation.abortAsync();
    ranAbortFp.wait();

    blockFp.off();

    assert.commandWorked(splitThread.returnData());

    // now that the decisionPromise is fullfilled we can remove the failpoint.
    ranAbortFp.off();
    assert.commandFailed(abortThread.returnData());
    assertMigrationState(donorPrimary, operation.migrationId, "committed");

    operation.forget();
    test.waitForGarbageCollection(operation.migrationId, tenantIds);
    test.stop();
}

failpoints.forEach(fp => {
    testAbortAfterSplitIsAppliedStillsCommits(fp);
});