Documentation ¶
Index ¶
- type Lease
- type State
- type WorkFunc
- type WriterLease
- func (l *WriterLease) Expire()
- func (l *WriterLease) Extend(key string)
- func (l *WriterLease) Len() int
- func (l *WriterLease) Remove(key string)
- func (l *WriterLease) Run(stopCh <-chan struct{})
- func (l *WriterLease) Try(key string, fn WorkFunc)
- func (l *WriterLease) Wait() bool
- func (l *WriterLease) WaitUntil(t time.Duration) (bool, bool)
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 WorkFunc ¶
type WorkFunc func() (extendLease, 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 ¶
LimitRetries allows a work function to be retried up to retries times.
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