gc

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package gc reclaims storage (decision 0010). A pass purges trash entries past their retention, reaps abandoned upload sessions, deletes blobs no item or trash entry references, and deletes content in the blob store that the index never recorded (a deploy whose transaction failed after its content was written). Passes run on a schedule and on POST /api/system/storage/gc, under a lease so two instances sharing a database never collect at once.

Every blob is removed in three steps: its index row is marked deleting, its content is deleted, and the row becomes a tombstone. A deleting row refuses references, and a deploy that revives a tombstone checks the content is still there, so a deploy of the same content racing the removal is refused and repeated rather than left referencing missing content.

Index

Constants

View Source
const (
	// DefaultInterval is Artifactory's default garbage collection schedule,
	// every four hours.
	DefaultInterval = 4 * time.Hour
	// DefaultGrace is how long a blob must have been unreferenced, or its
	// content unindexed, before it is deleted. It must outlast any upload in
	// flight: content is written before its reference, so younger
	// unreferenced content may be a deploy about to commit.
	DefaultGrace = time.Hour
	// DefaultUploadExpiry is how long an upload session may sit untouched
	// before it is abandoned and reaped.
	DefaultUploadExpiry = 24 * time.Hour
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

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

Collector runs garbage collection passes over one store and its blob store. Passes in one process run one at a time.

func New

func New(st store.Store, blobs blob.Store, o Options) (*Collector, error)

New returns a Collector over st and blobs.

func (*Collector) Loop

func (c *Collector) Loop(
	ctx context.Context,
	every time.Duration,
	onRun func(Report, error),
) error

Loop runs a pass every interval until ctx ends, then returns ctx's error. Each pass's report and error go to onRun when it is set; a failed pass does not stop the loop.

func (*Collector) Run

func (c *Collector) Run(ctx context.Context) (Report, error)

Run makes one pass. A step that fails does not stop the others; their errors are joined.

type Options

type Options struct {
	Grace        time.Duration
	UploadExpiry time.Duration
	// Reapers discard stale upload sessions of other kinds, keyed by the
	// session's Backend: a JFrog CLI multipart session holds staged parts
	// on local disk as well as a blob upload. Sessions of a backend with no
	// reaper are blob store uploads.
	Reapers map[string]func(context.Context, store.Upload) error
	// Expirers remove finished uploads nothing took in time: the registry's
	// <image>/_uploads files, which a manifest push links from (decision
	// 0031). Each removes what was last written before the cutoff it is
	// given, the upload expiry ago, and returns how many it removed.
	Expirers []func(ctx context.Context, before time.Time) (int, error)
	// Now supplies the time; nil means time.Now.
	Now func() time.Time
}

Options configures New. Zero values mean the defaults.

type Report

type Report struct {
	// Skipped is set when another instance held the lease; nothing was done.
	Skipped        bool
	TrashPurged    int
	UploadsReaped  int
	BlobsDeleted   int
	OrphansDeleted int
	BytesFreed     int64
	// Kept counts blobs that were referenced again while being collected,
	// and so were left alone.
	Kept int
	// Pruned counts tombstones dropped and revived rows forgotten after
	// tombstoneRetention.
	Pruned int64
	// TokensExpired counts access-token records removed after their refresh
	// grace ran out.
	TokensExpired int64
}

Report is what one pass did.

Jump to

Keyboard shortcuts

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