libraft-0.5.0.0: Raft consensus algorithm

Safe HaskellNone
LanguageHaskell2010

Raft

Contents

Synopsis

State machine type class

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

Networking type classes

class RaftSendRPC m v where Source #

Interface for nodes to send messages to one another. E.g. Control.Concurrent.Chan, Network.Socket, etc.

Methods

sendRPC :: NodeId -> RPCMessage v -> m () Source #

Instances
(Monad m, RaftSendRPC m v) => RaftSendRPC (RaftPostgresT m) v Source # 
Instance details

Defined in Raft.Log.PostgreSQL

(MonadIO m, MonadMask m, RaftSendRPC m v) => RaftSendRPC (RaftPersistFileStoreT m) v Source # 
Instance details

Defined in Examples.Raft.FileStore.Persistent

(Monad m, RaftSendRPC m v) => RaftSendRPC (RaftLogFileStoreT m) v Source # 
Instance details

Defined in Examples.Raft.FileStore.Log

(MonadCatch m, MonadMask m, MonadIO m, Serialize v, Show v) => RaftSendRPC (RaftSocketT sm v m) v Source # 
Instance details

Defined in Examples.Raft.Socket.Node

Methods

sendRPC :: NodeId -> RPCMessage v -> RaftSocketT sm v m () Source #

class Show (RaftRecvRPCError m v) => RaftRecvRPC m v where Source #

Interface for nodes to receive messages from one another

Associated Types

type RaftRecvRPCError m v Source #

class RaftStateMachinePure sm v => RaftSendClient m sm v where Source #

Interface for Raft nodes to send messages to clients

Methods

sendClient :: ClientId -> ClientResponse sm v -> m () Source #

Instances
(Monad m, RaftSendClient m sm v) => RaftSendClient (RaftPostgresT m) sm v Source # 
Instance details

Defined in Raft.Log.PostgreSQL

(MonadIO m, MonadMask m, RaftSendClient m sm v) => RaftSendClient (RaftPersistFileStoreT m) sm v Source # 
Instance details

Defined in Examples.Raft.FileStore.Persistent

(Monad m, RaftSendClient m sm v) => RaftSendClient (RaftLogFileStoreT m) sm v Source # 
Instance details

Defined in Examples.Raft.FileStore.Log

(RaftStateMachinePure sm v, MonadMask m, MonadCatch m, MonadIO m, Serialize sm, Serialize v) => RaftSendClient (RaftSocketT sm v m) sm v Source # 
Instance details

Defined in Examples.Raft.Socket.Node

Methods

sendClient :: ClientId -> ClientResponse sm v -> RaftSocketT sm v m () Source #

class Show (RaftRecvClientError m v) => RaftRecvClient m v where Source #

Interface for Raft nodes to receive messages from clients

Associated Types

type RaftRecvClientError m v Source #

class Monad m => RaftPersist m where Source #

Provides an interface to read and write the persistent state to disk.

Associated Types

type RaftPersistError m Source #

Instances
RaftPersist m => RaftPersist (RaftPostgresT m) Source # 
Instance details

Defined in Raft.Log.PostgreSQL

Associated Types

type RaftPersistError (RaftPostgresT m) :: Type Source #

MonadIO m => RaftPersist (RaftPersistFileStoreT m) Source # 
Instance details

Defined in Examples.Raft.FileStore.Persistent

Associated Types

type RaftPersistError (RaftPersistFileStoreT m) :: Type Source #

RaftPersist m => RaftPersist (RaftLogFileStoreT m) Source # 
Instance details

Defined in Examples.Raft.FileStore.Log

Associated Types

type RaftPersistError (RaftLogFileStoreT m) :: Type Source #

(MonadIO m, RaftPersist m) => RaftPersist (RaftSocketT sm v m) Source # 
Instance details

Defined in Examples.Raft.Socket.Node

Associated Types

type RaftPersistError (RaftSocketT sm v m) :: Type Source #

data RaftEnv v m Source #

The raft server environment composed of the concurrent variables used in the effectful raft layer.

Instances
Monad m => MonadReader (RaftEnv v m) (RaftT v m) Source # 
Instance details

Defined in Raft.Monad

Methods

ask :: RaftT v m (RaftEnv v m) #

local :: (RaftEnv v m -> RaftEnv v m) -> RaftT v m a -> RaftT v m a #

