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
|
/*
* Tests that primary retains commit quorum provided to createIndexes across restarts.
* @tags: [requires_persistence]
*/
(function() {
"use strict";
load("jstests/replsets/rslib.js");
load('jstests/noPassthrough/libs/index_build.js');
const rst = new ReplSetTest({nodes: [{}, {rsConfig: {priority: 0}}]});
rst.startSet();
rst.initiate();
const dbName = jsTest.name();
const collName = "coll";
let primary = rst.getPrimary();
let primaryDB = primary.getDB(dbName);
const primaryColl = primaryDB[collName];
const collNss = primaryColl.getFullName();
const secondary = rst.getSecondary();
const secondaryDB = secondary.getDB(dbName);
jsTestLog("Do a document write.");
assert.commandWorked(
primaryColl.insert({_id: 0, x: 0}, {"writeConcern": {"w": "majority"}}));
rst.awaitReplication();
// This makes sure the index build on primary hangs before receiving any votes from itself and
// secondary.
IndexBuildTest.pauseIndexBuilds(secondary);
IndexBuildTest.pauseIndexBuilds(primary);
jsTestLog("Start index build.");
const awaitBuild = IndexBuildTest.startIndexBuild(
primary, collNss, {i: 1}, {}, [ErrorCodes.InterruptedDueToReplStateChange]);
jsTestLog("Wait for secondary to reach collection scan phase.");
IndexBuildTest.waitForIndexBuildToScanCollection(secondaryDB, collName, 'i_1');
jsTestLog("Wait for primary to reach collection scan phase.");
IndexBuildTest.waitForIndexBuildToScanCollection(primaryDB, collName, 'i_1');
jsTestLog("Restarting the primary");
rst.stop(primary, undefined, {skipValidation: true});
rst.start(primary, {}, true);
jsTestLog("Wait for primary to get re-elected.");
primary = rst.getPrimary();
primaryDB = primary.getDB(dbName);
awaitBuild();
jsTestLog("Resume index build on secondary.");
IndexBuildTest.resumeIndexBuilds(secondary);
IndexBuildTest.waitForIndexBuildToStop(primaryDB, collName, "i_1");
rst.awaitReplication();
// Check to see if the index was successfully created.
IndexBuildTest.assertIndexes(primaryDB[collName], 2, ['_id_', 'i_1']);
rst.stopSet();
})();
|