compaction

package
v1.13.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DefaultSegmentWalkInterval = 1 * time.Hour

DefaultSegmentWalkInterval is how long a walked segment's derivation is trusted before it is walked again (hint growth bypasses it). Walk volume needs no count cap: reads are paced by the shared compaction I/O limiter.

Variables

This section is empty.

Functions

func NewCompactionRateLimiter added in v1.10.2

func NewCompactionRateLimiter(bytesPerSecond int64) *rate.Limiter

NewCompactionRateLimiter creates the shared payload budget used by all background compaction work. A positive limit allows one startup burst no larger than 64 KiB or the configured per-second rate, whichever is smaller. A non-positive limit leaves a directly constructed Compactor unthrottled.

func PrepareEntryForCompaction

func PrepareEntryForCompaction(key, filePath string) ([]byte, []byte)

PrepareEntryForCompaction prepares the key and value to store in compaction index.

Types

type Compactor

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

func NewCompactorWithConfig

func NewCompactorWithConfig(cfg *CompactorConfig) *Compactor

NewCompactorWithConfig creates a new compactor with configuration

func (*Compactor) Close

func (c *Compactor) Close()

Close stops the background compaction loop and waits for it to exit.

func (*Compactor) CompactFiles

func (c *Compactor) CompactFiles(ctx context.Context, workerID int) (int, int64)

CompactFiles scans the RocksDB file-index and migrates files into segments. The context parameter allows for cancellation of the compaction process. The workerID is used to partition work across multiple workers. Compaction continues until the current segment is full or there are no more entries. Returns the number of files processed.

func (*Compactor) RateLimitBytesPerSecond added in v1.10.2

func (c *Compactor) RateLimitBytesPerSecond() int64

RateLimitBytesPerSecond reports the configured shared payload-read budget, or 0 when compaction is unthrottled. Exposed so callers (and tests) can verify the configured budget actually reached the compactor.

func (*Compactor) Start

func (c *Compactor) Start()

Start launches background goroutines for file and segment compaction

type CompactorConfig

type CompactorConfig struct {
	MetaDB            *metadata.MetaDB
	FileManager       *files.FileManager
	SegmentManager    *segment.Manager
	DeletionQueue     *deletion.Queue
	CompactionThreads int // Number of compaction threads
	// Recompaction settings (optional)
	EnableRecompaction   bool
	FragThreshold        float64
	MinSegmentAge        time.Duration
	MinSegments          int
	RecompactionInterval time.Duration

	// CompactionBytesPerSecond is shared by file compaction and recompaction.
	// A non-positive value disables limiting for directly constructed compactors.
	CompactionBytesPerSecond int64
}

CompactorConfig contains configuration for the compactor

type ErrFileSizeMismatch

type ErrFileSizeMismatch struct {
	Key          string
	FilePath     string
	ActualSize   int64
	ExpectedSize int64
}

ErrFileSizeMismatch is returned when a file's actual size doesn't match its metadata

func (*ErrFileSizeMismatch) Error

func (e *ErrFileSizeMismatch) Error() string

type SegmentRecompactor

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

SegmentRecompactor handles recompaction of fragmented segments

func NewSegmentRecompactor

func NewSegmentRecompactor(meta *metadata.MetaDB, sm *segment.Manager, deletionQueue *deletion.Queue, fragThreshold float64, minSegmentAge time.Duration, minSegments int) *SegmentRecompactor

NewSegmentRecompactor creates a new segment recompactor without a rate limit. NewCompactorWithConfig uses the internal constructor to share its limiter with file compaction workers.

func (*SegmentRecompactor) RecompactFragmentedSegments

func (sr *SegmentRecompactor) RecompactFragmentedSegments(ctx context.Context) error

RecompactFragmentedSegments identifies and recompacts fragmented segments

Jump to

Keyboard shortcuts

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