gen

package
v0.47.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: 5 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 gen generates the archives and the queries the aggregate differential fuzzer runs.

A grouped aggregate over an archive can be answered by several different pieces of code -- an index/metadata path that reads no records, a columnar accelerator path, and a record scan -- and they must all produce identical answers. The fuzzer compares them; this package's whole job is to produce data and queries where the FAST paths actually fire. Random data lands almost entirely on the record scan, and a fuzz run where every query takes the reference path is a green run that tested nothing, so every attribute below exists to steer one specific decision in the storage layer:

  • Schema inference drops attributes. buildAdSchema keeps an attribute only when its dominant storable kind is present in at least 90% of the sampled ads, so the columnar columns here are written in >= ~92% of records, and `Rare` is deliberately written in 30% so there is also an attribute that is NOT columnar whatever else happens.
  • String dictionaries only form when they pay: dictWorthwhile needs distinct*2 <= records in the block. `Owner` has 40 distinct values and takes the dictionary reader; `Host` is distinct per record and takes the positional string walk. Both are present in every fixture, so a run cannot miss either reader.
  • Zone maps only prune SEALED segments, so Shape.SegmentBytes is small (tens of KiB) and a fixture seals a dozen or so. `Ts` advances monotonically, which is what makes a segment's zone fall inside one bucket and lets the bucketed index path attribute it wholesale.
  • Column width drives the raw/vectorized read, so the integer columns span 1, 2, 4, 6 and 8 bytes, signed and unsigned, and `Mem` has a ~2% tail that does not fit its 2-byte slot (under baseFit = 0.95 the width is still chosen) so some records escape into the cold tail.
  • Constraints have to be winnable, so the literals a query draws come from the value domains below rather than from the whole int64 range.

The other half is values that must appear BY CONSTRUCTION rather than by luck, because that is where the bugs have been. Group identity is the RENDERED TEXT, so two values that render alike have to land in one group: `Site` carries an absent attribute, the UNDEFINED keyword and the literal string "undefined" (three spellings, one group), plus the number 42 beside the string "42"; `NumLike` is a string column whose text is the decimal spelling of an integer; `Rate` mixes integral reals (3.0, which renders "3") with integers; `Flag` is a boolean; `Expr` holds an expression where a literal usually is; `Err` evaluates to ERROR; `Rate` also carries +/-Inf literals and a stored NaN, and `Calc` carries a NaN reached by arithmetic instead, which is a different storage path and the one production data takes.

Everything here is a pure function of (Shape, record index): no clock, no rand. That is what lets a failure be reported as a list of record indices and replayed exactly, and what lets the shrinker rebuild subsets.

Index

Constants

View Source
const (
	TsBase = 1_700_000_000
	TsStep = 37
	// OwnerCardinality is the number of distinct Owner values. See Source for why it is this low.
	OwnerCardinality = 16
)

Value-domain constants. A query draws its literals from these so its constraints are winnable -- comparing Ts against a random int64 matches everything or nothing and tests neither.

Variables

View Source
var (
	// CategoricalAttrs is indexed per segment by value; Owner is a string literal in EVERY record,
	// which is what lets the postings account for all of them (the index path compares its summed
	// total against the record count and declines when they disagree).
	CategoricalAttrs = []string{"Owner"}
	// ValueAttrs gets a per-segment value index (and a zone map for free).
	//
	// Rate is here for one reason: it holds a NaN in a minority of records, and a value index is
	// keyed by the value, so a NaN key can never be looked up again -- the index built a sorted
	// key list holding a NaN whose own lookup returned a nil bitmap and dereferenced it. This
	// fixture crashed on that during index build, which is why Rate was kept out of the set while
	// the bug stood. It is fixed now, so the set covers it: drop Rate from here and the only
	// indexed column is one that cannot hold a NaN, which is the shape that let the crash exist.
	ValueAttrs = []string{"ClusterId", "Rate"}
	// ZoneAttrs get per-segment [min,max] zone maps, and the set is deliberately mixed, because a
	// zone is only interesting where it is NOT total. Ts/ClusterId/Mem hold a number in every
	// record, so their zones come out Full and a segment can be attributed to a range wholesale
	// without reading it; before the other three were added, every zone in every fixture was Full
	// and the Full guard never decided anything.
	//
	// The other three each clear Full a different way. Rate holds a NaN in a minority of records
	// and no comparison is true of a NaN, so it is left out of the bounds. Calc holds an
	// expression in a minority, which no bound can cover at all. Rare is simply absent from 70% of
	// records. The resulting zones bound only the values they CAN, so a range every bounded value
	// satisfies reads as always-true over the zone -- and attributing a segment wholesale on that
	// basis would count the records the zone left out. Full is the only thing between those two
	// readings, and this is the data that makes it matter.
	ZoneAttrs = []string{"Ts", "ClusterId", "Mem", "Rate", "Calc", "Rare"}
)

Index configuration the fixture must be created with. These are not arbitrary: the categorical index over Owner is the only thing the index tier can read group counts out of, and the zone maps over Ts/ClusterId/Mem are what let a constrained count be attributed to a whole segment.

Functions

func Bytes

func Bytes(k int) []byte

Bytes is the deterministic fuzz input for sweep step k: a 16-byte splitmix64 stream, long enough that QueryFrom never wraps on a single query. The sweep and the fuzzer's seed corpus are built from the same bytes, so the two explore one space rather than two that can drift apart.

func IsStringAttr

func IsStringAttr(attr string) bool