reader :: (RaftEnv v m -> a) -> RaftT v m a #

runRaftNode Source #

Arguments

:: (Typeable m, Show v, Show sm, Serialize v, Show (Action sm v), Show (RaftLogError m), Show (RaftStateMachinePureError sm v), MonadIO m, MonadCatch m, MonadFail m, MonadMask m, MonadRaft v m, RaftStateMachine m sm v, RaftSendRPC m v, RaftRecvRPC m v, RaftSendClient m sm v, RaftRecvClient m v, RaftLog m v, RaftLogExceptions m, RaftPersist m, Exception (RaftPersistError m)) 
=> RaftNodeConfig

Node configuration

-> OptionalRaftNodeConfig

Config values that can be provided optionally

-> LogCtx (RaftT v m)

The means with which to log messages

-> sm

Initial state machine state

-> m () 

Run timers, RPC and client request handlers and start event loop. It should run forever

runRaftT :: Monad m => RaftNodeState v -> RaftEnv v m -> RaftT v m a -> m a Source #

Client data types

data ClientRequest v Source #

Representation of a client request coupled with the client id

Constructors

ClientRequest ClientId (ClientReq v) 
Instances
Show v => Show (ClientRequest v) Source # 
Instance details

Defined in Raft.Client

Generic (ClientRequest v) Source # 
Instance details

Defined in Raft.Client

Associated Types

type Rep (ClientRequest v) :: Type -> Type #

Serialize v => Serialize (ClientRequest v) Source # 
Instance details

Defined in Raft.Client

type Rep (ClientRequest v) Source # 
Instance details

Defined in Raft.Client

type Rep (ClientRequest v) = D1 (MetaData "ClientRequest" "Raft.Client" "libraft-0.5.0.0-J9sQlo4v2xjSwCkwompQR" False) (C1 (MetaCons "ClientRequest" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 ClientId) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (ClientReq v))))

data ClientReq v Source #

Representation of a client request

Constructors

ClientReadReq ClientReadReq

Request the latest state of the state machine

ClientWriteReq (ClientWriteReq v)

Write a command

ClientMetricsReq ClientMetricsReq

Request the metrics of a raft node

Instances
Show v => Show (ClientReq v) Source # 
Instance details

Defined in Raft.Client

Generic (ClientReq v) Source # 
Instance details

Defined in Raft.Client

Associated Types

type Rep (ClientReq v) :: Type -> Type #

Methods

from :: ClientReq v -> Rep (ClientReq v) x #

to :: Rep (ClientReq v) x -> ClientReq v #

Serialize v => Serialize (ClientReq v) Source # 
Instance details

Defined in Raft.Client

Methods

put :: Putter (ClientReq v) #

get :: Get (ClientReq v) #

type Rep (ClientReq v) Source # 
Instance details

Defined in Raft.Client

data ClientResponse sm v Source #

The datatype sent back to the client as an actual response

Constructors

ClientReadResponse (ClientReadResp sm v)

Respond with the latest state of the state machine.

ClientWriteResponse (ClientWriteResp sm v)

Respond with the index of the entry appended to the log

ClientRedirectResponse ClientRedirResp

Respond with the node id of the current leader

ClientMetricsResponse ClientMetricsResp

Respond with the node's current metrics

Instances
(Show sm, Show v, Show (ClientWriteResp sm v)) => Show (ClientResponse sm v) Source # 
Instance details

Defined in Raft.Client

Generic (ClientResponse sm v) Source # 
Instance details

Defined in Raft.Client

Associated Types

type Rep (ClientResponse sm v) :: Type -> Type #

Methods

from :: ClientResponse sm v -> Rep (ClientResponse sm v) x #

to :: Rep (ClientResponse sm v) x -> ClientResponse sm v #

(Serialize sm, Serialize v, Serialize (ClientWriteResp sm v)) => Serialize (ClientResponse sm v) Source # 
Instance details

Defined in Raft.Client

Methods

put :: Putter (ClientResponse sm v) #

get :: Get (ClientResponse sm v) #

type Rep (ClientResponse sm v) Source # 
Instance details

Defined in Raft.Client

data ClientReadResp sm v Source #

Representation of a read response to a client

Instances
(Show sm, Show v) => Show (ClientReadResp sm v) Source # 
Instance details

Defined in Raft.Client

Generic (ClientReadResp sm v) Source # 
Instance details

