Skip to content

Commit

Permalink
Add comment explaining why RandomAccessFileReader* is not passed in a…
Browse files Browse the repository at this point in the history
…t construction time
  • Loading branch information
archang19 committed Dec 6, 2024
1 parent be7703b commit 33760b2
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions file/file_prefetch_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,14 @@ class FilePrefetchBuffer {
// offset : the file offset to start reading from.
// n : the number of bytes to read.
//
// Note: Why do we pass in the RandomAccessFileReader* for every single call
// to Prefetch/PrefetchAsync/TryReadFromCache? Why can't we just pass it in at
// construction time?
// Although the RandomAccessFileReader* is often available when creating
// the FilePrefetchBuffer, this is not true for BlobDB (see
// BlobSource::GetBlob). The file reader gets retrieved or created inside
// BlobFileCache::GetBlobFileReader, after we have already allocated a new
// FilePrefetchBuffer.
Status Prefetch(const IOOptions& opts, RandomAccessFileReader* reader,
uint64_t offset, size_t n);

Expand Down Expand Up @@ -488,6 +496,10 @@ class FilePrefetchBuffer {
// Whether we reuse the file system provided buffer
// Until we also handle the async read case, only enable this optimization
// for the synchronous case when num_buffers_ = 1.
// Note: Although it would be more convenient if we could determine
// whether we want to reuse the file system buffer at construction time,
// this would not work in all cases, because not all clients (BlobDB in
// particular) have a RandomAccessFileReader* available at construction time.
bool UseFSBuffer(RandomAccessFileReader* reader) {
return reader->file() != nullptr && !reader->use_direct_io() &&
fs_ != nullptr &&
Expand Down

0 comments on commit 33760b2

Please sign in to comment.