Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Legion is framework for building clusters of homogenous nodes that must maintain a shared, replicated state.
For instance, maybe in order to scale a service you are using a partitioning strategy to direct traffic for users A-H to node 1, users I-Q to node 2, and R-Z to node 3. The partition table itself is something all the nodes have to agree on and would make an excellent candidate for the "shared, replicated state" managed by this framework.
To update the shared state, whatever it is, use:
Additionally, since Legion already has to understand about different nodes in the cluster, and how to talk to them, we provide a variety of tools to help facilitate inter-node communication:
cast
: We support sending arbitrary messages to other peers without waiting on a response.call
: We support sending requests to other peers that block on a response.broadcast
: We support sending a message to _every_ other peer without waiting on a responsebroadcall
: We support sending a request to every other peer, and blocking until we recieve a response from them all.
Synopsis
- forkLegionary :: (EventConstraints e, MonadConstraints m) => (ByteString -> IO ByteString) -> (ByteString -> IO ()) -> (Peer -> EventFold ClusterName Peer e -> IO ()) -> Int -> StartupMode e -> m (Runtime e)
- type EventConstraints e = (Binary (Output e), Binary (State e), Binary e, Default (State e), Eq (Output e), Eq e, Event Peer e, Show (Output e), Show (State e), Show e, ToJSON (Output e), ToJSON (State e), ToJSON e)
- type MonadConstraints m = (MonadCatch m, MonadFail m, MonadLoggerIO m, MonadTimeSpec m, MonadUnliftIO m, Race)
- data StartupMode e
- data Runtime e
- applyFast :: MonadIO m => Runtime e -> e -> m (Output e)
- applyConsistent :: MonadIO m => Runtime e -> e -> m (Output e)
- cast :: MonadIO m => Runtime e -> Peer -> ByteString -> m ()
- call :: MonadIO m => Runtime e -> Peer -> ByteString -> m ByteString
- broadcast :: MonadIO m => Runtime e -> ByteString -> m ()
- broadcall :: MonadIO m => Runtime e -> DiffTime -> ByteString -> m (Map Peer (Maybe ByteString))
- readState :: MonadIO m => Runtime e -> m (EventFold ClusterName Peer e)
- getSelf :: Runtime e -> Peer
- getClusterName :: Runtime e -> ClusterName
- getStats :: MonadIO m => Runtime e -> m Stats
- newtype Stats = Stats {}
- eject :: MonadIO m => Runtime e -> Peer -> m ()
- newtype Peer = Peer {}
- newtype ClusterName = ClusterName {}
Starting up the runtime.
:: (EventConstraints e, MonadConstraints m) | |
=> (ByteString -> IO ByteString) | Handle a user call request. |
-> (ByteString -> IO ()) | Handle a user cast message. |
-> (Peer -> EventFold ClusterName Peer e -> IO ()) | Callback when the cluster-wide eventfold changes. |
-> Int | The propagation interval, in microseconds (for use with
|
-> StartupMode e | How to start the runtime, by creating new cluster or joining an existing cluster. |
-> m (Runtime e) |
Fork the Legion runtime system.
type EventConstraints e = (Binary (Output e), Binary (State e), Binary e, Default (State e), Eq (Output e), Eq e, Event Peer e, Show (Output e), Show (State e), Show e, ToJSON (Output e), ToJSON (State e), ToJSON e) Source #
Shorthand for all the constraints needed for the event type. Mainly used so that documentation renders better.
type MonadConstraints m = (MonadCatch m, MonadFail m, MonadLoggerIO m, MonadTimeSpec m, MonadUnliftIO m, Race) Source #
Shorthand for all the monad constraints, mainly use so that documentation renders better.
data StartupMode e Source #
This defines the various ways a node can be spun up.
NewCluster | Indicates that we should bootstrap a new cluster at startup. |
| |
JoinCluster | Indicates that the node should try to join an existing cluster. |
| |
Recover | Resume operation given the previously saved state. |
|
Instances
(Show e, Show (Output e), Show (State e)) => Show (StartupMode e) Source # | |
Defined in OM.Legion.Runtime showsPrec :: Int -> StartupMode e -> ShowS # show :: StartupMode e -> String # showList :: [StartupMode e] -> ShowS # |
A handle on the Legion runtime.
Applying state changes.
:: MonadIO m | |
=> Runtime e | The runtime handle. |
-> e | The event to be applied. |
-> m (Output e) | Returns the possibly inconsistent event output. |
Update the distributed cluster state by applying an event. The event output will be returned immediately and may not reflect a totally consistent view of the cluster. The state update itself, however, is guaranteed to be applied atomically and consistently throughout the cluster.
:: MonadIO m | |
=> Runtime e | The runtime handle. |
-> e | The event to be applied. |
-> m (Output e) | Returns the strongly consistent event output. |
Update the distributed cluster state by applying an event. Both the event output and resulting state will be totally consistent throughout the cluster.
Sending messages around the cluster.
cast :: MonadIO m => Runtime e -> Peer -> ByteString -> m () Source #
Send a user message to some other peer, without waiting on a response.
call :: MonadIO m => Runtime e -> Peer -> ByteString -> m ByteString Source #
Send a user message to some other peer, and block until a response is received.
broadcast :: MonadIO m => Runtime e -> ByteString -> m () Source #
Send a user message to all peers, without wating on a response.
:: MonadIO m | |
=> Runtime e | |
-> DiffTime | The timeout. |
-> ByteString | |
-> m (Map Peer (Maybe ByteString)) |
Send a user message to all peers, and block until a response is received from all of them.
Inspecting the current state.
readState :: MonadIO m => Runtime e -> m (EventFold ClusterName Peer e) Source #
Read the current powerstate value.
getClusterName :: Runtime e -> ClusterName Source #
Obtain the ClusterName
.
Observability
getStats :: MonadIO m => Runtime e -> m Stats Source #
Retrieve some basic stats that can be used to intuit the health of the cluster.
Some basic stats that can be used to intuit the health of the cluster. We currently only report on how long it has been since some peer has made some progress.
Stats | |
|
Cluster Topology
The identification of a node within the legion cluster.
Instances
FromJSON Peer Source # | |
FromJSONKey Peer Source # | |
Defined in OM.Legion.MsgChan | |
ToJSON Peer Source # | |
Defined in OM.Legion.MsgChan | |
ToJSONKey Peer Source # | |
Defined in OM.Legion.MsgChan | |
Show Peer Source # | |
Binary Peer Source # | |
Eq Peer Source # | |
Ord Peer Source # | |
FromHttpApiData Peer Source # | |
Defined in OM.Legion.MsgChan parseUrlPiece :: Text -> Either Text Peer # parseHeader :: ByteString -> Either Text Peer # | |
ToHttpApiData Peer Source # | |
Defined in OM.Legion.MsgChan toUrlPiece :: Peer -> Text # toEncodedUrlPiece :: Peer -> Builder # toHeader :: Peer -> ByteString # toQueryParam :: Peer -> Text # |
newtype ClusterName Source #
The name of a cluster.