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-17 00:12:19 +0000
commit08bcd3ec37715a36a6b2320aea65546f006e243a (patch)
tree172609fa8151c3f343c7e9d1adc9f1c6ca634c8c
parent4bf05dc66d1a7b64e2100508a0814849772e7999 (diff)
downloadmongo-08bcd3ec37715a36a6b2320aea65546f006e243a.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 f229d2848c8..40dbdd36626 100644
--- a/jstests/noPassthrough/validate_memory_limit.js
+++ b/jstests/noPassthrough/validate_memory_limit.js
@@ -34,12 +34,18 @@ 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_"}}));
+}
+
// Insert a document with a key larger than maxValidateMemoryUsageMB and test that we still report
// at least one inconsistency.
const indexKey = "a".repeat(kIndexKeyLength);
assert.commandWorked(coll.insert({_id: indexKey}));
corruptIndex();
checkValidate(1, {minMissingKeys: 1, maxMissingKeys: 1});
+checkValidateLogs();
// Clear collection between tests.
coll.drop();
@@ -56,6 +62,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();
MongoRunner.stopMongod(conn, null, {skipValidation: true});
})(); \ No newline at end of file
diff --git a/src/mongo/db/catalog/collection_validation.cpp b/src/mongo/db/catalog/collection_validation.cpp
index 0eaa4992ad6..81c92a4f46e 100644
--- a/src/mongo/db/catalog/collection_validation.cpp
+++ b/src/mongo/db/catalog/collection_validation.cpp
@@ -248,6 +248,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,
ValidateResultsMap* indexNsResultsMap,
@@ -268,6 +282,7 @@ void _reportValidationResults(OperationContext* opCtx,
for (const auto& [indexName, vr] : *indexNsResultsMap) {
if (!vr.valid) {
results->valid = false;
+ _printIndexSpec(validateState, indexName);
}
if (validateState->getSkippedIndexes().contains(indexName)) {