leader

package
v0.0.0-...-a355528 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2017 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckLeaderFunc

type CheckLeaderFunc func() (bool, error)

CheckLeaderFunc is all that a special backend needs to implement. It can be used with the NewPoller function to return a polling implementation of the Detector interface. This function returns true or false for leadership when there are no errors. Returned error is reported and the status of the event will be set to `Unknown`.

func Always

func Always(leader bool) CheckLeaderFunc

Always is a trivial implementation that asserts the current instance to always be the leader (or not)

type Detector

type Detector interface {

	// Start starts leadership detection
	Start() (<-chan Leadership, error)

	// Receive allocates a channel for the caller to receive on. Messages are sent to all receivers.
	Receive() <-chan Leadership

	// Stop stops
	Stop()
}

Detector is the interface for determining whether this instance is a leader

type Leadership

type Leadership struct {
	Status Status
	Error  error
}

Leadership is a struct that captures the leadership state, possibly error if exception occurs

type Poller

type Poller struct {
	// contains filtered or unexported fields
}

Poller is the entity that polls for different backend / control planes to determine leadership

func NewPoller

func NewPoller(pollInterval time.Duration, f CheckLeaderFunc) *Poller

NewPoller returns a detector implementation given the poll interval and function that polls

func (*Poller) Receive

func (l *Poller) Receive() <-chan Leadership

Receive returns a channel to receive on. It broadcasts so that all channel receivers will get the same message.

func (*Poller) Start

func (l *Poller) Start() (<-chan Leadership, error)

Start implements Detect.Start

func (*Poller) Stop

func (l *Poller) Stop()

Stop implements Detect.Stop

type Status

type Status int

Status indicates leadership status

const (
	// NotLeader means the current node is not a leader
	NotLeader Status = iota

	// Leader means the current node / instance is a leader
	Leader

	// Unknown indicates some exception happened while determining leadership.  Consumer will interpret accordingly.
	Unknown
)

type Store

type Store interface {

	// UpdateLocation sets the leader to the given URL
	UpdateLocation(*url.URL) error

	// GetLocation returns the location of the current leader.  It's possible that the leader location isn't
	// known despite no errors in querying.  So the url can be nil
	GetLocation() (*url.URL, error)
}

Store is an interface implemented by the environment that supports storing and retrieving the current leader location

Directories

Path Synopsis
etcd
v3

Jump to

Keyboard shortcuts

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