From ae25546a7a7e0b88b3f4fc3ba7ca6ad4638e6fca Mon Sep 17 00:00:00 2001 From: Siying Dong Date: Tue, 11 Dec 2018 13:51:08 -0800 Subject: [PATCH] Direct I/O Close() shouldn't rewrite the last block (#4771) Summary: In Direct I/O case, WritableFileWriter::Close() rewrites the last block again, even if there is nothing new. The reason is that, Close() flushes the buffer. For non-direct I/O case, the buffer is empty in this case so it is a no-op. However, in direct I/O case, the partial data in the last block is kept in the buffer because it needs to be rewritten for the next write. This piece of data is flushed again. This commit fixes it by skipping this write out if `pending_sync_` flag shows that there isn't new data sync last sync. Pull Request resolved: https://github.com/facebook/rocksdb/pull/4771 Differential Revision: D13420426 Pulled By: siying fbshipit-source-id: 9d39ec9a215b1425d4ed40d85e0eba1f5daa75c6 --- util/file_reader_writer.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/util/file_reader_writer.cc b/util/file_reader_writer.cc index 821d657b0..e0ae9cb0e 100644 --- a/util/file_reader_writer.cc +++ b/util/file_reader_writer.cc @@ -327,7 +327,9 @@ Status WritableFileWriter::Flush() { if (buf_.CurrentSize() > 0) { if (use_direct_io()) { #ifndef ROCKSDB_LITE - s = WriteDirect(); + if (pending_sync_) { + s = WriteDirect(); + } #endif // !ROCKSDB_LITE } else { s = WriteBuffered(buf_.BufferStart(), buf_.CurrentSize());