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
|
/**
* Tests that hybrid index builds are only enabled in FCV 4.2.
*/
(function() {
'use strict';
const dbName = "test";
const collName = "hybrid_indexes";
const dbpath = MongoRunner.dataPath + "hybrid_indexes";
load("jstests/libs/feature_compatibility_version.js");
let conn = MongoRunner.runMongod({binVersion: "latest", cleanData: true, dbpath: dbpath});
let testDB = conn.getDB(dbName);
let testColl = testDB[collName];
testColl.insert({i: 0});
assert.commandWorked(conn.adminCommand({setFeatureCompatibilityVersion: "4.0"}));
let buildIndex = function(config) {
const background = config.background;
const expected = config.expected;
let res = testDB.adminCommand({getParameter: 1, featureCompatibilityVersion: 1});
assert.commandWorked(res);
let fcv = res.version;
clearRawMongoProgramOutput();
assert.commandWorked(testDB.adminCommand(
{configureFailPoint: 'hangBeforeIndexBuildOf', mode: "alwaysOn", data: {"i": 0}}));
let awaitBuild;
if (background) {
awaitBuild = startParallelShell(function() {
assert.commandWorked(db.hybrid_indexes.createIndex({i: 1}, {background: true}));
}, conn.port);
} else {
awaitBuild = startParallelShell(function() {
assert.commandWorked(db.hybrid_indexes.createIndex({i: 1}, {background: false}));
}, conn.port);
}
let msg =
"starting on test.hybrid_indexes properties: { v: 2, key: { i: 1.0 }, name: \"i_1\"" +
", ns: \"test.hybrid_indexes\", background: " + background + " } using method: " +
expected;
print(msg);
assert.soon(() => rawMongoProgramOutput().indexOf(msg) >= 0, "Index build not started");
assert.soon(() => rawMongoProgramOutput().indexOf("Hanging before index build of i=0") >= 0,
"Index build not hanging");
if (expected === "Background" || expected === "Hybrid") {
assert.commandWorked(testColl.insert({i: 1}));
} else {
assert.commandFailedWithCode(
testDB.runCommand({insert: collName, documents: [{i: 2}], maxTimeMS: 100}),
ErrorCodes.MaxTimeMSExpired);
}
assert.commandWorked(
testDB.adminCommand({configureFailPoint: 'hangBeforeIndexBuildOf', mode: "off"}));
awaitBuild();
assert.commandWorked(testColl.dropIndex("i_1"));
};
// Test: Background indexes behave as background indexes on FCV 4.0.
buildIndex({background: true, expected: "Background"});
// Test: Foreground indexes behave as foreground idnexes on FCV 4.0.
buildIndex({background: false, expected: "Foreground"});
// Test: Upgrade to FCV 4.2 while a background index build is in progress fails. This is subject
// to change, but characterizes the current behavior.
clearRawMongoProgramOutput();
assert.commandWorked(testDB.adminCommand(
{configureFailPoint: 'hangAfterStartingIndexBuildUnlocked', mode: "alwaysOn"}));
let awaitBuild = startParallelShell(function() {
// This fails because of the unlock failpoint.
assert.commandFailedWithCode(db.hybrid_indexes.createIndex({i: 1}, {background: true}),
ErrorCodes.OperationFailed);
}, conn.port);
assert.soon(() => rawMongoProgramOutput().indexOf("Hanging index build with no locks") >= 0,
"Index build not hanging");
assert.commandFailedWithCode(testDB.adminCommand({setFeatureCompatibilityVersion: "4.2"}),
ErrorCodes.BackgroundOperationInProgressForNamespace);
assert.commandWorked(testDB.adminCommand(
{configureFailPoint: 'hangAfterStartingIndexBuildUnlocked', mode: "off"}));
awaitBuild();
// Test: Background indexes behave as hybrid indexes on FCV 4.2.
assert.commandWorked(conn.adminCommand({setFeatureCompatibilityVersion: "4.2"}));
buildIndex({background: true, expected: "Hybrid"});
// Test: Foreground indexes behave as hybrid indexes on FCV 4.2.
buildIndex({background: false, expected: "Hybrid"});
MongoRunner.stopMongod(conn);
})();
|