avoid ftruncate twice in buffered io

Summary:
in buffered io, the filesize_ is the real size.
Closes https://github.com/facebook/rocksdb/pull/1991

Differential Revision: D4711433

Pulled By: lightmark

fbshipit-source-id: ad604b9
main
Aaron Gao 8 years ago committed by Facebook Github Bot
parent d52f334cbd
commit 9272e12f19
  1. 5
      util/file_reader_writer.cc

@ -184,12 +184,15 @@ Status WritableFileWriter::Close() {
s = Flush(); // flush cache to OS s = Flush(); // flush cache to OS
Status interim;
// In direct I/O mode we write whole pages so // In direct I/O mode we write whole pages so
// we need to let the file know where data ends. // we need to let the file know where data ends.
Status interim = writable_file_->Truncate(filesize_); if (use_direct_io()) {
interim = writable_file_->Truncate(filesize_);
if (!interim.ok() && s.ok()) { if (!interim.ok() && s.ok()) {
s = interim; s = interim;
} }
}
TEST_KILL_RANDOM("WritableFileWriter::Close:0", rocksdb_kill_odds); TEST_KILL_RANDOM("WritableFileWriter::Close:0", rocksdb_kill_odds);
interim = writable_file_->Close(); interim = writable_file_->Close();

Loading…
Cancel
Save