rafted_value v0.1.1 RaftedValue
Public interface functions of RaftedValue
package.
Summary
Functions
Executes a command on the stored value of leader
Make a new instance of RaftedValue.Config
struct
Executes a read-only query on the stored value of leader
Removes a follower from a consensus group
Replaces current leader of a consensus group from current_leader
to new_leader
Starts a new member of consensus group
Retrieves status of a member in a consensus group
Types
command_identifier :: reference | any
consensus_group_info ::
{:create_new_consensus_group, RaftedValue.Config.t} |
{:join_existing_consensus_group, [GenServer.server]}
not_leader :: {:not_leader, nil | pid}
remove_follower_error_reason ::
:uncommitted_membership_change |
:not_member |
:pending_leader_change |
:will_break_quorum |
not_leader
replace_leader_error_reason ::
:uncommitted_membership_change |
:not_member |
:new_leader_unresponsive |
not_leader
status_result :: %{from: pid, members: [pid], leader: nil | pid, unresponsive_followers: [pid], current_term: RaftedValue.TermNumber.t, state_name: :leader | :candidate | :follower, config: RaftedValue.Config.t}
Functions
Specs
command(GenServer.server, RaftedValue.Data.command_arg, timeout, command_identifier) ::
{:ok, RaftedValue.Data.command_ret} |
{:error, not_leader}
Executes a command on the stored value of leader
.
id
is an identifier of the command and can be used to filter out duplicate requests.
Specs
make_config(atom, Keyword.t(any)) :: RaftedValue.Config.t
Make a new instance of RaftedValue.Config
struct.
data_module
must be an implementation of RaftedValue.Data
behaviour.
Available options:
leader_hook_module
: An implementation ofRaftedValue.LeaderHook
. Defaults toRaftedValue.LeaderHook.NoOp
.communication_module
: A module to define member-to-member async communication (send_event/2
andreply/2
). This is configurable for internal testing purpose. Defaults to:gen_fsm
.heartbeat_timeout
: Raft’s heartbeat timeout in milliseconds. Defaults to1000
.election_timeout
: Raft’s leader election timeout in milliseconds. The acrual timeout value in each member is randomly chosen fromelection_timeout .. 2 * election_timeout
. Defaults to200
.election_timeout_clock_drift_margin
: A time margin in milliseconds to judge whether leader lease has expired or not. When a leader gets responses from majority it gets a lease forelection_timeout - margin
. During the lease the leader can assume that no other members have elected leader. This enables the leader to skip message round trip during processing read-only query. Defaults to the value ofelection_timeout
(i.e. no lease time, disabling this clock-based optimization).max_retained_committed_lgos
: Number of committed log entries to keep in each member. Defaults to100
.max_retained_command_results
: Number of command results to be cached, in order to prevent doubly applying the same command. Defaults to100
.
Specs
query(GenServer.server, RaftedValue.Data.query_arg, timeout) ::
{:ok, RaftedValue.Data.query_ret} |
{:error, not_leader}
Executes a read-only query on the stored value of leader
.
Specs
remove_follower(GenServer.server, pid) ::
:ok |
{:error, remove_follower_error_reason}
Removes a follower from a consensus group.
Specs
replace_leader(GenServer.server, nil | pid) ::
:ok |
{:error, replace_leader_error_reason}
Replaces current leader of a consensus group from current_leader
to new_leader
.
Specs
start_link(consensus_group_info, atom) :: GenServer.on_start
Starts a new member of consensus group.
The 1st argument specifies the consensus group to belong to:
{:create_new_consensus_group, Config.t}
: Creates a new consensus group using the givenConfig.t
. The group’s only member is the newly-created process and it is spawned as the leader.{:join_existing_consensus_group, [servers]}
: Joins an already running consensus grouop as a new follower.
The second argument is (if given) used for name registration.
Specs
status(GenServer.server) :: status_result
Retrieves status of a member in a consensus group.