polity

package
v0.0.0-...-54674d8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2014 License: MIT Imports: 8 Imported by: 0

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

View Source
var (
	ErrAborted      = errors.New("election aborted")
	ErrLostElection = errors.New("lost election")
	ErrRoleUnfilled = errors.New("cannot recall unfilled role")
)

Errors

View Source
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 Create

func Create(s *serf.Serf, eventCh <-chan serf.Event) *Polity

Create initializes a polity based on a serf instance and event channel.

func CreateWithAgent

func CreateWithAgent(a *agent.Agent) *Polity

CreateWithAgent initializes a polity based on a serf.Agent. The polity will register a handler to receive events.

func (*Polity) QueryRole

func (p *Polity) QueryRole(role string) (string, error)

QueryRole submits a query to the cluster asking which node, if any, has a particular role.

func (*Polity) RunElection

func (p *Polity) RunElection(role string) <-chan error

RunElection initiates an election for role with the local node as the candidate.

func (*Polity) RunRecallElection

func (p *Polity) RunRecallElection(role string) <-chan error

RunRecallElection starts a vote to empty a role.

func (*Polity) Serf

func (p *Polity) Serf() *serf.Serf

Serf returns the polity's underlying serf instance.

type QuorumFunc

type QuorumFunc func(population int) (votesRequired int)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL