Skip to content

Commit

Permalink
RandomAccessFileReader::MultiRead() should not return read bytes not …
Browse files Browse the repository at this point in the history
…read (facebook#8941)

Summary:
Right now, if underlying read returns fewer bytes than asked for, RandomAccessFileReader::MultiRead() still returns those in the buffer to upper layer. This can be a surprise to upper layer.
This is unlikely to cause incorrect data. To cause incorrect data, checksum checking in upper layer should pass with short reads, whose chance is low.

Pull Request resolved: facebook#8941

Test Plan: Run stress tests for a while

Reviewed By: anand1976

Differential Revision: D31085780

fbshipit-source-id: 999adf2d6c2712f1323d14bb68b678df59969973
  • Loading branch information
siying authored and facebook-github-bot committed Sep 21, 2021
1 parent 1de5886 commit fcce1f2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions file/random_access_file_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,14 @@ IOStatus RandomAccessFileReader::MultiRead(const IOOptions& opts,
r.status = fs_r.status;
if (r.status.ok()) {
uint64_t offset = r.offset - fs_r.offset;
size_t len = std::min(r.len, static_cast<size_t>(fs_r.len - offset));
r.result = Slice(fs_r.scratch + offset, len);
if (fs_r.result.size() <= offset) {
// No byte in the read range is returned.
r.result = Slice();
} else {
size_t len = std::min(
r.len, static_cast<size_t>(fs_r.result.size() - offset));
r.result = Slice(fs_r.scratch + offset, len);
}
} else {
r.result = Slice();
}
Expand Down

0 comments on commit fcce1f2

Please sign in to comment.