Don't lose pieces out of the middle of writing files
We didn't get all the accounting right when writing out aligned subsets
of buffers and unaligned subsets. Fix the correctness issues in that
and add tests (Alexei wrote most of the tests).
Change-Id: I8ac6bcbd6b762174b3f47d41ab5da1dff2cfec44
Signed-off-by: Austin Schuh <austin.schuh@bluerivertech.com>
diff --git a/aos/events/logging/logfile_utils.cc b/aos/events/logging/logfile_utils.cc
index 0338057..990e742 100644
--- a/aos/events/logging/logfile_utils.cc
+++ b/aos/events/logging/logfile_utils.cc
@@ -210,10 +210,12 @@
while (encoder_->space() == 0 ||
encoder_->queued_bytes() > static_cast<size_t>(FLAGS_flush_size) ||
encoder_->queue_size() >= IOV_MAX ||
- now > last_flush_time_ +
- chrono::duration_cast<chrono::nanoseconds>(
- chrono::duration<double>(FLAGS_flush_period))) {
- VLOG(1) << "Chose to flush at " << now << ", last " << last_flush_time_;
+ (now > last_flush_time_ +
+ chrono::duration_cast<chrono::nanoseconds>(
+ chrono::duration<double>(FLAGS_flush_period)) &&
+ encoder_->queued_bytes() != 0)) {
+ VLOG(1) << "Chose to flush at " << now << ", last " << last_flush_time_
+ << " queued bytes " << encoder_->queued_bytes();
Flush(now);
}
}