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 ¶
- Variables
- func Collect(ctx context.Context, collector pack.Collector, idx backup.Index, ...) (*pack.CollectReport, error)
- func RecordDamage(ctx context.Context, idx backup.Index, lost []*proto.Ref) (*backup.DamageReport, error)
- func Repair(ctx context.Context, store backup.ObjectStore, idx backup.Index) (*pack.RepairReport, *backup.DamageReport, error)
- type Attributor
- type Collected
- type Measurer
- type Presence
- type Ran
- type Reindexer
- type Repairer
- type Runner
- func (r *Runner) BuildPresence(ctx context.Context)
- func (r *Runner) Collect(ctx context.Context) (*pack.CollectReport, error)
- func (r *Runner) Compact(ctx context.Context) (*pack.CompactReport, error)
- func (r *Runner) Due(ctx context.Context) (Ran, error)
- func (r *Runner) MeasureSets(ctx context.Context)
- func (r *Runner) Retire(ctx context.Context) (int, error)
- func (r *Runner) Run(ctx context.Context)
- func (r *Runner) Sweep()
- type Schedule
- type Scrubber
- type SetLister
- type Store
Constants ¶
This section is empty.
Variables ¶
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 ¶
func Repair(ctx context.Context, store backup.ObjectStore, idx backup.Index) (*pack.RepairReport, *backup.DamageReport, error)
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 Measurer ¶
Measurer is an index that stores the sizes of the sets whose commits changed, and reports the sets it measured.
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 ¶
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 ¶
NewRunner is the runner of the jobs store and idx support, found by what the innermost store and the index implement.
func (*Runner) BuildPresence ¶
BuildPresence builds the presence filters that are missing.
func (*Runner) Collect ¶
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 ¶
Compact rewrites small archives and rebuilds the indexes that churned. Without a Store it does nothing.
func (*Runner) Due ¶
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 ¶
MeasureSets measures the sets whose commits changed.
func (*Runner) Retire ¶
Retire tombstones every retired commit past its window and rebuilds the indexes that churned. Without a Retirer it does nothing.
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.