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

memlease

package
v0.18.1 Latest Latest
Warning

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

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

Documentation

Overview

Package memlease is the in-memory reference port.SessionLease: the offline, clock-injected single-writer lease the conformance suite validates and that composition can wire as the default-store opt-in. It keeps per-session lease records in a mutex-guarded map and derives expiry from an injected port.Clock, so tests advance a fake clock past the TTL to exercise expiry/takeover without real sleeps.

It is the reference for the SAME port.SessionLease contract the flock, gRPC-driver, and k8s adapters implement; the contract is the port, the in-memory map is one adapter.

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 concurrency-safe in-memory SessionLease. The token counter is per-id monotone (advanced on every takeover), so a successful takeover always returns a strictly greater token than any prior grant for that id.

func New

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

New constructs an in-memory lease with the given TTL and clock. A nil clock or a non-positive ttl is a programming error at the only construction sites (composition, tests), so they are not defended here beyond a sane default ttl.

func (*Lease) Acquire

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

Acquire grants the lease for id to owner when it is free, expired, or already held by owner; otherwise it returns ErrLeaseHeld. A takeover bumps the per-id token strictly past any prior grant; a same-owner re-acquire keeps the existing token (the hold is unchanged, only the expiry refreshes).

func (*Lease) Release

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

Release relinquishes a lease the caller holds (owner + token match); it is idempotent (an unknown id or a mismatched owner/token is a no-op success).

func (*Lease) Renew

func (l *Lease) Renew(_ context.Context, in port.Lease) (port.Lease, error)

Renew extends a lease the caller still holds (owner + token match, unexpired), returning the refreshed lease with the SAME token and a new expiry. Otherwise it returns ErrLeaseHeld (the loss signal).

Jump to

Keyboard shortcuts

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