pub struct FileCache { /* private fields */ }Expand description
On-disk BatchCache: one file per encoded batch, so a crash or an offline shutdown loses
nothing and the next launch replays what is left.
Files are written as .tmp and renamed into place, so a crash never leaves a half batch
readable; eviction is drop-oldest above max_bytes or 512 files (MAX_BATCHES), and the
newest batch always stays. Age is the exporter’s call (24 h, judged by the timestamp in the id
rather than file metadata — an Apple “required reason” API).
Writes, recovery and clears serialize across instances in this process, including clear’s
listing through deletion. A clear does not revoke future writes; its caller owns consent.
Implementations§
Source§impl FileCache
impl FileCache
Sourcepub fn open(dir: impl Into<PathBuf>, max_bytes: u64) -> Result<Self>
pub fn open(dir: impl Into<PathBuf>, max_bytes: u64) -> Result<Self>
Open the cache directory (created if missing; its parent must exist), finish or roll back a split interrupted by a crash — before anything is evicted — and discard stray or half-written files (only here: a replaced pipeline may still be writing its own).
Trait Implementations§
Source§impl BatchCache for FileCache
The durability boundary: a batch is committed once push returns Ok — its file was written
to a .tmp, fsynced, renamed into place and the directory fsynced; if any of that fails
the file is removed and push errs (the caller keeps the batch in memory instead). A crash
before that point loses only the batch being written (its .tmp is removed at the next
open). Deletes are fsynced the same way. A split (replace) is journaled: see
FileCache::recover.
impl BatchCache for FileCache
The durability boundary: a batch is committed once push returns Ok — its file was written
to a .tmp, fsynced, renamed into place and the directory fsynced; if any of that fails
the file is removed and push errs (the caller keeps the batch in memory instead). A crash
before that point loses only the batch being written (its .tmp is removed at the next
open). Deletes are fsynced the same way. A split (replace) is journaled: see
FileCache::recover.
Source§fn replace(&self, old: &str, new: &[(String, Vec<u8>)]) -> Result<Vec<String>>
fn replace(&self, old: &str, new: &[(String, Vec<u8>)]) -> Result<Vec<String>>
Journaled: both halves are written, fsynced and renamed to <old>@<half>.pend, the
directory is fsynced, then old is deleted — the commit point — and the halves are
published. Before the commit point any failure rolls back; an existing old stays whole. After it
the halves are safe in the journal and published by the next listing. Nothing is evicted
until the replacement is complete. A rebinding (a host-less old that a half extends with
its project) has exactly one member. Otherwise this returns InvalidInput and writes
nothing.
Source§fn push(&self, id: &str, body: &[u8]) -> Result<Vec<String>>
fn push(&self, id: &str, body: &[u8]) -> Result<Vec<String>>
id: once this returns Ok the batch is committed (for
FileCache, on disk). Returns the ids of older batches evicted to make room (the
exporter counts their events as dropped).Source§fn read(&self, id: &str) -> Result<Vec<u8>>
fn read(&self, id: &str) -> Result<Vec<u8>>
id: ErrorKind::NotFound when it is gone, another error when it
exists but cannot be read right now (e.g. a locked device’s file protection).Source§fn remove(&self, id: &str) -> Result<()>
fn remove(&self, id: &str) -> Result<()>
Source§fn clear(&self) -> Result<()>
fn clear(&self) -> Result<()>
Err when
something could not be deleted.