leader

package
v0.0.0-...-9889f28 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2021 License: Apache-2.0 Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAlreadyExists

func IsAlreadyExists(err error) bool

IsAlreadyExists determines if the specified error identifies a duplicate node event

func IsContextError

func IsContextError(err error) bool

IsContextError returns true if the provided error indicates a canceled or expired context.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound determines if the specified error identifies a not found error

func IsWatchExpired

func IsWatchExpired(err error) bool

IsWatchExpired determines 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(ctx context.Context, key, prevValue, newValue string)

CallbackFn specifies callback that is called by AddWatchCallback whenever leader changes

type Client

type Client struct {
	Config
	// 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(ctx context.Context, key, value string, term time.Duration)

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. The method is idempotent and does nothing if invoked multiple times

func (*Client) AddWatch

func (l *Client) AddWatch(key string, valuesC chan string)

AddWatch starts watching the key for changes and sending them to the valuesC until the client is stopped.

func (*Client) AddWatchCallback

func (l *Client) AddWatchCallback(key string, 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) RemoveVoter

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

RemoveVoter stops the voting loop.

func (*Client) StepDown

func (l *Client) StepDown(ctx context.Context)

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

type Config

type Config struct {
	// Client is the ETCD client to use
	Client client.Client
	// contains filtered or unexported fields
}

Config sets leader election configuration options

Jump to

Keyboard shortcuts

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