Files
mongo/jstests/replsets/dbcheck/dbcheck_detects_missing_id_index.js
Zac 591928c619 SERVER-108478 JS formatted by prettier and remove clang-format (#39656)
GitOrigin-RevId: 6c8f6aded47f260aa4f7c231b17dae3302cb1e04
2025-08-21 17:27:09 +00:00

75 lines
2.2 KiB
JavaScript

/**
* Tests that dbCheck reports an error when the _id index is missing in a collection.
*
* @tags: [
* requires_fcv_80
* ]
*/
import {configureFailPoint} from "jstests/libs/fail_point_util.js";
import {ReplSetTest} from "jstests/libs/replsettest.js";
import {
checkHealthLog,
clearHealthLog,
logEveryBatch,
logQueries,
resetAndInsert,
runDbCheck,
} from "jstests/replsets/libs/dbcheck_utils.js";
// Skipping data consistency checks because secondary will be missing _id index.
TestData.skipCollectionAndIndexValidation = true;
TestData.skipCheckDBHashes = true;
const rst = new ReplSetTest({
nodes: 2,
});
rst.startSet();
rst.initiate();
rst.awaitReplication();
const primary = rst.getPrimary();
const secondary = rst.getSecondary();
const dbName = "test";
const db = primary.getDB(dbName);
const collName = "testColl";
const primaryHealthLog = primary.getDB("local").system.healthlog;
const secondaryHealthLog = secondary.getDB("local").system.healthlog;
logEveryBatch(rst);
const skipIdIndexFp = configureFailPoint(secondary, "skipIdIndex");
resetAndInsert(rst, db, collName, 100);
skipIdIndexFp.off();
runDbCheck(rst, db, collName, {}, true /* awaitCompletion */);
// Verify that secondary logs an error with missing _id index.
checkHealthLog(primaryHealthLog, logQueries.allErrorsOrWarningsQuery, 0);
checkHealthLog(secondaryHealthLog, logQueries.missingIdIndex, 1);
checkHealthLog(secondaryHealthLog, logQueries.allErrorsOrWarningsQuery, 1);
// Clear healthlog entries.
clearHealthLog(rst);
// Step up secondary.
rst.stepUp(secondary);
rst.awaitNodesAgreeOnPrimary();
rst.awaitReplication();
const newPrimary = secondary;
const newSecondary = primary;
const newPrimaryHealthLog = newPrimary.getDB("local").system.healthlog;
const newSecondaryHealthLog = newSecondary.getDB("local").system.healthlog;
runDbCheck(rst, newPrimary.getDB(dbName), collName, {}, true /* awaitCompletion */);
// Verify that the new primary logs an error with missing _id index.
checkHealthLog(newSecondaryHealthLog, logQueries.allErrorsOrWarningsQuery, 0);
checkHealthLog(newPrimaryHealthLog, logQueries.missingIdIndex, 1);
checkHealthLog(newPrimaryHealthLog, logQueries.allErrorsOrWarningsQuery, 1);
rst.stopSet();