election

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2021 License: Apache-2.0 Imports: 8 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 ...primitive.Option) (Election, error)
}

Client provides an API for creating Elections

type Election

type Election interface {
	primitive.Primitive

	// ID returns the election identifier
	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, ch chan<- Event) error
}

Election provides distributed leader election

func New

func New(ctx context.Context, name string, conn *grpc.ClientConn, opts ...primitive.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 (
	// EventChange indicates the election term changed
	EventChange EventType = "change"
)

type Option

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

Option is a election option

type Term

type Term struct {
	meta.ObjectMeta

	// 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