diff options
author | Dan Larkin-York <dan.larkin-york@mongodb.com> | 2023-01-30 22:17:36 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-02-11 19:36:49 +0000 |
commit | 1239081e30fb48fc06cae77dc1993e19b56f506c (patch) | |
tree | 33ce52f49b973dd22ae1ff68c8b639beb5ec4088 | |
parent | a2cc20bf8bc252e7eb01a71a8a3b180e31980594 (diff) | |
download | mongo-1239081e30fb48fc06cae77dc1993e19b56f506c.tar.gz |
SERVER-72677 Surface index validation errors arising from WT::verify
(cherry picked from commit 40c93f028e36f78c06756f4bfd358d240bdd9b34)
-rw-r--r-- | jstests/noPassthrough/background_validation_checkpoint_existence.js | 20 | ||||
-rw-r--r-- | src/mongo/db/catalog/collection_validation.cpp | 21 | ||||
-rw-r--r-- | src/mongo/db/catalog/collection_validation_test.cpp | 13 | ||||
-rw-r--r-- | src/mongo/db/catalog/validate_state.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/catalog/validate_state.h | 8 | ||||
-rw-r--r-- | src/mongo/db/storage/wiredtiger/wiredtiger_index_util.cpp | 10 |
6 files changed, 57 insertions, 21 deletions
diff --git a/jstests/noPassthrough/background_validation_checkpoint_existence.js b/jstests/noPassthrough/background_validation_checkpoint_existence.js index 8b5a1cd8ea0..438278b9aea 100644 --- a/jstests/noPassthrough/background_validation_checkpoint_existence.js +++ b/jstests/noPassthrough/background_validation_checkpoint_existence.js @@ -32,30 +32,30 @@ for (let i = 0; i < 5; i++) { // The collection has not been checkpointed yet, so there is nothing to validate. let res = assert.commandWorked(db.runCommand({validate: collName, background: true})); -assert.eq(true, res.valid); -assert.eq(false, res.hasOwnProperty("nrecords")); -assert.eq(false, res.hasOwnProperty("nIndexes")); +assert.eq(true, res.valid, res); +assert.eq(false, res.hasOwnProperty("nrecords"), res); +assert.eq(false, res.hasOwnProperty("nIndexes"), res); forceCheckpoint(); res = assert.commandWorked(db.runCommand({validate: collName, background: true})); -assert.eq(true, res.valid); -assert.eq(true, res.hasOwnProperty("nrecords")); -assert.eq(true, res.hasOwnProperty("nIndexes")); +assert.eq(true, res.valid, res); +assert.eq(true, res.hasOwnProperty("nrecords"), res); +assert.eq(true, res.hasOwnProperty("nIndexes"), res); assert.commandWorked(coll.createIndex({x: 1})); // Shouldn't validate the newly created index here as it wasn't checkpointed yet. res = assert.commandWorked(db.runCommand({validate: collName, background: true})); -assert.eq(true, res.valid); -assert.eq(1, res.nIndexes); +assert.eq(true, res.valid, res); +assert.eq(1, res.nIndexes, res); forceCheckpoint(); // Validating after the checkpoint should validate the newly created index. res = assert.commandWorked(db.runCommand({validate: collName, background: true})); -assert.eq(true, res.valid); -assert.eq(2, res.nIndexes); +assert.eq(true, res.valid, res); +assert.eq(2, res.nIndexes, res); MongoRunner.stopMongod(conn); }());
\ 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 2c6661a4f5c..6f97ed729a4 100644 --- a/src/mongo/db/catalog/collection_validation.cpp +++ b/src/mongo/db/catalog/collection_validation.cpp @@ -261,19 +261,20 @@ void _reportValidationResults(OperationContext* opCtx, // Report detailed index validation results gathered when using {full: true} for validated // indexes. - for (const auto& index : validateState->getIndexes()) { - const std::string indexName = index->descriptor()->indexName(); - auto& indexResultsMap = results->indexResultsMap; - if (indexResultsMap.find(indexName) == indexResultsMap.end()) { - continue; - } - - auto& vr = indexResultsMap.at(indexName); - + int nIndexes = results->indexResultsMap.size(); + for (const auto& [indexName, vr] : results->indexResultsMap) { if (!vr.valid) { results->valid = false; } + if (validateState->getSkippedIndexes().contains(indexName)) { + // Index internal state was checked and cleared, so it was reported in indexResultsMap, + // but we did not verify the index contents against the collection, so we should exclude + // it from this report. + --nIndexes; + continue; + } + BSONObjBuilder bob(indexDetails.subobjStart(indexName)); bob.appendBool("valid", vr.valid); @@ -292,7 +293,7 @@ void _reportValidationResults(OperationContext* opCtx, results->errors.insert(results->errors.end(), vr.errors.begin(), vr.errors.end()); } - output->append("nIndexes", static_cast<int>(validateState->getIndexes().size())); + output->append("nIndexes", nIndexes); output->append("keysPerIndex", keysPerIndex.done()); output->append("indexDetails", indexDetails.done()); } diff --git a/src/mongo/db/catalog/collection_validation_test.cpp b/src/mongo/db/catalog/collection_validation_test.cpp index 15f8f475aec..03f460af790 100644 --- a/src/mongo/db/catalog/collection_validation_test.cpp +++ b/src/mongo/db/catalog/collection_validation_test.cpp @@ -276,6 +276,19 @@ TEST_F(CollectionValidationTest, ValidateEnforceFastCount) { {CollectionValidation::ValidateMode::kForegroundFullEnforceFastCount}); } +TEST_F(CollectionValidationDiskTest, ValidateIndexDetailResultsSurfaceVerifyErrors) { + FailPointEnableBlock fp{"WTValidateIndexStructuralDamage"}; + auto opCtx = operationContext(); + insertDataRange(opCtx, 0, 5); // initialize collection + foregroundValidate( + opCtx, + /*valid*/ false, + /*numRecords*/ std::numeric_limits<int32_t>::min(), // uninitialized + /*numInvalidDocuments*/ std::numeric_limits<int32_t>::min(), // uninitialized + /*numErrors*/ 1, + {CollectionValidation::ValidateMode::kForegroundFull}); +} + /** * Waits for a parallel running collection validation operation to start and then hang at a * failpoint. diff --git a/src/mongo/db/catalog/validate_state.cpp b/src/mongo/db/catalog/validate_state.cpp index 9f0fd873f59..5b64ada4226 100644 --- a/src/mongo/db/catalog/validate_state.cpp +++ b/src/mongo/db/catalog/validate_state.cpp @@ -272,6 +272,7 @@ void ValidateState::initializeCursors(OperationContext* opCtx) { "checkpoint.", "desc_indexName"_attr = desc->indexName(), "nss"_attr = _nss); + _skippedIndexes.emplace(desc->indexName()); continue; } @@ -289,12 +290,15 @@ void ValidateState::initializeCursors(OperationContext* opCtx) { "yet in a checkpoint.", "desc_indexName"_attr = desc->indexName(), "nss"_attr = _nss); + _skippedIndexes.emplace(desc->indexName()); continue; } auto iam = entry->accessMethod()->asSortedData(); - if (!iam) + if (!iam) { + _skippedIndexes.emplace(desc->indexName()); continue; + } _indexCursors.emplace( desc->indexName(), diff --git a/src/mongo/db/catalog/validate_state.h b/src/mongo/db/catalog/validate_state.h index c508a6b5850..14f9008207d 100644 --- a/src/mongo/db/catalog/validate_state.h +++ b/src/mongo/db/catalog/validate_state.h @@ -145,6 +145,10 @@ public: return _indexes; } + const StringSet& getSkippedIndexes() const { + return _skippedIndexes; + } + /** * Map of index names to index cursors. */ @@ -257,6 +261,10 @@ private: std::unique_ptr<SeekableRecordThrottleCursor> _traverseRecordStoreCursor; std::unique_ptr<SeekableRecordThrottleCursor> _seekRecordStoreCursor; + // Stores the set of indexes that will not be validated for some reason, e.g. they are not + // ready. + StringSet _skippedIndexes; + RecordId _firstRecordId; DataThrottle _dataThrottle; diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_index_util.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_index_util.cpp index 273b692c375..38fa4c4ccc8 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_index_util.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_index_util.cpp @@ -37,6 +37,7 @@ namespace mongo { MONGO_FAIL_POINT_DEFINE(WTCompactIndexEBUSY); +MONGO_FAIL_POINT_DEFINE(WTValidateIndexStructuralDamage); bool WiredTigerIndexUtil::appendCustomStats(OperationContext* opCtx, BSONObjBuilder* output, @@ -122,6 +123,15 @@ bool WiredTigerIndexUtil::validateStructure(OperationContext* opCtx, const std::string& uri, IndexValidateResults* fullResults) { if (fullResults && !WiredTigerRecoveryUnit::get(opCtx)->getSessionCache()->isEphemeral()) { + if (WTValidateIndexStructuralDamage.shouldFail()) { + std::string msg = str::stream() << "verify() returned an error. " + << "This indicates structural damage. " + << "Not examining individual index entries."; + fullResults->errors.push_back(msg); + fullResults->valid = false; + return false; + } + int err = WiredTigerUtil::verifyTable(opCtx, uri, &(fullResults->errors)); if (err == EBUSY) { std::string msg = str::stream() |