Defined in Raft.Client

Associated Types

type Rep (ClientReadResp sm v) :: Type -> Type #

Methods

from :: ClientReadResp sm v -> Rep (ClientReadResp sm v) x #

to :: Rep (ClientReadResp sm v) x -> ClientReadResp sm v #

(Serialize sm, Serialize v) => Serialize (ClientReadResp sm v) Source # 
Instance details

Defined in Raft.Client

Methods

put :: Putter (ClientReadResp sm v) #

get :: Get (ClientReadResp sm v) #

type Rep (ClientReadResp sm v) Source # 
Instance details

Defined in Raft.Client

type Rep (ClientReadResp sm v) = D1 (MetaData "ClientReadResp" "Raft.Client" "libraft-0.5.0.0-J9sQlo4v2xjSwCkwompQR" False) (C1 (MetaCons "ClientReadRespStateMachine" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 sm)) :+: (C1 (MetaCons "ClientReadRespEntry" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Entry v))) :+: C1 (MetaCons "ClientReadRespEntries" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Entries v)))))

data ClientWriteResp sm v Source #

Representation of a write response to a client

Constructors

ClientWriteRespSuccess Index SerialNum

Index of the entry appended to the log due to the previous client request

ClientWriteRespFail SerialNum (RaftStateMachinePureError sm v) 
Instances
(Show sm, Show v, Show (RaftStateMachinePureError sm v)) => Show (ClientWriteResp sm v) Source # 
Instance details

Defined in Raft.Client

Generic (ClientWriteResp sm v) Source # 
Instance details

Defined in Raft.Client

Associated Types

type Rep (ClientWriteResp sm v) :: Type -> Type #

Methods

from :: ClientWriteResp sm v -> Rep (ClientWriteResp sm v) x #

to :: Rep (ClientWriteResp sm v) x -> ClientWriteResp sm v #

(Serialize sm, Serialize v, Serialize (RaftStateMachinePureError sm v)) => Serialize (ClientWriteResp sm v) Source # 
Instance details

Defined in Raft.Client

Methods

put :: Putter (ClientWriteResp sm v) #

get :: Get (ClientWriteResp sm v) #

type Rep (ClientWriteResp sm v) Source # 
Instance details

Defined in Raft.Client

data ClientRedirResp Source #

Representation of a redirect response to a client

Instances
Show ClientRedirResp Source # 
Instance details

Defined in Raft.Client

Generic ClientRedirResp Source # 
Instance details

Defined in Raft.Client

Associated Types

type Rep ClientRedirResp :: Type -> Type #

Serialize ClientRedirResp Source # 
Instance details

Defined in Raft.Client

type Rep ClientRedirResp Source # 
Instance details

Defined in Raft.Client

type Rep ClientRedirResp = D1 (MetaData "ClientRedirResp" "Raft.Client" "libraft-0.5.0.0-J9sQlo4v2xjSwCkwompQR" False) (C1 (MetaCons "ClientRedirResp" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 CurrentLeader)))

Configuration

data RaftNodeConfig Source #

Configuration of a node in the cluster

Constructors

RaftNodeConfig 

Fields

Instances
Show RaftNodeConfig Source # 
Instance details

Defined in Raft.Config

Events

data Event v Source #

Representation of events a raft node can send and receive

Instances
Show v => Show (Event v) Source # 
Instance details

Defined in Raft.Event

Methods

showsPrec :: Int -> Event v -> ShowS #

show :: Event v -> String #

showList :: [Event v] -> ShowS #

data Timeout Source #

Representation of timeouts

Constructors

ElectionTimeout

Timeout after which a follower will become candidate

HeartbeatTimeout

Timeout after which a leader will send AppendEntries RPC to all peers

Instances
Show Timeout Source # 
Instance details

Defined in Raft.Event

data MessageEvent v Source #

Representation of message events to a node

Constructors

RPCMessageEvent (RPCMessage v)

Incoming event from a peer

ClientRequestEvent (ClientRequest v)

Incoming event from a client

Instances
Show v => Show (MessageEvent v) Source # 
Instance details

Defined in Raft.Event

Generic (MessageEvent v) Source # 
Instance details

Defined in Raft.Event

Associated Types

type Rep (MessageEvent v) :: Type -> Type #

Methods

from :: MessageEvent v -> Rep (MessageEvent v) x #

