From 73843aa6361bab52b10299b9a45b5f5d85c4752b Mon Sep 17 00:00:00 2001 From: Siying Dong Date: Fri, 18 Nov 2016 19:17:25 -0800 Subject: [PATCH] Direct I/O Reads Handle the last sector correctly. Summary: Currently, in the Direct I/O read mode, the last sector of the file, if not full, is not handled correctly. If the return value of pread is not multiplier of kSectorSize, we still go ahead and continue reading, even if the buffer is not aligned. With the commit, if the return value is not multiplier of kSectorSize, and all but the last sector has been read, we simply return. Closes https://github.com/facebook/rocksdb/pull/1550 Differential Revision: D4209609 Pulled By: lightmark fbshipit-source-id: cb0b439 --- util/io_posix.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/util/io_posix.cc b/util/io_posix.cc index 426d2c560..111f899ee 100644 --- a/util/io_posix.cc +++ b/util/io_posix.cc @@ -105,6 +105,11 @@ Status ReadAligned(int fd, Slice* data, const uint64_t offset, break; } bytes_read += status; + if (status % static_cast(kSectorSize) != 0) { + // Bytes reads don't fill sectors. Should only happen at the end + // of the file. + break; + } } *data = Slice(scratch, bytes_read);