diff options
author | Yuhong Zhang <yuhong.zhang@mongodb.com> | 2022-08-08 14:21:30 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-08-08 15:15:22 +0000 |
commit | e48f8c6dd6fd3568863c64228b9e28562650906b (patch) | |
tree | 530907c39d8d79111009130a2254a8d5c0a3dc26 /jstests/disk | |
parent | e16c09dbe5ad520fe54f8c7e0e1b5aca13c08f70 (diff) | |
download | mongo-e48f8c6dd6fd3568863c64228b9e28562650906b.tar.gz |
SERVER-68186 Reconcile index table metadata during startup if there is a mismatch to the index type
Diffstat (limited to 'jstests/disk')
-rw-r--r-- | jstests/disk/libs/wt_file_helper.js | 13 | ||||
-rw-r--r-- | jstests/disk/repair_index_format_version.js | 47 |
2 files changed, 60 insertions, 0 deletions
diff --git a/jstests/disk/libs/wt_file_helper.js b/jstests/disk/libs/wt_file_helper.js index afcb3b2e06c..adf05b779ed 100644 --- a/jstests/disk/libs/wt_file_helper.js +++ b/jstests/disk/libs/wt_file_helper.js @@ -241,6 +241,19 @@ let truncateUriAndRestartMongod = function(uri, conn, mongodOptions) { }; /** + * Stops the given mongod and runs the alter command to modify the index table's metadata. + */ +let alterIndexFormatVersion = function(uri, conn, formatVersion) { + MongoRunner.stopMongod(conn, null, {skipValidation: true}); + runWiredTigerTool( + "-h", + conn.dbpath, + "alter", + "table:" + uri, + "app_metadata=(formatVersion=" + formatVersion + "),exclusive_refreshed=false"); +}; + +/** * Stops the given mongod, dumps the table with the uri, modifies the content, and loads it back to * the table. */ diff --git a/jstests/disk/repair_index_format_version.js b/jstests/disk/repair_index_format_version.js new file mode 100644 index 00000000000..46922a98b09 --- /dev/null +++ b/jstests/disk/repair_index_format_version.js @@ -0,0 +1,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}); +})(); |