RaftEx.Machine behaviour
(raft_ex v0.1.0)
View Source
Behaviour for RaftEx state machines.
Implement init/1 and apply/3 as mandatory callbacks. All other
callbacks (tick, state_enter, snapshot hooks, versioning, etc.) are
optional — sensible defaults are used when they are absent.
Effects
apply/3 may return a third element containing one or more effects that
the Raft framework will execute after the entry is applied. Effects are
described by effect/0.
Summary
Functions
Determine which arity of handle_aux the module exports (5 or 6 args),
returning {:handle_aux, arity} or nil if neither is exported.
Types
@type command_meta() :: %{ optional(:machine_version) => version(), optional(:from) => term(), optional(:reply_mode) => term(), system_time: integer(), index: non_neg_integer(), term: non_neg_integer() }
@type effect() :: {:send_msg, to :: term(), msg :: term()} | {:send_msg, to :: term(), msg :: term(), opts :: term()} | {:mod_call, module(), atom(), [term()]} | {:append, cmd :: term()} | {:append, cmd :: term(), reply_mode :: term()} | {:monitor, :process, pid()} | {:monitor, :node, node()} | {:demonitor, :process, pid()} | {:demonitor, :node, node()} | {:timer, term(), non_neg_integer() | :infinity} | {:release_cursor, RaftEx.Types.index(), state()} | {:release_cursor, RaftEx.Types.index(), state(), map()} | {:release_cursor, RaftEx.Types.index()} | {:checkpoint, RaftEx.Types.index(), state()} | {:aux, term()} | :garbage_collection
@type effects() :: [effect()]
@type milliseconds() :: non_neg_integer()
@type reply() :: term()
@type state() :: term()
@type user_command() :: term()
@type version() :: non_neg_integer()
Callbacks
@callback live_indexes(state()) :: [RaftEx.Types.index()] | {:ra_seq, term()}
@callback snapshot_module() :: module()
@callback tick(milliseconds(), state()) :: effects()
@callback version() :: version()
Functions
@spec tick(module(), milliseconds(), state()) :: effects()
@spec which_aux_fun(module()) :: {:handle_aux, 5 | 6} | nil
Determine which arity of handle_aux the module exports (5 or 6 args),
returning {:handle_aux, arity} or nil if neither is exported.