writerlease

package
v3.10.13-1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lease

type Lease interface {
	// Wait waits for the first work function to complete and then returns whether the current
	// process is the leader. This function will block forever if no work has been requested or if the
	// work retries forever.
	Wait() bool
	// WaitUntil waits at most the provided duration for the frist work function to complete.
	// If the duration expires without work completing it will return false for expired, otherwise
	// it will return whether the lease is held by this process.
	WaitUntil(t time.Duration) (leader bool, ok bool)
	// Try runs the provided function when the lease is held is the leader. It retries work until
	// the work func indicates retry is not necessary.
	Try(key string, fn WorkFunc)
	// Extend indicates that the caller has observed another writer performing work against
	// the specified key. This will clear the work remaining for the lease and extend the lease
	// interval.
	Extend(key string)
	// Remove clears any pending work for the provided key.
	Remove(key string)
}

Lease performs the equivalent of leader election by competing to perform work (such as updating a contended resource). Every successful work unit is considered a lease renewal, while work that is observed from others or that fails is treated as renewing another processes lease. When a lease expires (no work is detected within the lease term) the writer competes to perform work. When competing for the lease, exponential backoff is used.

type State

type State int

State is the state of the lease.

const (
	// Election is before a work unit has been completed.
	Election State = iota
	Leader
	Follower
)

type WorkFunc

type WorkFunc func() (result WorkResult, retry bool)

WorkFunc is a retriable unit of work. It should return an error if the work couldn't be completed successfully, or true if we can assume our lease has been extended. If the lease could not be extended, we drop this unit of work.

func LimitRetries

func LimitRetries(retries int, fn WorkFunc) WorkFunc

LimitRetries allows a work function to be retried up to retries times.

type WorkResult

type WorkResult int
const (
	None WorkResult = iota
	Extend
	Release
)

type WriterLease

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

func New

func New(leaseDuration, retryInterval time.Duration) *WriterLease

New creates a new Lease. Specify the duration to hold leases for and the retry interval on requests that fail.

func NewWithBackoff

func NewWithBackoff(name string, leaseDuration, retryInterval time.Duration, backoff wait.Backoff) *WriterLease

NewWithBackoff creates a new Lease. Specify the duration to hold leases for and the retry interval on requests that fail.

func (*WriterLease) Expire

func (l *WriterLease) Expire()

func (*WriterLease) Extend

func (l *WriterLease) Extend(key string)

func (*WriterLease) Len

func (l *WriterLease) Len() int

func (*WriterLease) Remove

func (l *WriterLease) Remove(key string)

func (*WriterLease) Run

func (l *WriterLease) Run(stopCh <-chan struct{})

func (*WriterLease) Try

func (l *WriterLease) Try(key string, fn WorkFunc)

func (*WriterLease) Wait

func (l *WriterLease) Wait() bool

func (*WriterLease) WaitUntil

func (l *WriterLease) WaitUntil(t time.Duration) (bool, bool)

Jump to

Keyboard shortcuts

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