compaction

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 2 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package compaction contains the option, metric, and transport values used by dataset compaction.

The types in this package are independent of a Dataset and of the native bindings. Dataset methods in the root package perform the actual native calls. Plan, task, and rewrite-result values are immutable snapshots: the native serialized JSON is authoritative, so a plan can be sent to another process and executed there without carrying a native handle across the boundary.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CandidateFile

type CandidateFile struct {
	Path       string
	Kind       FileKind
	Unverified bool
	SizeBytes  uint64
}

CandidateFile is one file observed by CleanupExplain.

type CleanupExplanation

type CleanupExplanation struct {
	ReadVersion             uint64
	Stats                   RemovalStats
	Candidates              []CandidateFile
	CandidateFilesTruncated bool
	CandidateFileLimit      uint64
	ReferencedBranches      []ReferencedBranch
	Warnings                []string
}

CleanupExplanation is an immutable snapshot of the cleanup candidates that existed when the explanation was requested.

It is not a deletion plan or a reservation. Running cleanup re-evaluates the current dataset state, so files listed here may no longer be removable, and files not listed here may have become removable.

type CleanupOldVersionsOptions

type CleanupOldVersionsOptions struct {
	// OlderThan is the relative age cutoff. Native Lance owns the exact
	// cutoff calculation.
	OlderThan time.Duration

	// DeleteUnverified allows deleting files that are not referenced by a
	// manifest.
	DeleteUnverified *bool

	// ErrorIfTaggedOldVersions fails instead of deleting a version that has
	// tags.
	ErrorIfTaggedOldVersions *bool
}

CleanupOldVersionsOptions configures the older-than cleanup helper.

type CleanupOperationOptions

type CleanupOperationOptions struct {
	// DeleteConcurrency limits concurrent deletions.
	DeleteConcurrency *uint64

	// DeleteRateLimit overrides CleanupPolicy.DeleteRateLimit.
	DeleteRateLimit *uint64

	// MaxCandidateFiles limits how many candidate files are included in an
	// explanation. Zero is valid and includes no candidates while still
	// reporting aggregate statistics and truncation.
	MaxCandidateFiles *uint64
}

CleanupOperationOptions controls one cleanup execution.

A nil *CleanupOperationOptions uses native operation defaults.

type CleanupPolicy

type CleanupPolicy struct {
	// BeforeTimestamp selects versions created before this time.
	BeforeTimestamp *time.Time

	// BeforeVersion selects versions older than this version.
	BeforeVersion *uint64

	// Versions selects specific versions.
	Versions []uint64

	// RetainVersions keeps this many latest versions. It is mutually
	// exclusive with BeforeVersion in the native selector.
	RetainVersions *uint64

	// DeleteUnverified allows deleting files that are not referenced by a
	// manifest.
	DeleteUnverified *bool

	// ErrorIfTaggedOldVersions fails instead of deleting a version that has
	// tags. Native defaults to true.
	ErrorIfTaggedOldVersions *bool

	// CleanReferencedBranches also cleans versions referenced by branches.
	CleanReferencedBranches *bool

	// DeleteRateLimit limits deletions per second.
	DeleteRateLimit *uint64
}

CleanupPolicy selects old versions and files for native cleanup.

The selectors are independent and combine with logical AND. Nil pointers leave the corresponding native default unchanged. A nil Versions slice leaves the native versions selector absent; a non-nil empty slice is passed through as an explicit empty selector and is rejected by native validation.

type FileKind

type FileKind int32

FileKind identifies a cleanup candidate file.

const (
	// FileKindManifest is a manifest file.
	FileKindManifest FileKind = 0
	// FileKindData is a data file.
	FileKindData FileKind = 1
	// FileKindTransaction is a transaction file.
	FileKindTransaction FileKind = 2
	// FileKindIndex is an index file.
	FileKindIndex FileKind = 3
	// FileKindDeletion is a deletion file.
	FileKindDeletion FileKind = 4
	// FileKindTemporaryManifest is a temporary manifest file.
	FileKindTemporaryManifest FileKind = 5
)

type IndexRemapMode

type IndexRemapMode int32

IndexRemapMode selects how compaction remaps indexes.

const (
	// IndexRemapCompact remaps indexes through the compaction path.
	IndexRemapCompact IndexRemapMode = 0
	// IndexRemapDirect remaps indexes directly.
	IndexRemapDirect IndexRemapMode = 1
)

func (IndexRemapMode) String

func (m IndexRemapMode) String() string

String returns the native option name.

type Metrics

