summaryrefslogtreecommitdiff
path: root/jstests/disk
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-18 17:02:53 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-18 17:02:53 -0300
commit959575a5ca598bf5f37fb5cebe7ed1d80d3d71f7 (patch)
treeacc8d60aedb12b70048e676e8a7349deb0010db8 /jstests/disk
parent76588293975fc059cf076779e4283e6ffaf8afff (diff)
New upstream version 6.0.20upstream
Diffstat (limited to 'jstests/disk')
-rw-r--r--jstests/disk/libs/wt_file_helper.js13
-rw-r--r--jstests/disk/repair_index_format_version.js47
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 862d189c85d..5fe8b299cb3 100644
--- a/jstests/disk/libs/wt_file_helper.js
+++ b/jstests/disk/libs/wt_file_helper.js
@@ -234,3 +234,16 @@ let truncateUriAndRestartMongod = function(uri, conn, mongodOptions) {
runWiredTigerTool("-h", conn.dbpath, "truncate", uri);
return startMongodOnExistingPath(conn.dbpath, 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");
+};
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});
+})();