engine

package
v0.0.0-...-0301fe8 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: 35 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

Index

Constants

View Source
const MaxPatternBytes = 256

MaxPatternBytes bounds a pattern's length.

Variables

View Source
var ErrStalled = errors.New("query engine stalled")

ErrStalled reports a stall in work Pitot owns: a Parquet publication running far past its budget, or an idle engine that does not answer a ping. Only a restart frees it.

Functions

func CreateCacheTables

func CreateCacheTables(db *sql.DB) error

CreateCacheTables creates DuckDB's tables: the rebuildable read caches and the anomaly history. The telemetry rows themselves live in immutable Parquet batches.

func CreateParquetViews

func CreateParquetViews(db *sql.DB, parquetDir string) error

CreateParquetViews exposes the fixed format-6 schema. Binding one file rather than unioning every footer bounds binder memory. Supplying a schema MAP suppresses DuckDB 2's VARIANT extraction pushdown, so read the physical schema directly; startup rejects mismatched batch schemas before this point. The bound file is the schema batch, listed first: a retired batch may be deleted between DuckDB's glob expansion and its bind. Reads of these views are bound to the captured catalog whenever it is not empty.

func CreateViews

func CreateViews(db *sql.DB) error

CreateViews creates stable clean-name views plus the attr() macro.

func NormalizeJSON

func NormalizeJSON(text string) string

NormalizeJSON makes the JSON text of a serialized column parseable. DuckDB writes nonfinite doubles as bare NaN, Infinity and -Infinity, which JSON cannot encode; they become the ProtoJSON strings of the same names. Storage remains typed.

func NormalizeLogQualifiers

func NormalizeLogQualifiers(node map[string]any)

NormalizeLogQualifiers binds approved schema-qualified log columns before the panel replaces logs with its redacted projection. Snapshot compilation uses the same lexical resolver for every relation it replaces.

func PatternParams

func PatternParams(value any) map[string]bool

PatternParams names the parameters a statement uses as patterns, so a caller can bound their values when it binds them.

Types

type Duck

type Duck struct {

	// DB is the read pool. Reads scan immutable Parquet concurrently, so it is
	// sized from the machine.
	DB *sql.DB
	// contains filtered or unexported fields
}

func NewDuck

func NewDuck(ctx context.Context, cfg config.Config, repository *telemetrystore.Repository) (*Duck, error)

func (*Duck) CheckpointHealth

func (d *Duck) CheckpointHealth() (lastOK, lastAt time.Time, consecutiveFailures int, lastErr error)

CheckpointHealth reports the rollup-cache checkpoint's own health, mirroring MaintenanceHealth: when a fold last succeeded, when one was last attempted, how many have failed in a row, and the most recent error (nil after a clean fold). It is surfaced via /readyz separately from maintenance so a transient refusal — retried on the 10s compaction cycle — does not degrade readiness, while a fold that keeps failing well past that cadence still does. A zero lastAt means no checkpoint has been attempted since the process started.

func (*Duck) Close

func (d *Duck) Close() error

func (*Duck) CompletedServiceRollupMinute

func (d *Duck) CompletedServiceRollupMinute(ctx context.Context) (time.Time, error)

CompletedServiceRollupMinute is the exclusive end of detector input. The minute containing the ingest watermark may still be incomplete.

func (*Duck) DefaultNamespace

func (d *Duck) DefaultNamespace() string

DefaultNamespace returns empty string so queries search all namespaces.

func (*Duck) DrainVersionRollup

func (d *Duck) DrainVersionRollup(ctx context.Context) (int64, bool, error)

DrainVersionRollup repeats passes while a pass's budget left batches behind, and reports whether a backlog still remains when the phase budget ends.

func (*Duck) Fatal

func (d *Duck) Fatal() <-chan error

Fatal delivers the first fatal engine error a background pass saw. DuckDB has invalidated the database by then and fails every later statement, so the process must restart; nothing in it can recover the instance.

func (*Duck) Live

func (d *Duck) Live(ctx context.Context) error

Live reports whether the engine can still serve. A stall fails it. A pool where statements returned recently is alive. Otherwise a ping confirms it, and a ping that fails while reads hold the pool may only have waited for them, not found the engine hung, so that is alive too.

func (*Duck) MaintenanceHealth

func (d *Duck) MaintenanceHealth() (lastOK, lastAt time.Time, consecutiveFailures int, lastErr error)

MaintenanceHealth reports the maintenance loop's own health: when it last completed cleanly, when a pass last executed at all (throttled calls don't count), and the error from the most recent executed pass (nil after a clean one). Surfaced via /readyz so an instance whose retention/compaction is failing — and therefore re-entering the storage growth spiral — tells its operator instead of only logging. lastAt distinguishes "failing right now" from a stale error awaiting the hourly retry; a zero lastAt means no pass has executed since the process started.

func (*Duck) Overruns

func (d *Duck) Overruns() int

Overruns counts the reads still running more than overrunGrace past their deadlines. They make readiness degraded, never liveness: a costly query holds its own connection while the engine serves the rest.

func (*Duck) ParseSQL

func (d *Duck) ParseSQL(ctx context.Context, query string) (map[string]any, error)

ParseSQL parses one statement with DuckDB's parser and returns its serialized node. It reads no telemetry and takes no snapshot.

func (*Duck) Ping

func (d *Duck) Ping(ctx context.Context) error

Ping runs a trivial statement on the read pool, recording progress when it answers. It is not tracked as a statement in flight; the connection it holds is counted in pings.

func (*Duck) PrepareTelemetrySQL

func (d *Duck) PrepareTelemetrySQL(ctx context.Context, query, describe string, maxRows int) (string, []bool, error)

