Skip to main content

Snapshot

Struct Snapshot 

Source
pub struct Snapshot { /* private fields */ }
Expand description

A frozen, consistent point-in-time view of the whole store.

let s = kevy_embedded::Store::open(kevy_embedded::Config::default())?;
s.set(b"u:1", b"a")?;
let frozen = s.snapshot();
s.set(b"u:2", b"b")?; // lands after the freeze
assert_eq!(frozen.keys_prefix(b"u:").len(), 1);
assert_eq!(s.snapshot().keys_prefix(b"u:").len(), 2);

Implementations§

Source§

impl Snapshot

Source

pub fn reconcile( &self, rows_prefix: &[u8], derived_prefixes: &[&[u8]], derived: impl FnMut(&[u8], &Value) -> Vec<Vec<u8>>, ) -> ReconcileReport

Rebuild every derived key from the rows under rows_prefix and diff it against what actually exists under derived_prefixes.

derived is the function from a row to the keys it implies — the same one the write path uses (cookbook §21). Whatever it returns for a row is what that row is entitled to; anything else under derived_prefixes is an orphan.

derived_prefixes must cover everywhere derived keys live. A derived key outside them is invisible to both directions of the diff: it cannot be reported missing (nothing looks for it) and it cannot be reported orphaned (nothing enumerates it). This is the one way to get a falsely clean report, so the prefixes are a required argument rather than an option with a default.

The snapshot is frozen, so a clean system reports clean no matter what writers are doing.

store.set(b"user:1", b"ann")?;
store.set(b"email:user:1", b"1")?; // the one key user:1 implies
store.set(b"dept:gone", b"1")?;    // implied by no row
let report = store.snapshot().reconcile(
    b"user:",
    &[b"email:", b"dept:"],
    |key, _row| vec![[b"email:".as_slice(), key].concat()],
);
assert!(!report.is_clean());
assert_eq!((report.missing_count, report.orphaned), (0, vec![b"dept:gone".to_vec()]));
Source§

impl Snapshot

Source

pub fn each_prefix<F: FnMut(&[u8], &Value, Option<u64>)>( &self, prefix: &[u8], f: F, )

Visit every entry under prefix as (key, value, ttl_ms) — the raw kevy_store::Value borrow, for callers that want the typed payload without copies.

Source

pub fn keys_prefix(&self, prefix: &[u8]) -> Vec<SnapshotEntry>

Collect the keys (+ TTLs) under prefix, unordered across shards.

Source

pub fn len(&self) -> usize

Total entries in the view.

Source

pub fn is_empty(&self) -> bool

Whether the view is empty.

Trait Implementations§

Source§

impl Debug for Snapshot

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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

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.