Skip to main content

PersistenceManager

Struct PersistenceManager 

Source
pub struct PersistenceManager {
    pub snapshot_interval: usize,
    /* private fields */
}
Expand description

Manages WAL + snapshot persistence for an crate::Anomalyzer data window.

Obtain one via PersistenceManager::open, then call recover to get the initial data vec, and record_push on every push.

Fields§

§snapshot_interval: usize

Compact after this many pushes (default 1 000).

Implementations§

Source§

impl PersistenceManager

Source

pub fn open(dir: impl AsRef<Path>) -> Result<Self>

Open (or create) the persistence directory.

§Errors

Returns io::Error if the directory cannot be created or files opened.

Source

pub fn recover(&self) -> Result<Vec<f64>>

Reconstruct the data window from snapshot + WAL.

Call once at startup; the returned Vec<f64> is passed as initial_data to crate::Anomalyzer::new.

Source

pub fn record_push(&mut self, value: f64, current_data: &[f64]) -> Result<()>

Record one push(value) to the WAL.

Fsync is called on every write — call this after a successful Anomalyzer::push so the WAL never leads the in-memory state.

Triggers a snapshot + WAL truncation every snapshot_interval calls.

Source

pub fn compact(&mut self, current_data: &[f64]) -> Result<()>

Force a snapshot + WAL truncation now.

Called automatically every snapshot_interval pushes; you can also call it on clean shutdown to minimise next startup replay time.

Source

pub fn wal_size_bytes(&self) -> Result<u64>

WAL size in bytes (useful for monitoring / alerting).

Source

pub fn pending_wal_entries(&self) -> usize

Number of WAL entries pending since the last snapshot.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V