/src/rocksdb/db/blob/prefetch_buffer_collection.h
Line | Count | Source |
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 | | #pragma once |
7 | | |
8 | | #include <cassert> |
9 | | #include <cstdint> |
10 | | #include <memory> |
11 | | #include <unordered_map> |
12 | | |
13 | | #include "file/file_prefetch_buffer.h" |
14 | | #include "rocksdb/rocksdb_namespace.h" |
15 | | |
16 | | namespace ROCKSDB_NAMESPACE { |
17 | | |
18 | | // A class that owns a collection of FilePrefetchBuffers using the file number |
19 | | // as key. Used for implementing compaction readahead for blob files. Designed |
20 | | // to be accessed by a single thread only: every (sub)compaction needs its own |
21 | | // buffers since they are guaranteed to read different blobs from different |
22 | | // positions even when reading the same file. |
23 | | class PrefetchBufferCollection { |
24 | | public: |
25 | | explicit PrefetchBufferCollection(uint64_t readahead_size) |
26 | 0 | : readahead_size_(readahead_size) { |
27 | | assert(readahead_size_ > 0); |
28 | 0 | } |
29 | | |
30 | | FilePrefetchBuffer* GetOrCreatePrefetchBuffer(uint64_t file_number); |
31 | | |
32 | | private: |
33 | | uint64_t readahead_size_; |
34 | | std::unordered_map<uint64_t, std::unique_ptr<FilePrefetchBuffer>> |
35 | | prefetch_buffers_; // maps file number to prefetch buffer |
36 | | }; |
37 | | |
38 | | } // namespace ROCKSDB_NAMESPACE |