Skip to main content

FsyncPolicy

Enum FsyncPolicy 

Source
pub enum FsyncPolicy {
    Never,
    EveryN(u64),
    Interval(Duration),
    IntervalOrBytes {
        period: Duration,
        max_bytes: u64,
    },
}
Expand description

Disk-side fsync policy for persistent RedexFiles.

Governs only the append path on the disk mirror. close() and explicit RedexFile::sync() calls always fsync regardless of policy — these are the caller’s explicit durability barriers.

PolicyProcess crashKernel / power crash
NeverLoses the tail since last close / sync()Same
EveryN(N)Loses ≤ (N−1) entries from the last sync pointSame
Interval(d)Loses ≤ d seconds of writesSame
IntervalOrBytes { period, max_bytes }Loses ≤ min(period of writes, max_bytes of writes)Same

Default is FsyncPolicy::Never, matching the pre-FsyncPolicy behavior — OS page cache only, fsync on close. Callers that need tighter bounds opt into EveryN, Interval, or IntervalOrBytes.

Variants§

§

Never

Never fsync on append. close() still syncs. Lowest latency; fine for telemetry / best-effort logs.

§

EveryN(u64)

Fsync after every N successful appends. The fsync runs on a background task — the appender returns as soon as the bytes land in the page cache and signals the worker; the worker runs fsync_all off the hot path. Concurrent notifies during an in-flight fsync coalesce into a single follow-up.

Worst-case loss bound: (N − 1) entries since the last sync point, plus the bytes from any fsync that was in flight when the crash interrupted it. 0 and 1 both collapse to “signal on every append.”

Under heavy concurrent appends the bound loosens slightly: the threshold check (fetch_add then if cross { reset }) is not a CAS, so K appenders racing past the threshold can each cross before any of them resets the counter. The next sync covers all K of those entries; the durability contract still holds (no entry survives unsynced past the next fsync), but the practical bound becomes (N − 1) + (concurrent appenders at threshold). Pick a smaller N if you need a tighter bound under contention.

§

Interval(Duration)

Fsync on a timer, independent of append rate. A per-file background tokio task drives the sync; close() cancels it.

§

IntervalOrBytes

Fsync when either period elapses or max_bytes of writes have accumulated since the last sync, whichever comes first. The byte threshold counts every byte written to dat, idx, and ts.

Use this for bursty workloads where a long period would leave too much data unsynced under load, but a short period would over-fsync when idle.

Configuration matrix:

periodmax_bytesBehavior
> 0> 0Full both-arms worker (timer + byte signal)
> 00Timer-only worker (equivalent to Interval(period))
0> 0Byte-only worker (no timer arm); fsyncs when the byte threshold crosses
00No worker; equivalent to Never

The same concurrency caveat as Self::EveryN applies to the byte arm: K concurrent appenders can each cross the threshold before any of them resets the counter, so the effective bound is max_bytes + (concurrent appenders' bytes at threshold).

Fields

§period: Duration

Maximum wall-clock interval between syncs. 0 disables the timer arm; pair with a non-zero max_bytes to get a byte-only worker.

§max_bytes: u64

Maximum bytes (across dat + idx + ts) accumulated since the last sync before the worker is signaled. 0 disables the byte arm; pair with a non-zero period to get a timer-only worker (equivalent to Interval).

Trait Implementations§

Source§

impl Clone for FsyncPolicy

Source§

fn clone(&self) -> FsyncPolicy

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 Copy for FsyncPolicy

Source§

impl Debug for FsyncPolicy

Source§

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

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

impl Default for FsyncPolicy

Source§

fn default() -> FsyncPolicy

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

impl Eq for FsyncPolicy

Source§

impl PartialEq for FsyncPolicy

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for FsyncPolicy

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<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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> 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, 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