Help us shape the future of Go! Take the 2026 Go Developer Survey

lease

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package lease gives one ynf instance an exclusive, fault-tolerant claim on a work item (ADR-005): a compare-and-swap on the item document that bumps an epoch, a heartbeat that renews it, and fencing so a holder that lost its lease without knowing cannot write.

Index

Constants

This section is empty.

Variables

View Source
var ErrHeld = errors.New("lease: held by another owner")

ErrHeld means another owner holds a live lease on the item.

View Source
var ErrLost = errors.New("lease: lost")

ErrLost means this holder no longer owns the item; it must stop and write nothing more.

Functions

func Create

func Create(ctx context.Context, s store.Store, it item.Item) error

Create writes a new item document; ErrConflict if one exists.

func Load

func Load(ctx context.Context, s store.Store, key string) (item.Item, string, error)

Load reads an item document.

Types

type Holder

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

Holder is a live claim on one item.

func Claim

func Claim(ctx context.Context, s store.Store, key, owner, stepID string, ttl time.Duration, now func() time.Time) (*Holder, error)

Claim takes the item if no live lease is held on it. stepID identifies this step's side effects (ADR-005: idempotency per step).

func (*Holder) Epoch

func (h *Holder) Epoch() int64

Epoch is this claim's epoch.

func (*Holder) Expired

func (h *Holder) Expired() bool

Expired reports whether this claim took over a lease that had run out, which means its holder died or stalled without releasing it.

func (*Holder) Heartbeat

func (h *Holder) Heartbeat(ctx context.Context, interval time.Duration, onRenewed func(item.Item), onLost func(error))

Heartbeat renews every interval until ctx ends, calling onRenewed (if set) with the item after each renewal. If a renewal fails, it calls onLost once and returns: the holder must stop the work it is doing.

func (*Holder) Item

func (h *Holder) Item() item.Item

Item returns the item as this holder last wrote it.

func (*Holder) Release

func (h *Holder) Release(ctx context.Context) error

Release clears the lease, keeping the item as last saved.

func (*Holder) Renew

func (h *Holder) Renew(ctx context.Context) error

Renew extends the lease. A holder whose renewal fails must stop.

func (*Holder) Save

func (h *Holder) Save(ctx context.Context, it item.Item) error

Save writes the item, fenced: it fails with ErrLost unless this holder's version is still current, which is only true while no one else has claimed the item.

func (*Holder) StepID

func (h *Holder) StepID() string

StepID is this claim's step id.

Jump to

Keyboard shortcuts

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