diff --git a/util/file_reader_writer.cc b/util/file_reader_writer.cc index dcf72531c5c..0237fc9d358 100644 --- a/util/file_reader_writer.cc +++ b/util/file_reader_writer.cc @@ -186,7 +186,9 @@ Status WritableFileWriter::Close() { // In direct I/O mode we write whole pages so // we need to let the file know where data ends. - Status interim = writable_file_->Truncate(filesize_); + if (use_direct_io()) { + Status interim = writable_file_->Truncate(filesize_); + } if (!interim.ok() && s.ok()) { s = interim; } diff --git a/util/io_posix.cc b/util/io_posix.cc index 74250c86840..b61f4b38f55 100644 --- a/util/io_posix.cc +++ b/util/io_posix.cc @@ -730,13 +730,11 @@ Status PosixWritableFile::PositionedAppend(const Slice& data, uint64_t offset) { Status PosixWritableFile::Truncate(uint64_t size) { Status s; - if (use_direct_io()) { - int r = ftruncate(fd_, size); - if (r < 0) { - s = IOError(filename_, errno); - } else { - filesize_ = size; - } + int r = ftruncate(fd_, size); + if (r < 0) { + s = IOError(filename_, errno); + } else { + filesize_ = size; } return s; }