flocklease

package
v0.0.32 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 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 only the exact current, unexpired, locally retained generation. Expiry or replacement is definitive loss: the local generation handle is relinquished and ErrLeaseHeld is returned.

Jump to

Keyboard shortcuts

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