to :: Rep (MessageEvent v) x -> MessageEvent v #

Serialize v => Serialize (MessageEvent v) Source # 
Instance details

Defined in Raft.Event

type Rep (MessageEvent v) Source # 
Instance details

Defined in Raft.Event

type Rep (MessageEvent v) = D1 (MetaData "MessageEvent" "Raft.Event" "libraft-0.5.0.0-J9sQlo4v2xjSwCkwompQR" False) (C1 (MetaCons "RPCMessageEvent" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (RPCMessage v))) :+: C1 (MetaCons "ClientRequestEvent" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (ClientRequest v))))

Log

data Entry v Source #

Representation of an entry in the replicated log

Constructors

Entry 

Fields

Instances
Eq v => Eq (Entry v) Source # 
Instance details

Defined in Raft.Log

Methods

(==) :: Entry v -> Entry v -> Bool #

(/=) :: Entry v -> Entry v -> Bool #

Show v => Show (Entry v) Source # 
Instance details

Defined in Raft.Log

Methods

showsPrec :: Int -> Entry v -> ShowS #

show :: Entry v -> String #

showList :: [Entry v] -> ShowS #

Generic (Entry v) Source # 
Instance details

Defined in Raft.Log

Associated Types

type Rep (Entry v) :: Type -> Type #

Methods

from :: Entry v -> Rep (Entry v) x #

to :: Rep (Entry v) x -> Entry v #

Serialize v => Serialize (Entry v) Source # 
Instance details

Defined in Raft.Log

Methods

put :: Putter (Entry v) #

get :: Get (Entry v) #

type Rep (Entry v) Source # 
Instance details

Defined in Raft.Log

type Entries v = Seq (Entry v) Source #

class (Show (RaftWriteLogError m), Monad m) => RaftWriteLog m v where Source #

Provides an interface for nodes to write log entries to storage.

Associated Types

type RaftWriteLogError m Source #

Methods

writeLogEntries :: Exception (RaftWriteLogError m) => Entries v -> m (Either (RaftWriteLogError m) ()) Source #

Write the given log entries to storage

data DeleteSuccess v Source #

Constructors

DeleteSuccess 

class (Show (RaftDeleteLogError m), Monad m) => RaftDeleteLog m v where Source #

Provides an interface for nodes to delete log entries from storage.

Associated Types

type RaftDeleteLogError m Source #

Methods

deleteLogEntriesFrom :: Exception (RaftDeleteLogError m) => Index -> m (Either (RaftDeleteLogError m) (DeleteSuccess v)) Source #

Delete log entries from a given index; e.g. 'deleteLogEntriesFrom 7' should delete every log entry with an index >= 7.

class (Show (RaftReadLogError m), Monad m) => RaftReadLog m v where Source #

Provides an interface for nodes to read log entries from storage.

Minimal complete definition

readLogEntry, readLastLogEntry

Associated Types

type RaftReadLogError m Source #

Methods

readLogEntry :: Exception (RaftReadLogError m) => Index -> m (Either (RaftReadLogError m) (Maybe (Entry v))) Source #

Read the log at a given index

readLogEntriesFrom :: Exception (RaftReadLogError m) => Index -> m (Either (RaftReadLogError m) (Entries v)) Source #

Read log entries from a specific index onwards, including the specific index

readLastLogEntry :: Exception (RaftReadLogError m) => m (Either (RaftReadLogError m) (Maybe (Entry v))) Source #

Read the last log entry in the log

readLogEntriesFrom :: Exception (RaftReadLogError m) => Index -> m (Either (RaftReadLogError m) (Entries v)) Source #

Read log entries from a specific index onwards, including the specific index

Instances
(Typeable v, Serialize v, MonadIO m) => RaftReadLog (RaftPostgresT m) v Source # 
Instance details

Defined in Raft.Log.PostgreSQL

Associated Types

type RaftReadLogError (RaftPostgresT m) :: Type Source #

RaftReadLog m v => RaftReadLog (RaftPersistFileStoreT m) v Source # 
Instance details

Defined in Examples.Raft.FileStore.Persistent

Associated Types

type RaftReadLogError (RaftPersistFileStoreT m) :: Type Source #

(MonadIO m, Serialize v) => RaftReadLog (RaftLogFileStoreT m) v Source # 
Instance details

Defined in Examples.Raft.FileStore.Log

Associated Types

