maintenance

package
v0.8.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: 22 Imported by: ? modules, 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 maintenance provides table maintenance operations, such as orphan file cleanup, that operate on a loaded table.Table. The operations are free functions that take the table as their first argument, for example:

result, err := maintenance.DeleteOrphanFiles(ctx, tbl, maintenance.WithCleanupFilesOlderThan(72*time.Hour))

Index

Constants

This section is empty.

Variables

View Source
var ErrStaleOrphanCleanupPlan = errors.New("orphan cleanup plan is stale")

ErrStaleOrphanCleanupPlan marks a plan that cannot be safely executed against the current table. Execution refreshes a copy of the table, so callers must refresh or reload their table before planning again after this error.

Functions

func PurgeFiles

func PurgeFiles(ctx context.Context, tbl *table.Table) error

PurgeFiles physically deletes all files under the table's warehouse location and any referenced files written outside the location root (e.g., via write.data.path or write.metadata.path properties).

It operates on a best-effort basis. Errors from individual file deletions are collected and returned together as a joined error. If files cannot be deleted (e.g. due to permission errors or missing paths), the errors are logged but the overall catalog drop operation should typically proceed so the catalog does not get out of sync with storage. Non-bulk deletion invokes Remove concurrently and is bounded to defaultPurgeMaxConcurrency operations because it is typically I/O-bound.

Types

type OrphanCleanupOption

type OrphanCleanupOption func(*orphanCleanupConfig)

OrphanCleanupOption configures an orphan-cleanup run. Options are passed to DeleteOrphanFiles, PlanOrphanFiles, and ExecuteOrphanCleanup.

func WithCleanupDeleteFunc

func WithCleanupDeleteFunc(deleteFunc func(context.Context, string) error) OrphanCleanupOption

WithCleanupDeleteFunc sets a custom delete function. If not provided, the table's FileIO delete method will be used.

func WithCleanupDryRun

func WithCleanupDryRun(enabled bool) OrphanCleanupOption

WithCleanupDryRun reports which files would be deleted without deleting them. Defaults to false.

func WithCleanupFilesOlderThan

func WithCleanupFilesOlderThan(duration time.Duration) OrphanCleanupOption

WithCleanupFilesOlderThan only considers files last modified before now minus duration. The duration must be non-negative and defaults to 72 hours. Keep it longer than the longest expected write so cleanup does not delete files from commits that are still in flight.

func WithCleanupLocation

func WithCleanupLocation(location string) OrphanCleanupOption

WithCleanupLocation sets the location to scan for orphan files. Defaults to the table's data location.

func WithCleanupMaxConcurrency

func WithCleanupMaxConcurrency(maxWorkers int) OrphanCleanupOption

WithCleanupMaxConcurrency sets the maximum number of goroutines for parallel deletion. Defaults to a reasonable number based on the system. Only used when deleteFunc is nil or when the FileIO doesn't support bulk operations.

func WithEqualAuthorities

func WithEqualAuthorities(authorities map[string]string) OrphanCleanupOption

WithEqualAuthorities specifies authorities that should be considered equivalent. For example, map["endpoint1.s3.amazonaws.com,endpoint2.s3.amazonaws.com"] = "s3.amazonaws.com" treats different S3 endpoints as equivalent. The key can be a comma-separated list.

func WithEqualSchemes

func WithEqualSchemes(schemes map[string]string) OrphanCleanupOption

WithEqualSchemes specifies schemes that should be considered equivalent. For example, map["s3,s3a,s3n"] = "s3" treats all S3 scheme variants as equivalent. The key can be a comma-separated list of schemes that map to the value scheme.

func WithPrefixMismatchMode

func WithPrefixMismatchMode(mode PrefixMismatchMode) OrphanCleanupOption

WithPrefixMismatchMode sets how to handle situations when metadata references files that match listed files except for authority/scheme differences.

type OrphanCleanupPlan

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

OrphanCleanupPlan contains the exact orphan files identified during one scan. The file list is private so callers can only obtain copies, keeping the plan stable between confirmation and execution.

func PlanOrphanFiles

