gc

package
v1.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package gc provides garbage collection for the content cache.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Interval         time.Duration // How often to run (default: 1h)
	StartupDelay     time.Duration // Delay before first run (default: 5m)
	MaxCacheBytes    int64         // Target max cache size
	BatchSize        int           // Max items to process per run (default: 1000)
	CompactInterval  time.Duration // How often to compact bbolt (default: 24h)
	CompactThreshold float64       // Compact if free pages > threshold (default: 0.3)
}

Config configures the GC manager.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default GC configuration.

type Manager

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

Manager manages garbage collection for the content cache.

func New

func New(db metadb.MetaDB, backend backend.Backend, config Config, metrics *Metrics, logger *slog.Logger) *Manager

New creates a new GC manager.

func (*Manager) RunNow

func (m *Manager) RunNow(ctx context.Context) (*Result, error)

RunNow triggers an immediate GC run.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context)

Start starts the background GC goroutine.

func (*Manager) Status

func (m *Manager) Status() *Result

Status returns the last GC run result.

func (*Manager) Stop

func (m *Manager) Stop(ctx context.Context) error

Stop gracefully stops the GC manager.

type ManagerOption

type ManagerOption func(*Manager)

ManagerOption configures a Manager.

func WithLogger

func WithLogger(logger *slog.Logger) ManagerOption

WithLogger sets the logger for the manager.

func WithMetrics

func WithMetrics(meter metric.Meter) ManagerOption

WithMetrics sets the metrics for the manager.

type Metrics

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

Metrics holds GC-related OpenTelemetry metric instruments.

func NewMetrics

func NewMetrics(meter metric.Meter) (*Metrics, error)

NewMetrics creates a new Metrics instance with the given meter.

type Result

type Result struct {
	StartedAt                time.Time     `json:"started_at"`
	Duration                 time.Duration `json:"duration"`
	UnreferencedBlobsDeleted int           `json:"unreferenced_blobs_deleted"`
	OrphanBlobsDeleted       int           `json:"orphan_blobs_deleted"`
	ExpiredMetaDeleted       int           `json:"expired_meta_deleted"`
	LRUBlobsEvicted          int           `json:"lru_blobs_evicted"`
	BytesReclaimed           int64         `json:"bytes_reclaimed"`
	Errors                   []string      `json:"errors,omitempty"`
}

Result contains the results of a GC run.

Jump to

Keyboard shortcuts

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