type RaftReadLogError (RaftLogFileStoreT m) :: Type Source #

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

Defined in Examples.Raft.Socket.Node

Associated Types

type RaftReadLogError (RaftSocketT sm v m) :: Type Source #

data RaftLogError m Source #

Representation of possible errors that come from reading, writing or deleting logs from the persistent storage

Instances
Show (RaftLogError m) Source # 
Instance details

Defined in Raft.Log

Logging

data LogCtx m Source #

Representation of the logs' context

Constructors

LogCtx 
NoLogs 

data LogDest m Source #

Representation of the logs' destination

Constructors

LogWith (MonadIO m => Severity -> Text -> m ()) 
LogFile FilePath 
LogStdout 

data Severity Source #

Representation of the severity of the logs

Constructors

Debug 
Info 
Critical 
Instances
Eq Severity Source # 
Instance details

Defined in Raft.Logging

Ord Severity Source # 
Instance details

Defined in Raft.Logging

Show Severity Source # 
Instance details

Defined in Raft.Logging

Raft node states

data Mode Source #

Constructors

Follower 
Candidate 
Leader 
Instances
Read Mode Source # 
Instance details

Defined in Raft.Types

Show Mode Source # 
Instance details

Defined in Raft.Types

Methods

showsPrec :: Int -> Mode -> ShowS #

show :: Mode -> String #

showList :: [Mode] -> ShowS #

data RaftNodeState v where Source #

Existential type hiding the internal node state

Constructors

RaftNodeState 

Fields

Instances
Show v => Show (RaftNodeState v) Source # 
Instance details

Defined in Raft.NodeState

Monad m => MonadState (RaftNodeState v) (RaftT v m) Source # 
Instance details

Defined in Raft.Monad

Methods

get :: RaftT v m (RaftNodeState v) #

put :: RaftNodeState v -> RaftT v m () #

state :: (RaftNodeState v -> (a, RaftNodeState v)) -> RaftT v m a #

data NodeState (a :: Mode) v where Source #

The volatile state of a Raft Node

Instances
Show v => Show (NodeState s v) Source # 
Instance details

Defined in Raft.NodeState

Methods

showsPrec :: Int -> NodeState s v -> ShowS #

show :: NodeState s v -> String #

showList :: [NodeState s v] -> ShowS #

data CurrentLeader Source #

Representation of the current leader in the cluster. The system is considered to be unavailable if there is no leader

Instances
Eq CurrentLeader Source # 
Instance details

Defined in Raft.Types

Show CurrentLeader Source # 
Instance details

Defined in Raft.Types

Generic CurrentLeader Source # 
Instance details

Defined in Raft.Types

Associated Types

type Rep CurrentLeader :: Type -> Type #

Serialize CurrentLeader Source # 
Instance details

Defined in Raft.Types

type Rep CurrentLeader Source # 
Instance details

Defined in Raft.Types

type Rep CurrentLeader = D1 (MetaData "CurrentLeader" "Raft.Types" "libraft-0.5.0.0-J9sQlo4v2xjSwCkwompQR" False) (C1 (MetaCons "CurrentLeader" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 LeaderId)) :+: C1 (MetaCons "NoLeader" PrefixI False) (U1 :: Type -> Type))

data FollowerState v Source #

Constructors

FollowerState 

Fields

Instances
Show v => Show (FollowerState v) Source # 
Instance details

Defined in Raft.NodeState

data CandidateState v Source #

Constructors

CandidateState 

Fields

Instances
Show v => Show (CandidateState v) Source # 
Instance details

Defined in Raft.NodeState

data LeaderState v Source #

Constructors

LeaderState 

Fields

Instances
Show v => Show (LeaderState v) Source # 
Instance details

Defined in Raft.NodeState

initRaftNodeState :: RaftNodeState v Source #

A node in Raft begins as a follower

isFollower :: NodeState s v -> Bool Source #

Check if node is in a follower state

isCandidate :: NodeState s v -> Bool Source #

Check if node is in a candidate state

isLeader :: NodeState s v -> Bool Source #

Check if node is in a leader state

setLastLogEntry :: NodeState s v -> Entries v -> NodeState s v Source #

Update the last log entry in the node's log

getLastLogEntry :: NodeState ns v -> LastLogEntry v Source #

Get the last applied index and the commit index of the last log entry in the node's log

getLastAppliedAndCommitIndex :: NodeState ns v -> (Index, Index) Source #

