]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/table/block_based/binary_search_index_reader.cc
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.
9 #include "table/block_based/binary_search_index_reader.h"
11 namespace ROCKSDB_NAMESPACE
{
12 Status
BinarySearchIndexReader::Create(
13 const BlockBasedTable
* table
, const ReadOptions
& ro
,
14 FilePrefetchBuffer
* prefetch_buffer
, bool use_cache
, bool prefetch
,
15 bool pin
, BlockCacheLookupContext
* lookup_context
,
16 std::unique_ptr
<IndexReader
>* index_reader
) {
17 assert(table
!= nullptr);
18 assert(table
->get_rep());
19 assert(!pin
|| prefetch
);
20 assert(index_reader
!= nullptr);
22 CachableEntry
<Block
> index_block
;
23 if (prefetch
|| !use_cache
) {
25 ReadIndexBlock(table
, prefetch_buffer
, ro
, use_cache
,
26 /*get_context=*/nullptr, lookup_context
, &index_block
);
31 if (use_cache
&& !pin
) {
37 new BinarySearchIndexReader(table
, std::move(index_block
)));
42 InternalIteratorBase
<IndexValue
>* BinarySearchIndexReader::NewIterator(
43 const ReadOptions
& read_options
, bool /* disable_prefix_seek */,
44 IndexBlockIter
* iter
, GetContext
* get_context
,
45 BlockCacheLookupContext
* lookup_context
) {
46 const BlockBasedTable::Rep
* rep
= table()->get_rep();
47 const bool no_io
= (read_options
.read_tier
== kBlockCacheTier
);
48 CachableEntry
<Block
> index_block
;
50 GetOrReadIndexBlock(no_io
, read_options
.rate_limiter_priority
,
51 get_context
, lookup_context
, &index_block
);
53 if (iter
!= nullptr) {
58 return NewErrorInternalIterator
<IndexValue
>(s
);
61 Statistics
* kNullStats
= nullptr;
62 // We don't return pinned data from index blocks, so no need
63 // to set `block_contents_pinned`.
64 auto it
= index_block
.GetValue()->NewIndexIterator(
65 internal_comparator()->user_comparator(),
66 rep
->get_global_seqno(BlockType::kIndex
), iter
, kNullStats
, true,
67 index_has_first_key(), index_key_includes_seq(), index_value_is_full());
69 assert(it
!= nullptr);
70 index_block
.TransferTo(it
);
74 } // namespace ROCKSDB_NAMESPACE