retention

package
v1.138.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package retention removes what the platform writes and nothing else ever removes (#1904): soft-deleted portal items past their grace period, with their objects; archived memory records; producer rows whose file is gone; and GraphQL operation embeddings of a schema a connection no longer has. One pass mends rather than removes: it names the portal bucket on asset rows written with none, ahead of the purge, which could not otherwise delete their objects (#1931).

Each sweep runs once a day under its own PostgreSQL advisory lock, so every replica may run the loop and only one of them deletes at a time, and one subsystem's sweep never waits on another's. The first pass runs at start rather than a day later, so a deployment that lowers a retention restarts into it.

Index

Constants

View Source
const (
	DefaultDeletedRetentionDays  = 30
	DefaultArchivedRetentionDays = 90
	DefaultProducerRetentionDays = 90
)

Retention defaults, in days. A deleted portal item is kept a month so a mistaken delete can still be taken up with an administrator; the others match the call catalog's and the audit log's ninety days.

View Source
const DefaultInterval = 24 * time.Hour

DefaultInterval is how often the sweeps run.

Variables

This section is empty.

Functions

func Days

func Days(configured, def int) int

Days resolves a configured retention: zero takes def, a negative value disables the sweep (reported as 0), and anything else is used as given.

Types

type Config

type Config struct {
	DB *sql.DB
	// Objects deletes the portal's stored objects; nil deletes rows only.
	Objects portalpurge.ObjectDeleter
	// Bucket is the portal bucket, where collection mosaics are stored.
	Bucket string
	// Portal is false where the portal is off, which purges nothing of it.
	Portal                                  bool
	DeletedDays, ArchivedDays, ProducerDays int
	Every                                   time.Duration
}

Config is what Assemble builds the sweeps from. Each *Days is already resolved by Days: 0 turns its sweep off.

type Loop

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

Loop runs a set of sweeps on an interval until Close.

func Assemble

func Assemble(cfg Config) *Loop

Assemble builds the loop over every sweep cfg turns on. It is nil without a database.

func New

func New(db *sql.DB, interval time.Duration, sweeps ...Sweep) *Loop

New builds a loop over sweeps. A non-positive interval takes DefaultInterval.

func (*Loop) Close

func (l *Loop) Close() error

Close stops the loop and waits for a running pass to return.

func (*Loop) RunOnce

func (l *Loop) RunOnce(ctx context.Context)

RunOnce runs every sweep once, each under its lock. A sweep another replica is running is skipped, and one that fails is logged and does not stop the others.

func (*Loop) Start

func (l *Loop) Start()

Start runs every sweep now and then on the interval, in its own goroutine. A second call, a loop with no database and a loop with no sweeps do nothing.

type Sweep

type Sweep struct {
	Name    string
	LockKey int64
	Run     func(ctx context.Context) (int64, error)
}

Sweep is one removal the loop runs. LockKey is its advisory lock, distinct from every other maintenance lock in the platform. Run reports how many rows it removed.

func AssetBucket added in v1.137.1

func AssetBucket(db *sql.DB, bucket string) []Sweep

AssetBucket is the pass that names the portal bucket on asset rows an early release wrote with none (#1931); see assetbucket. It removes nothing, so it reports nothing to the loop and logs what it wrote itself. Nothing without a portal bucket.

func MemoryArchived

func MemoryArchived(db *sql.DB, days int) []Sweep

MemoryArchived is the sweep that deletes memory records archived more than days ago. Nothing when days is 0.

func OrphanedProducers

func OrphanedProducers(db *sql.DB, days int) []Sweep

OrphanedProducers is the sweep that deletes producer rows whose file is gone. Nothing when days is 0.

func PortalDeleted

func PortalDeleted(p *portalpurge.Purger, days int) []Sweep

PortalDeleted is the sweep that purges portal items deleted more than days ago, with their objects. Nothing when days is 0.

func SupersededGraphQL

func SupersededGraphQL(db *sql.DB) []Sweep

SupersededGraphQL is the sweep that deletes embeddings of superseded GraphQL schemas. It takes no age: a superseded schema's vectors are never read again.

Jump to

Keyboard shortcuts

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