Skip to main content

FileCache

Struct FileCache 

Source
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

Source

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.

Source§

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>>

Store one encoded batch under 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 pending(&self) -> Vec<String>

Ids of stored batches, oldest first.
Source§

fn read(&self, id: &str) -> Result<Vec<u8>>

The body stored under 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<()>

Delete one batch; a batch already gone is not an error.
Source§

fn clear(&self) -> Result<()>

Discard everything (telemetry disabled: nothing may be replayed later); Err when something could not be deleted.
Source§

fn take_evicted(&self) -> Vec<String>

Ids evicted before the exporter could see them (over the bounds when the cache was opened), handed over once so they are counted as lost.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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