]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/table/block_based/block_prefetcher.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / table / block_based / block_prefetcher.h
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 #include "table/block_based/block_based_table_reader.h"
11
12 namespace ROCKSDB_NAMESPACE {
13 class BlockPrefetcher {
14 public:
15 explicit BlockPrefetcher(size_t compaction_readahead_size,
16 size_t initial_auto_readahead_size)
17 : compaction_readahead_size_(compaction_readahead_size),
18 readahead_size_(initial_auto_readahead_size),
19 initial_auto_readahead_size_(initial_auto_readahead_size) {}
20
21 void PrefetchIfNeeded(const BlockBasedTable::Rep* rep,
22 const BlockHandle& handle, size_t readahead_size,
23 bool is_for_compaction,
24 const bool no_sequential_checking,
25 Env::IOPriority rate_limiter_priority);
26 FilePrefetchBuffer* prefetch_buffer() { return prefetch_buffer_.get(); }
27
28 void UpdateReadPattern(const uint64_t& offset, const size_t& len) {
29 prev_offset_ = offset;
30 prev_len_ = len;
31 }
32
33 bool IsBlockSequential(const uint64_t& offset) {
34 return (prev_len_ == 0 || (prev_offset_ + prev_len_ == offset));
35 }
36
37 void ResetValues(size_t initial_auto_readahead_size) {
38 num_file_reads_ = 1;
39 // Since initial_auto_readahead_size_ can be different from
40 // the value passed to BlockBasedTableOptions.initial_auto_readahead_size in
41 // case of adaptive_readahead, so fallback the readahead_size_ to that value
42 // in case of reset.
43 initial_auto_readahead_size_ = initial_auto_readahead_size;
44 readahead_size_ = initial_auto_readahead_size_;
45 readahead_limit_ = 0;
46 return;
47 }
48
49 void SetReadaheadState(ReadaheadFileInfo::ReadaheadInfo* readahead_info) {
50 num_file_reads_ = readahead_info->num_file_reads;
51 initial_auto_readahead_size_ = readahead_info->readahead_size;
52 TEST_SYNC_POINT_CALLBACK("BlockPrefetcher::SetReadaheadState",
53 &initial_auto_readahead_size_);
54 }
55
56 private:
57 // Readahead size used in compaction, its value is used only if
58 // lookup_context_.caller = kCompaction.
59 size_t compaction_readahead_size_;
60
61 // readahead_size_ is used if underlying FS supports prefetching.
62 size_t readahead_size_;
63 size_t readahead_limit_ = 0;
64 // initial_auto_readahead_size_ is used if RocksDB uses internal prefetch
65 // buffer.
66 uint64_t initial_auto_readahead_size_;
67 uint64_t num_file_reads_ = 0;
68 uint64_t prev_offset_ = 0;
69 size_t prev_len_ = 0;
70 std::unique_ptr<FilePrefetchBuffer> prefetch_buffer_;
71 };
72 } // namespace ROCKSDB_NAMESPACE