type Metrics struct {
	FragmentsRemoved uint64
	FragmentsAdded   uint64
	FilesRemoved     uint64
	FilesAdded       uint64
}

Metrics reports the fragments and files changed by a compaction.

type Mode

type Mode int32

Mode selects how compaction rewrites fragments.

const (
	// ModeReencode rewrites data through the normal encoding path.
	ModeReencode Mode = 0
	// ModeTryBinaryCopy uses binary copy when it is safe, and re-encodes
	// fragments that cannot be copied.
	ModeTryBinaryCopy Mode = 1
	// ModeForceBinaryCopy requires binary copy and fails when a fragment
	// cannot be copied.
	ModeForceBinaryCopy Mode = 2
)

func (Mode) String

func (m Mode) String() string

String returns the native option name.

type OptimizeOptions

type OptimizeOptions struct {
	// NumIndicesToMerge limits how many existing index segments one merge
	// absorbs. Unset leaves the native default (None): a split build appends a
	// delta, while the single-process optimizer may instead merge all delta
	// segments when a vector index's partitions need rebalancing. Some(n)
	// merges the latest n segments plus the new updates, and Some(0) disables
	// merging and appends a delta.
	NumIndicesToMerge Optional[uint64]

	// EnablePartitionRebalancing lets native optimization rebalance index
	// partitions. Native validation rejects it together with Some(0) or with
	// MaxRowsPerTask or MaxRowsPerSegment.
	EnablePartitionRebalancing bool

	// IndexNames limits optimization to the named indices. Unset and None
	// leave the native default of every index; Some(nil) or Some with an
	// empty slice explicitly selects no index.
	IndexNames Optional[[]string]

	// Retrain merges every segment of a selected vector index into one and
	// retrains it. Native optimization only supports this for v3 vector
	// indices.
	Retrain bool

	// TransactionProperties adds properties to the commit transaction. Nil
	// leaves the native option unset; a non-nil map, including an empty one,
	// sets it. The map is copied before the call returns.
	TransactionProperties map[string]string

	// MaxRowsPerTask bounds the rows one build task covers. Unset and None both
	// leave the native bound unset (unbounded); Some sets it, including zero.
	MaxRowsPerTask Optional[uint64]

	// MaxRowsPerSegment bounds the rows in one output segment. Unset and None
	// both leave the native bound unset (unbounded); Some sets it, including
	// zero.
	MaxRowsPerSegment Optional[uint64]
}

OptimizeOptions configures native index optimization.

