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: usizeCompact after this many pushes (default 1 000).
Implementations§
Source§impl PersistenceManager
impl PersistenceManager
Sourcepub fn open(dir: impl AsRef<Path>) -> Result<Self>
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.
Sourcepub fn recover(&self) -> Result<Vec<f64>>
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.
Sourcepub fn record_push(&mut self, value: f64, current_data: &[f64]) -> Result<()>
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.
Sourcepub fn compact(&mut self, current_data: &[f64]) -> Result<()>
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.
Sourcepub fn wal_size_bytes(&self) -> Result<u64>
pub fn wal_size_bytes(&self) -> Result<u64>
WAL size in bytes (useful for monitoring / alerting).
Sourcepub fn pending_wal_entries(&self) -> usize
pub fn pending_wal_entries(&self) -> usize
Number of WAL entries pending since the last snapshot.