leases

package
v0.412.6 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrConflict = errors.New("lease already held")

ErrConflict is returned when a lease is already held.

Functions

This section is empty.

Types

type FakeLease

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

func (*FakeLease) Release

func (f *FakeLease) Release() error

func (*FakeLease) String

func (f *FakeLease) String() string

type FakeLeaser

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

FakeLeaser is a fake implementation of the Leaser interface.

func NewFakeLeaser

func NewFakeLeaser() *FakeLeaser

func (*FakeLeaser) AcquireLease

func (f *FakeLeaser) AcquireLease(ctx context.Context, key Key, ttl time.Duration) (Lease, context.Context, error)

type Key

type Key []string

Key is a unique identifier for a lease.

It is a / separated list of strings where each element is URL-path-escaped.

Userspace leases are always in the form "/module/<module>/..." (eg. "/module/idv/user/bob"). Internal leases are always in the form "/system/..." (eg. "/system/runner/deployment-reservation/<deployment").

Keys should always be created using the SystemKey or ModuleKey functions.

func ModuleKey

func ModuleKey(module string, parts ...string) Key

ModuleKey creates a user-space module key.

func ParseLeaseKey

func ParseLeaseKey(s string) (Key, error)

func SystemKey

func SystemKey(parts ...string) Key

SystemKey creates an internal system key.

func (*Key) Scan

func (l *Key) Scan(dest any) error

func (Key) String

func (l Key) String() string

func (*Key) Value

func (l *Key) Value() (driver.Value, error)

type Lease

type Lease interface {
	Release() error
}

Lease represents a lease that is held by a controller.

var NoopLease Lease = noopLease{}

NoopLease is a no-op implementation of Lease.

type Leaser

type Leaser interface {
	// AcquireLease attempts to acquire a new lease.
	//
	// A lease is a mechanism to ensure that only one controller is performing a
	// specific task at a time. The lease is held for a specific duration, and must
	// be renewed periodically to prevent it from expiring. If the lease expires, it
	// is released and another controller can acquire it.
	//
	// The lease is automatically renewed in the background, and can be
	// released by calling the [Lease.Release] method.
	//
	// This function will return [ErrConflict] if a lease is already held. The [ttl]
	// must be at _least_ 5 seconds.
	//
	// The returned context will be cancelled when the lease fails to renew.
	AcquireLease(ctx context.Context, key Key, ttl time.Duration) (Lease, context.Context, error)
}

Leaser is an interface for acquiring, renewing and releasing leases.

func NewClientLeaser

func NewClientLeaser(ctx context.Context) Leaser

Jump to

Keyboard shortcuts

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