maintenance

package
v1.66.0 Latest Latest
Warning

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

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

Documentation

Overview

Package maintenance runs a store's housekeeping on a schedule. The store only exposes the operations; whoever owns the store, a server with one or a host with many, decides when they run.

Index

Constants

This section is empty.

Variables

View Source
var DefaultSchedule = Schedule{
	Sweep:    30 * time.Second,
	Compact:  time.Hour,
	Collect:  7 * 24 * time.Hour,
	Retire:   time.Hour,
	Presence: 30 * time.Second,
}

DefaultSchedule is how often a store server runs each job unless told otherwise.

Functions

func Collect

func Collect(ctx context.Context, collector pack.Collector, idx backup.Index, opts pack.CollectOptions) (*pack.CollectReport, error)

Collect garbage collects the store with opts. When idx is an Attributor, what survives is grouped by the set that owns it and what each set takes up is recorded; when it is a Reindexer, the indexes the collection churned are rebuilt. idx may be nil.

func RecordDamage

func RecordDamage(ctx context.Context, idx backup.Index, lost []*proto.Ref) (*backup.DamageReport, error)

RecordDamage places the lost objects at the paths of every set of idx that held them, so the next backup of each set reads them again; see backup.ReportDamage. It returns nil when idx records no damage.

func Repair

Repair rewrites the damage out of store and records in idx where what it lost was held, as RecordDamage does. It fails with an error matching errors.ErrUnsupported when the store cannot be repaired.

Types

type Attributor

type Attributor interface {
	RootOwner(ctx context.Context) (func(root []byte) pack.Attribution, error)
	RecordSetSizes(ctx context.Context, report *pack.CollectReport) error
}

Attributor is an index that names the set behind each root and keeps what a collection attributed to every set.

type Collected

type Collected interface {
	LastCollected() (time.Time, error)
}

Collected is a store that knows when it was last garbage collected.

type Measurer

type Measurer interface {
	MeasureSets(ctx context.Context) ([]index.SetInfo, error)
}

Measurer is an index that stores the sizes of the sets whose commits changed, and reports the sets it measured.

type Presence

type Presence interface {
	BuildPendingPresence(ctx context.Context) (int, error)
}

Presence is an index that builds presence filters on demand.

type Ran

type Ran struct {
	Swept             bool
	Retired, Presence int
	// Compacted is nil when no compaction ran; alongside a failed one it
	// counts what that finished.
	Compacted *pack.CompactReport
	// Measured is how many sets had their sizes measured.
	Measured int
	// Collected is nil when no collection was due.
	Collected *pack.CollectReport
	// Reindexed are the tables whose indexes the run's churn rebuilt.
	Reindexed []index.Reindexed
}

Ran is what one pass of Due did.

type Reindexer

type Reindexer interface {
	ReindexChurned(ctx context.Context) ([]index.Reindexed, error)
}

Reindexer is an index that rebuilds the indexes of its tables a maintenance run churned, and reports the tables it rebuilt.

type Repairer

type Repairer interface {
	Repair(ctx context.Context) (*pack.RepairReport, error)
}

Repairer is a store that rewrites the archives holding corrupt objects.

type Runner

type Runner struct {
	Store      Store
	Collector  pack.Collector
	Attributor Attributor
	Retirer    backup.Retirer
	Presence   Presence
	Measurer   Measurer
	Reindexer  Reindexer
	Schedule   Schedule
	// OnCollect sees every garbage collection report; nil ignores them.
	OnCollect func(*pack.CollectReport)
	// Logger is where failures go; nil means slog.Default.
	Logger *slog.Logger
	// Now is the clock; nil means time.Now.
	Now func() time.Time
}

Runner ticks the jobs of one store. A nil member skips its jobs.

func NewRunner

func NewRunner(store backup.ObjectStore, idx backup.Index, schedule Schedule) *Runner

NewRunner is the runner of the jobs store and idx support, found by what the innermost store and the index implement.

func (*Runner) BuildPresence

func (r *Runner) BuildPresence(ctx context.Context)

BuildPresence builds the presence filters that are missing.

func (*Runner) Collect

func (r *Runner) Collect(ctx context.Context) (*pack.CollectReport, error)

Collect garbage collects the store, hands the report to OnCollect and rebuilds the indexes that churned. Without a Collector it returns nil.

func (*Runner) Compact

func (r *Runner) Compact(ctx context.Context) (*pack.CompactReport, error)

Compact rewrites small archives and rebuilds the indexes that churned. Without a Store it does nothing.

func (*Runner) Due

func (r *Runner) Due(ctx context.Context) (Ran, error)

Due runs every scheduled job once, except a collection, which runs only when the store's last one is at least Schedule.Collect old, and then reindexes what they churned. It is what a cron job calls; errors are joined and every job still runs.

func (*Runner) MeasureSets

func (r *Runner) MeasureSets(ctx context.Context)

MeasureSets measures the sets whose commits changed.

func (*Runner) Retire

func (r *Runner) Retire(ctx context.Context) (int, error)

Retire tombstones every retired commit past its window and rebuilds the indexes that churned. Without a Retirer it does nothing.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context)

Run sweeps once, then runs every scheduled job at its interval until ctx ends. Jobs of one runner never overlap.

func (*Runner) Sweep

func (r *Runner) Sweep()

Sweep finalizes idle archives and ends expired sessions.

type Schedule

type Schedule struct {
	Sweep   time.Duration
	Compact time.Duration
	Collect time.Duration
	Retire  time.Duration
	// Presence also measures the sets whose commits changed.
	Presence time.Duration
}

Schedule is how often each job runs; zero never runs it.

type Scrubber

type Scrubber interface {
	Scrub(ctx context.Context) (*pack.ScrubReport, error)
}

Scrubber is a store that rehashes everything it holds.

type SetLister

type SetLister interface {
	ListSets(ctx context.Context) ([]index.SetInfo, error)
}

SetLister is an index that names its sets.

type Store

type Store interface {
	Sweep(now time.Time)
	Compact(ctx context.Context) (*pack.CompactReport, error)
}

Store is what the runner sweeps and compacts.

Jump to

Keyboard shortcuts

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