elector_strategy_behaviour behaviour (elector v0.3.3)

View Source

Defines the base behaviour for election strategies.

Summary

Functions

Returns the candidate nodes for the next election.

Starts the election process by triggering the strategy modules elect() function. The election implementation should only contain the logic for selecting the leader node and returning the leader node name. The elect/0 function is triggered on all nodes automatically by the elector application. This means the strategy implementation does not have to worry about starting the election on all nodes.

Returns whether the local node is currently a candidate. Exported so remote nodes can query it via erpc from candidate_nodes/0.

Types

candidate_nodes/0

-type candidate_nodes() :: [node()].

leader/0

-type leader() :: node().

Callbacks

elect/1

-callback elect(CandidateNodes :: candidate_nodes()) -> Leader :: leader().

Functions

candidate_nodes()

-spec candidate_nodes() -> CandidateNodes :: candidate_nodes().

Returns the candidate nodes for the next election.

Queries each connected node live (in parallel) for its current candidate status. The async candidate cache races with candidate_status propagation during cluster join — a node electing against an unpopulated cache self-elects and the wrong leader can stick — so we ask the source of truth on every election instead.

elect()

-spec elect() -> Leader :: leader().

Starts the election process by triggering the strategy modules elect() function. The election implementation should only contain the logic for selecting the leader node and returning the leader node name. The elect/0 function is triggered on all nodes automatically by the elector application. This means the strategy implementation does not have to worry about starting the election on all nodes.

is_local_candidate()

-spec is_local_candidate() -> boolean().

Returns whether the local node is currently a candidate. Exported so remote nodes can query it via erpc from candidate_nodes/0.