rafted_value v0.1.1 RaftedValue

Public interface functions of RaftedValue package.

Summary

Functions

Executes a command on the stored value of leader

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

command(leader, command_arg, timeout \\ 5000, id \\ make_ref)

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.

make_config(data_module, opts \\ [])

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 of RaftedValue.LeaderHook. Defaults to RaftedValue.LeaderHook.NoOp.
  • communication_module: A module to define member-to-member async communication (send_event/2 and reply/2). This is configurable for internal testing purpose. Defaults to :gen_fsm.
  • heartbeat_timeout: Raft’s heartbeat timeout in milliseconds. Defaults to 1000.
  • election_timeout: Raft’s leader election timeout in milliseconds. The acrual timeout value in each member is randomly chosen from election_timeout .. 2 * election_timeout. Defaults to 200.
  • 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 for election_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 of election_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 to 100.
  • max_retained_command_results: Number of command results to be cached, in order to prevent doubly applying the same command. Defaults to 100.
query(leader, query_arg, timeout \\ 5000)

Executes a read-only query on the stored value of leader.

remove_follower(leader, follower_pid)

Specs

remove_follower(GenServer.server, pid) ::
  :ok |
  {:error, remove_follower_error_reason}

Removes a follower from a consensus group.

replace_leader(current_leader, new_leader)

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.

start_link(info, name_or_nil \\ nil)

Specs

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 given Config.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.

status(server)

Specs

Retrieves status of a member in a consensus group.