gc

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlobIDs

func BlobIDs(snap any) map[string]struct{}

BlobIDs extracts blob hex IDs from a snapshot. Returns nil if the snapshot does not implement UsedBlobIDs.

func Collect

func Collect(others map[string]any, accessor func(any) map[string]struct{}) map[string]struct{}

Collect aggregates ID sets from all snapshots in others using the given accessor. Snapshots that don't support the accessor return nil and are silently skipped.

Usage:

blobIDs := gc.Collect(others, gc.BlobIDs)
vmIDs   := gc.Collect(others, gc.VMIDs)

func Register

func Register[S any](o *Orchestrator, m Module[S])

Register adds a typed Module to the Orchestrator. This is a package-level function (not a method) because Go methods cannot have type parameters.

func VMIDs

func VMIDs(snap any) map[string]struct{}

VMIDs extracts active VM IDs from a snapshot. Returns nil if the snapshot does not implement ActiveVMIDs.

Types

type Module

type Module[S any] struct {
	Name   string
	Locker lock.Locker

	// ReadDB reads the module's current state (called while the lock is held).
	ReadDB func(ctx context.Context) (S, error)

	// Resolve analyses this module's typed snapshot and returns IDs to delete.
	// others contains snapshots from all other modules (typed as any).
	// Use type assertions on others for cross-module analysis (e.g. vm pinning images).
	Resolve func(snap S, others map[string]any) []string

	// Collect removes the given IDs (called while the lock is held).
	Collect func(ctx context.Context, ids []string) error
}

Module[S] describes a typed storage module that participates in GC. S is the snapshot type returned by ReadDB and consumed by Resolve, giving the Resolve implementation full type safety on its own data.

type Orchestrator

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

Orchestrator runs GC across all registered modules.

func New

func New() *Orchestrator

New creates an empty Orchestrator.

func (*Orchestrator) Run

func (o *Orchestrator) Run(ctx context.Context) error

Run executes one GC cycle:

  1. TryLock all modules; skip those whose lock is busy.
  2. ReadDB each locked module to build a snapshot.
  3. Resolve deletion targets per module. Each module's Resolve receives all other snapshots (typed as any) for cross-module analysis — e.g., image GC checks UsedBlobIDs from the VM snapshot to protect active blobs.
  4. Collect targets for each snapshotted module.
  5. Unlock all (deferred).

All locks are held for the entire cycle so that the snapshot, resolve, and collect phases see a consistent view. GC runs infrequently and executes fast, so the extended lock hold is acceptable.

Jump to

Keyboard shortcuts

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