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 ¶
- Variables
- func Create(ctx context.Context, s store.Store, it item.Item) error
- func Load(ctx context.Context, s store.Store, key string) (item.Item, string, error)
- type Holder
- func (h *Holder) Epoch() int64
- func (h *Holder) Expired() bool
- func (h *Holder) Heartbeat(ctx context.Context, interval time.Duration, onRenewed func(item.Item), ...)
- func (h *Holder) Item() item.Item
- func (h *Holder) Release(ctx context.Context) error
- func (h *Holder) Renew(ctx context.Context) error
- func (h *Holder) Save(ctx context.Context, it item.Item) error
- func (h *Holder) StepID() string
Constants ¶
This section is empty.
Variables ¶
var ErrHeld = errors.New("lease: held by another owner")
ErrHeld means another owner holds a live lease on the item.
var ErrLost = errors.New("lease: lost")
ErrLost means this holder no longer owns the item; it must stop and write nothing more.
Functions ¶
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) Expired ¶
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.