A nil *OptimizeOptions passed to a Dataset method selects the native defaults (the C API's NULL options). A non-nil value starts from native defaults and applies only the fields that are set.

Unset optional fields leave the native default unchanged; None sets the native option to None explicitly; Some sets it, including an explicit zero or an empty slice. IndexNames and TransactionProperties are copied before the call returns.

Native plan, task, merge and result JSON do not serialize OptimizeOptions. Task JSON carries the merge options that execution re-applies (NumIndicesToMerge, EnablePartitionRebalancing and Retrain). IndexNames and the row bounds only select and split the plan. TransactionProperties apply only to a commit, so pass them again to CommitOptimizeIndices when the results crossed a JSON transport boundary.

type Optional

type Optional[T any] struct {
	// contains filtered or unexported fields
}

Optional represents a native optional option. Its zero value is unset, which leaves the corresponding native default unchanged.

Some and None map to the native setter's has_value flag. The distinction matters for options whose native default is Some(...), such as MaxOverlaysPerFragment and BinaryCopyReadBatchBytes.

func None

func None[T any]() Optional[T]

None returns an optional value that is explicitly absent.

func Some

func Some[T any](value T) Optional[T]

Some returns an optional value with a value present.

func Unset

func Unset[T any]() Optional[T]

Unset returns an unset optional value.

func (Optional[T]) Get

func (o Optional[T]) Get() (T, bool)

Get returns the option value and whether a value is present.

func (Optional[T]) IsNone

func (o Optional[T]) IsNone() bool

IsNone reports whether the option was explicitly set to none.

func (Optional[T]) IsSet

func (o Optional[T]) IsSet() bool

IsSet reports whether the option was set to either a value or none.

type Options

type Options struct {
	// TargetRowsPerFragment is the target number of rows per output
	// fragment. Nil leaves the native default (1048576) unchanged.
	TargetRowsPerFragment *uint64

	// MaxRowsPerGroup is the maximum number of rows per output group. Nil
	// leaves the native default (1024) unchanged.
	MaxRowsPerGroup *uint64

	// MaxBytesPerFile limits output file size. Nil leaves the native
	// default (none) unchanged; Some(0) is an explicit native value.
	MaxBytesPerFile Optional[uint64]

	// MaterializeDeletions controls whether deletions are materialized.
	MaterializeDeletions *bool

	// MaterializeDeletionsThreshold is the deletion density above which
	// deletions are materialized. It is converted to a native float.
	MaterializeDeletionsThreshold *float64

	// NumThreads limits native compaction parallelism.
	NumThreads Optional[uint64]

	// BatchSize sets the native read batch size.
	BatchSize Optional[uint64]

	// IOBufferSize sets the native I/O buffer size.
	IOBufferSize Optional[uint64]

	// DeferIndexRemap defers index remapping to the commit path.
	DeferIndexRemap *bool

	// IndexRemapMode selects the index remap strategy.
	IndexRemapMode *IndexRemapMode

	// CompactionMode selects re-encode or binary copy.
	CompactionMode Optional[Mode]

	// BinaryCopyReadBatchBytes sets the binary-copy read batch size.
	BinaryCopyReadBatchBytes Optional[uint64]

	// MaxSourceFragments limits how many source fragments one task reads.
	MaxSourceFragments Optional[uint64]

	// MaxSourceRows limits how many source rows one task reads.
	MaxSourceRows Optional[uint64]

	// MaxSourceBytes limits how many source bytes one task reads.
	MaxSourceBytes Optional[uint64]

	// ExcludedFragmentIDs lists fragments that must not be compacted.
	ExcludedFragmentIDs []uint32

	// MaxOverlaysPerFragment limits the number of deletion overlays
	// considered per fragment.
	MaxOverlaysPerFragment Optional[uint64]

	// DataStorageVersion selects the output storage version, for example
	// "2.1" or "stable". None explicitly clears the native option.
	DataStorageVersion Optional[string]

	// TransactionProperties adds properties to the commit transaction. Nil
	// leaves the native option unset; a non-nil map, including an empty one,
	// sets it. The map is copied before the call returns.
	//
	// Native plan and task JSON does not serialize transaction properties.
	// Pass them again to CommitCompaction when a plan or result crossed a
	// JSON transport boundary.
	TransactionProperties map[string]string
}

Options configures native CompactionOptionsV2.

A nil *Options passed to a Dataset method selects the native from-dataset-config options (the C API's NULL options). A non-nil Options starts from native defaults and applies only the fields that are set.

Pointer fields distinguish an absent value from an explicit zero or false. Optional fields additionally distinguish an explicit native None from an unset value. ExcludedFragmentIDs and TransactionProperties are copied before the call returns.

Example

This example builds options for Dataset.CompactFiles and Dataset.PlanCompaction. A pointer field sets an explicit value, while an Optional field distinguishes an unset value, an explicit native None, and a value including zero.

package main

import (
	"fmt"

	"github.com/lance-format/lance-go/compaction"
)

func main() {
	targetRows := uint64(1 << 18)
	options := &compaction.Options{
		// A non-nil pointer forwards the value; nil leaves the native default.
		TargetRowsPerFragment: &targetRows,
		// Some forwards an explicit value, including zero.
		CompactionMode: compaction.Some(compaction.ModeTryBinaryCopy),
		// None clears a native option whose default is Some(...).
		MaxOverlaysPerFragment: compaction.None[uint64](),
		// Fields left at the zero Optional stay unset, so native defaults apply.
	}

	// options is passed to dataset.CompactFiles(ctx, options) or
	// dataset.PlanCompaction(ctx, options).

	mode, hasMode := options.CompactionMode.Get()
	fmt.Println("compaction mode:", mode, hasMode)
	fmt.Println("max overlays is none:", options.MaxOverlaysPerFragment.IsNone())
	fmt.Println("num threads is set:", options.NumThreads.IsSet())
}
Output:
compaction mode: TryBinaryCopy true
max overlays is none: true
num threads is set: false

type ReferencedBranch

type ReferencedBranch struct {
	Name             string
	Version          uint64
	CleanupCandidate bool
}

ReferencedBranch is a branch observed by CleanupExplain.

type RemovalStats

type RemovalStats struct {
	BytesRemoved            uint64
	OldVersions             uint64
	DataFilesRemoved        uint64
	TransactionFilesRemoved uint64
	IndexFilesRemoved       uint64
	DeletionFilesRemoved    uint64
	FailedDeletes           uint64
}

RemovalStats reports the work performed by a cleanup.

Jump to

Keyboard shortcuts

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