lease

package
v0.165.0 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: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package lease holds the machine's shared resources, one holder at a time: kind labs, shared installations, the browser. A lease is a directory (mkdir is atomic) holding the holder's record; the record's fields are the ones the lab's earlier shell lock wrote, so both read the same directory.

While a supervisor is recorded, a free lease is not permission: a session claims only what the supervisor granted it, in the order the grants were given, from the supervisor's start to a deliberate stop, whether its session runs or has crashed. Grants live in the state document.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(st *state.State, g Gate) (int, error)

Check decides whether the caller may claim and, when a grant carries the claim, returns its index in st.Grants (-1 when none is needed). While an upgrade runs on the installation of the resource's name only an upgrade-unblock grant admits a claim, in grant order.

func LabDiff added in v0.160.0

func LabDiff(was, now []byte) ([]string, error)

LabDiff names the keys in which two agentlab.yaml files differ, as dotted paths to the first value that is no map (a list is one value), sorted.

func Pending

func Pending(st *state.State, res string, held bool, now time.Time, ttl time.Duration) []state.Grant

Pending returns the grants of res still claimable, in order.

func Prune

func Prune(st *state.State, held map[string]bool, now time.Time, ttl time.Duration)

Prune drops the grants whose time ran out; held says which resources are held right now (their grants wait without expiring).

func ToHead added in v0.148.0

func ToHead(st *state.State, i int, now time.Time) int

ToHead moves st.Grants[i] before every other grant of its resource, as given at now: the grants it passes keep their order behind it. It returns the grant's new index.

Types

type Dir

type Dir string

Dir is the lease directory.

func (Dir) Claim

func (d Dir) Claim(res string, h Holder) (*Holder, error)

Claim takes res for h. It returns the current holder instead when res is held already.

func (Dir) ClaimedLabConfig added in v0.160.0

func (d Dir) ClaimedLabConfig(res string) ([]byte, error)

ClaimedLabConfig is the agentlab.yaml the claim of res kept.

func (Dir) DropLabChange added in v0.160.0

func (d Dir) DropLabChange(res string) error

DropLabChange ends the wait of the change left for res: its claim took it.

func (Dir) Get

func (d Dir) Get(res string) (*Holder, error)

Get returns the holder of res, or nil when it is free.

func (Dir) Hand added in v0.140.1

func (d Dir) Hand(h Holder) error

Hand gives the lease h.Env, held, to h: its record is replaced in one rename, so a reader sees the old holder or the new one, never none.

func (Dir) KeepLabConfig added in v0.160.0

func (d Dir) KeepLabConfig(res string, raw []byte) error

KeepLabConfig keeps raw, the lab's agentlab.yaml at the claim of res, in the lease of res.

func (Dir) LabChangeOf added in v0.160.0

func (d Dir) LabChangeOf(res string) (*LabChange, error)

LabChangeOf is the change a release of res left for its next claim, nil when none waits.

func (Dir) LeaveLabChange added in v0.160.0

func (d Dir) LeaveLabChange(res string, c LabChange) error

LeaveLabChange keeps c for the next claim of res.

func (Dir) List

func (d Dir) List() ([]Holder, error)

List returns every held lease, oldest first.

func (Dir) Release

func (d Dir) Release(res string) error

Release frees res.

func (Dir) RestoreLabConfig added in v0.160.0

func (d Dir) RestoreLabConfig(res, path string) (string, error)

RestoreLabConfig writes the claim-time agentlab.yaml of res back to path in one rename; the configuration it replaces is kept as path.released. It returns where that copy is.

type Gate

type Gate struct {
	Resource string
	Caller   state.Party
	// Supervisor is the recorded supervisor, nil when none is.
	Supervisor *state.Supervisor
	// RestartUntil is set while the supervisor's CLI may still come back
	// as a restart; Gone once its CLI stayed away longer: claims wait for
	// its successor.
	RestartUntil time.Time
	Gone         bool
	// Held is whether the resource is held right now (by anyone).
	Held bool
	Now  time.Time
	TTL  time.Duration
}

Gate is what a claim is checked against.

type Holder

type Holder struct {
	// Env is the resource; the field name is the shell lock's.
	Env         string `json:"env"`
	Holder      string `json:"holder"`
	Session     string `json:"session"`
	HostSession string `json:"hostSession,omitempty"`
	Name        string `json:"name,omitempty"`
	// Person, Team and Host are the holder party's.
	Person  string `json:"person,omitempty"`
	Team    string `json:"team,omitempty"`
	Host    string `json:"host,omitempty"`
	Purpose string `json:"purpose"`
	Since   string `json:"since"`
	// UpgradeUnblock is the reason of the upgrade-unblock grant the claim
	// was admitted by during an upgrade, empty for any other claim.
	UpgradeUnblock string `json:"upgradeUnblock,omitempty"`
	// BudgetGiB is what the holder's models may hold on the model server,
	// 0 on every other resource.
	BudgetGiB int `json:"budgetGiB,omitempty"`
	// LabConfig is a lab's agentlab.yaml at the claim, nil on every other
	// resource and on a lab whose configuration the claim could not read.
	LabConfig *LabConfig `json:"labConfig,omitempty"`
	// LabChange is the change the lab's previous release left, shown to
	// this holder at its claim.
	LabChange *LabChange `json:"labChange,omitempty"`
}

Holder is the record in <leaseDir>/<resource>/holder.json.

func (Holder) Label added in v0.40.0

func (h Holder) Label() string

Label is the resource with the budget its claim carries.

func (Holder) Party

func (h Holder) Party() state.Party

Party is the holder as the state names it.

func (Holder) SinceTime

func (h Holder) SinceTime() time.Time

SinceTime parses Since.

type LabChange added in v0.160.0

type LabChange struct {
	By   string   `json:"by"`
	At   string   `json:"at"`
	Keys []string `json:"keys"`
	// Why is the holder's declaration (release --keep-config), empty for a
	// change released with --force and not declared.
	Why string `json:"why,omitempty"`
}

LabChange is a lab's configuration a release left different from its claim-time state, kept for the next claim of the lab.

func (LabChange) Text added in v0.160.0

func (c LabChange) Text() string

Text says what the change is, for a claim and a status.

type LabConfig added in v0.160.0

type LabConfig struct {
	Path string `json:"path"`
	// SHA256 is the hash of the parsed configuration, so a comment agentlab
	// rewrites (its version line) is no change.
	SHA256      string   `json:"sha256"`
	ValuesFiles []string `json:"valuesFiles,omitempty"`
}

LabConfig is a lab's agentlab.yaml as the claim of its lease found it.

func ReadLabConfig added in v0.160.0

func ReadLabConfig(path string) (LabConfig, []byte, error)

ReadLabConfig reads the agentlab.yaml at path: its record and its bytes.

type Refusal

type Refusal struct {
	Reason   string
	Position int
	Ahead    string
}

Refusal is why a claim is not allowed. A claim queued behind earlier grants carries its place: Position (from 1) and Ahead, the grantee who claims first.

func (*Refusal) Error

func (r *Refusal) Error() string

Jump to

Keyboard shortcuts

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