diff options
author | Dan Larkin-York <dan.larkin-york@mongodb.com> | 2023-03-07 17:20:55 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-03-16 20:51:23 +0000 |
commit | 750e7811aa7d391d71396679f385893b61dffb4f (patch) | |
tree | d7d13fef8aa8aa7cef420c57ca5a838f25e7ddc1 | |
parent | 45b1dcb60b936fc16ae7c60ac3740a684d019b0a (diff) | |
download | mongo-750e7811aa7d391d71396679f385893b61dffb4f.tar.gz |
SERVER-74631 Log index spec when validation detects index key inconsistencies
(cherry picked from commit 354b3b2ff1a72bef452b0037a707ecdc6879bff1)
-rw-r--r-- | jstests/noPassthrough/validate_memory_limit.js | 7 | ||||
-rw-r--r-- | src/mongo/db/catalog/collection_validation.cpp | 15 |
2 files changed, 22 insertions, 0 deletions
diff --git a/jstests/noPassthrough/validate_memory_limit.js b/jstests/noPassthrough/validate_memory_limit.js index 5a576743177..2b8c026c820 100644 --- a/jstests/noPassthrough/validate_memory_limit.js +++ b/jstests/noPassthrough/validate_memory_limit.js @@ -37,6 +37,11 @@ function checkValidate(maxMemoryUsage, {minMissingKeys, maxMissingKeys}) { assert.lte(res.missingIndexEntries.length, maxMissingKeys, tojson(res)); } +function checkValidateLogs() { + assert(checkLog.checkContainsOnceJson( + conn, 7463100, {"spec": {"v": 2, "key": {"_id": 1}, "name": "_id_"}})); +} + function checkValidateRepair() { const res = coll.validate({repair: true}); assert.commandWorked(res); @@ -50,6 +55,7 @@ const indexKey = "a".repeat(kIndexKeyLength); assert.commandWorked(coll.insert({_id: indexKey})); corruptIndex(); checkValidate(1, {minMissingKeys: 1, maxMissingKeys: 1}); +checkValidateLogs(); // Can't repair successfully if there aren't any index inconsistencies reported. checkValidateRepair(); @@ -69,6 +75,7 @@ corruptIndex(); // each key is counted twice, so realistically we only expect to track 2 of them. However, there's // a small chance we could get hash collisions that would lead to us reporting only 1. checkValidate(1, {minMissingKeys: 1, maxMissingKeys: 2}); +checkValidateLogs(); // Repair, but incompletely if only some inconsistencies are reported. checkValidateRepair(); diff --git a/src/mongo/db/catalog/collection_validation.cpp b/src/mongo/db/catalog/collection_validation.cpp index c445763680b..024b801949c 100644 --- a/src/mongo/db/catalog/collection_validation.cpp +++ b/src/mongo/db/catalog/collection_validation.cpp @@ -244,6 +244,20 @@ void _validateIndexKeyCount(OperationContext* opCtx, } } +void _printIndexSpec(const ValidateState* validateState, StringData indexName) { + auto& indexes = validateState->getIndexes(); + auto indexEntry = + std::find_if(indexes.begin(), + indexes.end(), + [&](const std::shared_ptr<const IndexCatalogEntry> indexEntry) -> bool { + return indexEntry->descriptor()->indexName() == indexName; + }); + if (indexEntry != indexes.end()) { + auto indexSpec = (*indexEntry)->descriptor()->infoObj(); + LOGV2_ERROR(7463100, "Index failed validation", "spec"_attr = indexSpec); + } +} + void _reportValidationResults(OperationContext* opCtx, ValidateState* validateState, ValidateResults* results, @@ -264,6 +278,7 @@ void _reportValidationResults(OperationContext* opCtx, for (const auto& [indexName, vr] : results->indexResultsMap) { if (!vr.valid) { results->valid = false; + _printIndexSpec(validateState, indexName); } if (validateState->getSkippedIndexes().contains(indexName)) { |