Files
mongo/jstests/replsets/dbcheck_detects_missing_id_index.js
Samy Lanka 1a568af823 Revert "SERVER-98574: Enable dbCheck feature flag (#30454)" (#30623)
GitOrigin-RevId: feed461c7a047bc91ac1b7aadd2f177e267026ed
2024-12-23 19:58:17 +00:00

75 lines
2.2 KiB
JavaScript

/**
* Tests that dbCheck reports an error when the _id index is missing in a collection.
*
* @tags: [
* featureFlagSecondaryIndexChecksInDbCheck
* ]
*/
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();