gc

package
v0.16.5 Latest Latest
Warning

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

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

Documentation

Overview

Package gc provides a generic background sweep worker used by all GC subsystems in xolu: blob storage, timeseries retention, FSM machine collection (v2), and event delivery log cleanup (v2).

The package implements the ticker-and-stop-channel lifecycle pattern once so that each sweeper only needs to implement the Sweeper interface. Workers are registered at server startup and exposed via the admin API at POST /api/v1/admin/gc/{name}/run and GET /api/v1/admin/gc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Report

type Report struct {
	Examined    int           // items inspected this cycle
	Collected   int           // items collected (deleted or hard-purged)
	Quarantined int           // items moved to a staging area (two-phase sweepers)
	Errors      int           // non-fatal errors encountered
	Duration    time.Duration // wall time for the sweep
}

Report summarises the result of a single sweep cycle. Zero values are valid; sweepers that do not track a field leave it at 0.

type Sweeper

type Sweeper interface {
	Sweep(ctx context.Context) (Report, error)
}

Sweeper is implemented by each GC subsystem. Sweep must be safe to call concurrently from RunOnce and the ticker goroutine.

type Worker

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

Worker runs a Sweeper on a ticker interval. It is safe for concurrent use.

func NewWorker

func NewWorker(name string, s Sweeper, interval time.Duration, logger zerolog.Logger) *Worker

NewWorker creates a Worker. Start must be called separately.

func (*Worker) LastReport

func (w *Worker) LastReport() (Report, time.Time)

LastReport returns the report from the most recent completed sweep and the time it started. Returns a zero Report and zero time if no sweep has completed yet.

func (*Worker) Name

func (w *Worker) Name() string

Name returns the worker's registered name.

func (*Worker) RunOnce

func (w *Worker) RunOnce(ctx context.Context) (Report, error)

RunOnce executes a single sweep synchronously. Used by the admin endpoint and by tests. Safe to call concurrently with the background goroutine.

func (*Worker) Start

func (w *Worker) Start()

Start launches the background sweep goroutine. Calling Start more than once on the same Worker panics.

func (*Worker) Stop

func (w *Worker) Stop()

Stop signals the worker to stop and blocks until it has exited. Calling Stop on a worker that has not been started blocks indefinitely.

Jump to

Keyboard shortcuts

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