election

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// AlreadyLockedError indicates that the lock is already locked.
	AlreadyLockedError = errors.New("already locked")
	// NotLockedError indicates that the lock is not locked when trying to unlock.
	NotLockedError = errors.New("not locked")
)

Functions

This section is empty.

Types

type LeaderElectionCell

type LeaderElectionCell[T comparable] struct {
	// contains filtered or unexported fields
}

func NewLeaderElectionCell

func NewLeaderElectionCell[T comparable](key []string, ttl time.Duration) *LeaderElectionCell[T]

func (*LeaderElectionCell[T]) GetLeaderCondition added in v0.3.1

func (l *LeaderElectionCell[T]) GetLeaderCondition(dataValue T) agency.ConditionsMap

GetLeaderCondition creates a condition which is resolved to true only if current value in agency equals provided dataValue

func (*LeaderElectionCell[T]) Read

func (l *LeaderElectionCell[T]) Read(ctx context.Context, cli agency.Agency) (T, error)

func (*LeaderElectionCell[T]) Resign

func (l *LeaderElectionCell[T]) Resign(ctx context.Context, cli agency.Agency) error

Resign tries to resign leadership. If error is returned, caller should retry

func (*LeaderElectionCell[T]) Update

func (l *LeaderElectionCell[T]) Update(ctx context.Context, cli agency.Agency, value T) (T, bool, time.Duration, error)

Update checks the current leader cell and if no leader is present it tries to put itself in there. Will return the value currently present, whether we are leader and a duration after which Updated should be called again.

type Lock

type Lock interface {
	// Lock tries to lock the lock.
	// If it is not possible to lock, an error is returned.
	// If the lock is already held by me, an error is returned.
	Lock(ctx context.Context, cli agency.Agency) error

	// Unlock tries to unlock the lock.
	// If it is not possible to unlock, an error is returned.
	// If the lock is not held by me, an error is returned.
	Unlock(ctx context.Context, cli agency.Agency) error

	// IsLocked return true if the lock is held by me.
	IsLocked() bool
}

Lock is an agency backed exclusive lock.

func NewLock

func NewLock(log Logger, key []string, id string, ttl time.Duration) (Lock, error)

NewLock creates a new lock on the given key.

type Logger

type Logger interface {
	Errorf(msg string, args ...interface{})
}

Logger abstracts a logger.

Jump to

Keyboard shortcuts

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