environment_param() = {data_dir, file:filename()} | {wal_data_dir, file:filename()} | {segment_max_entries, non_neg_integer()} | {wal_max_size_bytes, non_neg_integer()} | {wal_compute_checksums, boolean()} | {wal_write_strategy, default | o_sync}
index() = ra_index()
query_fun() = fun((term()) -> term()) | {M::module(), F::atom(), A::list()}
ra_cmd_ret() = ra_server_proc:ra_cmd_ret()
server_id() = ra_server_id()
add_member/2 | Add a ra server id to a ra cluster's membership configuration. |
add_member/3 | Same as add_member/2 but also accepts a timeout. |
aux_command/2 | |
cast_aux_command/2 | |
consistent_query/2 | Query the state machine with a consistency guarantee. |
consistent_query/3 | Same as consistent_query/2 but accepts a custom timeout. |
delete_cluster/1 | Deletes a ra cluster in an orderly fashion This function commits and end of life command which after each server applies it will cause that server to shut down and delete all it's data. |
delete_cluster/2 | Same as delete_cluster/1 but also accepts a timeout. |
force_delete_server/1 | Deletes a ra server The server is forcefully deleted. |
initial_members/1 | |
initial_members/2 | |
leader_query/2 | Query the machine state on the current leader node. |
leader_query/3 | Same as leader_query/2 but accepts a custom timeout. |
leave_and_delete_server/1 | A safe way for a an active server to force remove itself from its cluster. |
leave_and_delete_server/2 | A safe way to remove an active server from its cluster. |
leave_and_delete_server/3 | Same as leave_and_delete_server/2 but also accepts a timeout. |
leave_and_terminate/1 | A safe way for a an active server to remove itself from its cluster. |
leave_and_terminate/2 | A safe way to remove an active server from its cluster. |
leave_and_terminate/3 | Same as leave_and_terminate/2 but also accepts a timeout. |
local_query/2 | Query the machine state on any available server. |
local_query/3 | Same as local_query/2 but accepts a custom timeout. |
members/1 | Returns a list of cluster members. |
members/2 | Returns a list of cluster members. |
new_uid/1 | generates a random uid using the provided source material for the first 6 characters. |
overview/0 | Returns a map of overview data of the Ra system on the current Erlang node. |
pipeline_command/2 | Sends a command to the ra server using a gen_statem:cast without any correlation identifier. |
pipeline_command/3 | Same as pipeline_command/4 but uses a hardcoded priority of low . |
pipeline_command/4 | Submits a command to the ra server using a gen_statem:cast, passing an optional process-scoped term as correlation identifier. |
process_command/2 | Same as process_command/3 with the default timeout of 5000 ms. |
process_command/3 | Submits a command to a ra server. |
register_external_log_reader/1 | Registers an external log reader. |
remove_member/2 | Removes a server from the cluster's membership configuration. |
remove_member/3 | Same as remove_member/2 but also accepts a timeout. |
restart_server/1 | Restarts a previously successfully started ra server. |
start/0 | Starts the ra application. |
start/1 | Starts the ra application. |
start_cluster/1 | Starts a new distributed ra cluster. |
start_cluster/2 | Same as start_cluster/1 but accepts a custom timeout. |
start_cluster/3 | Starts a new distributed ra cluster. |
start_cluster/4 | Starts a new distributed ra cluster. |
start_in/1 | Starts the ra application with a provided data directory. |
start_or_restart_cluster/3 | Starts or restarts a ra cluster. |
start_or_restart_cluster/4 | Same as start_or_restart_cluster/3 but accepts a custom timeout. |
start_server/1 | Starts a ra server. |
start_server/4 | Starts a new distributed ra cluster. |
stop_server/1 | Stops a ra server. |
transfer_leadership/2 | Transfers leadership from the leader to a follower. |
trigger_election/1 | Makes the server to enter a pre-vote state and attempt to become the leader. |
trigger_election/2 | Same as trigger_election/2 but also accepts a timeout. |
add_member(ServerLoc::ra_server_id() | [ra_server_id()], ServerId::ra_server_id()) -> ra_cmd_ret() | {error, already_member} | {error, cluster_change_not_permitted}
ServerLoc: the ra server or servers to try to send the command to
ServerId: the ra server id of the new server.
Add a ra server id to a ra cluster's membership configuration. This commits a join command to the leader log. After this has been replicated the leader will start replicating entries to the new server. This function returns after appending the command to the log. New node does not have to be running at the time of addition but it is expected to come online in a reasonable amount of time. A new member that's been announced to its new cluster but taking a long time to start will affect said cluster's availability characteristics (by increasing quorum node count).
add_member(ServerLoc::ra_server_id() | [ra_server_id()], ServerId::ra_server_id(), Timeout::timeout()) -> ra_cmd_ret() | {error, already_member} | {error, cluster_change_not_permitted}
Same as add_member/2
but also accepts a timeout.
See also: add_member/2.
aux_command(ServerRef::ra_server_id(), Cmd::term()) -> term()
cast_aux_command(ServerRef::ra_server_id(), Cmd::term()) -> ok
consistent_query(ServerId::ra_server_id(), QueryFun::query_fun()) -> ra_server_proc:ra_leader_call_ret(term())
ServerId: the ra server id to send the query to
QueryFun: the query function to run
Query the state machine with a consistency guarantee. This allows the caller to query the state machine on the leader node with an additional heartbeat to check that the node is still the leader. Consistency guarantee is that the query will return result containing at least all changes, committed before this query is issued. This may include changes which were committed while the query is running.
consistent_query(ServerId::ra_server_id(), QueryFun::query_fun(), Timeout::timeout()) -> ra_server_proc:ra_leader_call_ret(term())
ServerId: the ra server id to send the query to
QueryFun: the query function to run
Timeout: the timeout to use
Same as consistent_query/2
but accepts a custom timeout.
See also: consistent_query/2.
delete_cluster(ServerIds::[ra_server_id()]) -> {ok, ra_server_id()} | {error, term()}
ServerIds: the ra_server_ids of the cluster
returns: {{ok, Leader} | error, nodedown}
Deletes a ra cluster in an orderly fashion This function commits and end of life command which after each server applies it will cause that server to shut down and delete all it's data. The leader will stay up until it has successfully replicated the end of life command to all servers after which it too will shut down and delete all it's data.
delete_cluster(ServerIds::[ra_server_id()], Timeout::timeout()) -> {ok, Leader::ra_server_id()} | {error, term()}
Same as delete_cluster/1
but also accepts a timeout.
See also: delete_cluster/1.
force_delete_server(ServerId::ra_server_id()) -> ok | {error, term()}
ServerId: the ra_server_id() of the server
returns: {ok | error, nodedown}
Deletes a ra server The server is forcefully deleted.
initial_members(ServerId::ra_server_id()) -> ra_server_proc:ra_leader_call_ret([ra_server_id()])
initial_members(ServerId::ra_server_id(), Timeout::timeout()) -> ra_server_proc:ra_leader_call_ret([ra_server_id()] | error)
leader_query(ServerId::ra_server_id(), QueryFun::query_fun()) -> {ok, {ra_idxterm(), term()}, ra_server_id() | not_known}
ServerId: the ra server id to send the query to
QueryFun: the query function to run
Query the machine state on the current leader node. This function works like local_query, but redirects to the current leader node. The leader state may be more up-to-date compared to local state of some followers. This function may still return stale results as it reads the current state and does not wait for commands to be applied.
leader_query(ServerId::ra_server_id(), QueryFun::query_fun(), Timeout::timeout()) -> {ok, {ra_idxterm(), term()}, ra_server_id() | not_known}
ServerId: the ra server id to send the query to
QueryFun: the query function to run
Timeout: the timeout to use
Same as leader_query/2
but accepts a custom timeout.
See also: leader_query/2.
leave_and_delete_server(ServerId) -> any()
A safe way for a an active server to force remove itself from its cluster. The server will be force removed after a membership transition command was added to the log. Use this when a node knows that it is being permanently decommissioned.
See also: leave_and_delete_server/3, leave_and_terminate/2.
leave_and_delete_server(ServerRef::ra_server_id() | [ra_server_id()], ServerId::ra_server_id()) -> ok | timeout | {error, noproc}
ServerRef: the ra server to send the command to and to remove
ServerId: the ra server to force remove
A safe way to remove an active server from its cluster.
The server will be force removed after a membership transition command was
added to the log.
The command is added to the log by the ServerRef
node.
Use this to decommission a node that's unable to start
or is permanently lost.
See also: leave_and_delete_server/3.
leave_and_delete_server(ServerRef::ra_server_id() | [ra_server_id()], ServerId::ra_server_id(), Timeout::timeout()) -> ok | timeout | {error, noproc}
ServerRef: the ra server to send the command to and to remove
ServerId: the ra server to force remove
Timeout: timeout to use
Same as leave_and_delete_server/2
but also accepts a timeout.
See also: leave_and_delete_server/2.
leave_and_terminate(ServerId) -> any()
A safe way for a an active server to remove itself from its cluster. The server is first removed, then asked to terminate. Use this when a node knows that it is being permanently decommissioned.
See also: remove_member/2.
leave_and_terminate(ServerRef::ra_server_id(), ServerId::ra_server_id()) -> ok | timeout | {error, noproc}
ServerRef: the ra server to send the command to and to remove
ServerId: the ra server to remove
A safe way to remove an active server from its cluster.
The command is added to the log by the ServerRef
node.
Use this to decommission a node that's unable to start
or is permanently lost.
See also: leave_and_terminate/3.
leave_and_terminate(ServerRef::ra_server_id(), ServerId::ra_server_id(), Timeout::timeout()) -> ok | timeout | {error, noproc}
ServerRef: the ra server to send the command to and to remove
ServerId: the ra server to remove
Timeout: timeout to use
Same as leave_and_terminate/2
but also accepts a timeout.
See also: leave_and_terminate/2.
local_query(ServerId::ra_server_id(), QueryFun::query_fun()) -> ra_server_proc:ra_leader_call_ret({ra_idxterm(), term()})
ServerId: the ra server id to send the query to
QueryFun: the query function to run
Query the machine state on any available server. This allows you to run the QueryFun over the server machine state and return the result. Any ra server can be addressed and will returns its local state at the time of querying. This can return stale results, including infinitely stale ones.
local_query(ServerId::ra_server_id(), QueryFun::query_fun(), Timeout::timeout()) -> ra_server_proc:ra_leader_call_ret({ra_idxterm(), term()})
ServerId: the ra server id to send the query to
QueryFun: the query function to run
Timeout: the timeout to use
Same as local_query/2
but accepts a custom timeout.
See also: local_query/2.
members(ServerId::ra_server_id()) -> ra_server_proc:ra_leader_call_ret([ra_server_id()])
ServerId: the Ra server to send the query to
Returns a list of cluster members
members(ServerId::ra_server_id(), Timeout::timeout()) -> ra_server_proc:ra_leader_call_ret([ra_server_id()])
ServerId: the Ra server to send the query to
Timeout: the timeout to use
Returns a list of cluster members
new_uid(Source) -> any()
generates a random uid using the provided source material for the first 6 characters.
overview() -> map()
Returns a map of overview data of the Ra system on the current Erlang node.
pipeline_command(ServerId::ra_server_id(), Command::term()) -> ok
ServerId: the ra server id to send the command to
Command: an arbitrary term that the state machine can handle
Sends a command to the ra server using a gen_statem:cast without
any correlation identifier.
Effectively the same as
ra:pipeline_command(ServerId, Command, low, no_correlation)
This is the least reliable way to interact with a ra system ("fire and forget")
and should only be used for commands that are of little importance
and/or where waiting for a response is prohibitively slow.
See also: pipeline_command/4.
pipeline_command(ServerId::ra_server_id(), Command::term(), Correlation::ra_server:command_correlation() | no_correlation) -> ok
ServerId: the ra server id to send the command to
Command: an arbitrary term that the state machine can handle
Correlation: a correlation identifier to be included to receive an
async notification after the command is applied to the state machine.
Same as pipeline_command/4
but uses a hardcoded priority of low
.
See also: pipeline_command/4.
pipeline_command(ServerId::ra_server_id(), Command::term(), Correlation::ra_server:command_correlation() | no_correlation, Priority::normal | low) -> ok
ServerId: the ra server id to send the command to
Command: an arbitrary term that the state machine can handle
Correlation: a correlation identifier to be included to receive an
async notification after the command is applied to the state machine. If the
Correlation is set to no_correlation
then no notifications will be sent.
Priority: command priority. low
priority commands will be held back
and appended to the Raft log in batches. NB: A normal
priority command sent
from the same process can overtake a low priority command that was
sent before. There is no high priority.
Only use priority level of low
with commands that
do not rely on total execution ordering.
Submits a command to the ra server using a gen_statem:cast, passing an optional process-scoped term as correlation identifier. A correlation id can be included to implement reliable async interactions with the ra system. The calling process can retain a map of commands that have not yet been applied to the state machine successfully and resend them if a notification is not received withing some time window. When the submitted command(s) is applied to the state machine, the ra server will send the calling process a ra_event of the following structure:
{ra_event, CurrentLeader, {applied, [{Correlation, Reply}]}}
Ra will batch notification and thus return a list of correlation and result tuples.
If the receiving ra server is not the cluster leader, a ra event of the following structure will be returned informing the caller that it cannot process the message. The message will include the current cluster leader, if one is known:
{ra_event, FromId, {rejected, {not_leader, Leader | undefined, Correlation}}}
The caller must then redirect the command for the correlation identifier to the correct ra server: the leader.
If instead the atom no_correlation
is passed for the correlation argument,
the calling process will not receive any notification of command processing
success or otherwise.
process_command(ServerId::ra_server_id() | [ra_server_id()], Command::term()) -> {ok, Reply::term(), Leader::ra_server_id()} | {error, term()} | {timeout, ra_server_id()}
ServerId: the server id to send the command to
Command: an arbitrary term that the state machine can handle
Same as process_command/3
with the default timeout of 5000 ms.
process_command(ServerId::ra_server_id() | [ra_server_id()], Command::term(), Timeout::non_neg_integer()) -> {ok, Reply::term(), Leader::ra_server_id()} | {error, term()} | {timeout, ra_server_id()}
ServerId: the server id to send the command to
Command: an arbitrary term that the state machine can handle
Timeout: the time to wait before returning {timeout, ServerId}
Submits a command to a ra server. Returns after the command has
been applied to the Raft state machine. If the state machine returned a
response it is included in the second element of the response tuple.
If no response was returned the second element is the atom noreply
.
If the server receiving the command isn't the current leader it will
redirect the call to the leader (if known) or hold on to the command until
a leader is known. The leader's server id is returned as the 3rd element
of the success reply tuple.
register_external_log_reader(ServerId::ra_server_id()) -> ra_log_reader:state()
Registers an external log reader. ServerId needs to be local to the node. Returns an initiated ra_log_reader:state() state.
remove_member(ServerRef::ra_server_id() | [ra_server_id()], ServerId::ra_server_id()) -> ra_cmd_ret() | {error, not_member} | {error, cluster_change_not_permitted}
ServerRef: the ra server to send the command to
ServerId: the ra server id of the server to remove
Removes a server from the cluster's membership configuration. This function returns after appending a cluster membership change command to the log.
After a server is removed from its cluster and the membership change is replicated, it would reject any commands it's asked to process.See also: add_member/2, leave_and_delete_server/2, leave_and_terminate/2, remove_member/3.
remove_member(ServerRef::ra_server_id() | [ra_server_id()], ServerId::ra_server_id(), Timeout::timeout()) -> ra_cmd_ret() | {error, not_member} | {error, cluster_change_not_permitted}
Same as remove_member/2
but also accepts a timeout.
See also: remove_member/2.
restart_server(ServerId::ra_server_id()) -> ok | {error, term()}
ServerId: the ra_server_id() of the server
returns: {ok | error, Error}
when error can be
not_found
or name_not_registered
when the ra server has never before
been started on the Erlang node.
Restarts a previously successfully started ra server
start() -> ok
Starts the ra application.
start(Params::[environment_param()]) -> {ok, [Started]} | {error, term()}
Starts the ra application. If the application is running it will be stopped and restarted.
start_cluster(ServerConfigs::[ra_server:ra_server_config()]) -> {ok, [ra_server_id()], [ra_server_id()]} | {error, cluster_not_formed}
ServerConfigs: a list of initial server configurations
returns:
{ok, Started, NotStarted}
if a cluster could be successfully
started. A cluster can be successfully started if more than half of the
servers provided could be started. Servers that could not be started need to
be retried periodically using start_server/1
{error, cluster_not_formed}
if a cluster could not be started.
Starts a new distributed ra cluster.
start_cluster(ServerConfigs::[ra_server:ra_server_config()], Timeout::non_neg_integer()) -> {ok, [ra_server_id()], [ra_server_id()]} | {error, cluster_not_formed}
ServerConfigs: a list of initial server configurations
Timeout: the timeout to use
Same as start_cluster/1
but accepts a custom timeout.
start_cluster(ClusterName::ra_cluster_name(), Machine::ra_server:machine_conf(), ServerIds::[ra_server_id()]) -> {ok, [ra_server_id()], [ra_server_id()]} | {error, cluster_not_formed}
ClusterName: the name of the cluster.
Machine: The ra_machine:machine/0
configuration.
ServerIds: The list of ra server ids.
returns:
{ok, Started, NotStarted}
if a cluster could be successfully
started. A cluster can be successfully started if more than half of the
servers provided could be started. Servers that could not be started need to
be retried periodically using start_server/1
{error, cluster_not_formed}
if a cluster could not be started.
Starts a new distributed ra cluster.
start_cluster(ClusterName::ra_cluster_name(), Machine::ra_server:machine_conf(), ServerIds::[ra_server_id()], Timeout::non_neg_integer()) -> {ok, [ra_server_id()], [ra_server_id()]} | {error, cluster_not_formed}
ClusterName: the name of the cluster.
Machine: The ra_machine:machine/0
configuration.
ServerIds: The list of ra server ids.
Timeout: The time to wait for each server to start
returns:
{ok, Started, NotStarted}
if a cluster could be successfully
started. A cluster can be successfully started if more than half of the
servers provided could be started. Servers that could not be started need to
be retried periodically using start_server/1
{error, cluster_not_formed}
if a cluster could not be started.
Starts a new distributed ra cluster.
start_in(DataDir::file:filename()) -> {ok, [Started]} | {error, term()}
Starts the ra application with a provided data directory. The same as ra:start([{data_dir, dir}]) If the application is running it will be stopped and restarted.
start_or_restart_cluster(ClusterName::ra_cluster_name(), Machine::ra_server:machine_conf(), ServerIds::[ra_server_id()]) -> {ok, [ra_server_id()], [ra_server_id()]} | {error, cluster_not_formed}
ClusterName: the name of the cluster.
Machine: The ra_machine:machine/0
configuration.
ServerIds: The list of ra server ids.
returns:
{ok, Started, NotStarted}
if a cluster could be successfully
started. A cluster can be successfully started if more than half of the
servers provided could be started. Servers that could not be started need to
be retried periodically using start_server/1
{error, cluster_not_formed}
if a cluster could not be started.
Starts or restarts a ra cluster.
start_or_restart_cluster(ClusterName::ra_cluster_name(), Machine::ra_server:machine_conf(), RemServers::[ra_server_id()], Timeout::non_neg_integer()) -> {ok, [ra_server_id()], [ra_server_id()]} | {error, cluster_not_formed}
ClusterName: the name of the cluster.
Machine: The ra_machine:machine/0
configuration.
Timeout: The time to wait for any server to restart or start
returns:
{ok, Started, NotStarted}
if a cluster could be successfully
started. A cluster can be successfully started if more than half of the
servers provided could be started. Servers that could not be started need to
be retried periodically using start_server/1
{error, cluster_not_formed}
if a cluster could not be started.
Same as start_or_restart_cluster/3
but accepts a custom timeout.
See also: start_or_restart_cluster/3.
start_server(Conf::ra_server:ra_server_config()) -> ok | {error, term()}
Conf: a ra_server_config() configuration map.
returns: {ok | error, Error}
Starts a ra server
start_server(ClusterName::ra_cluster_name(), ServerId::ra_server_id(), Machine::ra_server:machine_conf(), ServerIds::[ra_server_id()]) -> ok | {error, term()}
ClusterName: the name of the cluster.
ServerId: the ra_server_id() of the server
Machine: The ra_machine:machine/0
configuration.
returns:
{ok, Started, NotStarted}
if a cluster could be successfully
started. A cluster can be successfully started if more than half of the
servers provided could be started. Servers that could not be started need to
be retried periodically using start_server/1
{error, cluster_not_formed}
if a cluster could not be started.
Starts a new distributed ra cluster.
See also: start_server/1.
stop_server(ServerId::ra_server_id()) -> ok | {error, nodedown}
ServerId: the ra_server_id() of the server
returns: {ok | error, nodedown}
Stops a ra server
transfer_leadership(ServerId::ra_server_id(), TargetServerId::ra_server_id()) -> ok | already_leader
Transfers leadership from the leader to a follower.
Returns already_leader
if the transfer targer is already the leader.
trigger_election(ServerId::ra_server_id()) -> ok
ServerId: the ra server id of the server to trigger the election on.
Makes the server to enter a pre-vote state and attempt to become the leader. It is necessary to call this function when starting a new cluster as a brand new Ra server (node) will not automatically enter the pre-vote state. This does not apply to recovering (previously started) servers: they will enter the pre-vote state and proceed to participate in an election on boot.
trigger_election(ServerId::ra_server_id(), Timeout::timeout()) -> ok
Same as trigger_election/2
but also accepts a timeout.
Generated by EDoc