compaction

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package compaction schedules database maintenance independently of the storage engine. Database growth is sampled at most every five minutes after committed writes, and reclaimability is checked after enough writes even without growth. Pending compaction waits for an idle period. Arriving writers cancel attempts up to the retry limit; subsequent attempts make writers wait. Changed policy state is checkpointed every five minutes and at close.

Index

Constants

This section is empty.

Variables

View Source
var ErrBusy = errors.New("database maintenance already requested or in progress")

Functions

func Files

func Files() map[string]*Scheduler

Files returns the databases with an attached compaction policy.

Types

type Backend

type Backend interface {
	CompactionStats() (db.CompactionStats, error)
	Compact(context.Context, db.CompactOptions) (db.CompactResult, error)
	Save(State) error
}

type Config

type Config struct {
	ManualOnly             bool
	WritesPerCheck         uint64
	SizeWatermark          int64
	SizeGrowthPercent      int64
	MinReclaimBytes        int64
	IdleTimeout            time.Duration
	MaxRetry               int
	MinReclaimPercent      int64
	MinReclaimPercentFloor int64
	Metrics                *Metrics `json:"-"`
}

func DefaultConfig

func DefaultConfig() Config

func (Config) Validate

func (c Config) Validate() error

type Metrics

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

Metrics shares instruments across databases using the daemon's meter provider.

func NewMetrics

func NewMetrics(mp metric.MeterProvider, stateDir string) (*Metrics, error)

type Outcome

type Outcome struct {
	Result db.CompactResult
	Error  string
}

type Request

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

func (*Request) Done

func (r *Request) Done() <-chan Outcome

func (*Request) Events

func (r *Request) Events() <-chan string

type Scheduler

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

func New

func New(ctx context.Context, config Config, state State, backend Backend) (*Scheduler, error)

New starts maintenance. Call Close before closing the backend.

func NewFile

func NewFile(config Config, path string, fresh bool, database db.Compactor) (*Scheduler, error)

NewFile starts a policy with checkpoints beside the database. Its lifetime is controlled by Stop and Close, rather than by a build request's context.

func (*Scheduler) Begin

func (s *Scheduler) Begin(write bool)

Begin records access before entering the database's transaction gate.

func (*Scheduler) Close

func (s *Scheduler) Close() error

Close checkpoints after the backend has stopped accepting transactions.

func (*Scheduler) End

func (s *Scheduler) End(committed bool)

End counts only committed writes. It must also run after callback errors or panics.

func (*Scheduler) Inspect

func (s *Scheduler) Inspect() (Status, error)

Inspect observes policy state without advancing watermarks or requesting maintenance.

func (*Scheduler) Request

func (s *Scheduler) Request(ctx context.Context) (*Request, error)

Request bypasses the automatic write interval and size watermark for one cancellable attempt after an idle period. It never consumes automatic retries or forces writers to wait for completion.

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop cancels and joins maintenance before the backend is closed.

type State

type State struct {
	Writes        uint64 `json:"writes"`
	SizeWatermark int64  `json:"sizeWatermark"`
}

type Status

type Status struct {
	Stats   db.CompactionStats
	Config  Config
	State   State
	Active  int
	Pending bool
	Manual  bool
}

Jump to

Keyboard shortcuts

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