#[non_exhaustive]pub enum FlushPolicy {
Batch(usize),
Interval(Duration),
BatchOrInterval {
batch_size: usize,
interval: Duration,
},
BatchOrIntervalMin {
batch_size: usize,
min_batch: usize,
interval: Duration,
max_interval: Duration,
},
Manual,
}Expand description
When to auto-flush pending items from memory to a segment file.
Passed to SegmentConfig via its flush_policy field. Replaces the
pre-v0.4.0 silent combination of two separate fields (max_batch_events
and flush_interval_secs) that OR’d together without telling the caller
which trigger fired.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Batch(usize)
Flush as soon as batch_size items are buffered. No interval trigger.
Interval(Duration)
Flush as soon as interval has elapsed since the last flush. No batch
trigger.
Timing note: the interval clock starts at open(), not at the
first append(). If the buffer sits idle after construction, the
first append will immediately trigger a flush.
BatchOrInterval
Flush when EITHER batch_size items are buffered OR interval has
elapsed since the last flush — whichever fires first. This is the
pre-v0.4.0 default behavior.
Caution: during low-throughput periods this policy creates tiny
segment files (as small as 1 event) every interval. Use
BatchOrIntervalMin to suppress interval
flushes below a minimum batch threshold.
Timing note: the interval clock starts at open(), not at the
first append().
Fields
BatchOrIntervalMin
Flush when batch_size items are buffered, OR when interval has
elapsed AND at least min_batch items are pending, OR when
max_interval has elapsed regardless of pending count.
This policy prevents tiny segment files during low-throughput periods:
the interval timer only triggers a flush if enough events have
accumulated to be worth writing. The max_interval safety valve
ensures events don’t sit in memory indefinitely during idle periods
(protecting crash-recovery latency).
Example: batch_size=256, min_batch=10, interval=5s, max_interval=60s
means: flush immediately at 256 events; every 5s, flush only if 10+
events are pending; every 60s, flush everything regardless.
Fields
Manual
Never auto-flush. The caller must call SegmentBuffer::flush
explicitly to make appends durable. Useful for tests and for callers
that want absolute control over write amplification.
Trait Implementations§
Source§impl Clone for FlushPolicy
impl Clone for FlushPolicy
Source§fn clone(&self) -> FlushPolicy
fn clone(&self) -> FlushPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more