summaryrefslogtreecommitdiff
path: root/jstests/disk/repair_index_format_version.js
blob: 46922a98b09044fcf9bf54ddc050374cb080d334 (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
/**
 * Tests that mismatch of index type and index format version will be resolved during startup.
 */

(function() {

load('jstests/disk/libs/wt_file_helper.js');

const baseName = "repair_index_format_version";
const collNamePrefix = "test_";
let count = 0;
const dbpath = MongoRunner.dataPath + baseName + "/";

resetDbpath(dbpath);

jsTestLog("Repair the format version of a unique index.");

// Uses the modified data files in the same dbpath over restarts.
let mongod = startMongodOnExistingPath(dbpath);
let db = mongod.getDB(baseName);
let collName = collNamePrefix + count++;
db.createCollection(collName);
let testColl = db[collName];
assert.commandWorked(testColl.createIndex({a: 1}, {unique: true}));

let uri = getUriForIndex(testColl, "a_1");
alterIndexFormatVersion(uri, mongod, 8);

mongod = startMongodOnExistingPath(dbpath);
checkLog.containsJson(mongod, 6818600);

jsTestLog("Repair the format version of a non-unique index.");

db = mongod.getDB(baseName);
collName = collNamePrefix + count++;
db.createCollection(collName);
testColl = db[collName];
assert.commandWorked(testColl.createIndex({b: 1}));

uri = getUriForIndex(testColl, "b_1");
alterIndexFormatVersion(uri, mongod, 14);

mongod = startMongodOnExistingPath(dbpath);
checkLog.containsJson(mongod, 6818600);

MongoRunner.stopMongod(mongod, null, {skipValidation: true});
})();