enginetest

package
v0.50.2 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 32 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 enginetest is the conformance suite the metric and record engines share: the part lifecycle, index-commit and repair invariants both must hold, written once against an Engine adapter. The adapters live in each engine's external test package, so this package imports neither engine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyObjects

func CopyObjects(t *testing.T, src, dst backend.Backend, prefix string)

CopyObjects copies every object under prefix from src to dst, which is what a repair fetch does to the objects of a part it pulls back. It fails t when prefix holds nothing.

func Run

func Run(t *testing.T, k Kind)

Run runs every suite test against k, each as <test>/<k.Name>.

Types

type Answer

Answer is how a Fetcher answers one want.

type Config

type Config struct {
	Backend backend.Backend
	Repair  bucketindex.PartFetcher
	WAL     *wal.SegmentWriter
	Obs     *obs.Obs
	// WriterID names the writer whose flush watermark the engine keeps in the bucket index.
	WriterID string
	// OrphanGrace and Now are the engine's orphan-sweep age guard and its clock.
	OrphanGrace time.Duration
	Now         func() time.Time
	// MergeCapBytes is the merge cap in the unit of [Part.Bytes]; 0 keeps the engine's derived cap.
	MergeCapBytes int64
	// Term is the writer's ownership term; nil is a writer with no cluster.
	Term func() uint64
}

Config is what the suite varies when opening an engine; everything else is the adapter's.

type Engine

type Engine interface {
	Store
	Loader
	Introspector
	Repairer
}

Engine is one engine adapted for the suite. Methods that share a name with the engine's own mean the same thing.

type Fetcher

type Fetcher struct {
	// contains filtered or unexported fields
}

Fetcher stands in for the cluster layer's part-sync pull: it records what repair asked for and answers with Answer, so the engine half of the seam runs without a peer, a transport or a syncer. A nil Answer reports every want absent.

func AnswerAlways

func AnswerAlways(outcome bucketindex.WantOutcome, err error) *Fetcher

AnswerAlways returns a Fetcher giving every want the same outcome.

func NewFetcher

func NewFetcher(a Answer) *Fetcher

NewFetcher returns a Fetcher answering with a.

func (*Fetcher) Asks

func (f *Fetcher) Asks() []string

Asks reports what repair has asked for, in call order.

func (*Fetcher) Calls

func (f *Fetcher) Calls() int

Calls reports how many batches repair issued: one per cycle, whatever the want count.

func (*Fetcher) FetchWants

func (f *Fetcher) FetchWants(_ context.Context, wants []bucketindex.Want) []bucketindex.FetchResult

FetchWants implements bucketindex.PartFetcher.

func (*Fetcher) SetAnswer

func (f *Fetcher) SetAnswer(a Answer)

SetAnswer replaces the answer for later fetches.

type Introspector

type Introspector interface {
	// AttrNames returns every Attr key the engine can serve.
	AttrNames(t *testing.T) []string
	// StreamCount is the number of distinct stream identities the engine knows.
	StreamCount() int
	// HeadRows is the number of rows buffered in the head.
	HeadRows() int
	Parts() []Part
	PartCount() int
	PartPrefixes() []string
	Stats() Stats
	// MergeShape is the merge shape under a retention cutoff (≤ 0 disables it).
	MergeShape(retainFrom int64) MergeShape
	// LoadState is every field an index load replaces, comparable with assert.Equal.
	LoadState() any
}

Introspector is what the engine reports about itself.

type Kind

type Kind struct {
	// Name names the subtest: "metrics" or "records".
	Name string
	// Prefix is the backend key prefix every engine Open returns writes under.
	Prefix string
	Open   func(t *testing.T, cfg Config) Engine

	// Identity is the identity the engine gives stream.
	Identity func(stream string) signal.Series
	// LegacyIdentityObject is the whole-set identity object older builds wrote at the prefix.
	LegacyIdentityObject string
	// Erodes reports whether an object key is one a partially lost part no longer has.
	Erodes func(key string) bool
	// IdentitySeed and IdentityRatio tune [Run]'s write-amplification check: the second flush of one
	// new stream must write under 1/IdentityRatio of the first flush's IdentitySeed streams.
	IdentitySeed, IdentityRatio int
}

Kind is one engine the suite runs against.

type Loader

type Loader interface {
	LoadParts(ctx context.Context) error
	LoadPartsUnclaimed(ctx context.Context) error
	LoadPartsReadOnly(ctx context.Context) error
	RefreshReplica(ctx context.Context) error
	ReloadFenced(ctx context.Context) error
	Replay(ctx context.Context, dir string) error
	WALState() (segments int, bytes int64, epoch uint64, ok bool)
}

Loader is how an engine recovers state from its backend and WAL.

type MergeShape

type MergeShape struct {
	Parts                       int
	Bytes                       int64
	Candidates, ForceCandidates int
}

MergeShape is the subset of the engine's merge shape the suite asserts on.

type Part

type Part struct {
	ID               string
	MinTime, MaxTime int64
	// Bytes is the size the merge selector weighs the part at.
	Bytes int64
}

Part is one live part as [Engine.Parts] reports it.

type Repairer

type Repairer interface {
	LosePart(prefix string, blocks bucketindex.Interval)
	AdoptWants(ws []bucketindex.Want)
	SetPartBlocks(prefix string, blocks bucketindex.Interval, level uint32)
	WantPrefixes() []string
	HasWants() bool
	WantOverlaps(start, end int64) bool
	Holes() []bucketindex.Entry
	LostParts() uint64
	RepairStats() bucketindex.RepairStats
}

Repairer is the repair-obligation surface, including the test-only LosePart and SetPartBlocks.

type Row

type Row struct {
	Stream string
	Ts     int64
	Val    int64
	// Attr is an optional key and value: a series label for metrics, a record attribute for records.
	Attr [2]string
}

Row is one sample or record. Val is a sample's value, or a record's body in decimal.

type Stats

type Stats struct {
	HeadAge     time.Duration
	WantedParts int
	Holes       int
	LostParts   uint64
	IndexFenced bool
	// TenureUnestablished is a clustered engine whose tenure's first commit has not landed.
	TenureUnestablished bool
}

Stats is the subset of the engine's stats the suite asserts on.

type Store

type Store interface {
	// Append buffers rows in the head, failing t on error.
	Append(t *testing.T, rows ...Row)
	// Read returns every row stream holds, in the engine's fetch order, with Attr unset.
	Read(ctx context.Context, stream string) ([]Row, error)
	Flush(ctx context.Context) error
	Merge(ctx context.Context, retainFrom int64) error
	// BackgroundMerge runs automatic maintenance, or a forced automatic turn.
	BackgroundMerge(ctx context.Context, retainFrom int64, force bool) (bool, error)
	// ForceMerge merges every part into one, whatever the merge policy would pick.
	ForceMerge(ctx context.Context) error
	Reset(ctx context.Context) error
	HeadBytes() int64
}

Store is the write, read and maintenance path.

Jump to

Keyboard shortcuts

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