CheckpointedStageState

Struct CheckpointedStageState 

Source
pub struct CheckpointedStageState<T> { /* private fields */ }
Expand description

A stage state wrapper with durable checkpoint/restore support.

Serializes the state to a BlockLease on checkpoint and deserializes on restore, using a format compatible with the grafos-collections Durable pattern.

§Fail-closed

If a checkpoint write fails, the error is propagated immediately. Callers should halt the stage rather than continue with an uncheckpointed state.

Implementations§

Source§

impl<T: Serialize + DeserializeOwned> CheckpointedStageState<T>

Source

pub fn new(state: T, block_lease: BlockLease) -> Self

Create a new checkpointed state wrapper.

Does not write an initial checkpoint. Call checkpoint to persist.

Source

pub fn checkpoint(&mut self) -> Result<(), EdgeError>

Serialize the current state to block storage.

Uses a header block + data block layout:

  • Block 0: magic (4) + version (4) + data_len (8)
  • Blocks 1..N: postcard-serialized state bytes
§Errors

Returns EdgeError::CheckpointFailed on serialization or I/O failure.

Source

pub fn restore(block_lease: BlockLease) -> Result<Self, EdgeError>

Restore a checkpointed state from block storage.

Reads the header block to determine data length, then reads and deserializes the state from the data blocks.

§Errors

Returns EdgeError::CheckpointFailed on corrupt data, version mismatch, or deserialization failure.

Source

pub fn state(&self) -> &T

Borrow the current state.

Source

pub fn state_mut(&mut self) -> &mut T

Mutably borrow the current state.

Source

pub fn into_block_lease(self) -> BlockLease

Consume the wrapper and return the underlying block lease.

This allows transferring the lease to a subsequent restore call so that both sides access the same underlying block storage.

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

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.