command() =
{command_type(),
command_meta(),
UserCommand :: term(),
command_reply_mode()} |
{noop,
command_meta(),
CurrentMachineVersion :: ra_machine:version()}
command_correlation() = integer() | reference()
command_meta() = #{from => from(), ts := integer()}
command_priority() = normal | low
command_reply_mode() =
after_log_append | await_consensus |
{notify, command_correlation(), pid()} |
noreply
command_type() =
'$usr' | '$ra_join' | '$ra_leave' | '$ra_cluster_change' |
'$ra_cluster'
config() = ra_server_config()
effect() =
ra_machine:effect() |
ra_log:effect() |
{reply, ra_reply_body()} |
{reply, term(), ra_reply_body()} |
{cast, ra_server_id(), term()} |
{send_vote_requests,
[{ra_server_id(), #request_vote_rpc{} | #pre_vote_rpc{}}]} |
{send_rpc, ra_server_id(), #append_entries_rpc{}} |
{send_snapshot,
To :: ra_server_id(),
{Module :: module(),
Ref :: term(),
LeaderId :: ra_server_id(),
Term :: ra_term()}} |
{next_event, ra_msg()} |
{next_event, cast, ra_msg()} |
{notify, #{pid() => [term()]}} |
{record_leader_msg, ra_server_id()} |
start_election_timeout
effects() = [effect()]
machine_conf() =
{module, module(), InitConfig :: map()} |
{simple, simple_apply_fun(term()), InitialState :: term()}
The machine configuration.
This is how ra knows which module to use to invoke the ra_machine callbacks
and the config to pass to the ra_machine:init/1 implementation.
The simple machine config is version that can only be used for simple state
machines that cannot access any of the advanced features.
mutable_config() =
#{cluster_name => ra_cluster_name(),
metrics_key => term(),
broadcast_time => non_neg_integer(),
tick_timeout => non_neg_integer(),
install_snap_rpc_timeout => non_neg_integer(),
await_condition_timeout => non_neg_integer(),
max_pipeline_count => non_neg_integer(),
ra_event_formatter => {module(), atom(), [term()]}}
ra_await_condition_fun() =
fun((ra_msg(), ra_server_state()) ->
{boolean(), ra_server_state()})
ra_event_formatter_fun() =
fun((ra_server_id(), Evt :: term()) -> term())
ra_msg() =
#append_entries_rpc{} |
{ra_server_id(), #append_entries_reply{}} |
{ra_server_id(), #install_snapshot_result{}} |
#request_vote_rpc{} |
#request_vote_result{} |
#pre_vote_rpc{} |
#pre_vote_result{} |
#install_snapshot_rpc{} |
election_timeout | await_condition_timeout |
{command, command()} |
{commands, [command()]} |
ra_log:event() |
{consistent_query, term(), ra:query_fun()} |
#heartbeat_rpc{} |
{ra_server_id, #heartbeat_reply{}}
ra_reply_body() =
#append_entries_reply{} |
#request_vote_result{} |
#install_snapshot_result{} |
#pre_vote_result{}
ra_server_config() =
#{id := ra_server_id(),
uid := ra_uid(),
cluster_name := ra_cluster_name(),
log_init_args := ra_log:ra_log_init_args(),
initial_members := [ra_server_id()],
machine := machine_conf(),
friendly_name => unicode:chardata(),
metrics_key => term(),
broadcast_time => non_neg_integer(),
tick_timeout => non_neg_integer(),
install_snap_rpc_timeout => non_neg_integer(),
await_condition_timeout => non_neg_integer(),
max_pipeline_count => non_neg_integer(),
ra_event_formatter => {module(), atom(), [term()]},
counter => counters:counters_ref(),
system_config => ra_system:config()}
ra_server_state() =
#{cfg := #cfg{},
leader_id => maybe(ra_server_id()),
cluster := ra_cluster(),
cluster_change_permitted := boolean(),
cluster_index_term := ra_idxterm(),
previous_cluster => {ra_index(), ra_term(), ra_cluster()},
current_term := ra_term(),
log := term(),
voted_for => maybe(ra_server_id()),
votes => non_neg_integer(),
commit_index := ra_index(),
last_applied := ra_index(),
persisted_last_applied => ra_index(),
stop_after => ra_index(),
machine_state := term(),
aux_state => term(),
condition => ra_await_condition_fun(),
condition_timeout_changes =>
#{transition_to := ra_state(), effects := [effect()]},
pre_vote_token => reference(),
query_index := non_neg_integer(),
queries_waiting_heartbeats :=
queue:queue({non_neg_integer(), consistent_query_ref()}),
pending_consistent_queries := [consistent_query_ref()],
commit_latency => maybe(non_neg_integer())}
ra_state() =
leader | follower | candidate | pre_vote | await_condition |
delete_and_terminate | terminating_leader |
terminating_follower | recover | recovered | stop |
receive_snapshot
simple_apply_fun(State) = fun((term(), State) -> State)
name(ClusterName :: ra_cluster_name(), UniqueSuffix :: string()) -> atom()
init(Config :: ra_server_config()) -> ra_server_state()
recover(State0) -> any()
handle_leader(Install_snapshot_rpc :: ra_msg(), State0 :: ra_server_state()) -> {ra_state(), ra_server_state(), effects()}
handle_candidate(Request_vote_result ::
ra_msg() | election_timeout,
State0 :: ra_server_state()) ->
{ra_state(), ra_server_state(), effects()}
handle_pre_vote(Append_entries_rpc :: ra_msg(), State0 :: ra_server_state()) -> {ra_state(), ra_server_state(), effects()}
handle_follower(Append_entries_rpc :: ra_msg(), State00 :: ra_server_state()) -> {ra_state(), ra_server_state(), effects()}
handle_receive_snapshot(Install_snapshot_rpc, State0) -> any()
handle_await_condition(Request_vote_rpc :: ra_msg(), State :: ra_server_state()) -> {ra_state(), ra_server_state(), effects()}
process_new_leader_queries(State0 :: ra_server_state()) -> {ra_server_state(), [from()]}
tick(X1 :: ra_server_state()) -> effects()
handle_state_enter(RaftState :: ra_state() | eol, State :: ra_server_state()) -> {ra_server_state() | eol, effects()}
overview(State :: ra_server_state()) -> map()
metrics(State :: ra_server_state()) -> {atom(), ra_term(), ra_index(), ra_index(), ra_index(), ra_index(), non_neg_integer()}
is_new(X1 :: ra_server_state()) -> boolean()
is_fully_persisted(X1 :: ra_server_state()) -> boolean()
is_fully_replicated(State :: ra_server_state()) -> boolean()
handle_aux(RaftState, Type, Cmd, State0) -> any()
id(X1 :: ra_server_state()) -> ra_server_id()
log_id(X1 :: ra_server_state()) -> unicode:chardata()
uid(X1 :: ra_server_state()) -> ra_uid()
system_config(X1 :: ra_server_state()) -> ra_system:config()
leader_id(State :: ra_server_state()) -> maybe(ra_server_id())
current_term(State :: ra_server_state()) -> maybe(ra_term())
machine_version(X1 :: ra_server_state()) -> non_neg_integer()
machine_query(QueryFun :: fun((term()) -> term()),
X2 :: ra_server_state()) ->
{ra_idxterm(), term()}
make_rpcs(State) -> any()
update_release_cursor(Index :: ra_index(), MacState :: term(), State :: ra_server_state()) -> {ra_server_state(), effects()}
persist_last_applied(State :: ra_server_state()) -> ra_server_state()
update_peer(PeerId :: ra_server_id(), Update :: #{next_index => non_neg_integer(), query_index => non_neg_integer(), commit_index_sent => non_neg_integer(), status => ra_peer_status()}, State :: ra_server_state()) -> ra_server_state()
register_external_log_reader(Pid :: pid(),
State :: ra_server_state()) ->
{ra_server_state(), effects()}
handle_down(RaftState :: ra_state(), Type :: machine | snapshot_sender | snapshot_writer | aux, Pid :: pid(), Info :: term(), State :: ra_server_state()) -> {ra_state(), ra_server_state(), effects()}
handle_node_status(RaftState :: ra_state(), Type :: machine | aux, Node :: node(), Status :: nodeup | nodedown, Infos :: term(), State :: ra_server_state()) -> {ra_state(), ra_server_state(), effects()}
terminate(State :: ra_server_state(), Reason :: {shutdown, delete} | term()) -> ok
log_fold(RaState :: ra_server_state(), Fun :: fun((term(), State) -> State), State) -> {ok, State, ra_server_state()} | {error, term(), ra_server_state()}
log_read(Indexes :: [ra_index()], State :: ra_server_state()) -> {ok, [term()], ra_server_state()} | {error, ra_server_state()}
Generated by EDoc