Get the index of highest log entry applied to state machine and the index of highest log entry known to be committed

Persistent state

data PersistentState Source #

Persistent state that all Raft nodes maintain, regardless of node state.

Constructors

PersistentState 

Fields

Instances
Eq PersistentState Source # 
Instance details

Defined in Raft.Persistent

Show PersistentState Source # 
Instance details

Defined in Raft.Persistent

Generic PersistentState Source # 
Instance details

Defined in Raft.Persistent

Associated Types

type Rep PersistentState :: Type -> Type #

Serialize PersistentState Source # 
Instance details

Defined in Raft.Persistent

MonadState PersistentState (TransitionM sm v) Source # 
Instance details

Defined in Raft.Transition

RaftLogger v (RWS (TransitionEnv sm v) [Action sm v] PersistentState) Source # 
Instance details

Defined in Raft.Transition

type Rep PersistentState Source # 
Instance details

Defined in Raft.Persistent

type Rep PersistentState = D1 (MetaData "PersistentState" "Raft.Persistent" "libraft-0.5.0.0-J9sQlo4v2xjSwCkwompQR" False) (C1 (MetaCons "PersistentState" PrefixI True) (S1 (MetaSel (Just "currentTerm") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Term) :*: S1 (MetaSel (Just "votedFor") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (Maybe NodeId))))

initPersistentState :: PersistentState Source #

A node initiates its persistent state with term 0 and with its vote blank

Basic types

type NodeId = ByteString Source #

Unique identifier of a Raft node

newtype ClientId Source #

Unique identifier of a client

Constructors

ClientId NodeId 
Instances
Eq ClientId Source # 
Instance details

Defined in Raft.Types

Ord ClientId Source # 
Instance details

Defined in Raft.Types

Read ClientId Source # 
Instance details

Defined in Raft.Types

Show ClientId Source # 
Instance details

Defined in Raft.Types

Generic ClientId Source # 
Instance details

Defined in Raft.Types

Associated Types

type Rep ClientId :: Type -> Type #

Methods

from :: ClientId -> Rep ClientId x #

to :: Rep ClientId x -> ClientId #

Serialize ClientId Source # 
Instance details

Defined in Raft.Types

type Rep ClientId Source # 
Instance details

Defined in Raft.Types

type Rep ClientId = D1 (MetaData "ClientId" "Raft.Types" "libraft-0.5.0.0-J9sQlo4v2xjSwCkwompQR" True) (C1 (MetaCons "ClientId" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 NodeId)))

newtype LeaderId Source #

Unique identifier of a leader

Constructors

LeaderId 

Fields

Instances
Eq LeaderId Source # 
Instance details

Defined in Raft.Types

Read LeaderId Source # 
Instance details

Defined in Raft.Types

Show LeaderId Source # 
Instance details

Defined in Raft.Types

Generic LeaderId Source # 
Instance details

Defined in Raft.Types

Associated Types

type Rep LeaderId :: Type -> Type #

Methods

from :: LeaderId -> Rep LeaderId x #

to :: Rep LeaderId x -> LeaderId #

Serialize LeaderId Source # 
Instance details

Defined in Raft.Types

type Rep LeaderId Source # 
Instance details

Defined in Raft.Types

type Rep LeaderId = D1 (MetaData "LeaderId" "Raft.Types" "libraft-0.5.0.0-J9sQlo4v2xjSwCkwompQR" True) (C1 (MetaCons "LeaderId" PrefixI True) (S1 (MetaSel (Just "unLeaderId") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 NodeId)))

newtype Term Source #

Representation of monotonic election terms

Constructors

Term Natural 
Instances
Enum Term Source # 
Instance details

Defined in Raft.Types

Methods

succ :: Term -> Term #

pred :: Term -> Term #

toEnum :: Int -> Term #

fromEnum :: Term -> Int #

enumFrom :: Term -> [Term] #

enumFromThen :: Term -> Term -> [Term] #

enumFromTo :: Term -> Term -> [Term] #

enumFromThenTo :: Term -> Term -> Term -> [Term] #

Eq Term Source # 
Instance details

Defined in Raft.Types

Methods

(==) :: Term -> Term -> Bool #

(/=) :: Term -> Term -> Bool #

Ord Term Source # 
Instance details

Defined in Raft.Types

Methods

