IStateMachine
interface
Namespace: Orleans.Journaling
Defines the replay, snapshot, and acknowledgement protocol for a journal-backed state machine.
public interface IStateMachineRemarks
Implementations are owned by a single Orleans.Journaling.JournaledStateManager and are accessed from one logical thread at a time. They participate in the journaling lifecycle as follows:
- User code mutates in-memory state synchronously (typically by invoking codec helpers that both apply the mutation locally and emit the corresponding command to the journal).
- When the application requests a write, the journaled state manager calls
IStateMachine(and occasionallyIStateMachine) to materialize the pending changes, then flushes the journal to durable storage. IStateMachineis invoked when the durable write has been acknowledged. Implementations that need to know when state has actually been persisted (for example, to release waiters or trigger downstream notifications) should hook into this callback rather than treating in-memory mutations as durable.- A failed journal operation permanently fences the manager and requests grain deactivation. A new manager initializes new state instances by calling
IStateMachineand replaying durable entries.
Application code prepares fallible work in operation-local data and stages only mutations which are safe to commit. Staged mutations are shared by all interleaved callers using the same manager. Storage acknowledgement establishes durability; recovery takes place in a fresh manager and state instances.
Methods
OnRecoveryCompletedNotifies the state that all prior journal entries and snapshots have been applied.OnWriteCompletedNotifies the state that all prior journal entries and snapshots which it has written have been written to stable storage.ReplayEntry(JournalEntry, JournalReplayContext)Replays one entry during journal recovery.Reset(JournalStreamWriter)Resets the state.WritePendingEntries(JournalStreamWriter)Writes pending state changes to the journal.WriteSnapshot(JournalStreamWriter)Writes a snapshot of the state to the provided writer.
