summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Larkin-York <dan.larkin-york@mongodb.com>2023-03-07 17:20:55 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-03-16 21:46:12 +0000
commit91958f623b194a19fa50d18958b24d73726ba488 (patch)
tree7acf6f8a06409a694b90352150b33fc6d68f3211
parent2c684d00b9f9695efda211d745ec5c461dc49e95 (diff)
downloadmongo-91958f623b194a19fa50d18958b24d73726ba488.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.js7
-rw-r--r--src/mongo/db/catalog/collection_validation.cpp15
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..63f55a0ed43 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.checkContainsWithAtLeastCountJson(
+ conn, 7463100, {"spec": {"v": 2, "key": {"_id": 1}, "name": "_id_"}}, 1));
+}
+
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 31ee797b02c..517c18aaeaf 100644
--- a/src/mongo/db/catalog/collection_validation.cpp
+++ b/src/mongo/db/catalog/collection_validation.cpp
@@ -242,6 +242,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,
@@ -262,6 +276,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)) {