Documentation
¶
Index ¶
- Variables
- func ReadFlatDocuments(r io.Reader, ...) (entries int, err error)
- func WriteFlatDocuments(w io.Writer, r io.Reader, limit int) (documents int, entries int, err error)
- type DB
- func (db *DB) BuildIndex() ([]Range, error)
- func (db *DB) Close() error
- func (db *DB) Indexes() ([]IndexInfo, error)
- func (db *DB) Manifest() (Manifest, error)
- func (db *DB) Metrics() *Metrics
- func (db *DB) ReadManifest() (Manifest, bool, error)
- func (db *DB) Scan(ctx context.Context, fn ScanFunc) (stats SearchStats, err error)
- func (db *DB) ScanWithOptions(ctx context.Context, opts ExecutionOptions, fn ScanFunc) (stats SearchStats, err error)
- func (db *DB) Search(ctx context.Context, q Query) (res *Result, err error)
- func (db *DB) WriteManifest(mode SyncMode) error
- func (db *DB) WriteManifestForNextEntry(nextEntry uint64, mode SyncMode) error
- func (db *DB) Writer() (*Writer, error)
- type DocumentCommitStats
- type DocumentIndexCacheStats
- type DocumentIndexOption
- type DocumentIndexer
- func (ix *DocumentIndexer) AddDocument(doc map[string]any) (uint64, int, error)
- func (ix *DocumentIndexer) AddFlatEntry(docIDText, path string, typ DocumentValueType, rawValue string) error
- func (ix *DocumentIndexer) AddJSON(data []byte) (uint64, int, error)
- func (ix *DocumentIndexer) CacheStats() DocumentIndexCacheStats
- func (ix *DocumentIndexer) Close() error
- func (ix *DocumentIndexer) Commit(mode SyncMode) error
- func (ix *DocumentIndexer) CommitWithStats(mode SyncMode) (DocumentCommitStats, error)
- type DocumentValueType
- type ErrCorruptBlock
- type ExecutionOptions
- type FieldDef
- type Hit
- type IndexInfo
- type Limits
- type Manifest
- type ManifestFile
- type ManifestStringMap
- type MatchMode
- type Metrics
- type MetricsOption
- type Option
- func WithBlockSizeTarget(n int) Option
- func WithIndexBuildInterval(n int) Option
- func WithIndexGranularity(n int) Option
- func WithLogger(fn func(level, msg string, kv ...any)) Option
- func WithMaxOpenIndexes(n int) Option
- func WithMetrics(m *Metrics) Option
- func WithPrefix(prefix string) Option
- func WithRecoverOnOpen(v bool) Option
- func WithScanTail(v bool) Option
- func WithVerifyPolicy(v VerifyPolicy) Option
- type Options
- type Predicate
- type Query
- type Range
- type ReadPolicy
- type Result
- type ReturnSpec
- type ScanAction
- type ScanDecision
- type ScanEntry
- type ScanFunc
- type Schema
- type SearchStats
- type StringDictionary
- func (d *StringDictionary) Close() error
- func (d *StringDictionary) ID(s string) (uint64, error)
- func (d *StringDictionary) Lookup(id uint64) (string, bool)
- func (d *StringDictionary) Save() error
- func (d *StringDictionary) SaveWithStats() (StringDictionarySaveStats, error)
- func (d *StringDictionary) Stats() StringDictionaryStats
- type StringDictionarySaveStats
- type StringDictionaryStats
- type SyncMode
- type Term
- type Tuple
- type VerifyPolicy
- type Writer
Constants ¶
This section is empty.
Variables ¶
var ( ErrSchemaMismatch = errors.New("scandex: schema hash mismatch") ErrWriterLocked = errors.New("scandex: writer lock held") ErrBudgetExceeded = errors.New("scandex: tracked identifier budget exceeded") ErrUnsupportedPredicate = errors.New("scandex: predicate shape not supported in this mode") ErrBadOption = errors.New("scandex: invalid option") ErrCorrupt = errors.New("scandex: corruption detected") )
Functions ¶
func ReadFlatDocuments ¶
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func (*DB) BuildIndex ¶
func (*DB) Metrics ¶
Metrics returns the Metrics bundle attached via WithMetrics, or nil. The returned value is safe to call recording methods on even when nil.
func (*DB) ScanWithOptions ¶
func (db *DB) ScanWithOptions(ctx context.Context, opts ExecutionOptions, fn ScanFunc) (stats SearchStats, err error)
func (*DB) WriteManifest ¶
func (*DB) WriteManifestForNextEntry ¶
type DocumentCommitStats ¶
type DocumentCommitStats struct {
Fields StringDictionarySaveStats
Documents StringDictionarySaveStats
AOF time.Duration
Total time.Duration
}
type DocumentIndexCacheStats ¶
type DocumentIndexOption ¶
type DocumentIndexOption func(*documentIndexOptions)
func WithDocumentIndexCaches ¶
func WithDocumentIndexCaches(documents, fields, values int) DocumentIndexOption
type DocumentIndexer ¶
type DocumentIndexer struct {
Strings *StringDictionary
Fields *StringDictionary
Documents *StringDictionary
// contains filtered or unexported fields
}
func OpenDocumentIndexer ¶
func OpenDocumentIndexer(db *DB, opts ...DocumentIndexOption) (*DocumentIndexer, error)
func (*DocumentIndexer) AddDocument ¶
func (*DocumentIndexer) AddFlatEntry ¶
func (ix *DocumentIndexer) AddFlatEntry(docIDText, path string, typ DocumentValueType, rawValue string) error
func (*DocumentIndexer) AddJSON ¶
func (ix *DocumentIndexer) AddJSON(data []byte) (uint64, int, error)
func (*DocumentIndexer) CacheStats ¶
func (ix *DocumentIndexer) CacheStats() DocumentIndexCacheStats
func (*DocumentIndexer) Close ¶
func (ix *DocumentIndexer) Close() error
func (*DocumentIndexer) Commit ¶
func (ix *DocumentIndexer) Commit(mode SyncMode) error
func (*DocumentIndexer) CommitWithStats ¶
func (ix *DocumentIndexer) CommitWithStats(mode SyncMode) (DocumentCommitStats, error)
type DocumentValueType ¶
type DocumentValueType uint64
const ( DocumentNull DocumentValueType = iota DocumentBool DocumentUint DocumentInt DocumentFloat DocumentString DocumentArray // DocumentValueTypeCount is one past the last value type. Anything that // enumerates every type should range over [DocumentNull, DocumentValueTypeCount). DocumentValueTypeCount )
type ErrCorruptBlock ¶
func (ErrCorruptBlock) Error ¶
func (e ErrCorruptBlock) Error() string
func (ErrCorruptBlock) Unwrap ¶
func (e ErrCorruptBlock) Unwrap() error
type ExecutionOptions ¶
type ExecutionOptions struct {
ReadPolicy ReadPolicy
TimeBudget time.Duration
}
type Manifest ¶
type Manifest struct {
Version int
Selection string
AOF []ManifestFile
Indexes []ManifestFile
StringMaps []ManifestStringMap
}
type ManifestFile ¶
type ManifestStringMap ¶
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics is a concurrency-safe bundle of scandex runtime counters and gauges, backed by statekit. It is the "separate object" attach point: create one with NewMetrics, hand it to Open via WithMetrics, and register it with a statekit registry from the outside via reg.RegisterCollectors(m.Collectors()...).
The object is maintained, not merely reported: scandex updates it in place on the reader, writer, and aggregation paths. Every metric is an atomic statekit Counter or Gauge, so a single Metrics value may be shared by any number of concurrent readers (and a writer) without further locking.
All recording methods are nil-safe, so an unset DB option (no metrics) costs a single nil-receiver method call at each operation boundary and nothing in the per-tuple hot loops: reader and aggregation stats are folded in once per completed operation from the SearchStats/Stats the engine already computes.
Note that aggregation runs through the reader (Match -> Search/Scan, Fill -> Scan), so its passes also advance the reader counters below. The reader counters therefore measure all read activity, aggregation included; the aggregation counters add the query-level view on top.
Besides raw counts, the object maintains derived state inside the recording methods rather than leaving it to be computed downstream: the running fraction of entries served from the unsorted AOF tail (a compaction-pressure signal), the running read selectivity (hits per entry examined), and slow-operation counts against a configurable threshold.
func NewMetrics ¶
func NewMetrics(opts ...MetricsOption) *Metrics
NewMetrics builds a fresh, zeroed Metrics bundle with every collector created and ready to register.
func (*Metrics) Collectors ¶
func (this *Metrics) Collectors() []statekit.PrometheusCollector
Collectors returns the statekit collectors held by this bundle, for registration from the outside:
reg.RegisterCollectors(m.Collectors()...)
func (*Metrics) ObserveAggregate ¶
ObserveAggregate folds one completed aggregation query into the aggregation counters. It is exported because the analytics layer lives in its own package; callers normally do not invoke it directly.
type MetricsOption ¶
type MetricsOption func(*Metrics)
MetricsOption configures a Metrics bundle at construction.
func WithSlowQueryThreshold ¶
func WithSlowQueryThreshold(d time.Duration) MetricsOption
WithSlowQueryThreshold sets the duration at or above which a read or aggregation is counted as slow. A non-positive threshold disables slow-query counting.
type Option ¶
func WithBlockSizeTarget ¶
func WithIndexBuildInterval ¶
WithIndexBuildInterval makes the writer automatically build an index for the uncovered tail every n records. 0 disables automatic building.
func WithIndexGranularity ¶
func WithLogger ¶
func WithMaxOpenIndexes ¶
func WithMetrics ¶
WithMetrics attaches a Metrics bundle that scandex maintains on the reader, writer, and aggregation paths. The same bundle may be passed to several Open calls to aggregate their metrics into one registerable object.
func WithPrefix ¶
func WithRecoverOnOpen ¶
func WithScanTail ¶
func WithVerifyPolicy ¶
func WithVerifyPolicy(v VerifyPolicy) Option
type Options ¶
type Options struct {
IndexGranularity int
// IndexBuildInterval, when > 0, makes the writer build an index for
// the uncovered tail every IndexBuildInterval records appended. 0 (the
// default) leaves index building entirely manual via DB.BuildIndex.
IndexBuildInterval int
BlockSizeTarget int
Verify VerifyPolicy
MaxOpenIndexes int
ScanTail bool
RecoverOnOpen bool
Prefix string
Logger func(level, msg string, kv ...any)
Metrics *Metrics
}
type Query ¶
type Query struct {
Scope []Term
Where Predicate
Mode MatchMode
Return ReturnSpec
Limits Limits
Execution ExecutionOptions
}
type Result ¶
type Result struct {
IDs []uint64
Hits []Hit
Stats SearchStats
}
type ReturnSpec ¶
type ReturnSpec struct {
Tuples bool
}
type ScanAction ¶
type ScanAction uint8
const ( ScanContinue ScanAction = iota ScanStop ScanSkipValue ScanSeek )
type ScanDecision ¶
type ScanDecision struct {
Action ScanAction
Field int
Target Tuple
}
type ScanFunc ¶
type ScanFunc func(ScanEntry) ScanDecision
type Schema ¶
type Schema struct {
Fields []FieldDef
}
func DocumentIndexSchema ¶
func DocumentIndexSchema() Schema
type SearchStats ¶
type StringDictionary ¶
type StringDictionary struct {
// contains filtered or unexported fields
}
func OpenStringDictionary ¶
func OpenStringDictionary(path string) (*StringDictionary, error)
func (*StringDictionary) Close ¶
func (d *StringDictionary) Close() error
func (*StringDictionary) Save ¶
func (d *StringDictionary) Save() error
func (*StringDictionary) SaveWithStats ¶
func (d *StringDictionary) SaveWithStats() (StringDictionarySaveStats, error)
func (*StringDictionary) Stats ¶
func (d *StringDictionary) Stats() StringDictionaryStats
type StringDictionaryStats ¶
type VerifyPolicy ¶
type VerifyPolicy uint8
const ( VerifyMagic VerifyPolicy = iota VerifyCRC VerifyOpen )
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
analytics
Package analytics computes group-by aggregations on top of documentquery.
|
Package analytics computes group-by aggregations on top of documentquery. |
|
federation
Package federation runs documentquery / analytics operations across several independent scandex engines ("segments") and merges the results into a single logical answer.
|
Package federation runs documentquery / analytics operations across several independent scandex engines ("segments") and merges the results into a single logical answer. |
|
examples
|
|
|
bluesky
command
Command bluesky loads the ClickHouse JSONBench Bluesky dataset (Jetstream firehose events, newline-delimited JSON) into a Scandex document index and lets you search or aggregate over it.
|
Command bluesky loads the ClickHouse JSONBench Bluesky dataset (Jetstream firehose events, newline-delimited JSON) into a Scandex document index and lets you search or aggregate over it. |
|
federation
command
Command federation demonstrates querying across several independent scandex segments and merging the results.
|
Command federation demonstrates querying across several independent scandex segments and merging the results. |
|
github_events
command
|
|
|
web_analytics
command
Command web_analytics serves a small browser UI over an existing Scandex document index.
|
Command web_analytics serves a small browser UI over an existing Scandex document index. |
|
internal
|
|
|
stringmap
Package stringmap provides a content-addressed string interning store with file-backed storage, split into two roles tuned for opposite access patterns.
|
Package stringmap provides a content-addressed string interning store with file-backed storage, split into two roles tuned for opposite access patterns. |