watermark

package
v0.56.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 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 watermark encodes a part's per-series durability watermark sidecar: the newest timestamp each series has in that part.

Both engines write it beside the part at flush and merge, and a replica refresh reads it instead of decoding the part's whole timestamp column. It is the same shape in both — the record engine's streams are signal.SeriesID too — so the codec lives here rather than twice.

Index

Constants

View Source
const (
	// PagedOrdinalMagic identifies ordinal watermarks with packed, independently seekable pages.
	PagedOrdinalMagic = 0x534d4150 // SMAP.

	// PagedWriterScratch accounts for one input page and its temporary encoded bytes.
	PagedWriterScratch = 2 * ordinalPageRows * 8
)
View Source
const OrdinalMagic = 0x534d414f // SMAO.

OrdinalMagic identifies a watermark sidecar whose IDs come from the associated SIDX.

Variables

View Source
var ErrCorrupt = errors.New("watermark: corrupt sidecar")

ErrCorrupt marks an unreadable sidecar. A reader treats it like an absent one and falls back to decoding the timestamp column.

View Source
var ErrUnbounded = errors.New("watermark: bounded reads unavailable")

ErrUnbounded means a backend cannot validate the sidecar through bounded reads.

Functions

func Encode

func Encode(dst []byte, entries []Entry) []byte

Encode serializes the entries in the caller's order: [magic][uvarint n] then per entry [u64 id.Hi][u64 id.Lo][i64 max], all big-endian, with a trailing CRC32C. Encode appends, and the checksum covers only the bytes it appended — whatever dst already held is not part of the record.

func EncodeEntries added in v0.55.0

func EncodeEntries(dst []byte, count int, entry func(int) Entry) []byte

EncodeEntries appends a sidecar without materializing a parallel entry slice.

func IsOrdinal added in v0.56.0

func IsOrdinal(raw []byte) bool

IsOrdinal identifies the legacy or packed coverage encodings bound to a part.

func Key

func Key(prefix string) string

Key is the backend key of a part's watermark sidecar (deleted with the part, since a part is removed by listing its prefix).

func MemoryBound added in v0.55.0

func MemoryBound() (resident, open int64)

MemoryBound prices a reader/cursor pair and sequential validation, including ranged-read copies.

func VisitOrdinal added in v0.56.0

func VisitOrdinal(raw []byte, binding [32]byte, count int, visit func(int64) bool) error

VisitOrdinal validates a complete sidecar and visits timestamps in SIDX order.

func WriteCheckedEntries added in v0.55.0

func WriteCheckedEntries(ctx context.Context, b backend.Backend, key string, count int, entry func(int) (Entry, error)) error

WriteCheckedEntries streams watermarks from a source that can fail.

func WriteEntries added in v0.55.0

func WriteEntries(ctx context.Context, b backend.Backend, key string, count int, entry func(int) Entry) error

WriteEntries streams the existing checked format through bounded scratch.

Types

type Cursor added in v0.55.0

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

Cursor reuses one bounded window of a validated immutable watermark sidecar.

func (*Cursor) At added in v0.55.0

func (c *Cursor) At(index int) (Entry, error)

At reads an ordinal, retaining its page for subsequent ordinals.

func (*Cursor) AtSeries added in v0.55.0

func (c *Cursor) AtSeries(index int, id signal.SeriesID) (Entry, error)

AtSeries reads a watermark at the ordinal of id in the bound SIDX.

func (*Cursor) Reset added in v0.55.0

func (c *Cursor) Reset(ctx context.Context, r *Reader)

Reset rebinds an operation-local window while retaining its scratch capacity.

type Entry

type Entry struct {
	ID  signal.SeriesID
	Max int64
}

Entry is one series' newest timestamp in a part.

func Decode

func Decode(data []byte) ([]Entry, error)

Decode parses a sidecar. It bounds-checks every field and never panics, returning ErrCorrupt on any malformed input so the caller can fall back to decoding.

type OrdinalWriter added in v0.56.0

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

OrdinalWriter writes legacy or packed watermarks in SIDX order. The paged layout is magic, packed deltas, directory, then the bound ordinal footer. Each directory entry contains a payload-relative offset, base, and width.

func OpenOrdinalWriter added in v0.56.0

func OpenOrdinalWriter(ctx context.Context, b backend.Backend, key string, paged bool) (*OrdinalWriter, error)

OpenOrdinalWriter starts a manifest-bound sidecar in the requested encoding.

func (*OrdinalWriter) Abort added in v0.56.0

func (w *OrdinalWriter) Abort()

Abort discards an uncommitted object and returns writer scratch.

func (*OrdinalWriter) Append added in v0.56.0

func (w *OrdinalWriter) Append(ctx context.Context, timestamp int64) error

Append writes an exact covered timestamp.

func (*OrdinalWriter) Commit added in v0.56.0

func (w *OrdinalWriter) Commit(ctx context.Context, binding [32]byte, count int) error

Commit closes the object with its page directory, binding, count and checksum.

func (*OrdinalWriter) DirectoryBytes added in v0.56.0

func (w *OrdinalWriter) DirectoryBytes() int64

DirectoryBytes accounts for the packed page directory retained until commit.

type Reader added in v0.55.0

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

Reader retains validated framing, without retaining per-series entries.

func OpenBoundReader added in v0.55.0

func OpenBoundReader(ctx context.Context, b backend.Backend, key string, count int, binding [32]byte) (*Reader, error)

OpenBoundReader accepts both legacy watermarks and manifest-bound SIDX ordinals.

func OpenReader added in v0.55.0

func OpenReader(ctx context.Context, b backend.Backend, key string, count int) (*Reader, error)

OpenReader validates the checksum and sorted IDs with at most 32 KiB of scratch.

func (*Reader) Cursor added in v0.55.0

func (r *Reader) Cursor(ctx context.Context) *Cursor

Cursor creates an operation-local reader with at most 32 KiB of scratch.

func (*Reader) Lookup added in v0.55.0

func (r *Reader) Lookup(ctx context.Context, id signal.SeriesID) (int64, bool, error)

Lookup reads one series' covered timestamp without decoding other entries.

func (*Reader) LookupSeries added in v0.55.0

func (r *Reader) LookupSeries(ctx context.Context, id signal.SeriesID, pos int) (int64, bool, error)

LookupSeries reads a coverage timestamp given its ID and known SIDX position.

func (*Reader) Ordinal added in v0.55.0

func (r *Reader) Ordinal() bool

Ordinal reports whether the reader uses only positions from SIDX.

Jump to

Keyboard shortcuts

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