Safe Haskell | None |
---|---|
Language | Haskell2010 |
Raft.StateMachine
Synopsis
- class RaftStateMachinePure sm v | sm -> v where
- data RaftStateMachinePureError sm v
- type RaftStateMachinePureCtx sm v = ctx | ctx -> sm v
- rsmTransition :: RaftStateMachinePureCtx sm v -> sm -> v -> Either (RaftStateMachinePureError sm v) sm
- class (Monad m, RaftStateMachinePure sm v) => RaftStateMachine m sm v where
- validateCmd :: v -> m (Either (RaftStateMachinePureError sm v) ())
- preprocessCmd :: v -> m v
- askRaftStateMachinePureCtx :: m (RaftStateMachinePureCtx sm v)
- data EntryValidation
- applyLogEntry :: RaftStateMachine m sm v => EntryValidation -> sm -> Entry v -> m (Either (RaftStateMachinePureError sm v) sm)
- applyLogCmd :: forall sm cmd m. RaftStateMachine m sm cmd => EntryValidation -> sm -> cmd -> m (Either (RaftStateMachinePureError sm cmd) sm)
Documentation
class RaftStateMachinePure sm v | sm -> v where Source #
Interface to handle commands in the underlying state machine. Functional dependency permitting only a single state machine command to be defined to update the state machine.
Associated Types
data RaftStateMachinePureError sm v Source #
type RaftStateMachinePureCtx sm v = ctx | ctx -> sm v Source #
Methods
rsmTransition :: RaftStateMachinePureCtx sm v -> sm -> v -> Either (RaftStateMachinePureError sm v) sm Source #
class (Monad m, RaftStateMachinePure sm v) => RaftStateMachine m sm v where Source #
Minimal complete definition
Methods
validateCmd :: v -> m (Either (RaftStateMachinePureError sm v) ()) Source #
Expensive validation using global state not cacheable in
RaftStateMachinePureCtx
preprocessCmd :: v -> m v Source #
Some state machines need the leader to preprocess commands issued by client; e.g. attaching a timestamp before creating the log entry
askRaftStateMachinePureCtx :: m (RaftStateMachinePureCtx sm v) Source #
Query the RaftStateMachinePureCtx
value from the monadic context
preprocessCmd :: v -> m v Source #
Some state machines need the leader to preprocess commands issued by client; e.g. attaching a timestamp before creating the log entry
Instances
data EntryValidation Source #
Constructors
NoMonadicValidation | |
MonadicValidation |
applyLogEntry :: RaftStateMachine m sm v => EntryValidation -> sm -> Entry v -> m (Either (RaftStateMachinePureError sm v) sm) Source #
Apply a log entry to the supplied state machine, allowing the user to specify whether or not to monadically validate the command in addition to the pure validation logic.
This function first unwraps the log entry to see if it is a no-op or contains an actual state machine command to apply.
applyLogCmd :: forall sm cmd m. RaftStateMachine m sm cmd => EntryValidation -> sm -> cmd -> m (Either (RaftStateMachinePureError sm cmd) sm) Source #
Apply a state machine command to the supplied state machine, allowing the user to specify whether or not to monadically validate the command in addition to the pure validation logic.