From 86d40fda4d156c0a439f1c5edb2b7890a085d337 Mon Sep 17 00:00:00 2001 From: Dianna Hohensee Date: Thu, 5 Mar 2020 19:01:26 -0500 Subject: SERVER-46666 Add extra validate logging for unit tests for debug proposes rename src/mongo/db/storage/{storage_unittest_debug_util.cpp => storage_debug_util.cpp} (73%) rename src/mongo/db/storage/{storage_unittest_debug_util.h => storage_debug_util.h} (80%) --- src/mongo/db/catalog/SConscript | 1 + src/mongo/db/catalog/collection_validation.cpp | 5 +- src/mongo/db/catalog/collection_validation.h | 3 +- src/mongo/db/catalog/index_consistency.cpp | 20 +++ src/mongo/db/catalog/validate_adaptor.cpp | 7 + src/mongo/db/catalog/validate_state.cpp | 9 +- src/mongo/db/catalog/validate_state.h | 19 ++- src/mongo/db/storage/SConscript | 4 +- src/mongo/db/storage/storage_debug_util.cpp | 160 +++++++++++++++++++++ src/mongo/db/storage/storage_debug_util.h | 75 ++++++++++ .../db/storage/storage_unittest_debug_util.cpp | 145 ------------------- src/mongo/db/storage/storage_unittest_debug_util.h | 59 -------- src/mongo/dbtests/SConscript | 2 +- src/mongo/dbtests/validate_tests.cpp | 18 ++- 14 files changed, 308 insertions(+), 219 deletions(-) create mode 100644 src/mongo/db/storage/storage_debug_util.cpp create mode 100644 src/mongo/db/storage/storage_debug_util.h delete mode 100644 src/mongo/db/storage/storage_unittest_debug_util.cpp delete mode 100644 src/mongo/db/storage/storage_unittest_debug_util.h (limited to 'src') diff --git a/src/mongo/db/catalog/SConscript b/src/mongo/db/catalog/SConscript index 6f14a2acd73..e81845269a9 100644 --- a/src/mongo/db/catalog/SConscript +++ b/src/mongo/db/catalog/SConscript @@ -369,6 +369,7 @@ env.Library( '$BUILD_DIR/mongo/db/logical_clock', '$BUILD_DIR/mongo/db/repl/repl_settings', '$BUILD_DIR/mongo/db/storage/storage_engine_common', + '$BUILD_DIR/mongo/db/storage/storage_debug_util', '$BUILD_DIR/mongo/db/transaction', 'index_build_block', 'throttle_cursor', diff --git a/src/mongo/db/catalog/collection_validation.cpp b/src/mongo/db/catalog/collection_validation.cpp index ffdff6aa52d..76e04d45bd6 100644 --- a/src/mongo/db/catalog/collection_validation.cpp +++ b/src/mongo/db/catalog/collection_validation.cpp @@ -430,14 +430,15 @@ Status validate(OperationContext* opCtx, ValidateOptions options, bool background, ValidateResults* results, - BSONObjBuilder* output) { + BSONObjBuilder* output, + bool turnOnExtraLoggingForTest) { invariant(!opCtx->lockState()->isLocked() || storageGlobalParams.repair); // Background validation does not support any type of full validation. invariant(!(background && (options != ValidateOptions::kNoFullValidation))); // This is deliberately outside of the try-catch block, so that any errors thrown in the // constructor fail the cmd, as opposed to returning OK with valid:false. - ValidateState validateState(opCtx, nss, background, options); + ValidateState validateState(opCtx, nss, background, options, turnOnExtraLoggingForTest); const auto replCoord = repl::ReplicationCoordinator::get(opCtx); // Check whether we are allowed to read from this node after acquiring our locks. If we are diff --git a/src/mongo/db/catalog/collection_validation.h b/src/mongo/db/catalog/collection_validation.h index 8809337edd8..fa1b9986589 100644 --- a/src/mongo/db/catalog/collection_validation.h +++ b/src/mongo/db/catalog/collection_validation.h @@ -75,7 +75,8 @@ Status validate(OperationContext* opCtx, ValidateOptions options, bool background, ValidateResults* results, - BSONObjBuilder* output); + BSONObjBuilder* output, + bool turnOnExtraLoggingForTest = false); /** * Checks whether a failpoint has been hit in the above validate() code.. diff --git a/src/mongo/db/catalog/index_consistency.cpp b/src/mongo/db/catalog/index_consistency.cpp index 966b0ada728..ebd4e5900dd 100644 --- a/src/mongo/db/catalog/index_consistency.cpp +++ b/src/mongo/db/catalog/index_consistency.cpp @@ -38,6 +38,8 @@ #include "mongo/db/catalog/index_catalog.h" #include "mongo/db/db_raii.h" #include "mongo/db/index/index_descriptor.h" +#include "mongo/db/storage/storage_debug_util.h" +#include "mongo/logv2/log.h" #include "mongo/util/string_map.h" namespace mongo { @@ -212,6 +214,15 @@ void IndexConsistency::addDocKey(OperationContext* opCtx, // keys encountered. _indexKeyCount[hash]++; indexInfo->numRecords++; + + if (MONGO_unlikely(_validateState->extraLoggingForTest())) { + LOGV2(46666002, "[validate](record) {hash_num}", "hash_num"_attr = hash); + const BSONObj& keyPatternBson = indexInfo->keyPattern; + auto keyStringBson = KeyString::toBsonSafe( + ks.getBuffer(), ks.getSize(), indexInfo->ord, ks.getTypeBits()); + StorageDebugUtil::printKeyString( + recordId, ks, keyPatternBson, keyStringBson, "[validate](record)"); + } } else if (_indexKeyCount[hash]) { // Found a document key for a hash bucket that had mismatches. @@ -246,6 +257,15 @@ void IndexConsistency::addIndexKey(const KeyString::Value& ks, // keys encountered. _indexKeyCount[hash]--; indexInfo->numKeys++; + + if (MONGO_unlikely(_validateState->extraLoggingForTest())) { + LOGV2(46666003, "[validate](index) {hash_num}", "hash_num"_attr = hash); + const BSONObj& keyPatternBson = indexInfo->keyPattern; + auto keyStringBson = KeyString::toBsonSafe( + ks.getBuffer(), ks.getSize(), indexInfo->ord, ks.getTypeBits()); + StorageDebugUtil::printKeyString( + recordId, ks, keyPatternBson, keyStringBson, "[validate](index)"); + } } else if (_indexKeyCount[hash]) { // Found an index key for a bucket that has inconsistencies. // If there is a corresponding document key for the index entry key, we remove the key from diff --git a/src/mongo/db/catalog/validate_adaptor.cpp b/src/mongo/db/catalog/validate_adaptor.cpp index 84183e6dce2..a6d5ca72b6b 100644 --- a/src/mongo/db/catalog/validate_adaptor.cpp +++ b/src/mongo/db/catalog/validate_adaptor.cpp @@ -69,6 +69,13 @@ Status ValidateAdaptor::validateRecord(OperationContext* opCtx, return exceptionToStatus(); } + if (MONGO_unlikely(_validateState->extraLoggingForTest())) { + LOGV2(46666001, + "[validate](record) {record_id}, Value: {record_data}", + "record_id"_attr = recordId, + "record_data"_attr = recordBson); + } + const Status status = validateBSON( recordBson.objdata(), recordBson.objsize(), Validator::enabledBSONVersion()); if (status.isOK()) { diff --git a/src/mongo/db/catalog/validate_state.cpp b/src/mongo/db/catalog/validate_state.cpp index f31a3fe8647..aa1b85d4d68 100644 --- a/src/mongo/db/catalog/validate_state.cpp +++ b/src/mongo/db/catalog/validate_state.cpp @@ -54,8 +54,13 @@ namespace CollectionValidation { ValidateState::ValidateState(OperationContext* opCtx, const NamespaceString& nss, bool background, - ValidateOptions options) - : _nss(nss), _background(background), _options(options), _dataThrottle(opCtx) { + ValidateOptions options, + bool turnOnExtraLoggingForTest) + : _nss(nss), + _background(background), + _options(options), + _dataThrottle(opCtx), + _extraLoggingForTest(turnOnExtraLoggingForTest) { // Subsequent re-locks will use the UUID when 'background' is true. if (_background) { diff --git a/src/mongo/db/catalog/validate_state.h b/src/mongo/db/catalog/validate_state.h index e316a850d9b..258fa6ca4c7 100644 --- a/src/mongo/db/catalog/validate_state.h +++ b/src/mongo/db/catalog/validate_state.h @@ -55,10 +55,15 @@ class ValidateState { ValidateState& operator=(const ValidateState&) = delete; public: + /** + * 'turnOnExtraLoggingForTest' turns on extra logging for test debugging. This parameter is for + * unit testing only. + */ ValidateState(OperationContext* opCtx, const NamespaceString& nss, bool background, - ValidateOptions options); + ValidateOptions options, + bool turnOnExtraLoggingForTest = false); const NamespaceString& nss() const { return _nss; @@ -132,6 +137,15 @@ public: */ void initializeCursors(OperationContext* opCtx); + /** + * Indicates whether extra logging should occur during validation. + * + * This is for unit testing only. Intended to improve diagnosibility. + */ + bool extraLoggingForTest() { + return _extraLoggingForTest; + } + private: ValidateState() = delete; @@ -196,6 +210,9 @@ private: // Used to detect when the catalog is re-opened while yielding locks. uint64_t _catalogGeneration; + + // Can be set by unit tests to obtain better insight into what validate sees/does. + bool _extraLoggingForTest; }; } // namespace CollectionValidation diff --git a/src/mongo/db/storage/SConscript b/src/mongo/db/storage/SConscript index 520a2229470..963b2fc0196 100644 --- a/src/mongo/db/storage/SConscript +++ b/src/mongo/db/storage/SConscript @@ -212,9 +212,9 @@ env.Library( ) env.Library( - target='storage_unittest_debug_util', + target='storage_debug_util', source=[ - 'storage_unittest_debug_util.cpp', + 'storage_debug_util.cpp', ], LIBDEPS_PRIVATE=[ '$BUILD_DIR/mongo/db/db_raii', diff --git a/src/mongo/db/storage/storage_debug_util.cpp b/src/mongo/db/storage/storage_debug_util.cpp new file mode 100644 index 00000000000..64c4bcbc591 --- /dev/null +++ b/src/mongo/db/storage/storage_debug_util.cpp @@ -0,0 +1,160 @@ +/** + * Copyright (C) 2020-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * . + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the Server Side Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kStorage + +#include "mongo/platform/basic.h" + +#include "mongo/db/storage/storage_debug_util.h" + +#include "mongo/db/db_raii.h" +#include "mongo/db/index/index_access_method.h" +#include "mongo/db/storage/key_string.h" +#include "mongo/logv2/log.h" + +namespace mongo { + +namespace StorageDebugUtil { + +void printKeyString(const RecordId& recordId, + const KeyString::Value& keyStringValue, + const BSONObj& keyPatternBson, + const BSONObj& keyStringBson, + std::string callerLogPrefix) { + // We need to rehydrate the keyString to something readable. + auto keyPatternIter = keyPatternBson.begin(); + auto keyStringIter = keyStringBson.begin(); + BSONObjBuilder b; + while (keyPatternIter != keyPatternBson.end() && keyStringIter != keyStringBson.end()) { + b.appendAs(*keyStringIter, keyPatternIter->fieldName()); + ++keyPatternIter; + ++keyStringIter; + } + // Wildcard index documents can have more values in the keystring. + while (keyStringIter != keyStringBson.end()) { + b.append(*keyStringIter); + ++keyStringIter; + } + BSONObj rehydratedKey = b.done(); + + LOGV2(51811, + "{caller} {record_id}, key: {rehydrated_key}, keystring: " + "{key_string}", + "caller"_attr = callerLogPrefix, + "record_id"_attr = recordId, + "rehydrated_key"_attr = rehydratedKey, + "key_string"_attr = keyStringValue); +} + +void printCollectionAndIndexTableEntries(OperationContext* opCtx, const NamespaceString& nss) { + invariant(!opCtx->lockState()->isLocked()); + AutoGetCollection autoColl(opCtx, nss, MODE_IS); + Collection* coll = autoColl.getCollection(); + + LOGV2(51807, "Dumping collection table and index tables' entries for debugging..."); + + // Iterate and print the collection table (record store) documents. + RecordStore* rs = coll->getRecordStore(); + auto rsCursor = rs->getCursor(opCtx); + boost::optional rec = rsCursor->next(); + LOGV2(51808, "[Debugging] Collection table entries:"); + while (rec) { + LOGV2(51809, + "[Debugging](record) {record_id}, Value: {record_data}", + "record_id"_attr = rec->id, + "record_data"_attr = rec->data.toBson()); + rec = rsCursor->next(); + } + + // Iterate and print each index's table of documents. + const auto indexCatalog = coll->getIndexCatalog(); + const auto it = indexCatalog->getIndexIterator(opCtx, /*includeUnfinished*/ false); + while (it->more()) { + const auto indexCatalogEntry = it->next(); + const auto indexDescriptor = indexCatalogEntry->descriptor(); + const auto iam = indexCatalogEntry->accessMethod(); + auto indexCursor = iam->newCursor(opCtx, /*forward*/ true); + + const BSONObj& keyPattern = indexDescriptor->keyPattern(); + const KeyString::Version version = iam->getSortedDataInterface()->getKeyStringVersion(); + const auto ordering = Ordering::make(keyPattern); + KeyString::Builder firstKeyString( + version, BSONObj(), ordering, KeyString::Discriminator::kExclusiveBefore); + + LOGV2(51810, + "[Debugging] {keyPattern_str} index table entries:", + "keyPattern_str"_attr = keyPattern); + + for (auto keyStringEntry = indexCursor->seekForKeyString(firstKeyString.getValueCopy()); + keyStringEntry; + keyStringEntry = indexCursor->nextKeyString()) { + auto keyString = KeyString::toBsonSafe(keyStringEntry->keyString.getBuffer(), + keyStringEntry->keyString.getSize(), + ordering, + keyStringEntry->keyString.getTypeBits()); + printKeyString(keyStringEntry->loc, + keyStringEntry->keyString, + keyPattern, + keyString, + "[Debugging](index)"); + } + } +} + +void printValidateResults(const ValidateResults& results) { + std::stringstream ss; + + ss << "ValidateResults:\nValid: " << results.valid << "\n" + << "Errors:\n"; + + for (const std::string& error : results.errors) { + ss << "\t" << error << "\n"; + } + + ss << "Warnings:\n"; + for (const std::string& warning : results.warnings) { + ss << "\t" << warning << "\n"; + } + + ss << "Extra index entries:\n"; + for (const BSONObj& obj : results.extraIndexEntries) { + ss << "\t" << obj << "\n"; + } + + ss << "Missing index entries:\n"; + for (const BSONObj& obj : results.missingIndexEntries) { + ss << "\t" << obj << "\n"; + } + + LOGV2(51812, "{results_string}", "results_string"_attr = ss.str()); +} + +} // namespace StorageDebugUtil + +} // namespace mongo diff --git a/src/mongo/db/storage/storage_debug_util.h b/src/mongo/db/storage/storage_debug_util.h new file mode 100644 index 00000000000..27e6be9a8a4 --- /dev/null +++ b/src/mongo/db/storage/storage_debug_util.h @@ -0,0 +1,75 @@ +/** + * Copyright (C) 2020-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * . + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the Server Side Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#pragma once + +#include "mongo/db/storage/key_string.h" + +namespace mongo { + +class BSONObj; +class NamespaceString; +class OperationContext; +class RecordId; +struct ValidateResults; + +/** + * Helpers to facilitate unit test debugging in the case of test failure. + */ +namespace StorageDebugUtil { + +/** + * Takes key string and key pattern information and uses it to present human-readable information + * about an index or collection entry. + * + * 'logPrefix' addes a logging prefix. Useful for differentiating callers. + */ +void printKeyString(const RecordId& recordId, + const KeyString::Value& keyStringValue, + const BSONObj& keyPatternBson, + const BSONObj& keyStringBson, + std::string callerLogPrefix); + +/** + * Prints all the document entries in the collection table and index tables associated with + * 'coll'. + * + * This is useful to facilitate debugging validate unit test failures: to more easily + * distinguish between validate code bugs and test or data persistence bugs. + */ +void printCollectionAndIndexTableEntries(OperationContext* opCtx, const NamespaceString& nss); + +/** + * Prints the parsed contents of 'results'. + */ +void printValidateResults(const ValidateResults& results); + +} // namespace StorageDebugUtil + +} // namespace mongo diff --git a/src/mongo/db/storage/storage_unittest_debug_util.cpp b/src/mongo/db/storage/storage_unittest_debug_util.cpp deleted file mode 100644 index 2c0d9243515..00000000000 --- a/src/mongo/db/storage/storage_unittest_debug_util.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/** - * Copyright (C) 2020-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kStorage - -#include "mongo/platform/basic.h" - -#include "mongo/db/storage/storage_unittest_debug_util.h" - -#include "mongo/db/db_raii.h" -#include "mongo/db/index/index_access_method.h" -#include "mongo/db/storage/key_string.h" -#include "mongo/logv2/log.h" - -namespace mongo { - -namespace StorageDebugUtil { - -void printCollectionAndIndexTableEntries(OperationContext* opCtx, const NamespaceString& nss) { - invariant(!opCtx->lockState()->isLocked()); - AutoGetCollection autoColl(opCtx, nss, MODE_IS); - Collection* coll = autoColl.getCollection(); - - LOGV2(51807, "Dumping collection table and index tables' entries for debugging..."); - - // Iterate and print the collection table (record store) documents. - RecordStore* rs = coll->getRecordStore(); - auto rsCursor = rs->getCursor(opCtx); - boost::optional rec = rsCursor->next(); - LOGV2(51808, "Collection table entries:"); - while (rec) { - LOGV2(51809, - "{record_id}, Value: {record_data}", - "record_id"_attr = rec->id, - "record_data"_attr = rec->data.toBson()); - rec = rsCursor->next(); - } - - // Iterate and print each index's table of documents. - const auto indexCatalog = coll->getIndexCatalog(); - const auto it = indexCatalog->getIndexIterator(opCtx, /*includeUnfinished*/ false); - while (it->more()) { - const auto indexCatalogEntry = it->next(); - const auto indexDescriptor = indexCatalogEntry->descriptor(); - const auto iam = indexCatalogEntry->accessMethod(); - auto indexCursor = iam->newCursor(opCtx, /*forward*/ true); - - const BSONObj& keyPattern = indexDescriptor->keyPattern(); - const KeyString::Version version = iam->getSortedDataInterface()->getKeyStringVersion(); - const auto ordering = Ordering::make(keyPattern); - KeyString::Builder firstKeyString( - version, BSONObj(), ordering, KeyString::Discriminator::kExclusiveBefore); - - LOGV2(51810, "{keyPattern_str} index table entries:", "keyPattern_str"_attr = keyPattern); - - for (auto keyStringEntry = indexCursor->seekForKeyString(firstKeyString.getValueCopy()); - keyStringEntry; - keyStringEntry = indexCursor->nextKeyString()) { - // We need to rehydrate the keyString to something readable. - auto keyString = KeyString::toBsonSafe(keyStringEntry->keyString.getBuffer(), - keyStringEntry->keyString.getSize(), - ordering, - keyStringEntry->keyString.getTypeBits()); - auto keyPatternIter = keyPattern.begin(); - auto keyStringIter = keyString.begin(); - BSONObjBuilder b; - while (keyPatternIter != keyPattern.end() && keyStringIter != keyString.end()) { - b.appendAs(*keyStringIter, keyPatternIter->fieldName()); - ++keyPatternIter; - ++keyStringIter; - } - // Wildcard index documents can have more values in the keystring. - while (keyStringIter != keyString.end()) { - b.append(*keyStringIter); - ++keyStringIter; - } - BSONObj rehydratedKey = b.done(); - - LOGV2(51811, - "{keyStringEntry_recId}, key: {rehydrated_key}, keystring: " - "{keyStringEntry_keyString}", - "keyStringEntry_recId"_attr = keyStringEntry->loc, - "rehydrated_key"_attr = rehydratedKey, - "keyStringEntry_keyString"_attr = keyStringEntry->keyString); - } - } -} - -void printValidateResults(const ValidateResults& results) { - std::stringstream ss; - - ss << "ValidateResults:\nValid: " << results.valid << "\n" - << "Errors:\n"; - - for (const std::string& error : results.errors) { - ss << "\t" << error << "\n"; - } - - ss << "Warnings:\n"; - for (const std::string& warning : results.warnings) { - ss << "\t" << warning << "\n"; - } - - ss << "Extra index entries:\n"; - for (const BSONObj& obj : results.extraIndexEntries) { - ss << "\t" << obj << "\n"; - } - - ss << "Missing index entries:\n"; - for (const BSONObj& obj : results.missingIndexEntries) { - ss << "\t" << obj << "\n"; - } - - LOGV2(51812, "{results_string}", "results_string"_attr = ss.str()); -} - -} // namespace StorageDebugUtil - -} // namespace mongo diff --git a/src/mongo/db/storage/storage_unittest_debug_util.h b/src/mongo/db/storage/storage_unittest_debug_util.h deleted file mode 100644 index ca4f249151c..00000000000 --- a/src/mongo/db/storage/storage_unittest_debug_util.h +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright (C) 2020-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#pragma once - -namespace mongo { - -class NamespaceString; -class OperationContext; -struct ValidateResults; - -/** - * Helpers to facilitate unit test debugging in the case of test failure. - */ -namespace StorageDebugUtil { - -/** - * Prints all the document entries in the collection table and index tables associated with - * 'coll'. - * - * This is useful to facilitate debugging validate unit test failures: to more easily - * distinguish between validate code bugs and test or data persistence bugs. - */ -void printCollectionAndIndexTableEntries(OperationContext* opCtx, const NamespaceString& nss); - -/** - * Prints the parsed contents of 'results'. - */ -void printValidateResults(const ValidateResults& results); - -} // namespace StorageDebugUtil - -} // namespace mongo diff --git a/src/mongo/dbtests/SConscript b/src/mongo/dbtests/SConscript index 28097a6453b..8c26c01d965 100644 --- a/src/mongo/dbtests/SConscript +++ b/src/mongo/dbtests/SConscript @@ -161,7 +161,7 @@ if not has_option('noshell') and usemozjs: "$BUILD_DIR/mongo/db/storage/durable_catalog_impl", "$BUILD_DIR/mongo/db/storage/ephemeral_for_test/storage_ephemeral_for_test", "$BUILD_DIR/mongo/db/storage/storage_engine_impl", - "$BUILD_DIR/mongo/db/storage/storage_unittest_debug_util", + "$BUILD_DIR/mongo/db/storage/storage_debug_util", "$BUILD_DIR/mongo/db/storage/wiredtiger/storage_wiredtiger" if wiredtiger else [], "$BUILD_DIR/mongo/db/transaction", "$BUILD_DIR/mongo/shell_core", diff --git a/src/mongo/dbtests/validate_tests.cpp b/src/mongo/dbtests/validate_tests.cpp index 275fd35e0eb..36a7f3a5b92 100644 --- a/src/mongo/dbtests/validate_tests.cpp +++ b/src/mongo/dbtests/validate_tests.cpp @@ -40,7 +40,7 @@ #include "mongo/db/index/index_access_method.h" #include "mongo/db/index/index_descriptor.h" #include "mongo/db/service_context.h" -#include "mongo/db/storage/storage_unittest_debug_util.h" +#include "mongo/db/storage/storage_debug_util.h" #include "mongo/dbtests/dbtests.h" namespace ValidateTests { @@ -48,7 +48,10 @@ namespace ValidateTests { using std::unique_ptr; namespace { + const auto kIndexVersion = IndexDescriptor::IndexVersion::kV2; +const bool kTurnOnExtraLoggingForTest = true; + } // namespace static const char* const _ns = "unittests.validate_tests"; @@ -105,8 +108,8 @@ protected: ValidateResults results; BSONObjBuilder output; - ASSERT_OK( - CollectionValidation::validate(&_opCtx, _nss, options, _background, &results, &output)); + ASSERT_OK(CollectionValidation::validate( + &_opCtx, _nss, options, _background, &results, &output, kTurnOnExtraLoggingForTest)); // Check if errors are reported if and only if valid is set to false. ASSERT_EQ(results.valid, results.errors.empty()); @@ -1209,7 +1212,8 @@ public: CollectionValidation::ValidateOptions::kFullValidation, _background, &results, - &output)); + &output, + kTurnOnExtraLoggingForTest)); auto dumpOnErrorGuard = makeGuard([&] { StorageDebugUtil::printValidateResults(results); @@ -1331,7 +1335,8 @@ public: CollectionValidation::ValidateOptions::kFullValidation, _background, &results, - &output)); + &output, + kTurnOnExtraLoggingForTest)); auto dumpOnErrorGuard = makeGuard([&] { StorageDebugUtil::printValidateResults(results); @@ -1429,7 +1434,8 @@ public: CollectionValidation::ValidateOptions::kFullValidation, _background, &results, - &output)); + &output, + kTurnOnExtraLoggingForTest)); auto dumpOnErrorGuard = makeGuard([&] { StorageDebugUtil::printValidateResults(results); -- cgit v1.2.1