Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Hydra.Network.Heartbeat
Description
An implementation of an application-level failure detector.
This module exposes a Component withHeartbeat
than can be used to
wrap another NetworkComponent
and piggy-back on it to send and propagate
Heartbeat
messages and detect other parties' liveness.
It is inspired by the Increasing timeout algorithms from the book Introduction to Reliable and Secure Distributed Programming by Cachin et al. which is an Eventually Perfect Failure Detector suitable for partially synchronous network settings. It has the following behaviour:
- It broadcasts a
Ping
to other parties through the underlyingNetwork
implementation if the last message has been sent more than 3s ago - When receiving messages from other parties, it records reception time and notifies underlying
node with a
Connected
message - If new messages are received from
alive
parties before 3s timeout expires no newConnected
message is sent * If main thread detects that a formerlyalive
party has not been seen for more than 3s, it is marked assuspected
and aDisconnected
message is sent to the node.
Synopsis
- data HeartbeatState = HeartbeatState {}
- initialHeartbeatState :: HeartbeatState
- data Heartbeat msg
- heartbeatDelay :: DiffTime
- livenessDelay :: DiffTime
- type ConnectionMessages m = Connectivity -> m ()
- withHeartbeat :: (MonadAsync m, MonadDelay m) => NodeId -> ConnectionMessages m -> NetworkComponent m (Heartbeat msg) a -> NetworkComponent m msg a
- updateStateFromIncomingMessages :: (MonadSTM m, MonadMonotonicTime m) => TVar m HeartbeatState -> ConnectionMessages m -> NetworkCallback msg m -> NetworkCallback (Heartbeat msg) m
- updateStateFromOutgoingMessages :: (MonadSTM m, MonadMonotonicTime m) => NodeId -> TVar m HeartbeatState -> Network m (Heartbeat msg) -> Network m msg
- updateLastSent :: MonadSTM m => TVar m HeartbeatState -> Time -> m ()
- checkHeartbeatState :: (MonadDelay m, MonadSTM m) => NodeId -> TVar m HeartbeatState -> Network m (Heartbeat msg) -> m ()
- shouldSendHeartbeat :: Time -> HeartbeatState -> Bool
- checkRemoteParties :: (MonadDelay m, MonadSTM m) => TVar m HeartbeatState -> ConnectionMessages m -> m ()
- updateSuspected :: MonadSTM m => TVar m HeartbeatState -> Time -> m (Set NodeId)
- checkTimeout :: (DiffTime -> DiffTime) -> Time -> Time -> Bool
Documentation
data HeartbeatState Source #
Constructors
HeartbeatState | |
Fields
|
Instances
Eq HeartbeatState Source # | |
Defined in Hydra.Network.Heartbeat Methods (==) :: HeartbeatState -> HeartbeatState -> Bool Source # (/=) :: HeartbeatState -> HeartbeatState -> Bool Source # |
Instances
heartbeatDelay :: DiffTime Source #
Delay between each heartbeat check.
livenessDelay :: DiffTime Source #
Maximal delay between expected and sent heartbeats.
type ConnectionMessages m = Connectivity -> m () Source #
withHeartbeat :: (MonadAsync m, MonadDelay m) => NodeId -> ConnectionMessages m -> NetworkComponent m (Heartbeat msg) a -> NetworkComponent m msg a Source #
Wrap a NetworkComponent
and handle sending/receiving of heartbeats.
updateStateFromIncomingMessages :: (MonadSTM m, MonadMonotonicTime m) => TVar m HeartbeatState -> ConnectionMessages m -> NetworkCallback msg m -> NetworkCallback (Heartbeat msg) m Source #
updateStateFromOutgoingMessages :: (MonadSTM m, MonadMonotonicTime m) => NodeId -> TVar m HeartbeatState -> Network m (Heartbeat msg) -> Network m msg Source #
updateLastSent :: MonadSTM m => TVar m HeartbeatState -> Time -> m () Source #
checkHeartbeatState :: (MonadDelay m, MonadSTM m) => NodeId -> TVar m HeartbeatState -> Network m (Heartbeat msg) -> m () Source #
shouldSendHeartbeat :: Time -> HeartbeatState -> Bool Source #
checkRemoteParties :: (MonadDelay m, MonadSTM m) => TVar m HeartbeatState -> ConnectionMessages m -> m () Source #
updateSuspected :: MonadSTM m => TVar m HeartbeatState -> Time -> m (Set NodeId) Source #
checkTimeout :: (DiffTime -> DiffTime) -> Time -> Time -> Bool Source #