compaction

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	FileID     uint32
	DeadBytes  uint64
	TotalBytes uint64
	DeadRatio  float64
}

type Compactor

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

func New

func New(d *db.DB) *Compactor

func (*Compactor) Candidates

func (c *Compactor) Candidates(opts Options) ([]Candidate, error)

func (*Compactor) CompactCandidates

func (c *Compactor) CompactCandidates(opts Options) error

func (*Compactor) CompactCandidatesWithContext

func (c *Compactor) CompactCandidatesWithContext(ctx context.Context, opts Options) error

func (*Compactor) CompactSlab

func (c *Compactor) CompactSlab(id uint32) error

CompactSlab performs compaction on a specific slab file. It rewrites live records to a new slab and updates pointers in micro-batches.

func (*Compactor) CompactSlabWithContext

func (c *Compactor) CompactSlabWithContext(ctx context.Context, id uint32, opts Options) error

CompactSlabWithContext compacts a slab using the provided options and context. If ctx is canceled, compaction aborts promptly and returns ctx.Err().

func (*Compactor) CompactSlabWithOptions

func (c *Compactor) CompactSlabWithOptions(id uint32, opts Options) error

CompactSlabWithOptions compacts a slab using the provided options.

type Options

type Options struct {
	DeadRatioThreshold float64
	MinTotalBytes      uint64
	MaxSlabs           int
	MicroBatchSize     int
	// IndexSwap rebuilds the index into a new file and swaps it in once after
	// compacting one or more slabs. This avoids high write amplification from
	// applying many pointer updates via COW B-Tree commits.
	IndexSwap bool
	// LiveSetMaxEntries controls the in-memory live pointer set size used to
	// skip per-record tree lookups during compaction. 0 uses a default; <0
	// disables the live-set optimization.
	LiveSetMaxEntries int

	// Assist is an optional hook invoked periodically during compaction work.
	// It must be fast and must not assume any compaction locks are held.
	// Typical use: coordinate with caching-layer backpressure by triggering a
	// bounded flush when backlog grows.
	Assist func()

	// Stats is an optional collector for compaction counters.
	Stats *Stats

	// RotateBeforeWrite forces a slab rotation once before moving any records.
	// This can reduce interference with the current active slab, but will create
	// a new slab file even if compaction ends up being a no-op.
	RotateBeforeWrite bool

	// CopyBytesPerSec limits compaction copy IO. 0 disables throttling.
	CopyBytesPerSec int64
	// CopyBurstBytes is the limiter burst size. 0 uses a 1-second burst.
	CopyBurstBytes int64
}

type Stats

type Stats struct {
	LiveSetEntries     uint64
	LiveSetAborted     bool
	LiveSetBloom       bool
	TreeLookups        uint64
	TreeLookupsSkipped uint64
}

Jump to

Keyboard shortcuts

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