From f6339de0d2e0383faa90fdf011a665c94be8f692 Mon Sep 17 00:00:00 2001 From: Hui Xiao Date: Tue, 17 May 2022 10:24:04 -0700 Subject: [PATCH] Clarify some SequentialFileReader::Read logic (#10002) Summary: **Context/Summary:** The logic related to PositionedRead in SequentialFileReader::Read confused me a bit as discussed here https://github.com/facebook/rocksdb/pull/9973#discussion_r872869256. Therefore I added a drawing with help from cbi42. Pull Request resolved: https://github.com/facebook/rocksdb/pull/10002 Test Plan: - no code change Reviewed By: anand1976, cbi42 Differential Revision: D36422632 Pulled By: hx235 fbshipit-source-id: 9a8311d2365564f90d216c430f542fc11b2d9cde --- file/sequence_file_reader.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/file/sequence_file_reader.cc b/file/sequence_file_reader.cc index 6a89d41d5..e8591589c 100644 --- a/file/sequence_file_reader.cc +++ b/file/sequence_file_reader.cc @@ -38,6 +38,13 @@ IOStatus SequentialFileReader::Read(size_t n, Slice* result, char* scratch) { IOStatus io_s; if (use_direct_io()) { #ifndef ROCKSDB_LITE + // + // |-offset_advance-|---bytes returned--| + // |----------------------buf size-------------------------| + // | | | | + // aligned offset offset + n Roundup(offset + n, + // offset alignment) + // size_t offset = offset_.fetch_add(n); size_t alignment = file_->GetRequiredBufferAlignment(); size_t aligned_offset = TruncateToPageBoundary(alignment, offset);