gc

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package gc reconciles the object store against the metadata table. It runs as a background sweep, never on the request path, and is a sibling use-case to the files service: it orchestrates storage + metadata but imports neither api nor files.

Each sweep does two jobs:

  1. Purge soft-deleted rows — delete the object, then hard-delete the row.
  2. Reclaim orphans — objects in the store with no backing row (e.g. a write whose metadata commit never landed because the process died) are deleted once older than the grace period.

The grace period is the safety valve: an in-flight upload writes the object before committing its row, so a just-written object briefly looks orphaned. Only objects older than the grace period are reclaimed, so a valid upload in progress is never destroyed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

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

Collector runs the reconciliation sweep.

func New

func New(store Store, repo Repo, log *slog.Logger, interval, grace, idemTTL time.Duration) *Collector

New constructs a Collector. idemTTL is the idempotency-key retention; a non-positive value disables key expiry.

func (*Collector) Run

func (c *Collector) Run(ctx context.Context)

Run sweeps on a ticker until ctx is cancelled. A non-positive interval disables the collector (it returns immediately).

func (*Collector) RunOnce

func (c *Collector) RunOnce(ctx context.Context) (Stats, error)

RunOnce performs a single reconciliation pass. Object deletes are idempotent, so a partial failure simply retries on the next sweep.

type Repo

type Repo interface {
	ListDeleted(ctx context.Context, limit int) ([]*metadata.File, error)
	Purge(ctx context.Context, id string) error
	StorageKeys(ctx context.Context) (map[string]struct{}, error)
	PurgeIdempotencyKeys(ctx context.Context, before time.Time) (int, error)
}

Repo is the slice of metadata.Repository the collector needs.

type Stats

type Stats struct {
	Purged      int // soft-deleted rows whose objects were removed
	Orphans     int // unreferenced objects reclaimed
	ExpiredKeys int // idempotency keys past their TTL
}

Stats reports what a single sweep reclaimed.

type Store

type Store interface {
	Delete(ctx context.Context, key string) error
	List(ctx context.Context, fn func(storage.StoredObject) error) error
}

Store is the slice of storage.Backend the collector needs.

Jump to

Keyboard shortcuts

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