/src/rocksdb/table/block_based/index_reader_common.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 | | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. |
7 | | // Use of this source code is governed by a BSD-style license that can be |
8 | | // found in the LICENSE file. See the AUTHORS file for names of contributors. |
9 | | #pragma once |
10 | | |
11 | | #include "table/block_based/block_based_table_reader.h" |
12 | | #include "table/block_based/reader_common.h" |
13 | | |
14 | | namespace ROCKSDB_NAMESPACE { |
15 | | // Encapsulates common functionality for the various index reader |
16 | | // implementations. Provides access to the index block regardless of whether |
17 | | // it is owned by the reader or stored in the cache, or whether it is pinned |
18 | | // in the cache or not. |
19 | | class BlockBasedTable::IndexReaderCommon : public BlockBasedTable::IndexReader { |
20 | | public: |
21 | | IndexReaderCommon(const BlockBasedTable* t, |
22 | | CachableEntry<Block>&& index_block) |
23 | 7.47k | : table_(t), index_block_(std::move(index_block)) { |
24 | 7.47k | assert(table_ != nullptr); |
25 | 7.47k | } |
26 | | |
27 | | void EraseFromCacheBeforeDestruction( |
28 | | uint32_t /*uncache_aggressiveness*/) override; |
29 | | |
30 | | protected: |
31 | | static Status ReadIndexBlock(const BlockBasedTable* table, |
32 | | FilePrefetchBuffer* prefetch_buffer, |
33 | | const ReadOptions& read_options, bool use_cache, |
34 | | GetContext* get_context, |
35 | | BlockCacheLookupContext* lookup_context, |
36 | | CachableEntry<Block>* index_block); |
37 | | |
38 | 13.5k | const BlockBasedTable* table() const { return table_; } |
39 | | |
40 | 13.5k | const InternalKeyComparator* internal_comparator() const { |
41 | 13.5k | assert(table_ != nullptr); |
42 | 13.5k | assert(table_->get_rep() != nullptr); |
43 | | |
44 | 13.5k | return &table_->get_rep()->internal_comparator; |
45 | 13.5k | } |
46 | | |
47 | 13.5k | bool index_has_first_key() const { |
48 | 13.5k | assert(table_ != nullptr); |
49 | 13.5k | assert(table_->get_rep() != nullptr); |
50 | 13.5k | return table_->get_rep()->index_has_first_key; |
51 | 13.5k | } |
52 | | |
53 | 13.5k | bool index_key_includes_seq() const { |
54 | 13.5k | assert(table_ != nullptr); |
55 | 13.5k | assert(table_->get_rep() != nullptr); |
56 | 13.5k | return table_->get_rep()->index_key_includes_seq; |
57 | 13.5k | } |
58 | | |
59 | 13.5k | bool index_value_is_full() const { |
60 | 13.5k | assert(table_ != nullptr); |
61 | 13.5k | assert(table_->get_rep() != nullptr); |
62 | 13.5k | return table_->get_rep()->index_value_is_full; |
63 | 13.5k | } |
64 | | |
65 | 0 | bool cache_index_blocks() const { |
66 | 0 | assert(table_ != nullptr); |
67 | 0 | assert(table_->get_rep() != nullptr); |
68 | 0 | return table_->get_rep()->table_options.cache_index_and_filter_blocks; |
69 | 0 | } |
70 | | |
71 | 13.5k | bool user_defined_timestamps_persisted() const { |
72 | 13.5k | assert(table_ != nullptr); |
73 | 13.5k | assert(table_->get_rep() != nullptr); |
74 | 13.5k | return table_->get_rep()->user_defined_timestamps_persisted; |
75 | 13.5k | } |
76 | | |
77 | | Status GetOrReadIndexBlock(GetContext* get_context, |
78 | | BlockCacheLookupContext* lookup_context, |
79 | | CachableEntry<Block>* index_block, |
80 | | const ReadOptions& read_options) const; |
81 | | |
82 | 0 | size_t ApproximateIndexBlockMemoryUsage() const { |
83 | 0 | assert(!index_block_.GetOwnValue() || index_block_.GetValue() != nullptr); |
84 | 0 | return index_block_.GetOwnValue() |
85 | 0 | ? index_block_.GetValue()->ApproximateMemoryUsage() |
86 | 0 | : 0; |
87 | 0 | } |
88 | | |
89 | | private: |
90 | | const BlockBasedTable* table_; |
91 | | CachableEntry<Block> index_block_; |
92 | | }; |
93 | | |
94 | | } // namespace ROCKSDB_NAMESPACE |