summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/index_build_external_and_internal_abort.js
blob: 3279823d992e28194a3e045a6f12c94b09325974 (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
/**
 * Validate a scenario where an external index build abort (e.g. collection drop) races with an
 * internal index build abort (e.g. build failed due to invalid keys).
 *
 * @tags: [
 *   requires_fcv_71,
 *   requires_replication,
 * ]
 */
(function() {
"use strict";

load("jstests/libs/feature_flag_util.js");
load('jstests/noPassthrough/libs/index_build.js');

const rst = new ReplSetTest({
    nodes: [
        {},
    ]
});
rst.startSet();
rst.initiate();

const primary = rst.getPrimary();
const testDB = primary.getDB('test');
const coll = testDB.getCollection('test');

assert.commandWorked(coll.insert({point: {x: -15.0, y: "abc"}}));

let indexBuilderThreadFP =
    configureFailPoint(testDB, 'hangIndexBuildBeforeTransitioningReplStateTokAwaitPrimaryAbort');
let connThreadFP = configureFailPoint(testDB, 'hangInRemoveIndexBuildEntryAfterCommitOrAbort');

// Will fail with error code 13026: "geo values must be 'legacy coordinate pairs' for 2d indexes"
const waitForIndexBuild =
    IndexBuildTest.startIndexBuild(primary, coll.getFullName(), {point: "2d"}, {}, 13026);

// Wait for the index builder to detect the malformed geo value and to hang before transitioning
// the index build state to kAwaitPrimaryAbort.
indexBuilderThreadFP.wait();

// Drop the underlying collection.
const awaitDropCollection =
    startParallelShell(funWithArgs(function(collName) {
                           assert.commandWorked(db.runCommand({drop: collName}));
                       }, coll.getName()), primary.port);

// Wait for the 'drop' command to hang while tearing down the index build, just after setting the
// index build state to kAborted.
connThreadFP.wait();

// Resume the index builder thread, which would now try to abort an index that's already in kAbort
// state.
indexBuilderThreadFP.off();

// Wait for the log to confirm the index builder won't attempt to abort the build, because it's
// already in aborted state.
checkLog.containsJson(primary, 7530800);

// Resume the collection drop and wait for its completion.
connThreadFP.off();
awaitDropCollection();

waitForIndexBuild();

// The collection does not exist.
assert.eq(testDB.getCollectionNames().indexOf(coll.getName()), -1, "collection still exists.");

rst.stopSet();
})();