Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
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
$sel:alive:HeartbeatState
parties before 3s timeout expires no newConnected
message is sent - If main thread detects that a formerly
$sel:alive:HeartbeatState
party has not been seen for more than 3s, it is marked as$sel:suspected:HeartbeatState
and aDisconnected
message is sent to the node.
Synopsis
- data HeartbeatState = HeartbeatState {}
- initialHeartbeatState :: HeartbeatState
- data Heartbeat msg
- isPing :: Heartbeat msg -> Bool
- heartbeatDelay :: DiffTime
- livenessDelay :: DiffTime
- withHeartbeat :: (MonadAsync m, MonadDelay m) => NodeId -> NetworkComponent m (Heartbeat inbound) (Heartbeat outbound) a -> NetworkComponent m (Either Connectivity inbound) outbound a
- updateStateFromIncomingMessages :: (MonadSTM m, MonadMonotonicTime m) => TVar m HeartbeatState -> NetworkCallback (Either Connectivity inbound) m -> NetworkCallback (Heartbeat inbound) m
- updateStateFromOutgoingMessages :: (MonadSTM m, MonadMonotonicTime m) => NodeId -> TVar m (Maybe Time) -> Network m (Heartbeat outbound) -> Network m outbound
- updateLastSent :: MonadSTM m => TVar m (Maybe Time) -> Time -> m ()
- checkHeartbeatState :: (MonadDelay m, MonadSTM m) => NodeId -> TVar m (Maybe Time) -> Network m (Heartbeat outbound) -> m ()
- shouldSendHeartbeat :: Time -> Maybe Time -> Bool
- checkRemoteParties :: (MonadDelay m, MonadSTM m) => TVar m HeartbeatState -> (Connectivity -> m ()) -> m ()
- updateSuspected :: MonadSTM m => TVar m HeartbeatState -> Time -> m (Set NodeId)
- checkTimeout :: (DiffTime -> DiffTime) -> Time -> Time -> Bool
Documentation
data HeartbeatState Source #
HeartbeatState | |
|
Instances
Eq HeartbeatState Source # | |
Defined in Hydra.Network.Heartbeat (==) :: HeartbeatState -> HeartbeatState -> Bool Source # (/=) :: HeartbeatState -> HeartbeatState -> Bool Source # |
Instances
heartbeatDelay :: DiffTime Source #
Delay between each heartbeat check.
NOTE: This could be made configurable.
livenessDelay :: DiffTime Source #
Maximal delay between expected and sent heartbeats.
NOTE: This could be made configurable.
:: (MonadAsync m, MonadDelay m) | |
=> NodeId | This node's id, used to identify |
-> NetworkComponent m (Heartbeat inbound) (Heartbeat outbound) a | Underlying |
-> NetworkComponent m (Either Connectivity inbound) outbound a | Returns a network component that can be used to send and consume arbitrary messages.
This layer will take care of peeling out/wrapping messages into |
Wrap a lower-level NetworkComponent
and handle sending/receiving of heartbeats.
Note that the type of consumed and sent messages can be different.
updateStateFromIncomingMessages :: (MonadSTM m, MonadMonotonicTime m) => TVar m HeartbeatState -> NetworkCallback (Either Connectivity inbound) m -> NetworkCallback (Heartbeat inbound) m Source #
updateStateFromOutgoingMessages :: (MonadSTM m, MonadMonotonicTime m) => NodeId -> TVar m (Maybe Time) -> Network m (Heartbeat outbound) -> Network m outbound Source #
updateLastSent :: MonadSTM m => TVar m (Maybe Time) -> Time -> m () Source #
checkHeartbeatState :: (MonadDelay m, MonadSTM m) => NodeId -> TVar m (Maybe Time) -> Network m (Heartbeat outbound) -> m () Source #
shouldSendHeartbeat :: Time -> Maybe Time -> Bool Source #
checkRemoteParties :: (MonadDelay m, MonadSTM m) => TVar m HeartbeatState -> (Connectivity -> m ()) -> m () Source #
updateSuspected :: MonadSTM m => TVar m HeartbeatState -> Time -> m (Set NodeId) Source #