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:
BlockPrefetcher(size_t compaction_readahead_size)15   explicit BlockPrefetcher(size_t compaction_readahead_size)
16       : compaction_readahead_size_(compaction_readahead_size) {}
17   void PrefetchIfNeeded(const BlockBasedTable::Rep* rep,
18                         const BlockHandle& handle, size_t readahead_size,
19                         bool is_for_compaction);
prefetch_buffer()20   FilePrefetchBuffer* prefetch_buffer() { return prefetch_buffer_.get(); }
21 
22  private:
23   // Readahead size used in compaction, its value is used only if
24   // lookup_context_.caller = kCompaction.
25   size_t compaction_readahead_size_;
26 
27   size_t readahead_size_ = BlockBasedTable::kInitAutoReadaheadSize;
28   size_t readahead_limit_ = 0;
29   int64_t num_file_reads_ = 0;
30   std::unique_ptr<FilePrefetchBuffer> prefetch_buffer_;
31 };
32 }  // namespace ROCKSDB_NAMESPACE
33