| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Raft
Contents
Synopsis
- class RSMP sm v | sm -> v where
- class (Monad m, RSMP sm v) => RSM sm v m | m sm -> v where
- validateCmd :: v -> m (Either (RSMPError sm v) ())
- askRSMPCtx :: m (RSMPCtx sm v)
- class RaftSendRPC m v where
- sendRPC :: NodeId -> RPCMessage v -> m ()
- class Show (RaftRecvRPCError m v) => RaftRecvRPC m v where
- type RaftRecvRPCError m v
- receiveRPC :: m (Either (RaftRecvRPCError m v) (RPCMessage v))
- class RaftSendClient m sm where
- sendClient :: ClientId -> ClientResponse sm -> m ()
- class Show (RaftRecvClientError m v) => RaftRecvClient m v where
- type RaftRecvClientError m v
- receiveClient :: m (Either (RaftRecvClientError m v) (ClientRequest v))
- class Monad m => RaftPersist m where
- type RaftPersistError m
- readPersistentState :: Exception (RaftPersistError m) => m (Either (RaftPersistError m) PersistentState)
- writePersistentState :: Exception (RaftPersistError m) => PersistentState -> m (Either (RaftPersistError m) ())
- type EventChan m v = TChan (STM m) (Event v)
- data RaftEnv v m = RaftEnv {
- eventChan :: EventChan m v
- resetElectionTimer :: m ()
- resetHeartbeatTimer :: m ()
- raftNodeConfig :: NodeConfig
- raftNodeLogDest :: LogDest
- runRaftNode :: (Show v, Show sm, Show (Action sm v), MonadIO m, MonadConc m, MonadFail m, RSM sm v m, Show (RSMPError sm v), RaftSendRPC m v, RaftRecvRPC m v, RaftSendClient m sm, RaftRecvClient m v, RaftLog m v, RaftLogExceptions m, RaftPersist m, Exception (RaftPersistError m)) => NodeConfig -> LogDest -> Int -> sm -> m ()
- runRaftT :: MonadConc m => RaftNodeState -> RaftEnv v m -> RaftT v m () -> m ()
- handleEventLoop :: forall sm v m. (Show v, Show sm, Show (Action sm v), MonadIO m, MonadConc m, MonadFail m, RSM sm v m, Show (RSMPError sm v), RaftPersist m, RaftSendRPC m v, RaftSendClient m sm, RaftLog m v, RaftLogExceptions m, RaftPersist m, Exception (RaftPersistError m)) => sm -> RaftT v m ()
- data ClientRequest v = ClientRequest ClientId (ClientReq v)
- data ClientReq v
- data ClientResponse s
- newtype ClientReadResp s = ClientReadResp s
- data ClientWriteResp = ClientWriteResp Index
- data ClientRedirResp = ClientRedirResp CurrentLeader
- data NodeConfig = NodeConfig {}
- data Event v
- data Timeout
- data MessageEvent v
- = RPCMessageEvent (RPCMessage v)
- | ClientRequestEvent (ClientRequest v)
- data Entry v = Entry {
- entryIndex :: Index
- entryTerm :: Term
- entryValue :: EntryValue v
- entryIssuer :: EntryIssuer
- type Entries v = Seq (Entry v)
- class Monad m => RaftWriteLog m v where
- type RaftWriteLogError m
- writeLogEntries :: Exception (RaftWriteLogError m) => Entries v -> m (Either (RaftWriteLogError m) ())
- data DeleteSuccess v = DeleteSuccess
- class Monad m => RaftDeleteLog m v where
- type RaftDeleteLogError m
- deleteLogEntriesFrom :: Exception (RaftDeleteLogError m) => Index -> m (Either (RaftDeleteLogError m) (DeleteSuccess v))
- class Monad m => RaftReadLog m v where
- type RaftReadLogError m
- readLogEntry :: Exception (RaftReadLogError m) => Index -> m (Either (RaftReadLogError m) (Maybe (Entry v)))
- readLogEntriesFrom :: Exception (RaftReadLogError m) => Index -> m (Either (RaftReadLogError m) (Entries v))
- readLastLogEntry :: Exception (RaftReadLogError m) => m (Either (RaftReadLogError m) (Maybe (Entry v)))
- type RaftLog m v = (RaftReadLog m v, RaftWriteLog m v, RaftDeleteLog m v)
- data RaftLogError m
- type RaftLogExceptions m = (Exception (RaftReadLogError m), Exception (RaftWriteLogError m), Exception (RaftDeleteLogError m))
- data LogDest
- data Severity
- data Mode
- data RaftNodeState where
- RaftNodeState :: {..} -> RaftNodeState
- data NodeState (a :: Mode) where
- data CurrentLeader
- data FollowerState = FollowerState {}
- data CandidateState = CandidateState {
- csCommitIndex :: Index
- csLastApplied :: Index
- csVotes :: NodeIds
- csLastLogEntryData :: (Index, Term)
- data LeaderState = LeaderState {}
- initRaftNodeState :: RaftNodeState
- isFollower :: NodeState s -> Bool
- isCandidate :: NodeState s -> Bool
- isLeader :: NodeState s -> Bool
- setLastLogEntryData :: NodeState ns -> Entries v -> NodeState ns
- getLastLogEntryData :: NodeState ns -> (Index, Term)
- getLastAppliedAndCommitIndex :: NodeState ns -> (Index, Index)
- data PersistentState = PersistentState {
- currentTerm :: Term
- votedFor :: Maybe NodeId
- initPersistentState :: PersistentState
- type NodeId = ByteString
- type NodeIds = Set NodeId
- newtype ClientId = ClientId NodeId
- newtype LeaderId = LeaderId {
- unLeaderId :: NodeId
- newtype Term = Term Natural
- newtype Index = Index Natural
- term0 :: Term
- index0 :: Index
- data RPC v
- class RPCType a v where
- data RPCMessage v = RPCMessage {}
- data AppendEntries v = AppendEntries {
- aeTerm :: Term
- aeLeaderId :: LeaderId
- aePrevLogIndex :: Index
- aePrevLogTerm :: Term
- aeEntries :: Entries v
- aeLeaderCommit :: Index
- aeReadRequest :: Maybe Int
- data AppendEntriesResponse = AppendEntriesResponse {
- aerTerm :: Term
- aerSuccess :: Bool
- aerReadRequest :: Maybe Int
- data RequestVote = RequestVote {}
- data RequestVoteResponse = RequestVoteResponse {
- rvrTerm :: Term
- rvrVoteGranted :: Bool
- data AppendEntriesData v = AppendEntriesData {
- aedTerm :: Term
- aedLeaderCommit :: Index
- aedEntriesSpec :: EntriesSpec v
State machine type class
class RSMP sm v | sm -> v where #
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.
Methods
applyCmdRSMP :: RSMPCtx sm v -> sm -> v -> Either (RSMPError sm v) sm #
Networking type classes
class RaftSendRPC m v where #
Interface for nodes to send messages to one another. E.g. Control.Concurrent.Chan, Network.Socket, etc.
Methods
sendRPC :: NodeId -> RPCMessage v -> m () #
Instances
| (MonadIO m, MonadConc m, Serialize v, Show v) => RaftSendRPC (RaftSocketT v m) v # | |
Defined in Examples.Raft.Socket.Node Methods sendRPC :: NodeId -> RPCMessage v -> RaftSocketT v m () # | |
class Show (RaftRecvRPCError m v) => RaftRecvRPC m v where #
Interface for nodes to receive messages from one another
Associated Types
type RaftRecvRPCError m v #
Methods
receiveRPC :: m (Either (RaftRecvRPCError m v) (RPCMessage v)) #
Instances
| (MonadIO m, MonadConc m, Show v) => RaftRecvRPC (RaftSocketT v m) v # | |
Defined in Examples.Raft.Socket.Node Associated Types type RaftRecvRPCError (RaftSocketT v m) v :: Type # Methods receiveRPC :: RaftSocketT v m (Either (RaftRecvRPCError (RaftSocketT v m) v) (RPCMessage v)) # | |
class RaftSendClient m sm where #
Interface for Raft nodes to send messages to clients
Methods
sendClient :: ClientId -> ClientResponse sm -> m () #
Instances
| (MonadIO m, MonadConc m, Serialize sm) => RaftSendClient (RaftSocketT v m) sm # | |
Defined in Examples.Raft.Socket.Node Methods sendClient :: ClientId -> ClientResponse sm -> RaftSocketT v m () # | |
class Show (RaftRecvClientError m v) => RaftRecvClient m v where #
Interface for Raft nodes to receive messages from clients
Associated Types
type RaftRecvClientError m v #
Methods
receiveClient :: m (Either (RaftRecvClientError m v) (ClientRequest v)) #
Instances
| (MonadIO m, MonadConc m, Serialize v) => RaftRecvClient (RaftSocketT v m) v # | |
Defined in Examples.Raft.Socket.Node Associated Types type RaftRecvClientError (RaftSocketT v m) v :: Type # Methods receiveClient :: RaftSocketT v m (Either (RaftRecvClientError (RaftSocketT v m) v) (ClientRequest v)) # | |
class Monad m => RaftPersist m where #
Provides an interface to read and write the persistent state to disk.
Associated Types
type RaftPersistError m #
Methods
readPersistentState :: Exception (RaftPersistError m) => m (Either (RaftPersistError m) PersistentState) #
writePersistentState :: Exception (RaftPersistError m) => PersistentState -> m (Either (RaftPersistError m) ()) #
Instances
| (MonadIO m, MonadConc m) => RaftPersist (RaftFileStoreT m) # | |
Defined in Examples.Raft.FileStore Associated Types type RaftPersistError (RaftFileStoreT m) :: Type # Methods readPersistentState :: RaftFileStoreT m (Either (RaftPersistError (RaftFileStoreT m)) PersistentState) # writePersistentState :: PersistentState -> RaftFileStoreT m (Either (RaftPersistError (RaftFileStoreT m)) ()) # | |
The raft server environment composed of the concurrent variables used in the effectful raft layer.
Constructors
| RaftEnv | |
Fields
| |
Arguments
| :: (Show v, Show sm, Show (Action sm v), MonadIO m, MonadConc m, MonadFail m, RSM sm v m, Show (RSMPError sm v), RaftSendRPC m v, RaftRecvRPC m v, RaftSendClient m sm, RaftRecvClient m v, RaftLog m v, RaftLogExceptions m, RaftPersist m, Exception (RaftPersistError m)) | |
| => NodeConfig | Node configuration |
| -> LogDest | Logs destination |
| -> Int | Timer seed |
| -> sm | Initial state machine state |
| -> m () |
Run timers, RPC and client request handlers and start event loop. It should run forever
runRaftT :: MonadConc m => RaftNodeState -> RaftEnv v m -> RaftT v m () -> m () #
handleEventLoop :: forall sm v m. (Show v, Show sm, Show (Action sm v), MonadIO m, MonadConc m, MonadFail m, RSM sm v m, Show (RSMPError sm v), RaftPersist m, RaftSendRPC m v, RaftSendClient m sm, RaftLog m v, RaftLogExceptions m, RaftPersist m, Exception (RaftPersistError m)) => sm -> RaftT v m () #
Client data types
data ClientRequest v #
Representation of a client request coupled with the client id
Constructors
| ClientRequest ClientId (ClientReq v) |
Instances
| Show v => Show (ClientRequest v) # | |
Defined in Raft.Client Methods showsPrec :: Int -> ClientRequest v -> ShowS # show :: ClientRequest v -> String # showList :: [ClientRequest v] -> ShowS # | |
| Generic (ClientRequest v) # | |
Defined in Raft.Client Associated Types type Rep (ClientRequest v) :: Type -> Type # Methods from :: ClientRequest v -> Rep (ClientRequest v) x # to :: Rep (ClientRequest v) x -> ClientRequest v # | |
| Serialize v => Serialize (ClientRequest v) # | |
Defined in Raft.Client | |
| type Rep (ClientRequest v) # | |
Defined in Raft.Client type Rep (ClientRequest v) = D1 (MetaData "ClientRequest" "Raft.Client" "libraft-0.1.1.0-K88ErXXABXGJHe9OF75EJD" 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)))) | |
Representation of a client request
Constructors
| ClientReadReq | Request the latest state of the state machine |
| ClientWriteReq v | Write a command |
Instances
| Show v => Show (ClientReq v) # | |
| Generic (ClientReq v) # | |
| Serialize v => Serialize (ClientReq v) # | |
| type Rep (ClientReq v) # | |
Defined in Raft.Client type Rep (ClientReq v) = D1 (MetaData "ClientReq" "Raft.Client" "libraft-0.1.1.0-K88ErXXABXGJHe9OF75EJD" False) (C1 (MetaCons "ClientReadReq" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "ClientWriteReq" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 v))) | |
data ClientResponse s #
Representation of a client response
Constructors
| ClientReadResponse (ClientReadResp s) | Respond with the latest state of the state machine. |
| ClientWriteResponse ClientWriteResp | Respond with the index of the entry appended to the log |
| ClientRedirectResponse ClientRedirResp | Respond with the node id of the current leader |
Instances
newtype ClientReadResp s #
Representation of a read response to a client
The s stands for the "current" state of the state machine
Constructors
| ClientReadResp s |
Instances
| Show s => Show (ClientReadResp s) # | |
Defined in Raft.Client Methods showsPrec :: Int -> ClientReadResp s -> ShowS # show :: ClientReadResp s -> String # showList :: [ClientReadResp s] -> ShowS # | |
| Generic (ClientReadResp s) # | |
Defined in Raft.Client Associated Types type Rep (ClientReadResp s) :: Type -> Type # Methods from :: ClientReadResp s -> Rep (ClientReadResp s) x # to :: Rep (ClientReadResp s) x -> ClientReadResp s # | |
| Serialize s => Serialize (ClientReadResp s) # | |
Defined in Raft.Client | |
| type Rep (ClientReadResp s) # | |
Defined in Raft.Client type Rep (ClientReadResp s) = D1 (MetaData "ClientReadResp" "Raft.Client" "libraft-0.1.1.0-K88ErXXABXGJHe9OF75EJD" True) (C1 (MetaCons "ClientReadResp" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 s))) | |
data ClientWriteResp #
Representation of a write response to a client
Constructors
| ClientWriteResp Index | Index of the entry appended to the log due to the previous client request |
Instances
| Show ClientWriteResp # | |
Defined in Raft.Client Methods showsPrec :: Int -> ClientWriteResp -> ShowS # show :: ClientWriteResp -> String # showList :: [ClientWriteResp] -> ShowS # | |
| Generic ClientWriteResp # | |
Defined in Raft.Client Associated Types type Rep ClientWriteResp :: Type -> Type # Methods from :: ClientWriteResp -> Rep ClientWriteResp x # to :: Rep ClientWriteResp x -> ClientWriteResp # | |
| Serialize ClientWriteResp # | |
Defined in Raft.Client | |
| type Rep ClientWriteResp # | |
Defined in Raft.Client type Rep ClientWriteResp = D1 (MetaData "ClientWriteResp" "Raft.Client" "libraft-0.1.1.0-K88ErXXABXGJHe9OF75EJD" False) (C1 (MetaCons "ClientWriteResp" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Index))) | |
data ClientRedirResp #
Representation of a redirect response to a client
Constructors
| ClientRedirResp CurrentLeader |
Instances
| Show ClientRedirResp # | |
Defined in Raft.Client Methods showsPrec :: Int -> ClientRedirResp -> ShowS # show :: ClientRedirResp -> String # showList :: [ClientRedirResp] -> ShowS # | |
| Generic ClientRedirResp # | |
Defined in Raft.Client Associated Types type Rep ClientRedirResp :: Type -> Type # Methods from :: ClientRedirResp -> Rep ClientRedirResp x # to :: Rep ClientRedirResp x -> ClientRedirResp # | |
| Serialize ClientRedirResp # | |
Defined in Raft.Client | |
| type Rep ClientRedirResp # | |
Defined in Raft.Client type Rep ClientRedirResp = D1 (MetaData "ClientRedirResp" "Raft.Client" "libraft-0.1.1.0-K88ErXXABXGJHe9OF75EJD" False) (C1 (MetaCons "ClientRedirResp" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 CurrentLeader))) | |
Configuration
data NodeConfig #
Configuration of a node in the cluster
Constructors
| NodeConfig | |
Fields
| |
Instances
| Show NodeConfig # | |
Defined in Raft.Config Methods showsPrec :: Int -> NodeConfig -> ShowS # show :: NodeConfig -> String # showList :: [NodeConfig] -> ShowS # | |
Events
Representation of events a raft node can send and receive
Constructors
| MessageEvent (MessageEvent v) | |
| TimeoutEvent Timeout |
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 |
data MessageEvent v #
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) # | |
Defined in Raft.Event Methods showsPrec :: Int -> MessageEvent v -> ShowS # show :: MessageEvent v -> String # showList :: [MessageEvent v] -> ShowS # | |
| Generic (MessageEvent v) # | |
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) # | |
Defined in Raft.Event | |
| type Rep (MessageEvent v) # | |
Defined in Raft.Event type Rep (MessageEvent v) = D1 (MetaData "MessageEvent" "Raft.Event" "libraft-0.1.1.0-K88ErXXABXGJHe9OF75EJD" 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
Representation of an entry in the replicated log
Constructors
| Entry | |
Fields
| |
Instances
| Show v => Show (Entry v) # | |
| Generic (Entry v) # | |
| Serialize v => Serialize (Entry v) # | |
| type Rep (Entry v) # | |
Defined in Raft.Log type Rep (Entry v) = D1 (MetaData "Entry" "Raft.Log" "libraft-0.1.1.0-K88ErXXABXGJHe9OF75EJD" False) (C1 (MetaCons "Entry" PrefixI True) ((S1 (MetaSel (Just "entryIndex") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Index) :*: S1 (MetaSel (Just "entryTerm") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Term)) :*: (S1 (MetaSel (Just "entryValue") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (EntryValue v)) :*: S1 (MetaSel (Just "entryIssuer") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 EntryIssuer)))) | |
class Monad m => RaftWriteLog m v where #
Provides an interface for nodes to write log entries to storage.
Associated Types
type RaftWriteLogError m #
Methods
writeLogEntries :: Exception (RaftWriteLogError m) => Entries v -> m (Either (RaftWriteLogError m) ()) #
Write the given log entries to storage
Instances
| (MonadIO m, MonadConc m, Serialize v) => RaftWriteLog (RaftFileStoreT m) v # | |
Defined in Examples.Raft.FileStore Associated Types type RaftWriteLogError (RaftFileStoreT m) :: Type # Methods writeLogEntries :: Entries v -> RaftFileStoreT m (Either (RaftWriteLogError (RaftFileStoreT m)) ()) # | |
data DeleteSuccess v #
Constructors
| DeleteSuccess |
class Monad m => RaftDeleteLog m v where #
Provides an interface for nodes to delete log entries from storage.
Associated Types
type RaftDeleteLogError m #
Methods
deleteLogEntriesFrom :: Exception (RaftDeleteLogError m) => Index -> m (Either (RaftDeleteLogError m) (DeleteSuccess v)) #
Delete log entries from a given index; e.g. 'deleteLogEntriesFrom 7' should delete every log entry with an index >= 7.
Instances
| (MonadIO m, MonadConc m, Serialize v) => RaftDeleteLog (RaftFileStoreT m) v # | |
Defined in Examples.Raft.FileStore Associated Types type RaftDeleteLogError (RaftFileStoreT m) :: Type # Methods deleteLogEntriesFrom :: Index -> RaftFileStoreT m (Either (RaftDeleteLogError (RaftFileStoreT m)) (DeleteSuccess v)) # | |
class Monad m => RaftReadLog m v where #
Provides an interface for nodes to read log entries from storage.
Minimal complete definition
Associated Types
type RaftReadLogError m #
Methods
readLogEntry :: Exception (RaftReadLogError m) => Index -> m (Either (RaftReadLogError m) (Maybe (Entry v))) #
Read the log at a given index
readLogEntriesFrom :: Exception (RaftReadLogError m) => Index -> m (Either (RaftReadLogError m) (Entries v)) #
Read log entries from a specific index onwards, including the specific index
readLastLogEntry :: Exception (RaftReadLogError m) => m (Either (RaftReadLogError m) (Maybe (Entry v))) #
Read the last log entry in the log
readLogEntriesFrom :: Exception (RaftReadLogError m) => Index -> m (Either (RaftReadLogError m) (Entries v)) #
Read log entries from a specific index onwards, including the specific index
Instances
| (MonadIO m, MonadConc m, Serialize v) => RaftReadLog (RaftFileStoreT m) v # | |
Defined in Examples.Raft.FileStore Associated Types type RaftReadLogError (RaftFileStoreT m) :: Type # Methods readLogEntry :: Index -> RaftFileStoreT m (Either (RaftReadLogError (RaftFileStoreT m)) (Maybe (Entry v))) # readLogEntriesFrom :: Index -> RaftFileStoreT m (Either (RaftReadLogError (RaftFileStoreT m)) (Entries v)) # readLastLogEntry :: RaftFileStoreT m (Either (RaftReadLogError (RaftFileStoreT m)) (Maybe (Entry v))) # | |
type RaftLog m v = (RaftReadLog m v, RaftWriteLog m v, RaftDeleteLog m v) #
data RaftLogError m #
Representation of possible errors that come from reading, writing or deleting logs from the persistent storage
Constructors
| RaftLogReadError (RaftReadLogError m) | |
| RaftLogWriteError (RaftWriteLogError m) | |
| RaftLogDeleteError (RaftDeleteLogError m) |
type RaftLogExceptions m = (Exception (RaftReadLogError m), Exception (RaftWriteLogError m), Exception (RaftDeleteLogError m)) #
Logging
Representation of the severity of the logs
Raft node states
data RaftNodeState where #
Existential type hiding the internal node state
Constructors
| RaftNodeState | |
Fields
| |
Instances
| Show RaftNodeState # | |
Defined in Raft.NodeState Methods showsPrec :: Int -> RaftNodeState -> ShowS # show :: RaftNodeState -> String # showList :: [RaftNodeState] -> ShowS # | |
data NodeState (a :: Mode) where #
The volatile state of a Raft Node
Constructors
| NodeFollowerState :: FollowerState -> NodeState Follower | |
| NodeCandidateState :: CandidateState -> NodeState Candidate | |
| NodeLeaderState :: LeaderState -> NodeState Leader |
data CurrentLeader #
Representation of the current leader in the cluster. The system is considered to be unavailable if there is no leader
Constructors
| CurrentLeader LeaderId | |
| NoLeader |
Instances
| Eq CurrentLeader # | |
Defined in Raft.NodeState Methods (==) :: CurrentLeader -> CurrentLeader -> Bool # (/=) :: CurrentLeader -> CurrentLeader -> Bool # | |
| Show CurrentLeader # | |
Defined in Raft.NodeState Methods showsPrec :: Int -> CurrentLeader -> ShowS # show :: CurrentLeader -> String # showList :: [CurrentLeader] -> ShowS # | |
| Generic CurrentLeader # | |
Defined in Raft.NodeState Associated Types type Rep CurrentLeader :: Type -> Type # | |
| Serialize CurrentLeader # | |
Defined in Raft.NodeState | |
| type Rep CurrentLeader # | |
Defined in Raft.NodeState type Rep CurrentLeader = D1 (MetaData "CurrentLeader" "Raft.NodeState" "libraft-0.1.1.0-K88ErXXABXGJHe9OF75EJD" False) (C1 (MetaCons "CurrentLeader" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 LeaderId)) :+: C1 (MetaCons "NoLeader" PrefixI False) (U1 :: Type -> Type)) | |
data FollowerState #
Constructors
| FollowerState | |
Fields
| |
Instances
| Show FollowerState # | |
Defined in Raft.NodeState Methods showsPrec :: Int -> FollowerState -> ShowS # show :: FollowerState -> String # showList :: [FollowerState] -> ShowS # | |
data CandidateState #
Constructors
| CandidateState | |
Fields
| |
Instances
| Show CandidateState # | |
Defined in Raft.NodeState Methods showsPrec :: Int -> CandidateState -> ShowS # show :: CandidateState -> String # showList :: [CandidateState] -> ShowS # | |
data LeaderState #
Constructors
| LeaderState | |
Fields
| |
Instances
| Show LeaderState # | |
Defined in Raft.NodeState Methods showsPrec :: Int -> LeaderState -> ShowS # show :: LeaderState -> String # showList :: [LeaderState] -> ShowS # | |
initRaftNodeState :: RaftNodeState #
A node in Raft begins as a follower
isFollower :: NodeState s -> Bool #
Check if node is in a follower state
isCandidate :: NodeState s -> Bool #
Check if node is in a candidate state
setLastLogEntryData :: NodeState ns -> Entries v -> NodeState ns #
Update the last log entry in the node's log
getLastLogEntryData :: NodeState ns -> (Index, Term) #
Get the last applied index and the commit index of the last log entry in the node's log
getLastAppliedAndCommitIndex :: NodeState ns -> (Index, Index) #
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 #
Persistent state that all Raft nodes maintain, regardless of node state.
Constructors
| PersistentState | |
Fields
| |
Instances
initPersistentState :: PersistentState #
A node initiates its persistent state with term 0 and with its vote blank
Basic types
type NodeId = ByteString #
Unique identifier of a Raft node
Unique identifier of a client
Unique identifier of a leader
Constructors
| LeaderId | |
Fields
| |
Representation of monotonic election terms
Representation of monotonic indices
RPC
Constructors
| AppendEntriesRPC (AppendEntries v) | |
| AppendEntriesResponseRPC AppendEntriesResponse | |
| RequestVoteRPC RequestVote | |
| RequestVoteResponseRPC RequestVoteResponse |
Instances
| Show v => Show (RPC v) # | |
| Generic (RPC v) # | |
| Serialize v => Serialize (RPC v) # | |
| type Rep (RPC v) # | |
Defined in Raft.RPC type Rep (RPC v) = D1 (MetaData "RPC" "Raft.RPC" "libraft-0.1.1.0-K88ErXXABXGJHe9OF75EJD" False) ((C1 (MetaCons "AppendEntriesRPC" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (AppendEntries v))) :+: C1 (MetaCons "AppendEntriesResponseRPC" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 AppendEntriesResponse))) :+: (C1 (MetaCons "RequestVoteRPC" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 RequestVote)) :+: C1 (MetaCons "RequestVoteResponseRPC" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 RequestVoteResponse)))) | |
Instances
| RPCType RequestVoteResponse v # | |
Defined in Raft.RPC Methods toRPC :: RequestVoteResponse -> RPC v # | |
| RPCType RequestVote v # | |
Defined in Raft.RPC Methods toRPC :: RequestVote -> RPC v # | |
| RPCType AppendEntriesResponse v # | |
Defined in Raft.RPC Methods toRPC :: AppendEntriesResponse -> RPC v # | |
| RPCType (AppendEntries v) v # | |
Defined in Raft.RPC Methods toRPC :: AppendEntries v -> RPC v # | |
data RPCMessage v #
Representation of a message sent between nodes
Constructors
| RPCMessage | |
Instances
| Show v => Show (RPCMessage v) # | |
Defined in Raft.RPC Methods showsPrec :: Int -> RPCMessage v -> ShowS # show :: RPCMessage v -> String # showList :: [RPCMessage v] -> ShowS # | |
| Generic (RPCMessage v) # | |
| Serialize v => Serialize (RPCMessage v) # | |
Defined in Raft.RPC | |
| type Rep (RPCMessage v) # | |
Defined in Raft.RPC type Rep (RPCMessage v) = D1 (MetaData "RPCMessage" "Raft.RPC" "libraft-0.1.1.0-K88ErXXABXGJHe9OF75EJD" 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 #
Representation of a message sent from a leader to its peers
Constructors
| AppendEntries | |
Fields
| |
Instances
data AppendEntriesResponse #
Representation of the response from a follower to an AppendEntries message
Constructors
| AppendEntriesResponse | |
Fields
| |
Instances
data RequestVote #
Representation of the message sent by candidates to their peers to request their vote
Constructors
| RequestVote | |
Fields
| |
Instances
| Show RequestVote # | |
Defined in Raft.RPC Methods showsPrec :: Int -> RequestVote -> ShowS # show :: RequestVote -> String # showList :: [RequestVote] -> ShowS # | |
| Generic RequestVote # | |
| Serialize RequestVote # | |
Defined in Raft.RPC | |
| RPCType RequestVote v # | |
Defined in Raft.RPC Methods toRPC :: RequestVote -> RPC v # | |
| type Rep RequestVote # | |
Defined in Raft.RPC type Rep RequestVote = D1 (MetaData "RequestVote" "Raft.RPC" "libraft-0.1.1.0-K88ErXXABXGJHe9OF75EJD" False) (C1 (MetaCons "RequestVote" PrefixI True) ((S1 (MetaSel (Just "rvTerm") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Term) :*: S1 (MetaSel (Just "rvCandidateId") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 NodeId)) :*: (S1 (MetaSel (Just "rvLastLogIndex") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Index) :*: S1 (MetaSel (Just "rvLastLogTerm") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Term)))) | |
data RequestVoteResponse #
Representation of a response to a RequestVote message
Constructors
| RequestVoteResponse | |
Fields
| |
Instances
data AppendEntriesData v #
The data used to construct an AppendEntries value, snapshotted from the node state at the time the AppendEntries val should be created.
Constructors
| AppendEntriesData | |
Fields
| |
Instances
| Show v => Show (AppendEntriesData v) # | |
Defined in Raft.RPC Methods showsPrec :: Int -> AppendEntriesData v -> ShowS # show :: AppendEntriesData v -> String # showList :: [AppendEntriesData v] -> ShowS # | |