func PlanOrphanFiles(ctx context.Context, tbl *table.Table, opts ...OrphanCleanupOption) (OrphanCleanupPlan, error)

PlanOrphanFiles identifies orphan files without deleting anything. The returned plan can be shown to a user and passed to ExecuteOrphanCleanup to delete exactly that set.

func (OrphanCleanupPlan) Cutoff

func (p OrphanCleanupPlan) Cutoff() time.Time

Cutoff returns the age cutoff used to create the cleanup plan. It is informational only; executing a plan does not re-evaluate file ages.

func (OrphanCleanupPlan) Files

func (p OrphanCleanupPlan) Files() []string

Files returns a copy of the files in the cleanup plan.

func (OrphanCleanupPlan) OrphanFiles

func (p OrphanCleanupPlan) OrphanFiles() []OrphanFile

OrphanFiles returns copies of the path and size entries in the cleanup plan.

func (OrphanCleanupPlan) TotalSizeBytes

func (p OrphanCleanupPlan) TotalSizeBytes() int64

TotalSizeBytes returns the combined size of files in the cleanup plan.

type OrphanCleanupResult

type OrphanCleanupResult struct {
	// OrphanFiles includes the path and size of each identified orphan.
	OrphanFiles  []OrphanFile
	DeletedFiles []string
	// TotalSizeBytes is the combined size of orphan files only, not all scanned files.
	TotalSizeBytes int64
}

OrphanCleanupResult reports the files found and deleted by orphan cleanup.

func DeleteOrphanFiles

func DeleteOrphanFiles(ctx context.Context, tbl *table.Table, opts ...OrphanCleanupOption) (OrphanCleanupResult, error)

DeleteOrphanFiles identifies files under a table location that are no longer referenced by table metadata and deletes them unless dry-run is enabled.

The table filesystem must implement io.ListableIO so orphan cleanup can fully enumerate candidate files before deciding what is safe to delete. A non-dry run requires a catalog-backed table. It refreshes a copy of tbl before planning and refreshes again to verify that the plan still matches the table before deleting files. Use an age threshold longer than the longest expected write (default 72 hours) to protect writes that commit after the second refresh. Dry runs plan from the supplied table metadata. Orphan cleanup, including dry runs, is rejected when garbage collection is disabled via gc.enabled.

func ExecuteOrphanCleanup

func ExecuteOrphanCleanup(ctx context.Context, tbl *table.Table, plan OrphanCleanupPlan, opts ...OrphanCleanupOption) (OrphanCleanupResult, error)

ExecuteOrphanCleanup deletes the files in plan if the table metadata has not changed since planning. Execution requires a catalog-backed table so it can refresh metadata and reject plans that are already stale. This check does not coordinate with commits that happen after the refresh; use an age threshold longer than the longest expected write (the default is 72 hours). If this returns ErrStaleOrphanCleanupPlan, tbl is unchanged; refresh or reload it before planning again. Orphan cleanup is rejected when garbage collection is disabled via gc.enabled.

type OrphanFile

type OrphanFile struct {
	Path      string
	SizeBytes int64
}

type PrefixMismatchMode

type PrefixMismatchMode int

PrefixMismatchMode defines how to handle cases where candidate files have different URI schemes or authorities compared to table location during orphan cleanup. This is useful when files may be referenced using different but equivalent schemes (e.g., s3:// vs s3a:// vs s3n://) or when cleaning up files across different locations.

const (
	// PrefixMismatchError causes cleanup to fail with an error when candidate files
	// have URI schemes/authorities that don't match the table location and are not
	// covered by configured equivalences. This is the safest default behavior.
	PrefixMismatchError PrefixMismatchMode = iota // default

	// PrefixMismatchIgnore skips candidate files that have mismatched URI schemes/authorities
	// without treating it as an error. Files are silently ignored and not considered for deletion.
	PrefixMismatchIgnore

	// PrefixMismatchDelete treats candidate files with mismatched URI schemes/authorities
	// as orphans and includes them for deletion. Use with caution as this may delete
	// files from unexpected locations.
	PrefixMismatchDelete
)

func (PrefixMismatchMode) String

func (p PrefixMismatchMode) String() string

Jump to

Keyboard shortcuts

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