bucketindex

package
v0.31.2 Latest Latest
Warning

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

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

Documentation

Overview

Package bucketindex maintains a compact, incremental index of the immutable parts under a key prefix, so a stateless reader enumerates a tenant's parts (and prunes them by time) from a single object instead of a full, expensive bucket LIST (DESIGN.md §11, the object-store-native read path). The index is itself a backend object, rewritten as parts are added by flush/merge and removed by retention.

The on-disk form is a small, versioned binary blob (see Index.AppendBinary / Decode); it is fuzzed for decode safety and golden-tested for format stability.

Index

Constants

View Source
const Object = "bucket-index.bin"

Object is the conventional backend key, relative to a prefix, under which the index is stored. Callers join it with the tenant/signal prefix, e.g. "default/metrics/" + Object.

Variables

View Source
var ErrCorrupt = errors.New("bucketindex: corrupt index")

ErrCorrupt is returned (wrapped) by Decode for malformed input.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Prefix  string
	MinTime int64
	MaxTime int64
}

Entry describes one immutable part: its key prefix (the part's object-group root, e.g. "default/metrics/0000000001") and the inclusive unix-nanosecond time range of its samples, used to prune parts that cannot intersect a query window.

type Index

type Index struct {
	Entries []Entry
	// FlushedEpoch is the highest WAL flush generation durably persisted in these parts (0 if
	// unused). It is the watermark a record engine reads on recovery to skip WAL records a part
	// already holds — advanced atomically with the part list, so exactly-once replay survives a
	// crash between a flush committing and its WAL being truncated. Added in format v2.
	FlushedEpoch uint64
}

Index is the set of parts under a prefix, kept sorted by Entry.Prefix. The zero value is a valid empty index.

func Decode

func Decode(data []byte) (*Index, error)

Decode parses the binary encoding produced by Index.AppendBinary. It is defensive against truncated/malformed input (it is fuzzed).

func Load

func Load(ctx context.Context, b backend.Backend, key string) (*Index, error)

Load reads the index stored under key from b. A missing object is reported as an empty index (the read path starts before any flush has written one).

func (*Index) Add

func (ix *Index) Add(e Entry)

Add inserts e, replacing any existing entry with the same prefix, keeping the index sorted.

func (*Index) AppendBinary

func (ix *Index) AppendBinary(dst []byte) []byte

AppendBinary appends the versioned binary encoding of the index to dst (append-style for buffer reuse).

func (*Index) Overlapping

func (ix *Index) Overlapping(start, end int64) []Entry

Overlapping returns, in index order, the parts whose time range intersects the inclusive window [start, end]. It is the read-path prune: only these parts need to be opened.

func (*Index) Remove

func (ix *Index) Remove(prefix string) bool

Remove deletes the entry with the given prefix, reporting whether one was removed.

func (*Index) Save

func (ix *Index) Save(ctx context.Context, b backend.Backend, key string) error

Save writes the index under key in b (overwriting the previous version atomically per the backend's per-object write atomicity).

Jump to

Keyboard shortcuts

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