leader

package
v0.0.0-...-12af3c0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAlreadyExist

func IsAlreadyExist(err error) bool

IsAlreadyExist determines if the specified error identifies a duplicate node event

func IsNotFound

func IsNotFound(err error) bool

IsNotFound determines if the specified error identifies a node not found event

func IsWatchExpired

func IsWatchExpired(err error) bool

IsWatchExpired determins if the specified error identifies an expired watch event

func NewUnlimitedExponentialBackOff

func NewUnlimitedExponentialBackOff() *backoff.ExponentialBackOff

NewUnlimitedExponentialBackOff returns a new exponential backoff interval w/o time limit

Types

type CallbackFn

type CallbackFn func(key, prevValue, newValue string)

CallbackFn specifies callback that is called by AddWatchCallback whenever leader changes

type Client

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

Client implements ETCD-backed leader election client that helps to elect new leaders for a given key and monitors the changes to the leaders

func NewClient

func NewClient(cfg Config) (*Client, error)

NewClient returns a new instance of leader election client

func (*Client) AddVoter

func (l *Client) AddVoter(context context.Context, key, value string, term time.Duration) error

AddVoter starts a goroutine that attempts to set the specified key to to the given value with the time-to-live value specified with term. The time-to-live value cannot be less than a second. After successfully setting the key, it attempts to renew the lease for the specified term indefinitely

func (*Client) AddWatch

func (l *Client) AddWatch(key string, retry time.Duration, valuesC chan string)

AddWatch starts watching the key for changes and sending them to the valuesC, the watch is stopped

func (*Client) AddWatchCallback

func (l *Client) AddWatchCallback(key string, retry time.Duration, fn CallbackFn)

AddWatchCallback adds the given callback to be invoked when changes are made to the specified key's value. The callback is called with new and previous values for the key. In the first call, both values are the same and reflect the value of the key at that moment

func (*Client) Close

func (l *Client) Close() error

Close stops current operations and releases resources

func (*Client) StepDown

func (l *Client) StepDown()

StepDown makes this participant to pause his attempts to re-elect itself thus giving up its leadership

type Config

type Config struct {
	// ETCD defines etcd configuration, client will be instantiated
	// if passed
	ETCD *config.Config
	// Clock is a time provider
	Clock clockwork.Clock
	// Client is ETCD client will be used if passed
	Client client.Client
}

Config sets leader election configuration options

Jump to

Keyboard shortcuts

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