Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
Summary:

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:
  • Loading branch information
akankshamahajan15 committed Dec 4, 2023
1 parent 07b9367 commit a3b1c95
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions file/file_prefetch_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ Status FilePrefetchBuffer::Prefetch(const IOOptions& opts,
TEST_SYNC_POINT("FilePrefetchBuffer::Prefetch:Start");

if (offset + n <= buf->offset_ + buf->buffer_.CurrentSize()) {
// All requested bytes are already in the curr_ buffer. So no need to Read
// again.
// All requested bytes are already in the buffer. So no need to Read again.
return Status::OK();
}

Expand Down Expand Up @@ -413,7 +412,7 @@ Status FilePrefetchBuffer::HandleOverlappingData(
// call ReadAsync on freed buffer.
if (!buf->async_read_in_progress_ && DoesBufferContainData(buf) &&
IsOffsetInBuffer(buf, offset) &&
(/*Data extends over curr_ buffer and second buffer either has data or in
(/*Data extends over two buffers and second buffer either has data or in
process of population=*/
(offset + length > next_buf->offset_) &&
(next_buf->async_read_in_progress_ ||
Expand Down Expand Up @@ -463,26 +462,20 @@ Status FilePrefetchBuffer::HandleOverlappingData(
}

// If async_io is enabled in case of sequential reads, PrefetchAsyncInternal is
// called. When buffers are switched, we clear the curr_ buffer as we assume the
// called. When data is outdated, we clear the first buffer and free it as the
// data has been consumed because of sequential reads.
// Data in buffers will always be sequential with curr_ following second and
// not vice versa.
//
// Scenarios for prefetching asynchronously:
// Case1: If both buffers are empty, prefetch n + readahead_size_/2 bytes
// synchronously in curr_ and prefetch readahead_size_/2 async in second
// buffer.
// Case2: If second buffer has partial or full data, make it current and
// prefetch readahead_size_/2 async in second buffer. In case of
// partial data, prefetch remaining bytes from size n synchronously to
// fulfill the requested bytes request.
// Case3: If curr_ has partial data, prefetch remaining bytes from size n
// synchronously in curr_ to fulfill the requested bytes request and
// prefetch readahead_size_/2 bytes async in second buffer.
// Case4: (Special case) If data is in both buffers, copy requested data from
// curr_, send async request on curr_, wait for poll to fill second
// buffer (if any), and copy remaining data from second buffer to third
// buffer.
// Case1: If all buffers are in free_bufs_, prefetch n + readahead_size_/2 bytes
// synchronously in first buffer and prefetch readahead_size_/2 async in
// remaining buffers (num_buffers_ -1 ).
// Case2: If first buffer has partial data, prefetch readahead_size_/2 async in
// remaining buffers. In case of partial data, prefetch remaining bytes
// from size n synchronously to fulfill the requested bytes request.
// Case5: (Special case) If data is overlapping in two buffers, copy requested
// data from first, free that buffer to send for async request, wait for
// poll to fill next buffer (if any), and copy remaining data from that
// buffer to overlap buffer.
Status FilePrefetchBuffer::PrefetchAsyncInternal(const IOOptions& opts,
RandomAccessFileReader* reader,
uint64_t offset, size_t length,
Expand Down

0 comments on commit a3b1c95

Please sign in to comment.