#[non_exhaustive]pub struct OpenReport {
pub replayed_commands: u64,
pub replayed_bytes: u64,
pub elapsed_ms: u64,
pub dropped_bytes: u64,
pub corrupt: bool,
pub quarantine_paths: Vec<PathBuf>,
pub resynced_bytes: u64,
pub stage_recovered: u64,
pub stage_discarded: u64,
}Expand description
What Store::open restored — and what it could not. The pull-style
twin of KevyMetric::Replay (Store::open_report()), so a host can
turn “the AOF lost bytes at boot” into a health-check verdict without
wiring a metric sink or scraping stderr.
let s = kevy_embedded::Store::open(kevy_embedded::Config::default())?;
let r = s.open_report();
assert_eq!((r.replayed_commands, r.dropped_bytes, r.corrupt), (0, 0, false));Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.replayed_commands: u64Commands replayed from the AOF(s), summed across shards.
assert_eq!(r.replayed_commands, 2); // the two SETs came back from the logreplayed_bytes: u64Bytes actually replayed (the valid prefixes).
let log = std::fs::metadata(dir.path().join("aof-0.aof"))?.len();
assert!(r.replayed_bytes > 0 && r.replayed_bytes <= log);elapsed_ms: u64Wall-clock time of the whole startup replay, in milliseconds.
assert!(r.elapsed_ms < 60_000); // a two-record log replays at oncedropped_bytes: u64Bytes dropped past the last replayable frame, summed across shards. Non-zero = the store recovered less than the files held.
// a record of length 4 whose checksum is wrong, then bytes behind it
let mut log = std::fs::OpenOptions::new().append(true).open(dir.path().join("aof-0.aof"))?;
std::io::Write::write_all(&mut log, &[4, 0, 0, 0, 0, 0, 0, 0, b'a', b'b', b'c', b'd', b'!'])?;
drop(log);
let s = Store::open(cfg())?;
let r = s.open_report();
assert_eq!(r.dropped_bytes, 13); // everything from the bad record on
assert_eq!(s.get(b"a")?.as_deref(), Some(&b"1"[..])); // the good prefix survivescorrupt: boolTrue when any shard’s replay stopped at a corrupt frame.
// a record of length 4 whose checksum is wrong, then bytes behind it
let mut log = std::fs::OpenOptions::new().append(true).open(dir.path().join("aof-0.aof"))?;
std::io::Write::write_all(&mut log, &[4, 0, 0, 0, 0, 0, 0, 0, b'a', b'b', b'c', b'd', b'!'])?;
drop(log);
let s = Store::open(cfg())?;
let r = s.open_report();
assert!(r.corrupt); // stopped at a bad record, not at a torn final onequarantine_paths: Vec<PathBuf>Quarantine files written while repairing dropped tails (one per affected shard).
// a record of length 4 whose checksum is wrong, then bytes behind it
let mut log = std::fs::OpenOptions::new().append(true).open(dir.path().join("aof-0.aof"))?;
std::io::Write::write_all(&mut log, &[4, 0, 0, 0, 0, 0, 0, 0, b'a', b'b', b'c', b'd', b'!'])?;
drop(log);
let s = Store::open(cfg())?;
let r = s.open_report();
assert_eq!(r.quarantine_paths.len(), 1);
assert_eq!(std::fs::metadata(&r.quarantine_paths[0])?.len(), 13); // what was cut offresynced_bytes: u64Bytes the resync replay hopped over (corrupt regions between valid records, summed across shards). Zero under strict replay.
use kevy_embedded::{AppendFsync, Config, ReplayMode, Store};
let dir = kevy_tmpdir::TmpDir::new("open-report-resync-doc");
let aof = dir.path().join("aof-0.aof");
let cfg = || Config::default().with_persist(dir.path()).with_appendfsync(AppendFsync::Always);
let s = Store::open(cfg())?;
s.set(b"a", b"1")?;
let head = std::fs::read(&aof)?;
s.set(b"b", b"2")?;
drop(s);
let all = std::fs::read(&aof)?;
// a record whose checksum lies, between the two good ones
let bad = [4, 0, 0, 0, 0, 0, 0, 0, b'a', b'b', b'c', b'd'];
std::fs::write(&aof, [&head[..], &bad[..], &all[head.len()..]].concat())?;
let s = Store::open(cfg().with_replay_mode(ReplayMode::Resync))?;
assert_eq!(s.open_report().resynced_bytes, bad.len() as u64);
assert_eq!(s.get(b"b")?.as_deref(), Some(&b"2"[..])); // recovered behind itstage_recovered: u64Writes the staging rings held that the AOFs did not — appended before the last process was killed and not yet drained — replayed and appended to the logs at this open, summed across shards.
// stands in for a killed process: no close runs, the lock goes with it
std::mem::forget(s);
std::fs::remove_file(dir.path().join("LOCK"))?;
let s = Store::open(cfg())?;
let r = s.open_report();
assert!(r.stage_recovered > 0); // the ring held the write the log had not
assert_eq!(s.get(b"k")?.as_deref(), Some(&b"v"[..]));stage_discarded: u64Staging rings set aside because they could not show where they continue their log; only a power loss or a log changed by hand leaves one.
// stands in for a killed process: no close runs, the lock goes with it
std::mem::forget(s);
std::fs::remove_file(dir.path().join("LOCK"))?;
let s = Store::open(cfg())?;
let r = s.open_report();
// a kill alone leaves a ring that shows where it continues its log
assert_eq!((r.stage_recovered > 0, r.stage_discarded), (true, 0));