lease

package
v1.3.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package lease provides a small, correctness-first DynamoDB lease/lock helper.

It is designed for ISR-style regeneration locks (FaceTheory) and similar distributed coordination needs.

Index

Constants

View Source
const (
	DefaultPKAttribute        = "pk"
	DefaultSKAttribute        = "sk"
	DefaultTokenAttribute     = "lease_token"
	DefaultExpiresAtAttribute = "lease_expires_at"
	DefaultTTLAttribute       = "ttl"
	DefaultLockSortKey        = "LOCK"
	DefaultTTLBuffer          = time.Hour
)

Variables

This section is empty.

Functions

func IsLeaseHeld

func IsLeaseHeld(err error) bool

func IsLeaseNotOwned

func IsLeaseNotOwned(err error) bool

Types

type DynamoDBLeaseAPI

type DynamoDBLeaseAPI interface {
	PutItem(ctx context.Context, params *dynamodb.PutItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.PutItemOutput, error)
	UpdateItem(ctx context.Context, params *dynamodb.UpdateItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.UpdateItemOutput, error)
	DeleteItem(ctx context.Context, params *dynamodb.DeleteItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.DeleteItemOutput, error)
}

type Key

type Key struct {
	PK string
	SK string
}

type Lease

type Lease struct {
	Key       Key
	Token     string
	ExpiresAt int64
}

type LeaseHeldError

type LeaseHeldError struct {
	Key Key
}

LeaseHeldError indicates a lease could not be acquired because it is held by another contender. This is the "expected" failure mode for lock contention.

func (*LeaseHeldError) Error

func (e *LeaseHeldError) Error() string

type LeaseNotOwnedError

type LeaseNotOwnedError struct {
	Key Key
}

LeaseNotOwnedError indicates a refresh attempt failed because the caller's token no longer owns the lease. This can happen if the lease expired and was acquired by another contender, or if the token is wrong.

func (*LeaseNotOwnedError) Error

func (e *LeaseNotOwnedError) Error() string

type Manager

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

func NewManager

func NewManager(client DynamoDBLeaseAPI, tableName string, opts ...Option) (*Manager, error)

func (*Manager) Acquire

func (m *Manager) Acquire(ctx context.Context, pk string, duration time.Duration) (*Lease, error)

func (*Manager) AcquireKey

func (m *Manager) AcquireKey(ctx context.Context, key Key, duration time.Duration) (*Lease, error)

func (*Manager) Refresh

func (m *Manager) Refresh(ctx context.Context, lease Lease, duration time.Duration) (*Lease, error)

func (*Manager) Release

func (m *Manager) Release(ctx context.Context, lease Lease) error

type Option

type Option func(*Manager)

func WithIncludeTTL

func WithIncludeTTL(include bool) Option

func WithKeyAttributeNames

func WithKeyAttributeNames(pkAttr, skAttr string) Option

func WithLeaseAttributeNames

func WithLeaseAttributeNames(tokenAttr, expiresAtAttr, ttlAttr string) Option

func WithLockSortKey

func WithLockSortKey(lockSortKey string) Option

func WithNow

func WithNow(now func() time.Time) Option

func WithTTLBuffer

func WithTTLBuffer(buffer time.Duration) Option

func WithTokenGenerator

func WithTokenGenerator(token func() string) Option

func WithValidateInput

func WithValidateInput(validate bool) Option

Jump to

Keyboard shortcuts

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