summaryrefslogtreecommitdiff
path: root/file/file_prefetch_buffer.h
diff options
context:
space:
mode:
authorLevi Tamasi <ltamasi@fb.com>2021-11-19 17:52:42 -0800
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>2021-11-19 17:53:47 -0800
commitdc5de45af8fc1bcc90edea5cd9a5695bd85a8baf (patch)
tree6f49ac343b9c3b678ebf57e81ecf43e9ef208ed9 /file/file_prefetch_buffer.h
parentcd4ea675e3d58a2e271c944956d11c8c55bf12df (diff)
Support readahead during compaction for blob files (#9187)
Summary: The patch adds a new BlobDB configuration option `blob_compaction_readahead_size` that can be used to enable prefetching data from blob files during compaction. This is important when using storage with higher latencies like HDDs or remote filesystems. If enabled, prefetching is used for all cases when blobs are read during compaction, namely garbage collection, compaction filters (when the existing value has to be read from a blob file), and `Merge` (when the value of the base `Put` is stored in a blob file). Pull Request resolved: https://github.com/facebook/rocksdb/pull/9187 Test Plan: Ran `make check` and the stress/crash test. Reviewed By: riversand963 Differential Revision: D32565512 Pulled By: ltamasi fbshipit-source-id: 87be9cebc3aa01cc227bec6b5f64d827b8164f5d
Diffstat (limited to 'file/file_prefetch_buffer.h')
-rw-r--r--file/file_prefetch_buffer.h32
1 files changed, 16 insertions, 16 deletions
diff --git a/file/file_prefetch_buffer.h b/file/file_prefetch_buffer.h
index e741a2cba..e91ee41ce 100644
--- a/file/file_prefetch_buffer.h
+++ b/file/file_prefetch_buffer.h
@@ -13,7 +13,6 @@
#include <sstream>
#include <string>
-#include "file/random_access_file_reader.h"
#include "file/readahead_file_info.h"
#include "port/port.h"
#include "rocksdb/env.h"
@@ -24,6 +23,9 @@ namespace ROCKSDB_NAMESPACE {
#define DEAFULT_DECREMENT 8 * 1024
+struct IOOptions;
+class RandomAccessFileReader;
+
// FilePrefetchBuffer is a smart buffer to store and read data from a file.
class FilePrefetchBuffer {
public:
@@ -31,7 +33,6 @@ class FilePrefetchBuffer {
// Constructor.
//
// All arguments are optional.
- // file_reader : the file reader to use. Can be a nullptr.
// readahead_size : the initial readahead size.
// max_readahead_size : the maximum readahead size.
// If max_readahead_size > readahead_size, the readahead size will be
@@ -46,18 +47,14 @@ class FilePrefetchBuffer {
// implicit_auto_readahead : Readahead is enabled implicitly by rocksdb after
// doing sequential scans for two times.
//
- // Automatic readhead is enabled for a file if file_reader, readahead_size,
+ // Automatic readhead is enabled for a file if readahead_size
// and max_readahead_size are passed in.
- // If file_reader is a nullptr, setting readahead_size and max_readahead_size
- // does not make any sense. So it does nothing.
// A user can construct a FilePrefetchBuffer without any arguments, but use
// `Prefetch` to load data into the buffer.
- FilePrefetchBuffer(RandomAccessFileReader* file_reader = nullptr,
- size_t readahead_size = 0, size_t max_readahead_size = 0,
+ FilePrefetchBuffer(size_t readahead_size = 0, size_t max_readahead_size = 0,
bool enable = true, bool track_min_offset = false,
bool implicit_auto_readahead = false)
: buffer_offset_(0),
- file_reader_(file_reader),
readahead_size_(readahead_size),
max_readahead_size_(max_readahead_size),
initial_readahead_size_(readahead_size),
@@ -77,18 +74,22 @@ class FilePrefetchBuffer {
Status Prefetch(const IOOptions& opts, RandomAccessFileReader* reader,
uint64_t offset, size_t n, bool for_compaction = false);
- // Tries returning the data for a file raed from this buffer, if that data is
+ // Tries returning the data for a file read from this buffer if that data is
// in the buffer.
// It handles tracking the minimum read offset if track_min_offset = true.
// It also does the exponential readahead when readahead_size is set as part
// of the constructor.
//
- // offset : the file offset.
- // n : the number of bytes.
- // result : output buffer to put the data into.
- // for_compaction : if cache read is done for compaction read.
- bool TryReadFromCache(const IOOptions& opts, uint64_t offset, size_t n,
- Slice* result, Status* s, bool for_compaction = false);
+ // opts : the IO options to use.
+ // reader : the file reader.
+ // offset : the file offset.
+ // n : the number of bytes.
+ // result : output buffer to put the data into.
+ // s : output status.
+ // for_compaction : true if cache read is done for compaction read.
+ bool TryReadFromCache(const IOOptions& opts, RandomAccessFileReader* reader,
+ uint64_t offset, size_t n, Slice* result, Status* s,
+ bool for_compaction = false);
// The minimum `offset` ever passed to TryReadFromCache(). This will nly be
// tracked if track_min_offset = true.
@@ -145,7 +146,6 @@ class FilePrefetchBuffer {
private:
AlignedBuffer buffer_;
uint64_t buffer_offset_;
- RandomAccessFileReader* file_reader_;
size_t readahead_size_;
// FilePrefetchBuffer object won't be created from Iterator flow if
// max_readahead_size_ = 0.