catalogprune

package
v0.30.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 18 Imported by: 1 module, 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 catalogprune deletes the catalog rows a catalog release stopped shipping once nothing holds them. A versioned reseed only marks such rows detached (meta.CatalogDetachedAt); a prune deletes a detached row that is not operator-edited, carries no overlay, is referenced by nothing but other detached rows deleted with it, and, for a model or a host binding, served no request inside the idle window. A model an operator's policy names in spec.models also stays. Every other detached row stays, and the next prune judges it again.

What references a row is the caller's answer (the control API's delete blockers and dropped links), so a prune and an admin delete agree on what holds a row. Out of scope: rows that never came from the catalog, usage history (never touched), and anything on the request path.

Index

Constants

View Source
const (
	Prune = "prune"
	Keep  = "keep"
)

Decision values.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decision

type Decision struct {
	Kind       string    `` /* 127-byte string literal not displayed */
	Name       string    `json:"name"       doc:"Slug of the row."`
	ID         string    `json:"id"         doc:"Id of the row."`
	DetachedAt time.Time `json:"detachedAt" doc:"When a catalog release stopped shipping the row."`
	Decision   string    `` /* 159-byte string literal not displayed */
	Reason     string    `` /* 205-byte string literal not displayed */

	// Owner and version are what the delete and its audit row need; Deleted
	// is set once the row is gone, which a run that fails part-way needs said.
	Owner   meta.Owner `json:"-"`
	Deleted bool       `json:"-"`
	// contains filtered or unexported fields
}

Decision is what a prune decided for one detached row.

type Options

type Options struct {
	// Idle is how long a model or host binding must have served no request.
	Idle time.Duration
	// Apply deletes the rows decided prune; false only decides.
	Apply bool
	// References lists the rows referencing the row id of kind (an API singular).
	References func(ctx context.Context, kind, id string) ([]Ref, error)
	// Usage answers the traffic guard; nil leaves it unknown.
	Usage UsageReader
	// Now defaults to time.Now.
	Now func() time.Time
}

Options configures one prune.

type Overlays

type Overlays interface {
	List(ctx context.Context) ([]*overlay.Overlay, error)
}

Overlays lists the overlays, whose targets a prune keeps.

type Ref

type Ref struct {
	// Kind is the referencing row's kind as an API singular (policy, host-key, …).
	Kind string
	ID   string
	Name string
}

Ref is a row that references a candidate.

type Report

type Report struct {
	// Idle is the traffic window the prune judged by.
	Idle time.Duration
	Rows []Decision
	// Pruned counts the rows deleted, or that a dry run would delete.
	Pruned int
	// Kept counts the rows that stay detached.
	Kept    int
	Applied bool
}

Report is what a prune decided and, when it applied, did.

func Run

func Run(ctx context.Context, s Stores, opts Options) (Report, error)

Run judges every detached row and, with opts.Apply, deletes the ones decided prune. Each delete re-reads the row's references and is conditional on the version judged, so a row edited or newly referenced meanwhile stays. A failed delete stops the run; rows already deleted stay deleted.

type Stores

type Stores struct {
	Providers  Table[provider.Provider]
	Hosts      Table[host.Host]
	Models     Table[model.Model]
	Pricings   Table[pricing.Pricing]
	Bindings   Table[binding.Binding]
	Policies   Table[policy.Policy]
	RateLimits Table[ratelimit.RateLimit]
	Overlays   Overlays
}

Stores are the kinds a release can drop.

type Table

type Table[T any] interface {
	List(ctx context.Context) ([]*T, error)
	DeleteAtVersion(ctx context.Context, id, version string) error
}

Table lists one kind and deletes a row of it only while the row still has the version that was read.

type UsageReader

type UsageReader interface {
	Events(ctx context.Context, q usage.EventQuery) ([]usage.Event, error)
}

UsageReader is the one usage read the traffic guard makes.

Jump to

Keyboard shortcuts

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