pub struct SnapshotStore { /* private fields */ }Expand description
redb-backed store for sealed full-tree snapshots.
The store is policy-free: it persists and retrieves snapshots without filtering by age. Staleness enforcement is the consumer’s responsibility.
Implementations§
Source§impl SnapshotStore
impl SnapshotStore
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self, BootnodeError>
pub fn open(path: impl AsRef<Path>) -> Result<Self, BootnodeError>
Open or create the snapshot store at path.
Sourcepub fn put(
&self,
header: &SnapshotHeader,
body: &[u8],
) -> Result<(), BootnodeError>
pub fn put( &self, header: &SnapshotHeader, body: &[u8], ) -> Result<(), BootnodeError>
Persist a snapshot. Overwrites any existing snapshot at the same sequence_no.
Header and body are written in a single transaction.
Sourcepub fn get(
&self,
sequence_no: u64,
) -> Result<Option<SnapshotHeader>, BootnodeError>
pub fn get( &self, sequence_no: u64, ) -> Result<Option<SnapshotHeader>, BootnodeError>
Retrieve the header at exactly sequence_no, if any.
Sourcepub fn latest_at_most(
&self,
up_to: u64,
) -> Result<Option<SnapshotHeader>, BootnodeError>
pub fn latest_at_most( &self, up_to: u64, ) -> Result<Option<SnapshotHeader>, BootnodeError>
Return the header with the largest sequence_no <= up_to, if any.
Sourcepub fn read_body(
&self,
sequence_no: u64,
writer: &mut impl Write,
) -> Result<Option<u64>, BootnodeError>
pub fn read_body( &self, sequence_no: u64, writer: &mut impl Write, ) -> Result<Option<u64>, BootnodeError>
Stream the body of snapshot sequence_no into writer.
Both tables are opened from the same read transaction for snapshot isolation. The header is the source of truth for existence:
- Header missing: returns
Ok(None)regardless ofBODIES_TABLEstate. The canonical “not sealed” signal. An orphan body without a matching header is silently inaccessible through this method — correct, because the only insertion path (put) writes header+body atomically, so an orphan body would be evidence of either external tampering or a redb-internal bug, neither of whichread_bodyshould service. - Header present, body missing: returns
BootnodeError::SnapshotBodyLenMismatchwithactual: 0. Indicates a torn write or partial restoration. - Header present, body present, lengths differ: returns
BootnodeError::SnapshotBodyLenMismatchwith the actual length. Indicates corruption or a write-side invariant violation. - Header present, body present, lengths match: streams body to
writer, returnsOk(Some(body_len)).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SnapshotStore
impl !RefUnwindSafe for SnapshotStore
impl Send for SnapshotStore
impl Sync for SnapshotStore
impl Unpin for SnapshotStore
impl UnsafeUnpin for SnapshotStore
impl !UnwindSafe for SnapshotStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more