summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/resumable_index_build_mixed_phases.js
blob: 21e64da1346f55d6fdd636c099a753368ad7099a (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/**
 * Tests that resumable index builds in different phases write their state to disk upon clean
 * shutdown and are resumed from the same phase to completion when the node is started back up.
 *
 * @tags: [
 *   requires_majority_read_concern,
 *   requires_persistence,
 *   requires_replication,
 * ]
 */
(function() {
"use strict";

load("jstests/noPassthrough/libs/index_build.js");
load("jstests/libs/sbe_util.js");  // For checkSBEEnabled.

const dbName = "test";

const rst = new ReplSetTest({nodes: 1});
rst.startSet();
rst.initiate();

const columnstoreEnabled = checkSBEEnabled(
    rst.getPrimary().getDB(dbName), ["featureFlagColumnstoreIndexes", "featureFlagSbeFull"], true);

const runTest = function(docs, indexSpecs, failPoints, resumePhases, resumeChecks, collNameSuffix) {
    const coll = rst.getPrimary().getDB(dbName).getCollection(
        jsTestName() + "_" + resumePhases[0].replace(" ", "_") + "_" +
        resumePhases[1].replace(" ", "_") + collNameSuffix);
    assert.commandWorked(coll.insert(docs));

    ResumableIndexBuildTest.run(rst,
                                dbName,
                                coll.getName(),
                                indexSpecs,
                                failPoints,
                                1,
                                resumePhases,
                                resumeChecks,
                                [{a: 4, b: 4}, {a: 5, b: 5}, {a: 6, b: 6}],
                                [{a: 7, b: 7}, {a: 8, b: 8}, {a: 9, b: 9}]);
};

const runTests = function(failPoints, resumePhases, resumeChecks) {
    runTest([{a: 1, b: 1}, {a: 2, b: 2}, {a: 3, b: 3}],
            [[{a: 1}], [{b: 1}]],
            failPoints,
            resumePhases,
            resumeChecks,
            "");
    runTest([{a: [1, 2]}, {a: 2, b: 2}, {a: 3, b: [3, 4]}],
            [[{a: 1}], [{b: 1}]],
            failPoints,
            resumePhases,
            resumeChecks,
            "_multikey");
    runTest([{a: [1, 2], b: {c: [3, 4]}}, {d: "", e: "", f: [[]]}, {g: null, h: 8}],
            [[{"$**": 1}], [{h: 1}]],
            failPoints,
            resumePhases,
            resumeChecks,
            "_wildcard");
};

runTests(
    [
        {name: "hangIndexBuildBeforeWaitingUntilMajorityOpTime", logIdWithBuildUUID: 4940901},
        {name: "hangIndexBuildDuringCollectionScanPhaseBeforeInsertion", logIdWithBuildUUID: 20386}
    ],
    ["initialized", "collection scan"],
    [{numScannedAfterResume: 6}, {numScannedAfterResume: 5}]);
runTests(
    [
        {name: "hangIndexBuildBeforeWaitingUntilMajorityOpTime", logIdWithBuildUUID: 4940901},
        {name: "hangIndexBuildDuringBulkLoadPhase", logIdWithIndexName: 4924400}
    ],
    ["initialized", "bulk load"],
    [{numScannedAfterResume: 6}, {skippedPhaseLogID: 20391}]);
runTests(
    [
        {name: "hangIndexBuildBeforeWaitingUntilMajorityOpTime", logIdWithBuildUUID: 4940901},
        {name: "hangIndexBuildDuringDrainWritesPhase", logIdWithIndexName: 4841800}
    ],
    ["initialized", "drain writes"],
    [{numScannedAfterResume: 6}, {skippedPhaseLogID: 20392}]);
runTests(
    [
        {name: "hangIndexBuildDuringCollectionScanPhaseBeforeInsertion", logIdWithBuildUUID: 20386},
        {name: "hangIndexBuildDuringBulkLoadPhase", logIdWithIndexName: 4924400}
    ],
    ["collection scan", "bulk load"],
    [{numScannedAfterResume: 5}, {skippedPhaseLogID: 20391}]);
runTests(
    [
        {name: "hangIndexBuildDuringCollectionScanPhaseBeforeInsertion", logIdWithBuildUUID: 20386},
        {name: "hangIndexBuildDuringDrainWritesPhase", logIdWithIndexName: 4841800}
    ],
    ["collection scan", "drain writes"],
    [{numScannedAfterResume: 5}, {skippedPhaseLogID: 20392}]);
runTests(
    [
        {name: "hangIndexBuildDuringBulkLoadPhase", logIdWithIndexName: 4924400},
        {name: "hangIndexBuildDuringDrainWritesPhase", logIdWithIndexName: 4841800}
    ],
    ["bulk load", "drain writes"],
    [{skippedPhaseLogID: 20391}, {skippedPhaseLogID: 20392}]);

// TODO (SERVER-65978): Add sidewrites to tests and combine columnTests with normal runTests once
// side writes are implemented as the numbers for numScannedAfterResume will match
if (columnstoreEnabled) {
    const runColumnTests = function(failPoints, resumePhases, resumeChecks) {
        const docs = [{a: 1, b: 1}, {a: 2, b: 2}, {a: 3, b: 3}];
        const coll = rst.getPrimary().getDB(dbName).getCollection(
            jsTestName() + "_" + resumePhases[0].replace(" ", "_") + "_" +
            resumePhases[1].replace(" ", "_") + "_columnstore");
        assert.commandWorked(coll.insert(docs));

        ResumableIndexBuildTest.run(rst,
                                    dbName,
                                    coll.getName(),
                                    [[{b: 1}], [{"$**": "columnstore"}]],
                                    failPoints,
                                    1,
                                    resumePhases,
                                    resumeChecks,
                                    [],
                                    [{a: 7, b: 7}, {a: 8, b: 8}, {a: 9, b: 9}]);
    };

    runColumnTests(
        [
            {name: "hangIndexBuildBeforeWaitingUntilMajorityOpTime", logIdWithBuildUUID: 4940901},
            {
                name: "hangIndexBuildDuringCollectionScanPhaseBeforeInsertion",
                logIdWithBuildUUID: 20386
            }
        ],
        ["initialized", "collection scan"],
        [{numScannedAfterResume: 3}, {numScannedAfterResume: 2}]);

    runColumnTests(
        [
            {name: "hangIndexBuildBeforeWaitingUntilMajorityOpTime", logIdWithBuildUUID: 4940901},
            {name: "hangIndexBuildDuringBulkLoadPhase", logIdWithIndexName: 4924400}

        ],
        ["initialized", "bulk load"],
        [{numScannedAfterResume: 3}, {skippedPhaseLogID: 20391}]);

    runColumnTests(
        [
            {
                name: "hangIndexBuildDuringCollectionScanPhaseBeforeInsertion",
                logIdWithBuildUUID: 20386
            },
            {name: "hangIndexBuildDuringBulkLoadPhase", logIdWithIndexName: 4924400}
        ],
        ["collection scan", "bulk load"],
        [{numScannedAfterResume: 2}, {skippedPhaseLogID: 20391}]);
}
rst.stopSet();
})();