Skip to main content

OpenReport

Struct OpenReport 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§replayed_commands: u64

Commands replayed from the AOF(s), summed across shards.

assert_eq!(r.replayed_commands, 2); // the two SETs came back from the log
§replayed_bytes: u64

Bytes 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: u64

Wall-clock time of the whole startup replay, in milliseconds.

assert!(r.elapsed_ms < 60_000); // a two-record log replays at once
§dropped_bytes: u64

Bytes 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 survives
§corrupt: bool

True 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 one
§quarantine_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 off
§resynced_bytes: u64

Bytes 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 it
§stage_recovered: u64

Writes 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: u64

Staging 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));

Trait Implementations§

Source§

impl Clone for OpenReport

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OpenReport

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for OpenReport

Source§

fn default() -> Self

Returns the “default value” for a type. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.