election

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const Type primitive.Type = "Election"

Type is the election type

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// GetElection gets the Election instance of the given name
	GetElection(ctx context.Context, name string, opts ...Option) (Election, error)
}

Client provides an API for creating Elections

type Election

type Election interface {
	primitive.Primitive

	// ID returns the ID of the instance of the election
	ID() string

	// GetTerm gets the current election term
	GetTerm(ctx context.Context) (*Term, error)

	// Enter enters the instance into the election
	Enter(ctx context.Context) (*Term, error)

	// Leave removes the instance from the election
	Leave(ctx context.Context) (*Term, error)

	// Anoint assigns leadership to the instance with the given ID
	Anoint(ctx context.Context, id string) (*Term, error)

	// Promote increases the priority of the instance with the given ID in the election queue
	Promote(ctx context.Context, id string) (*Term, error)

	// Evict removes the instance with the given ID from the election
	Evict(ctx context.Context, id string) (*Term, error)

	// Watch watches the election for changes
	Watch(ctx context.Context, c chan<- *Event) error
}

Election provides distributed leader election

func New

func New(ctx context.Context, name primitive.Name, partitions []*primitive.Session, opts ...Option) (Election, error)

New creates a new election primitive

type Event

type Event struct {
	// Type is the type of the event
	Type EventType

	// Term is the term that occurs as a result of the election event
	Term Term
}

Event is an election event

type EventType

type EventType string

EventType is the type of an Election event

const (
	// EventChanged indicates the election term changed
	EventChanged EventType = "changed"
)

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is an election option

func WithID

func WithID(id string) Option

WithID sets the election instance identifier

type Term

type Term struct {
	// ID is a globally unique, monotonically increasing term number
	ID uint64

	// Leader is the ID of the leader that was elected
	Leader string

	// Candidates is a list of candidates currently participating in the election
	Candidates []string
}

Term is a leadership term A term is guaranteed to have a monotonically increasing, globally unique ID.

Jump to

Keyboard shortcuts

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