diff options
author | Daniel Solnik <dansolnik@gmail.com> | 2019-07-29 10:13:23 -0400 |
---|---|---|
committer | Daniel Solnik <dansolnik@gmail.com> | 2019-08-16 15:05:05 -0400 |
commit | 65754fc06966fb438c114f113ccae2d742eaa963 (patch) | |
tree | f1fd2b38b41f9d7507cdd4f512c9533098af3e8e /src/mongo/db/catalog/validate_adaptor.h | |
parent | 8494ca7d8a88aa3d5df96e89beafacd4caca3801 (diff) | |
download | mongo-65754fc06966fb438c114f113ccae2d742eaa963.tar.gz |
SERVER-42222 Move data cursors for collection validation to the start of collection validation
Diffstat (limited to 'src/mongo/db/catalog/validate_adaptor.h')
-rw-r--r-- | src/mongo/db/catalog/validate_adaptor.h | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/src/mongo/db/catalog/validate_adaptor.h b/src/mongo/db/catalog/validate_adaptor.h new file mode 100644 index 00000000000..aefa26dc41b --- /dev/null +++ b/src/mongo/db/catalog/validate_adaptor.h @@ -0,0 +1,113 @@ +/** + * Copyright (C) 2019-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 + * <http://www.mongodb.com/licensing/server-side-public-license>. + * + * 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/catalog/index_catalog.h" +#include "mongo/db/catalog/index_consistency.h" +#include "mongo/db/index/index_access_method.h" +#include "mongo/db/index/index_descriptor.h" +#include "mongo/db/operation_context.h" +#include "mongo/db/storage/record_store.h" + +namespace mongo { + +class IndexConsistency; + +enum ValidateCmdLevel : int { kValidateNormal = 0x01, kValidateFull = 0x02 }; + +namespace { + +using ValidateResultsMap = std::map<std::string, ValidateResults>; + +} // namespace + +/** + * The record store validate adaptor is used to keep track of the index consistency during + * a validation that's running. + */ +class ValidateAdaptor { +public: + ValidateAdaptor(OperationContext* opCtx, + IndexConsistency* indexConsistency, + ValidateCmdLevel level, + IndexCatalog* ic, + ValidateResultsMap* irm) + + : _opCtx(opCtx), + _indexConsistency(indexConsistency), + _level(level), + _indexCatalog(ic), + _indexNsResultsMap(irm) {} + + /** + * Validates the record data and traverses through its key set to keep track of the + * index consistency. + */ + virtual Status validateRecord( + const RecordId& recordId, + const RecordData& record, + const std::unique_ptr<SeekableRecordCursor>& seekRecordStoreCursor, + size_t* dataSize); + + /** + * Traverses the index getting index entriess to validate them and keep track of the index keys + * for index consistency. + */ + void traverseIndex(int64_t* numTraversedKeys, + const std::unique_ptr<SortedDataInterface::Cursor>& indexCursor, + const IndexDescriptor* descriptor, + ValidateResults* results); + + /** + * Traverses the record store to retrieve every record and go through its document key + * set to keep track of the index consistency during a validation. + */ + void traverseRecordStore(RecordStore* recordStore, + const RecordId& firstRecordId, + const std::unique_ptr<SeekableRecordCursor>& traverseRecordStoreCursor, + const std::unique_ptr<SeekableRecordCursor>& seekRecordStoreCursor, + ValidateResults* results, + BSONObjBuilder* output); + + /** + * Validate that the number of document keys matches the number of index keys. + */ + void validateIndexKeyCount(const IndexDescriptor* idx, + int64_t numRecs, + ValidateResults& results); + +private: + OperationContext* _opCtx; + IndexConsistency* _indexConsistency; + ValidateCmdLevel _level; + IndexCatalog* _indexCatalog; + ValidateResultsMap* _indexNsResultsMap; +}; +} // namespace mongo |