Skip to content

Commit

Permalink
Demonstrate how flexible read could look like
Browse files Browse the repository at this point in the history
  • Loading branch information
archang19 committed Jan 24, 2025
1 parent 4ac85f0 commit f2de8e4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions file/file_prefetch_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions file/random_access_file_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions include/rocksdb/file_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit f2de8e4

Please sign in to comment.