Fix the race condition when rotating the logger.
There's a small race condition which allows for over polling_period_ of
data to be written per channel, violating the max out of order duration
in the header.
1) while (LogUntil(last_synchronized_time_ + polling_period_)) flushes
until "now" into the old log. All good there.
2) WriteConfiguration() takes 300ms to compress the config and write
it. The same effect can be triggered by the kernel preempting the
logger for over 300ms here as well. That's not impossible either.
3) WriteHeader() updates last_synchronized_time_, ie over 300ms after we
last flushed data to disk.
4) The new "double logging" portion of the logger which is supposed to
make sure everything gets logged up to the start time in the old log
does this all in 1 go. So, it writes 300ms+ of data per channel, up
to the new last_synchronized_time_ from WriteHeader().
This generates a corrupted log.
To fix this, we just need to pick a start time which is after the last
message in the previous log (step 1), but is guarenteed to be before we
start double logging and needs to be at most polling_period_ since the
last time we flushed. Pick the min of last_synchronized_time_ and right
after we finished flushing in step 1), which is guarenteed to have both
those properties.
Change-Id: I117fc77186e489d3eb8936336ff744d56a2a5fb5
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/events/logging/log_writer.h b/aos/events/logging/log_writer.h
index 3c75f29..7beef03 100644
--- a/aos/events/logging/log_writer.h
+++ b/aos/events/logging/log_writer.h
@@ -224,7 +224,10 @@
// Start/Restart write configuration into LogNamer space.
std::string WriteConfiguration(LogNamer* log_namer);
- void WriteHeader();
+ void WriteHeader(aos::monotonic_clock::time_point monotonic_start_time =
+ aos::monotonic_clock::min_time,
+ aos::realtime_clock::time_point realtime_start_time =
+ aos::realtime_clock::min_time);
// Makes a template header for all the follower nodes.
aos::SizePrefixedFlatbufferDetachedBuffer<LogFileHeader> MakeHeader(