logging: Dedicated log flush timer

Log flushing is currently triggered based on the threading heartbeat timer
of WriterBackends and the hard-coded WRITE_BUFFER_SIZE 1000.

This change introduces a separate timer that is managed by the logger
manager instead of piggy-backing on the heartbeat timer, as well as a
const &redef for the buffer size.

This allows to modify the log flush frequency and batch size independently
of the threading heartbeat interval. Later, this will allow to re-use the
buffering and flushing logic of writer frontends for non-Broker cluster
backends, too.

One change here is that even frontends that do not have a backend will
be flushed regularly. This is wanted for non-Broker backends and should be
very cheap. Possibly, Broker can piggy back on this timer down the road, too,
rather than using its own script-level timer (see Broker::log_flush()).
This commit is contained in:
Arne Welzel 2024-09-27 11:37:23 +02:00
parent 77b9510c8a
commit 0d925e935e
11 changed files with 87 additions and 23 deletions

View file

@ -32,6 +32,8 @@ class RotationTimer;
namespace detail {
class LogFlushWriteBufferTimer;
class DelayInfo;
using WriteIdx = uint64_t;
@ -348,6 +350,7 @@ protected:
friend class RotationFinishedMessage;
friend class RotationFailedMessage;
friend class RotationTimer;
friend class detail::LogFlushWriteBufferTimer;
// Instantiates a new WriterBackend of the given type (note that
// doing so creates a new thread!).
@ -364,6 +367,12 @@ protected:
bool FinishedRotation(WriterFrontend* writer, const char* new_name, const char* old_name, double open, double close,
bool success, bool terminating);
// Flush write buffers of all writers.
void FlushAllWriteBuffers();
// Start the regular log flushing timer.
void StartLogFlushTimer();
private:
struct Filter;
struct Stream;
@ -404,6 +413,9 @@ private:
zeek_uint_t last_delay_token = 0;
std::vector<detail::WriteContext> active_writes;
// Timer for flushing write buffers of frontends.
detail::LogFlushWriteBufferTimer* log_flush_timer = nullptr;
};
} // namespace logging