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).
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.
11 #include "table/block_based/block_based_table_reader.h"
13 #include "table/block_based/reader_common.h"
15 namespace ROCKSDB_NAMESPACE
{
16 // Encapsulates common functionality for the various index reader
17 // implementations. Provides access to the index block regardless of whether
18 // it is owned by the reader or stored in the cache, or whether it is pinned
19 // in the cache or not.
20 class BlockBasedTable::IndexReaderCommon
: public BlockBasedTable::IndexReader
{
22 IndexReaderCommon(const BlockBasedTable
* t
,
23 CachableEntry
<Block
>&& index_block
)
24 : table_(t
), index_block_(std::move(index_block
)) {
25 assert(table_
!= nullptr);
29 static Status
ReadIndexBlock(const BlockBasedTable
* table
,
30 FilePrefetchBuffer
* prefetch_buffer
,
31 const ReadOptions
& read_options
, bool use_cache
,
32 GetContext
* get_context
,
33 BlockCacheLookupContext
* lookup_context
,
34 CachableEntry
<Block
>* index_block
);
36 const BlockBasedTable
* table() const { return table_
; }
38 const InternalKeyComparator
* internal_comparator() const {
39 assert(table_
!= nullptr);
40 assert(table_
->get_rep() != nullptr);
42 return &table_
->get_rep()->internal_comparator
;
45 bool index_has_first_key() const {
46 assert(table_
!= nullptr);
47 assert(table_
->get_rep() != nullptr);
48 return table_
->get_rep()->index_has_first_key
;
51 bool index_key_includes_seq() const {
52 assert(table_
!= nullptr);
53 assert(table_
->get_rep() != nullptr);
54 return table_
->get_rep()->index_key_includes_seq
;
57 bool index_value_is_full() const {
58 assert(table_
!= nullptr);
59 assert(table_
->get_rep() != nullptr);
60 return table_
->get_rep()->index_value_is_full
;
63 bool cache_index_blocks() const {
64 assert(table_
!= nullptr);
65 assert(table_
->get_rep() != nullptr);
66 return table_
->get_rep()->table_options
.cache_index_and_filter_blocks
;
69 Status
GetOrReadIndexBlock(bool no_io
, GetContext
* get_context
,
70 BlockCacheLookupContext
* lookup_context
,
71 CachableEntry
<Block
>* index_block
) const;
73 size_t ApproximateIndexBlockMemoryUsage() const {
74 assert(!index_block_
.GetOwnValue() || index_block_
.GetValue() != nullptr);
75 return index_block_
.GetOwnValue()
76 ? index_block_
.GetValue()->ApproximateMemoryUsage()
81 const BlockBasedTable
* table_
;
82 CachableEntry
<Block
> index_block_
;
85 } // namespace ROCKSDB_NAMESPACE