storeops

package
v0.5.48 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package storeops runs the periodic operations that treat the bbolt file as an operational artifact rather than a set of rows: timestamped snapshots with retention pruning, and the file-size and freelist gauges.

Both were background goroutine bodies on Server. They read four things — the store, the metrics recorder, the live config, and the disk-full classifier — which is the same Deps-plus-a-live-config shape the scheduler package already takes, so they belong beside it rather than on the composition root. The two share a package because they share a subject: one writes the file, the other measures it, and both are the only code that cares how large it is.

Index

Constants

View Source
const StoreMetricsInterval = 5 * time.Minute

StoreMetricsInterval is how often the store file-size and freelist gauges are refreshed. 5 minutes keeps the /metrics scrape cheap (no per-request View tx) while still catching file growth early enough for alerting.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deps

type Deps struct {
	DB      Store
	Metrics Metrics
	// Cfg resolves the LIVE config each cycle, so enable, frequency, retention
	// and path changes take effect on the next iteration without a restart. It
	// returns nil in unconfigured mode, which the backup loop treats as disabled.
	Cfg func() *config.Config
	// RecordStoreWriteError classifies a write failure as a possible disk-full
	// condition. Injected rather than imported: the classifier needs the concrete
	// engine's error taxonomy, and this package names no engine.
	RecordStoreWriteError func(error)
}

Deps is what the runners need.

type Metrics

type Metrics interface {
	RecordBackupSuccess(dur time.Duration)
	RecordStoreFileSize(bytes int64)
	RecordStoreFreelistBytes(bytes int64)
}

Metrics is the narrow observability surface for these operations. The concrete *obs.Metrics satisfies it structurally.

type Runner

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

Runner owns the periodic store-file operations.

func New

func New(deps Deps) *Runner

New returns a Runner over deps.

func (*Runner) RunBackup

func (r *Runner) RunBackup(ctx context.Context)

RunBackup periodically writes a database snapshot and prunes old backups until ctx is cancelled.

func (*Runner) RunMetrics

func (r *Runner) RunMetrics(ctx context.Context)

RunMetrics periodically reads the bbolt file size and freelist stats and records them as Prometheus gauges. It exits when ctx is cancelled.

type Store

type Store interface {
	BackupInto(ctx context.Context, dest string) error
	StoreFileStats() (fileBytes, freelistBytes int64)
}

Store is the two methods these operations need of the store: snapshot the whole file, and report its size. Both are whole-file concerns, which is why neither appears in any row-level store interface.

Jump to

Keyboard shortcuts

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