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
|
/**
* If reIndex crashes after dropping indexes but before rebuilding them, a collection may exist
* without an _id index. On startup, mongod should automatically build any missing _id indexes.
*
* @tags: [
* requires_persistence
* ]
*/
(function() {
load("jstests/libs/index_catalog_helpers.js"); // For IndexCatalogHelpers.
// This test triggers an unclean shutdown, which may cause inaccurate fast counts.
TestData.skipEnforceFastCountOnValidate = true;
const baseName = 'reindex_crash_rebuilds_id_index';
const collName = baseName;
const dbpath = MongoRunner.dataPath + baseName + '/';
resetDbpath(dbpath);
const mongodOptions = {
dbpath: dbpath,
noCleanData: true
};
let conn = MongoRunner.runMongod(mongodOptions);
let testDB = conn.getDB('test');
let testColl = testDB.getCollection(collName);
// Insert a single document and create the collection.
testColl.insert({a: 1});
let spec = IndexCatalogHelpers.findByKeyPattern(testColl.getIndexes(), {_id: 1});
assert.neq(null, spec, "_id index not found");
assert.eq("_id_", spec.name, tojson(spec));
// Enable a failpoint that causes reIndex to crash after dropping the indexes but before
// rebuilding them.
assert.commandWorked(
testDB.adminCommand({configureFailPoint: 'reIndexCrashAfterDrop', mode: 'alwaysOn'}));
assert.throws(() => testColl.runCommand({reIndex: collName}));
// The server should have crashed from the failpoint.
MongoRunner.stopMongod(conn, null, {allowedExitCode: MongoRunner.EXIT_ABRUPT});
// The server should start up successfully after rebuilding the _id index.
conn = MongoRunner.runMongod(mongodOptions);
testDB = conn.getDB('test');
testColl = testDB.getCollection(collName);
assert(testColl.exists());
// The _id index should exist.
spec = IndexCatalogHelpers.findByKeyPattern(testColl.getIndexes(), {_id: 1});
assert.neq(null, spec, "_id index not found");
assert.eq("_id_", spec.name, tojson(spec));
MongoRunner.stopMongod(conn);
})();
|