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
This commit is contained in:
Hui Xiao 2022-05-17 10:24:04 -07:00 committed by Facebook GitHub Bot
parent b11ff347b4
commit f6339de0d2

View File

@ -38,6 +38,13 @@ IOStatus SequentialFileReader::Read(size_t n, Slice* result, char* scratch) {
IOStatus io_s; IOStatus io_s;
if (use_direct_io()) { if (use_direct_io()) {
#ifndef ROCKSDB_LITE #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 offset = offset_.fetch_add(n);
size_t alignment = file_->GetRequiredBufferAlignment(); size_t alignment = file_->GetRequiredBufferAlignment();
size_t aligned_offset = TruncateToPageBoundary(alignment, offset); size_t aligned_offset = TruncateToPageBoundary(alignment, offset);