compare :: Term -> Term -> Ordering #

(<) :: Term -> Term -> Bool #

(<=) :: Term -> Term -> Bool #

(>) :: Term -> Term -> Bool #

(>=) :: Term -> Term -> Bool #

max :: Term -> Term -> Term #

min :: Term -> Term -> Term #

Show Term Source # 
Instance details

Defined in Raft.Types

Methods

showsPrec :: Int -> Term -> ShowS #

show :: Term -> String #

showList :: [Term] -> ShowS #

Generic Term Source # 
Instance details

Defined in Raft.Types

Associated Types

type Rep Term :: Type -> Type #

Methods

from :: Term -> Rep Term x #

to :: Rep Term x -> Term #

Serialize Term Source # 
Instance details

Defined in Raft.Types

Methods

put :: Putter Term #

get :: Get Term #

FromField Term Source # 
Instance details

Defined in Raft.Types

ToField Term Source # 
Instance details

Defined in Raft.Types

Methods

toField :: Term -> Action #

type Rep Term Source # 
Instance details

Defined in Raft.Types

type Rep Term = D1 (MetaData "Term" "Raft.Types" "libraft-0.5.0.0-J9sQlo4v2xjSwCkwompQR" True) (C1 (MetaCons "Term" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Natural)))

newtype Index Source #

Representation of monotonic indices

Constructors

Index Natural 
Instances
Enum Index Source # 
Instance details

Defined in Raft.Types

Eq Index Source # 
Instance details

Defined in Raft.Types

Methods

(==) :: Index -> Index -> Bool #

(/=) :: Index -> Index -> Bool #

Integral Index Source # 
Instance details

Defined in Raft.Types

Num Index Source # 
Instance details

Defined in Raft.Types

Ord Index Source # 
Instance details

Defined in Raft.Types

Methods

compare :: Index -> Index -> Ordering #

(<) :: Index -> Index -> Bool #

(<=) :: Index -> Index -> Bool #

(>) :: Index -> Index -> Bool #

(>=) :: Index -> Index -> Bool #

max :: Index -> Index -> Index #

min :: Index -> Index -> Index #

Read Index Source # 
Instance details

Defined in Raft.Types

Real Index Source # 
Instance details

Defined in Raft.Types

Methods

toRational :: Index -> Rational #

Show Index Source # 
Instance details

Defined in Raft.Types

Methods

showsPrec :: Int -> Index -> ShowS #

show :: Index -> String #

showList :: [Index] -> ShowS #

Generic Index Source # 
Instance details

Defined in Raft.Types

Associated Types

type Rep Index :: Type -> Type #

Methods

from :: Index -> Rep Index x #

to :: Rep Index x -> Index #

Serialize Index Source # 
Instance details

Defined in Raft.Types

Methods

put :: Putter Index #

get :: Get Index #

FromField Index Source # 
Instance details

Defined in Raft.Types

ToField Index Source # 
Instance details

Defined in Raft.Types

Methods

toField :: Index -> Action #

type Rep Index Source # 
Instance details

Defined in Raft.Types

type Rep Index = D1 (MetaData "Index" "Raft.Types" "libraft-0.5.0.0-J9sQlo4v2xjSwCkwompQR" True) (C1 (MetaCons "Index" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Natural)))

term0 :: Term Source #

Initial term. Terms start at 0

index0 :: Index Source #

Initial index. Indeces start at 0

RPC

data RPC v Source #

Instances
Show v => Show (RPC v) Source # 
Instance details

Defined in Raft.RPC

Methods

showsPrec :: Int -> RPC v -> ShowS #

show :: RPC v -> String #

showList :: [RPC v] -> ShowS #

Generic (RPC v) Source # 
Instance details

Defined in Raft.RPC

Associated Types

type Rep (RPC v) :: Type -> Type #

Methods

from :: RPC v -> Rep (RPC v) x #

to :: Rep (RPC v) x -> RPC v #

Serialize v => Serialize (RPC v) Source # 
Instance details

Defined in Raft.RPC

Methods

put :: Putter (RPC v) #

get :: Get (RPC v) #

type Rep (RPC v) Source # 
Instance details

Defined in Raft.RPC

class RPCType a v where Source #

Methods

toRPC :: a -> RPC v Source #

Instances
RPCType RequestVoteResponse v Source # 
Instance details

Defined in Raft.RPC

