]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/table/block_based/binary_search_index_reader.cc
update ceph source to reef 18.1.2
[ceph.git] / 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).
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 #include "table/block_based/binary_search_index_reader.h"
10
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);
21
22 CachableEntry<Block> index_block;
23 if (prefetch || !use_cache) {
24 const Status s =
25 ReadIndexBlock(table, prefetch_buffer, ro, use_cache,
26 /*get_context=*/nullptr, lookup_context, &index_block);
27 if (!s.ok()) {
28 return s;
29 }
30
31 if (use_cache && !pin) {
32 index_block.Reset();
33 }
34 }
35
36 index_reader->reset(
37 new BinarySearchIndexReader(table, std::move(index_block)));
38
39 return Status::OK();
40 }
41
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;
49 const Status s =
50 GetOrReadIndexBlock(no_io, read_options.rate_limiter_priority,
51 get_context, lookup_context, &index_block);
52 if (!s.ok()) {
53 if (iter != nullptr) {
54 iter->Invalidate(s);
55 return iter;
56 }
57
58 return NewErrorInternalIterator<IndexValue>(s);
59 }
60
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());
68
69 assert(it != nullptr);
70 index_block.TransferTo(it);
71
72 return it;
73 }
74 } // namespace ROCKSDB_NAMESPACE