Documentation ¶
Overview ¶
Package polity implements strong consensus, heavily inspired by raft, over a gossip-based network (serf).
With a polity, you can run elections to elect the current node into a unique role. The election will broadcast to all peers that it would like to assume a role. If the remote node sees that role as unfilled, it will vote for the candidate and fill the role, otherwise it will vote no.
By default, the quorum required is (n/2)+1 where n is the maximum population known of all nodes that voted. (This is configurable by providing a different QuorumFunc to a Polity.)
A node will hold a position until it is recalled. Nodes will always vote yes to a recall, but a quorum must still reply for the recall to succeed.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrAborted = errors.New("election aborted") ErrLostElection = errors.New("lost election") ErrRoleUnfilled = errors.New("cannot recall unfilled role") )
Errors
var SimpleMajority = QuorumPercentage(.5, 3)
SimpleMajority is a QuorumFunc that requires 50% + 1 nodes, with a minimum of 3.
Functions ¶
This section is empty.
Types ¶
type LamportWindow ¶
type LamportWindow struct {
// contains filtered or unexported fields
}
LamportWindow is an interval of Lamport Times.
func (*LamportWindow) After ¶
func (l *LamportWindow) After(t serf.LamportTime) bool
After tests if t is after l.
func (*LamportWindow) Before ¶
func (l *LamportWindow) Before(t serf.LamportTime) bool
Before tests if t is before l.
func (*LamportWindow) Witness ¶
func (l *LamportWindow) Witness(other serf.LamportTime)
Witness grows l to encompass other.
type Polity ¶
type Polity struct { Log *log.Logger QuorumFunc QuorumFunc // contains filtered or unexported fields }
Polity represents a distributed cluster capable of electing nodes for particular roles.
func CreateWithAgent ¶
CreateWithAgent initializes a polity based on a serf.Agent. The polity will register a handler to receive events.
func (*Polity) QueryRole ¶
QueryRole submits a query to the cluster asking which node, if any, has a particular role.
func (*Polity) RunElection ¶
RunElection initiates an election for role with the local node as the candidate.
func (*Polity) RunRecallElection ¶
RunRecallElection starts a vote to empty a role.
type QuorumFunc ¶
QuorumFunc is a function that determines how many votes are required to establish a voting quorum.
func QuorumPercentage ¶
func QuorumPercentage(minimumPercent float64, minimumVotes int) QuorumFunc
QuorumPercentage creates a QuorumFunc requires a minimum percentage of votes equal to or above a minimum number of votes.