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>
impl<T: Serialize + DeserializeOwned> CheckpointedStageState<T>
Sourcepub fn new(state: T, block_lease: BlockLease) -> Self
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.
Sourcepub fn checkpoint(&mut self) -> Result<(), EdgeError>
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.
Sourcepub fn restore(block_lease: BlockLease) -> Result<Self, EdgeError>
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.
Sourcepub fn into_block_lease(self) -> BlockLease
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.