capacity

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	Lock(context.Context) (func(), error)
	Snapshot(context.Context) (Snapshot, error)
	Busy(context.Context) (bool, error)
	Reclaim(context.Context, ReclaimRequest) (ReclaimReport, error)
	Emergency(context.Context) error
}

type CapacityStore

type CapacityStore interface {
	WorkerBusy(context.Context) (bool, error)
	TerminalJobIDsBefore(context.Context, time.Time) ([]string, error)
	CapacityImagePolicies(context.Context) ([]ImagePolicy, error)
}

type Commands

type Commands interface {
	Run(context.Context, ...string) error
	Output(context.Context, ...string) ([]byte, error)
}

type Controller

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

func New

func New(policy Policy, backend Backend) *Controller

func (*Controller) Admit added in v0.1.8

func (c *Controller) Admit(ctx context.Context, reserve func() error) error

Admit serializes the capacity decision and the caller's durable operation reservation with maintenance. This closes the idle-check/admission race: a collector cannot begin after capacity was checked but before the FIFO lease records the worker as busy.

func (*Controller) Check

func (c *Controller) Check(ctx context.Context) error

func (*Controller) Ensure

func (c *Controller) Ensure(ctx context.Context) error

func (*Controller) Maintain

func (c *Controller) Maintain(ctx context.Context, trigger Trigger) (Status, error)

func (*Controller) Status

func (c *Controller) Status() Status

type DockerCommands

type DockerCommands struct {
	Binary string
	Host   string
}

func (DockerCommands) Output

func (d DockerCommands) Output(ctx context.Context, arguments ...string) ([]byte, error)

func (DockerCommands) Run

func (d DockerCommands) Run(ctx context.Context, arguments ...string) error

type Host

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

func NewHost

func NewHost(config HostConfig) *Host

func (*Host) Busy added in v0.1.8

func (h *Host) Busy(ctx context.Context) (bool, error)

func (*Host) Emergency

func (h *Host) Emergency(ctx context.Context) error

func (*Host) Lock added in v0.1.8

func (h *Host) Lock(ctx context.Context) (func(), error)

func (*Host) Reclaim

func (h *Host) Reclaim(ctx context.Context, request ReclaimRequest) (ReclaimReport, error)

func (*Host) Snapshot

func (h *Host) Snapshot(context.Context) (Snapshot, error)

type HostConfig

type HostConfig struct {
	CapacityPath string
	JobsRoot     string
	CacheRoot    string
	LockPath     string
	Store        CapacityStore
	Commands     Commands
	Emergency    func(context.Context) error
	Now          func() time.Time
	DryRun       bool
}

type ImagePolicy

type ImagePolicy struct {
	Reference  string
	LastUsedAt time.Time
	Protected  bool
}

type Policy

type Policy struct {
	SoftFreePercent      uint64
	SoftFreeMinimumBytes uint64
	HardFreePercent      uint64
	HardFreeMinimumBytes uint64
	SweepPercent         uint64
	SweepMinimumBytes    uint64
	MinimumFreeInodes    uint64
	JobRetention         time.Duration
	CacheHighPercent     uint64
	CacheLowPercent      uint64
	NormalObjectAge      time.Duration
	PressureThrottle     time.Duration
}

func DefaultPolicy

func DefaultPolicy() Policy

func (Policy) Thresholds

func (p Policy) Thresholds(total uint64) Thresholds

type ReclaimReport

type ReclaimReport struct {
	ReclaimedBytes uint64   `json:"reclaimed_bytes"`
	RemovedJobs    int      `json:"removed_jobs"`
	RemovedCaches  int      `json:"removed_caches"`
	Commands       []string `json:"commands,omitempty"`
}

type ReclaimRequest

type ReclaimRequest struct {
	Trigger         Trigger
	Pressure        bool
	TargetFreeBytes uint64
	JobRetention    time.Duration
	CacheHighBytes  uint64
	CacheLowBytes   uint64
	NormalObjectAge time.Duration
}

type ResourceExhaustedError

type ResourceExhaustedError struct {
	FreeBytes      uint64
	RequiredBytes  uint64
	FreeInodes     uint64
	RequiredInodes uint64
}

func (*ResourceExhaustedError) Error

func (e *ResourceExhaustedError) Error() string

type Snapshot

type Snapshot struct {
	TotalBytes  uint64    `json:"total_bytes"`
	FreeBytes   uint64    `json:"free_bytes"`
	TotalInodes uint64    `json:"total_inodes"`
	FreeInodes  uint64    `json:"free_inodes"`
	ObservedAt  time.Time `json:"observed_at"`
}

type Status

type Status struct {
	State       string        `json:"state"`
	Trigger     Trigger       `json:"trigger"`
	Before      Snapshot      `json:"before"`
	After       Snapshot      `json:"after"`
	Thresholds  Thresholds    `json:"thresholds"`
	Reclaim     ReclaimReport `json:"reclaim"`
	Error       string        `json:"error,omitempty"`
	CompletedAt time.Time     `json:"completed_at"`
}

type Thresholds

type Thresholds struct {
	SoftFreeBytes   uint64
	TargetFreeBytes uint64
	HardFreeBytes   uint64
}

type Trigger

type Trigger string
const (
	TriggerAdmission Trigger = "admission"
	TriggerPeriodic  Trigger = "periodic"
	TriggerPressure  Trigger = "pressure"
	TriggerManual    Trigger = "manual"
)

Jump to

Keyboard shortcuts

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