Safe Haskell | None |
---|---|
Language | Haskell2010 |
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)
- 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 RaftStateMachinePure sm v => RaftSendClient m sm v where
- sendClient :: ClientId -> ClientResponse sm v -> 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
- initializePersistentState :: Exception (RaftPersistError m) => m (Either (RaftPersistError m) ())
- readPersistentState :: Exception (RaftPersistError m) => m (Either (RaftPersistError m) PersistentState)
- writePersistentState :: Exception (RaftPersistError m) => PersistentState -> m (Either (RaftPersistError m) ())
- data RaftEnv v m = RaftEnv {
- eventChan :: RaftEventChan v m
- resetElectionTimer :: m ()
- resetHeartbeatTimer :: m ()
- raftNodeConfig :: RaftNodeConfig
- raftNodeLogCtx :: LogCtx (RaftT v m)
- raftNodeMetrics :: Metrics
- runRaftNode :: forall m sm v. (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 -> OptionalRaftNodeConfig -> LogCtx (RaftT v m) -> sm -> m ()
- runRaftT :: Monad m => RaftNodeState v -> RaftEnv v m -> RaftT v m a -> m a
- handleEventLoop :: forall sm v m. (Show v, Serialize v, Show sm, Show (Action sm v), Show (RaftLogError m), Typeable m, MonadIO m, MonadRaft v m, MonadFail m, MonadThrow m, MonadMask m, RaftStateMachine m sm v, Show (RaftStateMachinePureError sm v), RaftPersist m, RaftSendRPC m v, RaftSendClient m sm v, 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 sm v
- data ClientReadResp sm v
- data ClientWriteResp sm v
- data ClientRedirResp = ClientRedirResp CurrentLeader
- data RaftNodeConfig = RaftNodeConfig {}
- data Event v
- data Timeout
- data MessageEvent v
- = RPCMessageEvent (RPCMessage v)
- | ClientRequestEvent (ClientRequest v)
- data Entry v = Entry {}
- type Entries v = Seq (Entry v)
- class (Show (RaftWriteLogError m), Monad m) => RaftWriteLog m v where
- type RaftWriteLogError m
- writeLogEntries :: Exception (RaftWriteLogError m) => Entries v -> m (Either (RaftWriteLogError m) ())
- data DeleteSuccess v = DeleteSuccess
- class (Show (RaftDeleteLogError m), Monad m) => RaftDeleteLog m v where
- type RaftDeleteLogError m
- deleteLogEntriesFrom :: Exception (RaftDeleteLogError m) => Index -> m (Either (RaftDeleteLogError m) (DeleteSuccess v))
- class (Show (RaftReadLogError m), 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 = (RaftInitLog m v, RaftReadLog m v, RaftWriteLog m v, RaftDeleteLog m v)
- data RaftLogError m
- type RaftLogExceptions m = (Exception (RaftInitLogError m), Exception (RaftReadLogError m), Exception (RaftWriteLogError m), Exception (RaftDeleteLogError m))
- data LogCtx m
- = LogCtx {
- logCtxDest :: LogDest m
- logCtxSeverity :: Severity
- | NoLogs
- = LogCtx {
- data LogDest m
- data Severity
- data Mode
- data RaftNodeState v where
- RaftNodeState :: {..} -> RaftNodeState v
- data NodeState (a :: Mode) v where
- NodeFollowerState :: FollowerState v -> NodeState Follower v
- NodeCandidateState :: CandidateState v -> NodeState Candidate v
- NodeLeaderState :: LeaderState v -> NodeState Leader v
- data CurrentLeader
- data FollowerState v = FollowerState {}
- data CandidateState v = CandidateState {}
- data LeaderState v = LeaderState {}
- initRaftNodeState :: RaftNodeState v
- isFollower :: NodeState s v -> Bool
- isCandidate :: NodeState s v -> Bool
- isLeader :: NodeState s v -> Bool
- setLastLogEntry :: NodeState s v -> Entries v -> NodeState s v
- getLastLogEntry :: NodeState ns v -> LastLogEntry v
- getLastAppliedAndCommitIndex :: NodeState ns v -> (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 {}
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.
data RaftStateMachinePureError sm v Source #
type RaftStateMachinePureCtx sm v = ctx | ctx -> sm v Source #
rsmTransition :: RaftStateMachinePureCtx sm v -> sm -> v -> Either (RaftStateMachinePureError sm v) sm Source #
class (Monad m, RaftStateMachinePure sm v) => RaftStateMachine m sm v where Source #
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
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.
sendRPC :: NodeId -> RPCMessage v -> m () Source #
Instances
(Monad m, RaftSendRPC m v) => RaftSendRPC (RaftPostgresT m) v Source # | |
Defined in Raft.Log.PostgreSQL sendRPC :: NodeId -> RPCMessage v -> RaftPostgresT m () Source # | |
(MonadIO m, MonadMask m, RaftSendRPC m v) => RaftSendRPC (RaftPersistFileStoreT m) v Source # | |
Defined in Examples.Raft.FileStore.Persistent sendRPC :: NodeId -> RPCMessage v -> RaftPersistFileStoreT m () Source # | |
(Monad m, RaftSendRPC m v) => RaftSendRPC (RaftLogFileStoreT m) v Source # | |
Defined in Examples.Raft.FileStore.Log sendRPC :: NodeId -> RPCMessage v -> RaftLogFileStoreT m () Source # | |
(MonadCatch m, MonadMask m, MonadIO m, Serialize v, Show v) => RaftSendRPC (RaftSocketT sm v m) v Source # | |
Defined in Examples.Raft.Socket.Node 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
type RaftRecvRPCError m v Source #
receiveRPC :: m (Either (RaftRecvRPCError m v) (RPCMessage v)) Source #
Instances
class RaftStateMachinePure sm v => RaftSendClient m sm v where Source #
Interface for Raft nodes to send messages to clients
sendClient :: ClientId -> ClientResponse sm v -> m () Source #
Instances
(Monad m, RaftSendClient m sm v) => RaftSendClient (RaftPostgresT m) sm v Source # | |
Defined in Raft.Log.PostgreSQL sendClient :: ClientId -> ClientResponse sm v -> RaftPostgresT m () Source # | |
(MonadIO m, MonadMask m, RaftSendClient m sm v) => RaftSendClient (RaftPersistFileStoreT m) sm v Source # | |
Defined in Examples.Raft.FileStore.Persistent sendClient :: ClientId -> ClientResponse sm v -> RaftPersistFileStoreT m () Source # | |
(Monad m, RaftSendClient m sm v) => RaftSendClient (RaftLogFileStoreT m) sm v Source # | |
Defined in Examples.Raft.FileStore.Log sendClient :: ClientId -> ClientResponse sm v -> RaftLogFileStoreT m () Source # | |
(RaftStateMachinePure sm v, MonadMask m, MonadCatch m, MonadIO m, Serialize sm, Serialize v) => RaftSendClient (RaftSocketT sm v m) sm v Source # | |
Defined in Examples.Raft.Socket.Node 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
type RaftRecvClientError m v Source #
receiveClient :: m (Either (RaftRecvClientError m v) (ClientRequest v)) Source #
Instances
class Monad m => RaftPersist m where Source #
Provides an interface to read and write the persistent state to disk.
type RaftPersistError m Source #
initializePersistentState :: Exception (RaftPersistError m) => m (Either (RaftPersistError m) ()) Source #
readPersistentState :: Exception (RaftPersistError m) => m (Either (RaftPersistError m) PersistentState) Source #
writePersistentState :: Exception (RaftPersistError m) => PersistentState -> m (Either (RaftPersistError m) ()) Source #
Instances
The raft server environment composed of the concurrent variables used in the effectful raft layer.
RaftEnv | |
|
:: (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
handleEventLoop :: forall sm v m. (Show v, Serialize v, Show sm, Show (Action sm v), Show (RaftLogError m), Typeable m, MonadIO m, MonadRaft v m, MonadFail m, MonadThrow m, MonadMask m, RaftStateMachine m sm v, Show (RaftStateMachinePureError sm v), RaftPersist m, RaftSendRPC m v, RaftSendClient m sm v, RaftLog m v, RaftLogExceptions m, RaftPersist m, Exception (RaftPersistError m)) => sm -> RaftT v m () Source #
Client data types
data ClientRequest v Source #
Representation of a client request coupled with the client id
Instances
Show v => Show (ClientRequest v) Source # | |
Defined in Raft.Client showsPrec :: Int -> ClientRequest v -> ShowS # show :: ClientRequest v -> String # showList :: [ClientRequest v] -> ShowS # | |
Generic (ClientRequest v) Source # | |
Defined in Raft.Client type Rep (ClientRequest v) :: Type -> Type # from :: ClientRequest v -> Rep (ClientRequest v) x # to :: Rep (ClientRequest v) x -> ClientRequest v # | |
Serialize v => Serialize (ClientRequest v) Source # | |
Defined in Raft.Client put :: Putter (ClientRequest v) # get :: Get (ClientRequest v) # | |
type Rep (ClientRequest v) Source # | |
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)))) |
Representation of a client request
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 # | |
Generic (ClientReq v) Source # | |
Serialize v => Serialize (ClientReq v) Source # | |
type Rep (ClientReq v) Source # | |
Defined in Raft.Client type Rep (ClientReq v) = D1 (MetaData "ClientReq" "Raft.Client" "libraft-0.5.0.0-J9sQlo4v2xjSwCkwompQR" False) (C1 (MetaCons "ClientReadReq" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 ClientReadReq)) :+: (C1 (MetaCons "ClientWriteReq" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (ClientWriteReq v))) :+: C1 (MetaCons "ClientMetricsReq" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 ClientMetricsReq)))) |
data ClientResponse sm v Source #
The datatype sent back to the client as an actual response
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
data ClientReadResp sm v Source #
Representation of a read response to a client
Instances
data ClientWriteResp sm v Source #
Representation of a write response to a client
ClientWriteRespSuccess Index SerialNum | Index of the entry appended to the log due to the previous client request |
ClientWriteRespFail SerialNum (RaftStateMachinePureError sm v) |
Instances
data ClientRedirResp Source #
Representation of a redirect response to a client
Instances
Show ClientRedirResp Source # | |
Defined in Raft.Client showsPrec :: Int -> ClientRedirResp -> ShowS # show :: ClientRedirResp -> String # showList :: [ClientRedirResp] -> ShowS # | |
Generic ClientRedirResp Source # | |
Defined in Raft.Client type Rep ClientRedirResp :: Type -> Type # from :: ClientRedirResp -> Rep ClientRedirResp x # to :: Rep ClientRedirResp x -> ClientRedirResp # | |
Serialize ClientRedirResp Source # | |
Defined in Raft.Client put :: Putter ClientRedirResp # get :: Get ClientRedirResp # | |
type Rep ClientRedirResp Source # | |
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
RaftNodeConfig | |
|
Instances
Show RaftNodeConfig Source # | |
Defined in Raft.Config showsPrec :: Int -> RaftNodeConfig -> ShowS # show :: RaftNodeConfig -> String # showList :: [RaftNodeConfig] -> ShowS # |
Events
Representation of events a raft node can send and receive
Representation of timeouts
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 Source #
Representation of message events to a node
RPCMessageEvent (RPCMessage v) | Incoming event from a peer |
ClientRequestEvent (ClientRequest v) | Incoming event from a client |
Instances
Log
Representation of an entry in the replicated log
Entry | |
|
Instances
Eq v => Eq (Entry v) Source # | |
Show v => Show (Entry v) Source # | |
Generic (Entry v) Source # | |
Serialize v => Serialize (Entry v) Source # | |
type Rep (Entry v) Source # | |
Defined in Raft.Log type Rep (Entry v) = D1 (MetaData "Entry" "Raft.Log" "libraft-0.5.0.0-J9sQlo4v2xjSwCkwompQR" 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) :*: S1 (MetaSel (Just "entryPrevHash") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 EntryHash))))) |
class (Show (RaftWriteLogError m), Monad m) => RaftWriteLog m v where Source #
Provides an interface for nodes to write log entries to storage.
type RaftWriteLogError m Source #
writeLogEntries :: Exception (RaftWriteLogError m) => Entries v -> m (Either (RaftWriteLogError m) ()) Source #
Write the given log entries to storage
Instances
data DeleteSuccess v Source #
class (Show (RaftDeleteLogError m), Monad m) => RaftDeleteLog m v where Source #
Provides an interface for nodes to delete log entries from storage.
type RaftDeleteLogError m Source #
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.
Instances
class (Show (RaftReadLogError m), Monad m) => RaftReadLog m v where Source #
Provides an interface for nodes to read log entries from storage.
type RaftReadLogError m Source #
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
type RaftLog m v = (RaftInitLog m v, RaftReadLog m v, RaftWriteLog m v, RaftDeleteLog m v) 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 # | |
Defined in Raft.Log showsPrec :: Int -> RaftLogError m -> ShowS # show :: RaftLogError m -> String # showList :: [RaftLogError m] -> ShowS # |
type RaftLogExceptions m = (Exception (RaftInitLogError m), Exception (RaftReadLogError m), Exception (RaftWriteLogError m), Exception (RaftDeleteLogError m)) Source #
Logging
Representation of the logs' context
LogCtx | |
| |
NoLogs |
Representation of the logs' destination
Representation of the severity of the logs
Raft node states
data RaftNodeState v where Source #
Existential type hiding the internal node state
RaftNodeState | |
|
Instances
Show v => Show (RaftNodeState v) Source # | |
Defined in Raft.NodeState showsPrec :: Int -> RaftNodeState v -> ShowS # show :: RaftNodeState v -> String # showList :: [RaftNodeState v] -> ShowS # | |
Monad m => MonadState (RaftNodeState v) (RaftT v m) Source # | |
Defined in Raft.Monad 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
NodeFollowerState :: FollowerState v -> NodeState Follower v | |
NodeCandidateState :: CandidateState v -> NodeState Candidate v | |
NodeLeaderState :: LeaderState v -> NodeState Leader v |
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 # | |
Defined in Raft.Types (==) :: CurrentLeader -> CurrentLeader -> Bool # (/=) :: CurrentLeader -> CurrentLeader -> Bool # | |
Show CurrentLeader Source # | |
Defined in Raft.Types showsPrec :: Int -> CurrentLeader -> ShowS # show :: CurrentLeader -> String # showList :: [CurrentLeader] -> ShowS # | |
Generic CurrentLeader Source # | |
Defined in Raft.Types type Rep CurrentLeader :: Type -> Type # from :: CurrentLeader -> Rep CurrentLeader x # to :: Rep CurrentLeader x -> CurrentLeader # | |
Serialize CurrentLeader Source # | |
Defined in Raft.Types put :: Putter CurrentLeader # get :: Get CurrentLeader # | |
type Rep CurrentLeader Source # | |
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 #
FollowerState | |
|
Instances
Show v => Show (FollowerState v) Source # | |
Defined in Raft.NodeState showsPrec :: Int -> FollowerState v -> ShowS # show :: FollowerState v -> String # showList :: [FollowerState v] -> ShowS # |
data CandidateState v Source #
CandidateState | |
|
Instances
Show v => Show (CandidateState v) Source # | |
Defined in Raft.NodeState showsPrec :: Int -> CandidateState v -> ShowS # show :: CandidateState v -> String # showList :: [CandidateState v] -> ShowS # |
data LeaderState v Source #
LeaderState | |
|
Instances
Show v => Show (LeaderState v) Source # | |
Defined in Raft.NodeState showsPrec :: Int -> LeaderState v -> ShowS # show :: LeaderState v -> String # showList :: [LeaderState v] -> ShowS # |
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
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.
PersistentState | |
|
Instances
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
Unique identifier of a client
Unique identifier of a leader
Representation of monotonic election terms
Representation of monotonic indices
Instances
Enum Index Source # | |
Eq Index Source # | |
Integral Index Source # | |
Num Index Source # | |
Ord Index Source # | |
Read Index Source # | |
Real Index Source # | |
Defined in Raft.Types toRational :: Index -> Rational # | |
Show Index Source # | |
Generic Index Source # | |
Serialize Index Source # | |
FromField Index Source # | |
Defined in Raft.Types | |
ToField Index Source # | |
Defined in Raft.Types | |
type Rep Index Source # | |
Defined in Raft.Types |
RPC
AppendEntriesRPC (AppendEntries v) | |
AppendEntriesResponseRPC AppendEntriesResponse | |
RequestVoteRPC RequestVote | |
RequestVoteResponseRPC RequestVoteResponse |
Instances
Show v => Show (RPC v) Source # | |
Generic (RPC v) Source # | |
Serialize v => Serialize (RPC v) Source # | |
type Rep (RPC v) Source # | |
Defined in Raft.RPC type Rep (RPC v) = D1 (MetaData "RPC" "Raft.RPC" "libraft-0.5.0.0-J9sQlo4v2xjSwCkwompQR" 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)))) |
class RPCType a v where Source #
Instances
RPCType RequestVoteResponse v Source # | |
RPCType RequestVote v Source # | |
RPCType AppendEntriesResponse v Source # | |
RPCType (AppendEntries v) v Source # | |
data RPCMessage v Source #
Representation of a message sent between nodes
Instances
Show v => Show (RPCMessage v) Source # | |
Defined in Raft.RPC showsPrec :: Int -> RPCMessage v -> ShowS # show :: RPCMessage v -> String # showList :: [RPCMessage v] -> ShowS # | |
Generic (RPCMessage v) Source # | |
Defined in Raft.RPC type Rep (RPCMessage v) :: Type -> Type # from :: RPCMessage v -> Rep (RPCMessage v) x # to :: Rep (RPCMessage v) x -> RPCMessage v # | |
Serialize v => Serialize (RPCMessage v) Source # | |
Defined in Raft.RPC put :: Putter (RPCMessage v) # get :: Get (RPCMessage v) # | |
type Rep (RPCMessage v) Source # | |
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
AppendEntries | |
|
Instances
data AppendEntriesResponse Source #
Representation of the response from a follower to an AppendEntries message
AppendEntriesResponse | |
|
Instances
Show AppendEntriesResponse Source # | |
Defined in Raft.RPC showsPrec :: Int -> AppendEntriesResponse -> ShowS # show :: AppendEntriesResponse -> String # showList :: [AppendEntriesResponse] -> ShowS # | |
Generic AppendEntriesResponse Source # | |
Serialize AppendEntriesResponse Source # | |
Defined in Raft.RPC | |
RPCType AppendEntriesResponse v Source # | |
type Rep AppendEntriesResponse Source # | |
Defined in Raft.RPC type Rep AppendEntriesResponse = D1 (MetaData "AppendEntriesResponse" "Raft.RPC" "libraft-0.5.0.0-J9sQlo4v2xjSwCkwompQR" False) (C1 (MetaCons "AppendEntriesResponse" PrefixI True) (S1 (MetaSel (Just "aerTerm") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Term) :*: (S1 (MetaSel (Just "aerSuccess") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Bool) :*: S1 (MetaSel (Just "aerReadRequest") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Maybe Int))))) |
data RequestVote Source #
Representation of the message sent by candidates to their peers to request their vote
RequestVote | |
|
Instances
data RequestVoteResponse Source #
Representation of a response to a RequestVote message
RequestVoteResponse | |
|
Instances
Show RequestVoteResponse Source # | |
Defined in Raft.RPC showsPrec :: Int -> RequestVoteResponse -> ShowS # show :: RequestVoteResponse -> String # showList :: [RequestVoteResponse] -> ShowS # | |
Generic RequestVoteResponse Source # | |
Defined in Raft.RPC type Rep RequestVoteResponse :: Type -> Type # from :: RequestVoteResponse -> Rep RequestVoteResponse x # to :: Rep RequestVoteResponse x -> RequestVoteResponse # | |
Serialize RequestVoteResponse Source # | |
Defined in Raft.RPC | |
RPCType RequestVoteResponse v Source # | |
type Rep RequestVoteResponse Source # | |
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 # | |
Defined in Raft.RPC showsPrec :: Int -> AppendEntriesData v -> ShowS # show :: AppendEntriesData v -> String # showList :: [AppendEntriesData v] -> ShowS # |