From f2de8e4f8faa2969677de82bc87296db2c5a573a Mon Sep 17 00:00:00 2001 From: Andrew Chang Date: Fri, 24 Jan 2025 11:19:19 -0800 Subject: [PATCH] Demonstrate how flexible read could look like --- file/file_prefetch_buffer.h | 5 +++++ file/random_access_file_reader.h | 2 ++ include/rocksdb/file_system.h | 11 +++++++++++ 3 files changed, 18 insertions(+) diff --git a/file/file_prefetch_buffer.h b/file/file_prefetch_buffer.h index b8b6812bc83..b1f944d2931 100644 --- a/file/file_prefetch_buffer.h +++ b/file/file_prefetch_buffer.h @@ -526,6 +526,11 @@ class FilePrefetchBuffer { read_req.offset = offset; read_req.len = n; read_req.scratch = nullptr; + // In IOOptions we may want to pass in option to allow/disallow + // additional_readahead_size Another option is for FSReadRequest to just + // have a bool allow_read_to_block_boundary, so that we do not even need to + // expose the block size information to begin with.. + read_req.additional_read_size = reader->GetBlockSize(); IOStatus s = reader->MultiRead(opts, &read_req, 1, nullptr); if (!s.ok()) { return s; diff --git a/file/random_access_file_reader.h b/file/random_access_file_reader.h index 945e685e3d0..dec3c40286d 100644 --- a/file/random_access_file_reader.h +++ b/file/random_access_file_reader.h @@ -192,5 +192,7 @@ class RandomAccessFileReader { AlignedBuf* aligned_buf); void ReadAsyncCallback(FSReadRequest& req, void* cb_arg); + + size_t GetBlockSize() const { return file_->GetBlockSize(); } }; } // namespace ROCKSDB_NAMESPACE diff --git a/include/rocksdb/file_system.h b/include/rocksdb/file_system.h index 27e497f432b..7179a797034 100644 --- a/include/rocksdb/file_system.h +++ b/include/rocksdb/file_system.h @@ -812,6 +812,11 @@ struct FSReadRequest { // returns fewer bytes if end of file is hit (or `status` is not OK). size_t len; + // Allows more than "len" bytes to be returned + // Alternative: bool allow_more_data which allows returning up to the next + // block + size_t additional_read_size; + // A buffer that MultiRead() can optionally place data in. It can // ignore this and allocate its own buffer. // The lifecycle of scratch will be until IO is completed. @@ -950,6 +955,12 @@ class FSRandomAccessFile { // aligned buffer for Direct I/O virtual size_t GetRequiredBufferAlignment() const { return kDefaultPageSize; } + // Default of 0 for when block size concept does not apply + // This method is not necessary if our FSReadRequest contains an option to + // allow a variable amount of additional data to be sent along the response + // (unrelated to the block size) + virtual size_t GetBlockSize() const { return 0; } + // Remove any kind of caching of data from the offset to offset+length // of this file. If the length is 0, then it refers to the end of file. // If the system is not caching the file contents, then this is a noop.