From a3b1c9528571960a244c418f7c64cf84cb699d7e Mon Sep 17 00:00:00 2001 From: akankshamahajan Date: Mon, 4 Dec 2023 10:38:46 -0800 Subject: [PATCH] Add comments Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: --- file/file_prefetch_buffer.cc | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/file/file_prefetch_buffer.cc b/file/file_prefetch_buffer.cc index 15c70f5f153b..4b02348c0294 100644 --- a/file/file_prefetch_buffer.cc +++ b/file/file_prefetch_buffer.cc @@ -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(); } @@ -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_ || @@ -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,