Documentation
¶
Overview ¶
Package store is the interface every engine implements and the types its callers speak. The engines live in subpackages (clickhouse, opensearch), the composite that serves one logical store from two is in composite, and factory builds any of them from configuration.
Where the engines differ ¶
A filter is meant to mean the same on any engine, and almost all of them do. These do not, and a caller that relies on the difference has to know:
Text matching. OpContains, OpNotContains, OpContainsAny and OpNotContainsAny are a case-insensitive substring on ClickHouse. On OpenSearch they are a "match" query, which compares analysed words: "deni" finds nothing in "denied" there, and word order and stemming play a part. OpSearch reads the raw-text column on ClickHouse and the field named in opensearch.Config.TextFields on OpenSearch, with every word required.
Anchored matching. OpStartsWith and OpEndsWith are case-insensitive on both, but OpenSearch evaluates them against the indexed terms, so the field has to be a keyword. On an analysed text field they match individual words, not the whole value.
Retention. ClickHouse can move data to a cold volume after Retention.ColdAfter. OpenSearch cannot: SetRetention changes Keep only, and asking it to add or remove a cold tier returns ErrUnsupported. Reading or setting retention there also needs an ISM policy id in the configuration.
Raw queries. RawQuerier takes the engine's own query text, so what runs on one does not run on the other.
Neither engine's behaviour has been changed to hide these: making OpenSearch answer a substring would need wildcard queries over keyword subfields, which depends on how an installation maps its indices.
Index ¶
- Constants
- Variables
- type Admin
- type Bucket
- type BulkWriter
- type CalendarUnit
- type Dataset
- type DatasetUsage
- type Field
- type Filter
- type Group
- type GroupOpts
- type Health
- type HealthStatus
- type Interval
- type Op
- type Page
- type Point
- type RawQuerier
- type Reader
- type Retention
- type Scope
- type Series
- type SortOrder
- type Store
- type Writer
Constants ¶
const AllTenants = "*"
AllTenants is the only way to read across tenants, so that doing so is explicit and greppable.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Admin ¶
type Admin interface {
Usage(ctx context.Context) ([]DatasetUsage, error)
Retention(ctx context.Context, dataset Dataset) (Retention, error)
SetRetention(ctx context.Context, dataset Dataset, r Retention) error
Health(ctx context.Context) (Health, error)
// Drop deletes every record matching the scope, and only those: it is
// bounded by the scope's tenant like any other operation.
Drop(ctx context.Context, s Scope) (int64, error)
}
type BulkWriter ¶
type BulkWriter interface {
Write(s Scope, doc []byte) error
Flush(ctx context.Context) error
Close(ctx context.Context) error
}
BulkWriter batches records. Write reports failures instead of dropping them.
type CalendarUnit ¶
type CalendarUnit string
const ( CalendarNone CalendarUnit = "" CalendarHour CalendarUnit = "hour" CalendarDay CalendarUnit = "day" CalendarWeek CalendarUnit = "week" CalendarMonth CalendarUnit = "month" )
type Dataset ¶
type Dataset string
Dataset names a family of records. The values are defined by the application, not here: what datasets exist and how they map to physical storage is product knowledge, and a driver receives that mapping as configuration.
type DatasetUsage ¶
type Field ¶
type Field struct {
Name string
Type string
Filterable bool // supports exact-match filters
Searchable bool // supports text matching
Conflict bool // type differs across the underlying storage
}
Field describes one queryable field of a dataset.
type Filter ¶
Filter is one predicate. Filters in a slice are ANDed; there is no OR and no nesting, so that a driver never has to implement a boolean evaluator.
type Health ¶
type Health struct {
Status HealthStatus
Message string
DiskUsedPct float64
}
type HealthStatus ¶
type HealthStatus string
const ( HealthOK HealthStatus = "ok" HealthDegraded HealthStatus = "degraded" )
type Interval ¶
type Interval struct {
Duration time.Duration
Calendar CalendarUnit
}
Interval buckets a timeline. Calendar takes precedence over Duration.
type Op ¶
type Op string
const ( OpEq Op = "eq" OpNotEq Op = "not_eq" OpIn Op = "in" OpNotIn Op = "not_in" OpGt Op = "gt" OpGte Op = "gte" OpLt Op = "lt" OpLte Op = "lte" OpBetween Op = "between" // Value is [2]any{lo, hi} OpContains Op = "contains" // substring on ClickHouse, word match on OpenSearch: see the package docs OpNotContains Op = "not_contains" OpExists Op = "exists" // Value ignored // Anchored matching. A prefix or suffix is not the same question as // "contains", and answering one as the other returns rows the caller did // not ask for. OpStartsWith Op = "starts_with" OpNotStartsWith Op = "not_starts_with" OpEndsWith Op = "ends_with" OpNotEndsWith Op = "not_ends_with" // The negations of the two above them. OpNotExists Op = "not_exists" // Value ignored OpNotBetween Op = "not_between" // OpSearch matches anywhere in the record rather than in a field, which is // what a search box asks. Field is ignored; a dataset that has no text to // search is an error rather than a query that matches nothing. OpSearch Op = "search" OpNotSearch Op = "not_search" // Value is a list: matches if any of them is contained. OpContainsAny Op = "contains_any" OpNotContainsAny Op = "not_contains_any" )
type RawQuerier ¶
type RawQuerier interface {
Dialect() string
RawQuery(ctx context.Context, s Scope, query string) ([]map[string]any, error)
}
RawQuerier carries engine-specific query text. It stays outside Store because anything reaching through it is unportable by construction.
type Reader ¶
type Reader interface {
Count(ctx context.Context, s Scope, filters []Filter) (int64, error)
// CountInWindow counts over a trailing window ending at Scope.To, or at now.
CountInWindow(ctx context.Context, s Scope, filters []Filter, window time.Duration) (int64, error)
FetchByID(ctx context.Context, s Scope, id string) (json.RawMessage, error)
FetchN(ctx context.Context, s Scope, filters []Filter, n int) ([]json.RawMessage, error)
FetchPage(ctx context.Context, s Scope, filters []Filter, page Page) ([]json.RawMessage, int64, error)
TopValues(ctx context.Context, s Scope, field string, filters []Filter, n int) ([]Bucket, error)
Timeline(ctx context.Context, s Scope, filters []Filter, interval Interval) ([]Point, error)
TimelineByField(ctx context.Context, s Scope, field string, filters []Filter, interval Interval, n int) ([]Series, error)
GroupBy(ctx context.Context, s Scope, fields []string, filters []Filter, opts GroupOpts) ([]Group, error)
//make sql queries over the storage
FetchQuery(ctx context.Context, s Scope, sql string) ([]json.RawMessage, error)
// DescribeFields lists the queryable fields of a dataset.
DescribeFields(ctx context.Context, s Scope) ([]Field, error)
}
type Retention ¶
Retention is how long data is kept. ColdAfter is only honoured by engines that can tier; OpenSearch rejects a change to it with ErrUnsupported.
type Scope ¶
Scope narrows an operation. Tenant is mandatory and drivers inject it themselves: empty is an error, not "every tenant".
type Writer ¶
type Writer interface {
// Insert generates an id when one is not given; an explicit id means upsert.
Insert(ctx context.Context, s Scope, id string, doc any) error
BulkWriter(dataset Dataset) (BulkWriter, error)
UpdateWhere(ctx context.Context, s Scope, filters []Filter, patch map[string]any) (int64, error)
// Flush makes prior writes visible to reads. Engines that are already
// read-your-writes may implement it as a no-op.
Flush(ctx context.Context, dataset Dataset) error
}
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cache is a thin, nil-safe wrapper around a shared Redis/Valkey instance.
|
Package cache is a thin, nil-safe wrapper around a shared Redis/Valkey instance. |
|
Package clickhouse implements store.Store over ClickHouse.
|
Package clickhouse implements store.Store over ClickHouse. |
|
Package composite serves one logical store from two: a primary that takes every write and holds everything from Cutover on, and a read-only secondary store that holds what came before.
|
Package composite serves one logical store from two: a primary that takes every write and holds everything from Cutover on, and a read-only secondary store that holds what came before. |
|
Package factory builds a store from configuration, so that every process of an installation — the event processor, the backend, the plugins — reaches its data the same way and the choice of engine is a setting, not code.
|
Package factory builds a store from configuration, so that every process of an installation — the event processor, the backend, the plugins — reaches its data the same way and the choice of engine is a setting, not code. |