lock

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LeaseName

func LeaseName(key ResourceKey) string

LeaseName returns the deterministic lease name for a resource.

Types

type ErrAlreadyLocked

type ErrAlreadyLocked struct {
	LeaseName string
	Holder    string
}

ErrAlreadyLocked indicates that a resource is locked by a different transaction.

func (*ErrAlreadyLocked) Error

func (e *ErrAlreadyLocked) Error() string

type ErrLockExpired

type ErrLockExpired struct {
	LeaseName string
}

ErrLockExpired indicates that a lock lease has expired.

func (*ErrLockExpired) Error

func (e *ErrLockExpired) Error() string

type LeaseManager

type LeaseManager struct {
	Client client.Client
}

LeaseManager implements Manager using coordination.k8s.io/v1 Lease objects.

func (*LeaseManager) Acquire

func (m *LeaseManager) Acquire(ctx context.Context, key ResourceKey, txnName string, timeout time.Duration) (string, error)

func (*LeaseManager) Release

func (m *LeaseManager) Release(ctx context.Context, lease LeaseRef, txnName string) error

func (*LeaseManager) ReleaseAll

func (m *LeaseManager) ReleaseAll(ctx context.Context, leases []LeaseRef, txnName string) error

func (*LeaseManager) Renew

func (m *LeaseManager) Renew(ctx context.Context, lease LeaseRef, txnName string, timeout time.Duration) error

type LeaseOpError

type LeaseOpError struct {
	Op        string // e.g. "creating", "getting", "deleting", "renewing", "taking over"
	LeaseName string
	Err       error
}

LeaseOpError wraps a Kubernetes API error with lease operation context.

func (*LeaseOpError) Error

func (e *LeaseOpError) Error() string

func (*LeaseOpError) Unwrap

func (e *LeaseOpError) Unwrap() error

type LeaseRef

type LeaseRef struct {
	Name      string
	Namespace string
}

LeaseRef identifies a Lease object by name and namespace.

type Manager

type Manager interface {
	// Acquire creates or takes over a Lease lock for the given resource.
	// Returns the lease name on success.
	Acquire(ctx context.Context, key ResourceKey, txnName string, timeout time.Duration) (string, error)

	// Release deletes a single Lease lock if held by the given transaction.
	// If the lease is held by a different transaction, the call is a no-op.
	Release(ctx context.Context, lease LeaseRef, txnName string) error

	// ReleaseAll releases multiple leases, returning the first error encountered.
	ReleaseAll(ctx context.Context, leases []LeaseRef, txnName string) error

	// Renew extends the lease duration for a lock held by the given transaction.
	// Returns an error if the lease is not found, expired, or held by a different transaction.
	Renew(ctx context.Context, lease LeaseRef, txnName string, timeout time.Duration) error
}

Manager manages Lease-based advisory locks for transaction resources.

type ResourceKey

type ResourceKey struct {
	Namespace string
	Kind      string
	Name      string
}

ResourceKey identifies a Kubernetes resource for locking purposes.

Jump to

Keyboard shortcuts

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