PrepareTelemetrySQL checks one untrusted SELECT (both query and describe, since binding describe can invoke table functions) against the telemetry SQL rules and wraps it in the projection that keeps nested values away from the Go driver. describe is the same statement with every placeholder replaced by NULL, which DESCRIBE can bind; the returned statement keeps query's placeholders and is run with QueryContext under the panel's read window.

func (*Duck) PublishParquet

func (d *Duck) PublishParquet(ctx context.Context, publish func(context.Context) error) error

PublishParquet runs one catalog swap. Readers are never excluded or waited for: the swap is atomic under the catalog lock, and what it replaces stays on disk until no pinned reader can open it. The budget only bounds the swap's own publish gate, rename and fsync.

func (*Duck) PublishParquetReplacement

func (d *Duck) PublishParquetReplacement(ctx context.Context, output telemetry.BatchMetadata, inputs []string, publish func(context.Context) error) error

PublishParquetReplacement reuses complete input caches when the SQL leases are idle. Busy leases defer the transfer to the refresh worker, without delaying the catalog swap or decoding the output again.

func (*Duck) QueryContext

func (d *Duck) QueryContext(ctx context.Context, query string, args ...any) (queryrows.Rows, error)

QueryContext executes a read against immutable Parquet files and DuckDB's local rollup cache.

func (*Duck) QueryRowScan

func (d *Duck) QueryRowScan(ctx context.Context, dest []any, query string, args ...any) error

QueryRowScan executes a single-row query against immutable Parquet files and DuckDB's local rollup cache.

func (*Duck) ReadConnections

func (d *Duck) ReadConnections() int

ReadConnections is the size of the read pool, so a caller can admit no more concurrent readers than there are connections.

func (*Duck) RecordAnomalies

func (d *Duck) RecordAnomalies(ctx context.Context, findings []annotations.Anomaly, now time.Time) error

func (*Duck) RefreshDashboardRollups

func (d *Duck) RefreshDashboardRollups(ctx context.Context) (int64, error)

RefreshDashboardRollups advances the analytical dashboard summaries. Each pass commits a complete set of affected service-minutes and its ingest horizon.

func (*Duck) RefreshReadCaches

func (d *Duck) RefreshReadCaches(ctx context.Context) (int64, error)

RefreshReadCaches acknowledges complete immutable files, not an ingest-time watermark. A pass only aggregates its selected batches: it never rebuilds a retained-history index. Contributions and acknowledgements commit together.

func (*Duck) RefreshVersionRollup

func (d *Duck) RefreshVersionRollup(ctx context.Context) (int64, error)

func (*Duck) RenderSQL

func (d *Duck) RenderSQL(ctx context.Context, node map[string]any) (string, error)

RenderSQL renders a statement node (as returned by ParseSQL) back to SQL text with DuckDB's own serializer. The text is canonical: comments, dollar quotes and other lexical forms the author used cannot survive it, so a caller that checked the node can bind and run the rendering instead of the author's text.

func (*Duck) RollupWatermark

func (d *Duck) RollupWatermark(ctx context.Context) (time.Time, error)

RollupWatermark is the committed ingest horizon shared by service_rollup and span_rollup. This standalone preflight precedes the panel's data snapshot; snapshot-bound coverage checks read persisted state in their own transaction.

func (*Duck) RunRollups

func (d *Duck) RunRollups(ctx context.Context)

func (*Duck) SetReadPressure

func (d *Duck) SetReadPressure(pressure func() bool)

SetReadPressure connects foreground admission to bounded background yielding.

func (*Duck) SnapshotCacheStats

func (d *Duck) SnapshotCacheStats() (hits, misses int64)

SnapshotCacheStats reports the cumulative snapshot-compile cache hits and misses since start. A miss is a statement whose compiled relation aliases had to be built; a hit reused them. It lets a benchmark or test measure the cache hit rate, which window-stable statement text is meant to raise.

func (*Duck) Stalled

func (d *Duck) Stalled() bool

Stalled reports whether a Parquet publication has run for publishStall: storage has stopped serving its rename or fsync.

func (*Duck) Trace

Trace pins the immutable Parquet snapshot for the full indexed-file read.

func (*Duck) TraceDetail

func (d *Duck) TraceDetail(ctx context.Context, query telemetry.TraceQuery) (telemetry.TraceDetail, error)

TraceDetail pins one snapshot for a trace's spans and logs together.

func (*Duck) TraceSummaries

func (d *Duck) TraceSummaries(ctx context.Context, ids []telemetry.TraceIdentity, start, end int64) ([]telemetry.TraceTotals, error)

TraceSummaries pins one snapshot for the bounded multi-trace root pass.

func (*Duck) Watch

func (d *Duck) Watch(ctx context.Context)

Watch reports read overruns, and delivers ErrStalled on Fatal once a stall in Pitot's own work has lasted stallExit, so the process exits and its supervisor restarts it. Overload and costly queries are no stall. It stops with ctx, so shutdown cannot fire it.

func (*Duck) WithReadTransaction

func (d *Duck) WithReadTransaction(ctx context.Context, read func(queryrows.Queryer) error) error

WithReadTransaction keeps derived annotation rows and completeness flags in one read snapshot. Its callback only receives the query surface.

func (*Duck) WriteGate

func (d *Duck) WriteGate() *writegate.Gate

WriteGate returns the gate that serializes writes to DuckDB's rebuildable rollup cache.

Directories

Path Synopsis
Package querytest builds mutable fixtures; production reads immutable Parquet.
Package querytest builds mutable fixtures; production reads immutable Parquet.
Package writegate serializes and measures writes to DuckDB's rebuildable rollup cache.
Package writegate serializes and measures writes to DuckDB's rebuildable rollup cache.

Jump to

Keyboard shortcuts

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