summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/index_abort_before_commit_signal.js
blob: 61e2a7ee7a040a0f43f57af39ef1af792e0b0ef9 (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
/*
 * Tests that an index build fails gracefully as it is interrupted just before it signals that it
 * is ready to commit by updating the corresponding document in config.system.indexBuilds.
 *
 * @tags: [
 *     requires_replication,
 * ]
 */
(function() {
'use strict';

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

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

const primary = rst.getPrimary();
const testDB = primary.getDB('test');
const coll = testDB.getCollection('coll');
const indexBuildsColl = primary.getCollection('config.system.indexBuilds');

assert.commandWorked(coll.insert({_id: 1, a: 1}));

// Enable fail point which makes index build hang before it reads the index build
const failPoint = configureFailPoint(primary, 'hangBeforeGettingIndexBuildEntry');

const createIndex = IndexBuildTest.startIndexBuild(primary, coll.getFullName(), {a: 1}, {}, [
    ErrorCodes.IndexBuildAborted,
    ErrorCodes.NoMatchingDocument
]);

failPoint.wait();

// Index build should be present in the config.system.indexBuilds collection.
const indexMap =
    IndexBuildTest.assertIndexes(coll, 2, ['_id_'], ['a_1'], {includeBuildUUIDs: true});
const indexBuildUUID = indexMap['a_1'].buildUUID;
assert(indexBuildsColl.findOne({_id: indexBuildUUID}));

// Abort the index build. It will remove the document for the index build from the
// config.system.indexBuilds collection.
jsTestLog('Aborting the index build');
const abortIndexThread = startParallelShell('assert.commandWorked(db.getMongo().getCollection("' +
                                                coll.getFullName() + '").dropIndex("a_1"))',
                                            primary.port);
checkLog.containsJson(primary, 4656010);

// Unblock the index build and wait for the threads to join.
failPoint.off();

abortIndexThread();

// Index build should be removed from the config.system.indexBuilds collection.
assert.isnull(indexBuildsColl.findOne({_id: indexBuildUUID}));

createIndex();

jsTestLog('Waiting for index build to complete');
IndexBuildTest.waitForIndexBuildToStop(testDB, coll.getName(), 'a_1');

IndexBuildTest.assertIndexes(coll, 1, ['_id_']);

rst.stopSet();
})();