Skip to main content

FlushPolicy

Enum FlushPolicy 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

§batch_size: usize

In-memory item count threshold.

§interval: Duration

Max time between flushes.

§

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

§batch_size: usize

In-memory item count threshold for immediate flush.

§min_batch: usize

Minimum pending items before an interval-triggered flush fires. Prevents writing tiny segments during low-throughput periods.

§interval: Duration

Interval after which to flush if at least min_batch items accumulated.

§max_interval: Duration

Absolute maximum time between flushes, regardless of pending count. Ensures events don’t sit in memory indefinitely during idle periods.

§

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.

Implementations§

Source§

impl FlushPolicy

Source

pub fn validate(&self)

Check internal constraints that, if violated, make the policy behave incorrectly (e.g. an interval trigger that can never fire).

Currently validates:

In debug builds, violations panic via debug_assert!. In release builds this method is a no-op — the policy is still usable but may behave surprisingly if the constraints are violated. Call this from any construction path that receives caller-supplied values.

§Panics

Panics in debug builds if a constraint is violated.

Trait Implementations§

Source§

impl Clone for FlushPolicy

Source§

fn clone(&self) -> FlushPolicy

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FlushPolicy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FlushPolicy

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for FlushPolicy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Human-readable representation suitable for logging and diagnostics.

The format is intentionally compact and stable across releases so operators can parse it in log-scraping tools without breakage.

Source§

impl Eq for FlushPolicy

Source§

impl PartialEq for FlushPolicy

Source§

fn eq(&self, other: &FlushPolicy) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FlushPolicy

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more