PaxosKV.Proposer (paxos_kv v0.6.0)

Copy Markdown

Implements the Proposer role in the Paxos consensus algorithm.

The Proposer initiates consensus rounds by proposing values to Acceptors. It coordinates the two-phase protocol (prepare and accept phases) to reach consensus on a value for a given key. When contention is detected, it falls back to a primary proposer to ensure liveness.

Summary

Functions

Returns a specification to start this module under a supervisor.

Asks the local Proposer to convince the cluster about a value.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

handle_call(arg, from, state, try_round \\ 1)

propose(key, value, opts)

Asks the local Proposer to convince the cluster about a value.

When it detects that there are other Proposer(s) trying to do the same, and the liveness property of Paxos is in danger, it falls back to a primary proposer (running on a node that is determined by the key) instead of the local service.

Return values:

  • {:ok, value}: the value is the chosen (consensus) value for the key
  • {:error, :no_quorum}: there are't enough nodes participating in the cluster
  • {:error, :invalid_value}: the pid or node provided in opts is not alive

start_link(opts)