RandomAccessFileReader::MultiRead() should not return read bytes not read (#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: https://github.com/facebook/rocksdb/pull/8941

Test Plan: Run stress tests for a while

Reviewed By: anand1976

Differential Revision: D31085780

fbshipit-source-id: 999adf2d6c2712f1323d14bb68b678df59969973
main
sdong 3 years ago committed by Facebook GitHub Bot
parent 1de588668c
commit fcce1f2c7a
  1. 10
      file/random_access_file_reader.cc

@ -296,8 +296,14 @@ IOStatus RandomAccessFileReader::MultiRead(const IOOptions& opts,
r.status = fs_r.status; r.status = fs_r.status;
if (r.status.ok()) { if (r.status.ok()) {
uint64_t offset = r.offset - fs_r.offset; uint64_t offset = r.offset - fs_r.offset;
size_t len = std::min(r.len, static_cast<size_t>(fs_r.len - offset)); if (fs_r.result.size() <= offset) {
r.result = Slice(fs_r.scratch + offset, len); // 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 { } else {
r.result = Slice(); r.result = Slice();
} }

Loading…
Cancel
Save