wal-backup 0.8.11

Embedded SQLite WAL replication to S3-compatible object storage. Not a sidecar — a library. Like Litestream, but embedded.
Documentation
use std::sync::Arc;

pub trait Metrics: Send + Sync {
    fn frames_shipped(&self, count: u32);
    fn snapshot_taken(&self, db_size: u64, wal_size: u64);
    fn sync_completed(&self, duration_ms: u64);
    fn restore_completed(&self, duration_ms: u64);
    fn segment_uploaded(&self, key: &str, size: u64);
    fn segment_deleted(&self, key: &str);
    fn shipper_error(&self, detail: &str);
    fn snapshot_error(&self, detail: &str) {
        let _ = detail;
    }
    fn restore_error(&self, detail: &str) {
        let _ = detail;
    }
    /// Called when an orphaned segment is deleted during GC.
    /// Active segments (referenced by current manifest) are not counted as orphans.
    fn orphan_deleted(&self, key: &str) {
        let _ = key;
    }
    /// Called when a checksum mismatch is detected but Recoverable mode is used.
    /// The operation proceeds, but the warning is logged for visibility.
    /// Implement this in your Metrics to surface alerts (e.g. increment a counter,
    /// send to PagerDuty, etc.).
    fn checksum_warning(&self, detail: &str) {
        let _ = detail;
    }
    /// Called when compaction merges L0 segments into an L1 file.
    /// `l0_count` is the number of L0 segments merged.
    /// `l1_key` is the bucket key of the new L1 file.
    fn segment_compacted(&self, l0_count: u32, l1_key: &str) {
        let _ = l0_count;
        let _ = l1_key;
    }
}

pub struct NoopMetrics;

impl Metrics for NoopMetrics {
    fn frames_shipped(&self, _count: u32) {}
    fn snapshot_taken(&self, _db_size: u64, _wal_size: u64) {}
    fn sync_completed(&self, _duration_ms: u64) {}
    fn restore_completed(&self, _duration_ms: u64) {}
    fn segment_uploaded(&self, _key: &str, _size: u64) {}
    fn segment_deleted(&self, _key: &str) {}
    fn shipper_error(&self, _detail: &str) {}
}

pub fn noop_metrics() -> Arc<dyn Metrics> {
    Arc::new(NoopMetrics)
}