RPCType RequestVote v Source # 
Instance details

Defined in Raft.RPC

Methods

toRPC :: RequestVote -> RPC v Source #

RPCType AppendEntriesResponse v Source # 
Instance details

Defined in Raft.RPC

RPCType (AppendEntries v) v Source # 
Instance details

Defined in Raft.RPC

Methods

toRPC :: AppendEntries v -> RPC v Source #

data RPCMessage v Source #

Representation of a message sent between nodes

Constructors

RPCMessage 

Fields

Instances
Show v => Show (RPCMessage v) Source # 
Instance details

Defined in Raft.RPC

Generic (RPCMessage v) Source # 
Instance details

Defined in Raft.RPC

Associated Types

type Rep (RPCMessage v) :: Type -> Type #

Methods

from :: RPCMessage v -> Rep (RPCMessage v) x #

to :: Rep (RPCMessage v) x -> RPCMessage v #

Serialize v => Serialize (RPCMessage v) Source # 
Instance details

Defined in Raft.RPC

Methods

put :: Putter (RPCMessage v) #

get :: Get (RPCMessage v) #

type Rep (RPCMessage v) Source # 
Instance details

Defined in Raft.RPC

type Rep (RPCMessage v) = D1 (MetaData "RPCMessage" "Raft.RPC" "libraft-0.5.0.0-J9sQlo4v2xjSwCkwompQR" False) (C1 (MetaCons "RPCMessage" PrefixI True) (S1 (MetaSel (Just "sender") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 NodeId) :*: S1 (MetaSel (Just "rpc") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (RPC v))))

data AppendEntries v Source #

Representation of a message sent from a leader to its peers

Constructors

AppendEntries 

Fields

Instances
Show v => Show (AppendEntries v) Source # 
Instance details

Defined in Raft.RPC

Generic (AppendEntries v) Source # 
Instance details

Defined in Raft.RPC

Associated Types

type Rep (AppendEntries v) :: Type -> Type #

Serialize v => Serialize (AppendEntries v) Source # 
Instance details

Defined in Raft.RPC

RPCType (AppendEntries v) v Source # 
Instance details

Defined in Raft.RPC

Methods

toRPC :: AppendEntries v -> RPC v Source #

type Rep (AppendEntries v) Source # 
Instance details

Defined in Raft.RPC

data AppendEntriesResponse Source #

Representation of the response from a follower to an AppendEntries message

Constructors

AppendEntriesResponse 

Fields

data RequestVote Source #

Representation of the message sent by candidates to their peers to request their vote

Constructors

RequestVote 

Fields

Instances
Show RequestVote Source # 
Instance details

Defined in Raft.RPC

Generic RequestVote Source # 
Instance details

Defined in Raft.RPC

Associated Types

type Rep RequestVote :: Type -> Type #

Serialize RequestVote Source # 
Instance details

Defined in Raft.RPC

RPCType RequestVote v Source # 
Instance details

Defined in Raft.RPC

Methods

toRPC :: RequestVote -> RPC v Source #

type Rep RequestVote Source # 
Instance details

Defined in Raft.RPC

data RequestVoteResponse Source #

Representation of a response to a RequestVote message

Constructors

RequestVoteResponse 

Fields

Instances
Show RequestVoteResponse Source # 
Instance details

Defined in Raft.RPC

Generic RequestVoteResponse Source # 
Instance details

Defined in Raft.RPC

Associated Types

type Rep RequestVoteResponse :: Type -> Type #

Serialize RequestVoteResponse Source # 
Instance details

Defined in Raft.RPC

RPCType RequestVoteResponse v Source # 
Instance details

Defined in Raft.RPC

type Rep RequestVoteResponse Source # 
Instance details

Defined in Raft.RPC

type Rep RequestVoteResponse = D1 (MetaData "RequestVoteResponse" "Raft.RPC" "libraft-0.5.0.0-J9sQlo4v2xjSwCkwompQR" False) (C1 (MetaCons "RequestVoteResponse" PrefixI True) (S1 (MetaSel (Just "rvrTerm") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Term) :*: S1 (MetaSel (Just "rvrVoteGranted") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Bool)))

data AppendEntriesData v Source #

The data used to construct an AppendEntries value, snapshotted from the node state at the time the AppendEntries val should be created.

Instances
Show v => Show (AppendEntriesData v) Source # 
Instance details

Defined in Raft.RPC