From b2274da0e54da2a4c7faac571377edd8ece43cec Mon Sep 17 00:00:00 2001 From: Siying Dong Date: Tue, 21 May 2019 12:17:15 -0700 Subject: [PATCH] LogWriter to only flush after finish generating whole record (#5328) Summary: Right now, in log writer, we call flush after writing each physical record. I don't see the necessarity of it. Right now, the underlying writer has a buffer, so there isn't a concern that the write request is too large either. On the other hand, in an Env where every flush is expensive, the current approach is significantly slower than only flushing after a whole record finishes, when the record is very large. Pull Request resolved: https://github.com/facebook/rocksdb/pull/5328 Differential Revision: D15425032 Pulled By: siying fbshipit-source-id: 440ebef002dfbb60c59d8388c9ddfc83d79700aa --- HISTORY.md | 1 + db/log_writer.cc | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index e9f06b532..b65f5a038 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -13,6 +13,7 @@ * DBIter::Next() can skip user key checking if previous entry's seqnum is 0. * Merging iterator to avoid child iterator reseek for some cases * Reduce iterator key comparision for upper/lower bound check. +* Log Writer will flush after finishing the whole record, rather than a fragment. ### General Improvements * Added new status code kColumnFamilyDropped to distinguish between Column Family Dropped and DB Shutdown in progress. diff --git a/db/log_writer.cc b/db/log_writer.cc index 6ee391981..c46965e16 100644 --- a/db/log_writer.cc +++ b/db/log_writer.cc @@ -102,6 +102,13 @@ Status Writer::AddRecord(const Slice& slice) { left -= fragment_length; begin = false; } while (s.ok() && left > 0); + + if (s.ok()) { + if (!manual_flush_) { + s = dest_->Flush(); + } + } + return s; } @@ -146,11 +153,6 @@ Status Writer::EmitPhysicalRecord(RecordType t, const char* ptr, size_t n) { Status s = dest_->Append(Slice(buf, header_size)); if (s.ok()) { s = dest_->Append(Slice(ptr, n)); - if (s.ok()) { - if (!manual_flush_) { - s = dest_->Flush(); - } - } } block_offset_ += header_size + n; return s;