IsStringAttr reports whether attr's columnar field is a STRING. Reading that off the attribute name would be guessing, so the pool itself answers.

Types

type Agg

type Agg struct {
	Func   Func
	Arg    string
	Filter string
}

Agg is one aggregate: a function over an argument attribute, with an optional per-aggregate FILTER restricting that one aggregate to the rows of its group matching it. The grouped columnar path serves a filter it can lower to column narrowing and declines the rest, so the draws below deliberately produce both: an answer that ignored a filter and a decline that got it wrong are different bugs and both have to be reachable.

type Func

type Func int

Func is an aggregate function. Mirrors db.AggFunc's set without importing it.

const (
	FuncCount Func = iota
	FuncSum
	FuncAvg
	FuncMin
	FuncMax
	FuncCountDistinct
)

func (Func) String

func (f Func) String() string

type Group

type Group struct {
	Attr        string
	BucketWidth int64
}

Group is one GROUP BY column, optionally floored into fixed-width buckets.

type Query

type Query struct {
	Constraint string
	Groups     []Group
	Aggs       []Agg
}

Query is one generated aggregate.

func QueryAt

func QueryAt(k int) Query

QueryAt is QueryFrom over the deterministic byte stream Bytes(k) returns, for the fixed sweep the coverage test runs.

func QueryFrom

func QueryFrom(b []byte) Query

QueryFrom builds a query from fuzz bytes. Deterministic: the same bytes always give the same query, which is what makes a saved corpus entry a reproducer.

The first draw is the query FAMILY, and that exists for a coverage reason rather than a generative one. Each fast path is gated on a narrow shape -- the index path wants exactly one unfiltered COUNT(*), the ungrouped columnar aggregate wants exactly one numeric aggregate and no grouping -- and drawing the aggregate list freely hits those shapes a few percent of the time. A first run of this generator without families reached the index tier TWICE in 2,146 queries, which is not a test of the index tier. The families make the gated shapes common and keep the free-form draw as the general case.

func (Query) String

func (q Query) String() string

String renders the query the way a reproducer should read it.

type Shape

type Shape struct {
	ID int
	// N is the record count. Large enough that several segments seal at SegmentBytes, small
	// enough that the reference scan is milliseconds.
	N int
	// RunLen is how many consecutive records share an Owner. 1 is the interleaved extreme (40
	// distinct values in every block, which still dictionary-encodes); 256 is the submit-burst
	// extreme (one or two per block).
	RunLen int
	// SegmentBytes is the sealed-segment size. Small, so segments actually seal: at the 8 MiB
	// default a fixture this size stays in one unsealed segment and no zone map ever prunes.
	SegmentBytes int
	// RowGroupBytes is the columnar row-group budget. It sets how many records share a block, and
	// so how many distinct values a block sees -- which is what dictWorthwhile decides on. 0 takes
	// the default.
	RowGroupBytes int
	// WideInts moves Disk and Big from 4-byte/1-byte columns to 6-byte/8-byte ones, so a run
	// covers the wide end of the slot widths as well as the narrow one.
	WideInts bool
	// HotTopN is how many numeric columns are kept in the HOT tier, and it is not only a
	// performance knob: a hot int column is re-fitted to cover ~every sampled value
	// (refitHotIntWidths), so nothing escapes it, while a cold one keeps the 0.95 fit percentile
	// and its outliers live in the cold tail. Half the shapes therefore keep the hot set small, so
	// the fuzzer actually reaches the cold-tail fallback on a NUMERIC column instead of only on a
	// string one.
	HotTopN int
}

Shape is one generated archive: a record count plus the storage knobs that decide which accelerator tiers its segments can serve.

func ShapeByID

func ShapeByID(id int) Shape

ShapeByID returns the shape with that id, wrapping, so any fuzz byte selects a valid shape.

func Shapes

func Shapes() []Shape

Shapes is the fixture set: the cross product of the knobs above, so a sweep covers every string clustering against both segment sizes and both integer width regimes.

func (Shape) Ad

func (s Shape) Ad(i int) *classad.ClassAd

Ad builds record i as a ClassAd, including the values the text form cannot carry.

func (Shape) Ads

func (s Shape) Ads() []*classad.ClassAd

Ads builds every record of the shape, in append order.

func (Shape) AdsAt

func (s Shape) AdsAt(idx []int) []*classad.ClassAd

AdsAt builds just the records at the given indices, in the order given. The shrinker uses it to rebuild a candidate subset, and a reproducer names its records this way.

func (Shape) Source

func (s Shape) Source(i int) string

Source renders record i of this shape in old-ClassAd text. It is the reproducer form: paste the lines a failure prints into a fixture and the same records come back.

NaN is the one value this text cannot carry AS A LITERAL, which is a narrower claim than "text cannot express NaN". The VALUE is perfectly expressible and both engines agree on it: `0.0/0.0` evaluates to NaN here and in libclassad (`0/0` is integer division and gives ERROR, not NaN), and `real("NaN")` is the canonical spelling. What old-ClassAd has no syntax for is a NaN LITERAL -- `nan` lexes as a bare reference and evaluates UNDEFINED -- and the literal is what matters, because only a stored literal reaches a column and an expression would be skipped by the very reader under test. So Rate's designated records write a placeholder here and Ad patches in a real NaN after the parse, while Calc carries the arithmetic form, which is how an ad in the wild actually acquires a NaN and which lands in the cold tail instead of the column.

Jump to

Keyboard shortcuts

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