/src/rocksdb/db/output_validator.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
2 | | // This source code is licensed under both the GPLv2 (found in the |
3 | | // COPYING file in the root directory) and Apache 2.0 License |
4 | | // (found in the LICENSE.Apache file in the root directory). |
5 | | // |
6 | | #pragma once |
7 | | #include "db/dbformat.h" |
8 | | #include "rocksdb/slice.h" |
9 | | #include "rocksdb/status.h" |
10 | | |
11 | | namespace ROCKSDB_NAMESPACE { |
12 | | // A class that validates key/value that is inserted to an SST file. |
13 | | // Pass every key/value of the file using OutputValidator::Add() |
14 | | // and the class validates key order and optionally calculate a hash |
15 | | // of all the key and value. |
16 | | class OutputValidator { |
17 | | public: |
18 | | explicit OutputValidator(const InternalKeyComparator& icmp, bool enable_hash, |
19 | | uint64_t precalculated_hash = 0) |
20 | | : icmp_(icmp), |
21 | | paranoid_hash_(precalculated_hash), |
22 | 10.7k | enable_hash_(enable_hash) {} |
23 | | |
24 | | // Add a key to the KV sequence, and return whether the key follows |
25 | | // criteria, e.g. key is ordered. |
26 | | Status Add(const Slice& key, const Slice& value); |
27 | | |
28 | | // Compare result of two key orders are the same. It can be used |
29 | | // to compare the keys inserted into a file, and what is read back. |
30 | | // Return true if the validation passes. |
31 | 0 | bool CompareValidator(const OutputValidator& other_validator) { |
32 | 0 | return GetHash() == other_validator.GetHash(); |
33 | 0 | } |
34 | | |
35 | | // Not (yet) intended to be persisted, so subject to change |
36 | | // without notice between releases. |
37 | 0 | uint64_t GetHash() const { return paranoid_hash_; } |
38 | | |
39 | | private: |
40 | | const InternalKeyComparator& icmp_; |
41 | | std::string prev_key_; |
42 | | uint64_t paranoid_hash_ = 0; |
43 | | bool enable_hash_; |
44 | | }; |
45 | | } // namespace ROCKSDB_NAMESPACE |