datastore

package
v1.801.468 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package datastore is cloud's one connection to the analytics warehouse — the columnar store behind usage, observability and billing.

Every read and write of a warehouse table in this binary goes through it. It is NOT the tenant-facing Hanzo Datastore product (apps/provisioning's `datastore` kind at /v1/datastore, a dedicated instance per org); one word, two things, and this is the platform's own handle.

One store, not one per tenant. Rows carry the tenant as a column and as the leading sort key, so a single-org read is a bound predicate over a shared table (WHERE organization = ?) and a fleet-wide aggregate is the same table with that predicate left off. That is the opposite of the relational plane in orgdb.go, where a tenant IS a SQLite file and a cross-tenant read is structurally impossible. The two planes share no connection and are configured independently; keeping them apart is what lets the leaderboard and the admin fleet views span every org while an entity read cannot leave one.

The connection opens from the environment on first use — DATASTORE_ADDR and friends, read by datastore.Env. Open never blocks and never fails, so a warehouse that is down at boot leaves the ledgers unavailable rather than taking down the process that owns them; callers gate on Ready and report an honest gap instead of fabricating zeroes. Because the connection is established once and never replaced, there is no wiring order to get wrong and no window in which a caller sees a half-built client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close() error

Close releases the connection. It is idempotent, and Exec and Query return datastore.ErrUnavailable afterwards.

func EnsureCloudUsage

func EnsureCloudUsage(ctx context.Context) error

EnsureCloudUsage creates hanzo.cloud_usage if absent, then applies the additive column migrations so a pre-existing table gains the newer columns. Only SUCCESS latches, so a warehouse still connecting at boot is retried on the next call rather than poisoned forever.

func Exec

func Exec(ctx context.Context, stmt string, args ...any) error

Exec runs a statement — engine DDL, or an insert. Placeholders bind positionally from args.

func Query

func Query(ctx context.Context, query string, args ...any) ([]map[string]any, error)

Query runs a read and materialises the result, decoding each column into its native scan type keyed by column name. Placeholders bind positionally from args and are never interpolated into the statement, so a tenant predicate holds whatever the tenant value contains.

func Ready

func Ready() bool

Ready reports whether the warehouse is reachable. Read paths gate on it to return an honest gap rather than zeroes, and write paths to skip an insert that would be lost. It is assignable as a bare func() bool.

func Wait

func Wait(ctx context.Context) error

Wait blocks until the warehouse is reachable, the context ends, or the client is closed. It returns datastore.ErrUnavailable for a client that can never become ready, so a readiness probe fails fast on a misconfiguration instead of timing out.

Types

This section is empty.

Jump to

Keyboard shortcuts

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