disk

package
v0.7.0 Latest Latest
Warning

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

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

Documentation

Overview

Package disk enforces the state directory cap by shrinking the TSDB first and reporting pressure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Budget

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

Budget enforces a byte cap over one directory.

func DiskBudget

func DiskBudget(dir string, capBytes int64, o Options) *Budget

DiskBudget returns a budget for dir with capBytes.

func (*Budget) Check

func (b *Budget) Check(ctx context.Context) (Report, error)

Check shrinks the TSDB above the high water mark and relaxes it below the low water mark.

func (*Budget) Last

func (b *Budget) Last() Report

Last returns the most recent report.

func (*Budget) Measure

func (b *Budget) Measure() Report

Measure reports usage without acting.

func (*Budget) Pressure

func (b *Budget) Pressure() bool

Pressure reports whether the last check stayed above the high water mark.

func (*Budget) Run

func (b *Budget) Run(ctx context.Context, every time.Duration, fn func(Report, error))

Run checks every interval until ctx ends, passing each report to fn.

type Options

type Options struct {
	TSDB Shrinker
	// TSDBDir and SpoolDir are measured separately; relative paths are under the budget directory.
	TSDBDir  string
	SpoolDir string
	// SpoolReserve is always counted as used, so nothing else can grow into it (host mode).
	SpoolReserve int64
	HighWater    float64
	LowWater     float64
}

Options configures a Budget.

type Report

type Report struct {
	Cap        int64
	Used       int64
	Spool      int64
	Reserved   int64
	TSDB       int64
	Other      int64
	Effective  int64
	TSDBTarget int64
	Freed      int64
	Pressure   bool
	Deficit    int64
}

Report is one measurement and the action taken.

type Shrinker

type Shrinker interface {
	Size() int64
	Shrink(ctx context.Context, target int64) (int64, error)
	Relax() error
}

Shrinker is the TSDB side of the budget.

Jump to

Keyboard shortcuts

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