/Users/deen/code/yugabyte-db/src/yb/rocksdb/table/filter_block.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 the BSD-style license found in the |
3 | | // LICENSE file in the root directory of this source tree. An additional grant |
4 | | // of patent rights can be found in the PATENTS file in the same directory. |
5 | | // |
6 | | // The following only applies to changes made to this file as part of YugaByte development. |
7 | | // |
8 | | // Portions Copyright (c) YugaByte, Inc. |
9 | | // |
10 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
11 | | // in compliance with the License. You may obtain a copy of the License at |
12 | | // |
13 | | // http://www.apache.org/licenses/LICENSE-2.0 |
14 | | // |
15 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
16 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
17 | | // or implied. See the License for the specific language governing permissions and limitations |
18 | | // under the License. |
19 | | // |
20 | | // Copyright (c) 2012 The LevelDB Authors. All rights reserved. |
21 | | // Use of this source code is governed by a BSD-style license that can be |
22 | | // found in the LICENSE file. See the AUTHORS file for names of contributors. |
23 | | // |
24 | | // A filter block is stored near the end of a Table file. It contains |
25 | | // filters (e.g., bloom filters) for all data blocks in the table combined |
26 | | // into a single filter block. |
27 | | // |
28 | | // It is a base class for BlockBasedFilter and FullFilter. |
29 | | // These two are both used in BlockBasedTable. The first one contain filter |
30 | | // For a part of keys in sst file, the second contain filter for all keys |
31 | | // in sst file. |
32 | | |
33 | | #pragma once |
34 | | |
35 | | #include <stddef.h> |
36 | | #include <stdint.h> |
37 | | |
38 | | #include <memory> |
39 | | #include <string> |
40 | | |
41 | | #include "yb/util/slice.h" |
42 | | |
43 | | namespace rocksdb { |
44 | | |
45 | | const uint64_t kNotValid = ULLONG_MAX; |
46 | | class FilterPolicy; |
47 | | |
48 | | // A FilterBlockBuilder is used to construct all of the filters for a |
49 | | // particular Table. It generates a single string which is stored as |
50 | | // a special block in the Table. |
51 | | // |
52 | | // The sequence of calls to FilterBlockBuilder must match the regexp: |
53 | | // (StartBlock Add*)* Finish |
54 | | // |
55 | | // BlockBased/Full FilterBlock would be called in the same way. |
56 | | class FilterBlockBuilder { |
57 | | public: |
58 | 7.54k | FilterBlockBuilder() {} |
59 | 7.54k | virtual ~FilterBlockBuilder() {} |
60 | | |
61 | | virtual void StartBlock(uint64_t block_offset) = 0; // Start new block filter |
62 | | virtual void Add(const Slice& key) = 0; // Add a key to current filter |
63 | | virtual Slice Finish() = 0; // Generate Filter |
64 | | virtual bool ShouldFlush() const = 0; // flush policy for fixed size filter |
65 | | |
66 | | private: |
67 | | // No copying allowed |
68 | | FilterBlockBuilder(const FilterBlockBuilder&); |
69 | | void operator=(const FilterBlockBuilder&); |
70 | | }; |
71 | | |
72 | | // A FilterBlockReader is used to parse filter from SST table. |
73 | | // KeyMayMatch and PrefixMayMatch would trigger filter checking |
74 | | // |
75 | | // BlockBased/FullFilter/FixedSizeFilter Block would be called in the same way. |
76 | | class FilterBlockReader { |
77 | | public: |
78 | 79.1k | FilterBlockReader() {} |
79 | 76.6k | virtual ~FilterBlockReader() {} |
80 | | |
81 | | virtual bool KeyMayMatch(const Slice& key, |
82 | | uint64_t block_offset = kNotValid) = 0; |
83 | | virtual bool PrefixMayMatch(const Slice& prefix, |
84 | | uint64_t block_offset = kNotValid) = 0; |
85 | | virtual size_t ApproximateMemoryUsage() const = 0; |
86 | | |
87 | | // convert this object to a human readable form |
88 | 0 | virtual std::string ToString() const { |
89 | 0 | std::string error_msg("Unsupported filter \n"); |
90 | 0 | return error_msg; |
91 | 0 | } |
92 | | |
93 | | private: |
94 | | // No copying allowed |
95 | | FilterBlockReader(const FilterBlockReader&); |
96 | | void operator=(const FilterBlockReader&); |
97 | | }; |
98 | | |
99 | | } // namespace rocksdb |