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
impl Snapshot
Sourcepub fn reconcile(
&self,
rows_prefix: &[u8],
derived_prefixes: &[&[u8]],
derived: impl FnMut(&[u8], &Value) -> Vec<Vec<u8>>,
) -> ReconcileReport
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
impl Snapshot
Sourcepub fn each_prefix<F: FnMut(&[u8], &Value, Option<u64>)>(
&self,
prefix: &[u8],
f: F,
)
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.
Sourcepub fn keys_prefix(&self, prefix: &[u8]) -> Vec<SnapshotEntry>
pub fn keys_prefix(&self, prefix: &[u8]) -> Vec<SnapshotEntry>
Collect the keys (+ TTLs) under prefix, unordered across
shards.