libraft-0.5.0.0: Raft consensus algorithm

Safe HaskellNone
LanguageHaskell2010

Raft.StateMachine

Synopsis

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 #

class (Monad m, RaftStateMachinePure sm v) => RaftStateMachine m sm v where Source #

Minimal complete definition

validateCmd, askRaftStateMachinePureCtx

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
RaftStateMachine m sm v => RaftStateMachine (RaftPostgresT m) sm v Source # 
Instance details

Defined in Raft.Log.PostgreSQL

RaftStateMachine m sm v => RaftStateMachine (RaftPersistFileStoreT m) sm v Source # 
Instance details

Defined in Examples.Raft.FileStore.Persistent

RaftStateMachine m sm v => RaftStateMachine (RaftLogFileStoreT m) sm v Source # 
Instance details

Defined in Examples.Raft.FileStore.Log

RaftStateMachine m sm v => RaftStateMachine (RaftSocketT sm v m) sm v Source # 
Instance details

Defined in Examples.Raft.Socket.Node

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.