flocklease

package
v0.0.37 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package flocklease is the single-host port.SessionLease implementation. It combines the generic expiry contract with immediate same-host crash detection: a stable per-session flock serializes record transitions only, while each lease generation retains its own liveness flock for the generation's lifetime.

Layout per session id <safeID> under the lease dir:

  • <safeID>.lock — stable, operation-scoped transition lock.
  • <safeID>.<token>.live — generation-specific retained liveness lock.
  • <safeID>.lease.json — atomic {owner, token, expiry} record.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lease

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

Lease is a single-host port.SessionLease over a lease directory.

func New

func New(dir string, ttl time.Duration, clock port.Clock) (*Lease, error)

New constructs a single-host lease rooted at dir. A non-positive ttl defaults to 30 seconds.

func (*Lease) Acquire

func (l *Lease) Acquire(ctx context.Context, id session.SessionID, owner string) (out port.Lease, err error)

Acquire serializes the record transition under the stable lock. An unexpired record is held only while its generation lock is live; a crashed holder can be replaced immediately. An expired record can always be replaced, even if its old process remains alive.

func (*Lease) Release

func (l *Lease) Release(ctx context.Context, in port.Lease) (err error)

Release tombstones and closes only the exact current generation. A stale release cannot alter or unlock a successor. If writing or closing fails, the retained handle remains tracked so a later call can retry cleanup.

func (*Lease) Renew

func (l *Lease) Renew(ctx context.Context, in port.Lease) (out port.Lease, err error)

Renew extends the exact current, locally retained generation, identified by matching owner+token in the durable record — read under the same stable transition lock Acquire/Release use to serialize takeovers. A record whose owner or token no longer match is definitive loss (a genuine competitor took over): the local generation handle is relinquished and ErrLeaseHeld is returned. Bare EXPIRY with the record still naming the caller at the caller's token is NOT, by itself, loss: on a single host that can only be true if nobody else raced an Acquire/takeover in the interim (issue #1333 — a process suspended past the TTL, e.g. laptop sleep, must not lose the lease to a competitor that never ran). Renew reclaims it with a fresh expiry instead, keeping the token unchanged. `held == nil` still hard-fails regardless of the record: it means a PRIOR Renew already declared loss and tore down local state.

Jump to

Keyboard shortcuts

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