Help us shape the future of Go! Take the 2026 Go Developer Survey

workload

package
v0.57.13 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package workload records the logical operations a Volume's storage engine serves, as runtime/trace log events, so the workload captured from a running app can be extracted from its execution trace and replayed against another engine.

Recording costs one trace.IsEnabled check per operation when no trace is running. Keys are recorded verbatim and values only by length, so a trace carries key material: capture traces from test data only.

Index

Constants

View Source
const Category = "hydra/volume-workload"

Category is the runtime/trace log category of every workload record.

Variables

This section is empty.

Functions

func AppendRecords

func AppendRecords(b []byte, records []Record) []byte

AppendRecords appends records in their text form, one per line.

func DiscardJournal

func DiscardJournal(adds, removes []block_gc.RefEdge) error

DiscardJournal accepts replayed journal changes without applying them. A replayed trace already carries the reference graph's own key-value writes.

func Fill

func Fill(ctx context.Context, t Target, n, size int) error

Fill writes n filler blocks of size bytes in bounded batches and syncs once, so a replay runs against a durable volume of realistic scale.

Types

type Event

type Event struct {
	// Time is the trace timestamp in nanoseconds.
	Time int64
	// Goroutine is the emitting goroutine. GoScript reports one goroutine for
	// every event, so replay orders by Time and correlates by Record IDs.
	Goroutine int64
	// Record is the logical operation.
	Record Record
}

Event is a Record with the trace time and goroutine that emitted it.

func Extract

func Extract(r io.Reader) ([]Event, error)

Extract reads a Go execution trace and returns its workload records in trace order, skipping every other event.

type Op

type Op string

Op names one logical storage operation.

const (
	// OpTxRead opens a read-only transaction.
	OpTxRead Op = "tx-read"
	// OpTxWrite opens a read-write transaction.
	OpTxWrite Op = "tx-write"
	// OpGet reads Key; Size is the value length, or -1 when absent.
	OpGet Op = "get"
	// OpExists checks Key; Size is 1 when present and 0 when absent.
	OpExists Op = "exists"
	// OpSet writes a value of Size bytes to Key.
	OpSet Op = "set"
	// OpDelete deletes Key.
	OpDelete Op = "delete"
	// OpIterate opens an iterator over the Key prefix; Size is 1 when reverse.
	OpIterate Op = "iterate"
	// OpSeek positions an iterator at Key.
	OpSeek Op = "seek"
	// OpIterEnd closes an iterator that visited Size entries.
	OpIterEnd Op = "iter-end"
	// OpCommit commits a transaction with Size pending mutations.
	OpCommit Op = "commit"
	// OpDiscard discards a transaction.
	OpDiscard Op = "discard"
)

Key-value transaction operations. ID is the transaction, except for iterator operations, where ID is the iterator and Parent its transaction.

const (
	// OpPut writes a block of Size bytes.
	OpPut Op = "put"
	// OpTombstone writes a deletion marker within a batch.
	OpTombstone Op = "tombstone"
	// OpPutBatch opens batch ID of Size entries; its entries follow.
	OpPutBatch Op = "put-batch"
	// OpRm removes a block.
	OpRm Op = "rm"
	// OpGetBlock reads a block; Size is its length, or -1 when absent.
	OpGetBlock Op = "get-block"
	// OpStatBlock stats a block; Size is its length, or -1 when absent.
	OpStatBlock Op = "stat-block"
	// OpBlockExists checks a block; Size is 1 when present and 0 when absent.
	OpBlockExists Op = "block-exists"
	// OpExistsBatch checks Size blocks in read scope ID; its checks follow.
	OpExistsBatch Op = "exists-batch"
	// OpReadBegin opens read scope ID over one consistent block view.
	OpReadBegin Op = "read-begin"
	// OpReadEnd releases read scope ID.
	OpReadEnd Op = "read-end"
	// OpSync makes every earlier block write durable.
	OpSync Op = "sync"
)

Block store operations. Key is the binary block reference. ID is the read scope or batch the operation belongs to, or 0 for a direct store call.

const (
	// OpJournalAppend durably journals a reference change of Size encoded bytes.
	OpJournalAppend Op = "journal-append"
	// OpJournalReplay applies and removes Size journal entries.
	OpJournalReplay Op = "journal-replay"
)

Garbage collection operations.

type OrderedJournal

type OrderedJournal interface {
	// AppendJournalOrdered journals reference graph changes with write
	// ordering only.
	AppendJournalOrdered(ctx context.Context, adds, removes []block_gc.RefEdge) error
}

OrderedJournal is a Target that can journal with write ordering in place of a full durability flush, like kvtx.OrderedCommitTx.

type Record

type Record struct {
	// Op names the operation.
	Op Op
	// ID identifies the transaction, iterator, read scope, or batch.
	ID uint64
	// Parent identifies the transaction that owns an iterator.
	Parent uint64
	// Size is the operation's length, count, or result, as its Op documents.
	Size int64
	// Key is the key, key prefix, or binary block reference.
	Key []byte
}

Record is one logical storage operation.

func ParseRecord

func ParseRecord(msg string) (Record, error)

ParseRecord decodes a record from the text AppendText produced.

func ParseRecords

func ParseRecords(text string) ([]Record, error)

ParseRecords decodes the lines AppendRecords produced.

func ReadTraceRecords

func ReadTraceRecords(path string) ([]Record, error)

ReadTraceRecords reads the workload records of the Go execution trace file at path.

func (Record) AppendText

func (r Record) AppendText(b []byte) []byte

AppendText appends the record's single-line text form, which ParseRecord decodes: op, id, parent, size, and the hexadecimal key.

func (Record) Log

func (r Record) Log(ctx context.Context)

Log emits the record to the running execution trace, if any.

type Replay

type Replay struct {

	// Ordered commits every key-value commit that writes no shared object head,
	// and every journal append, with write ordering only, so only block Sync
	// and head commits flush.
	Ordered bool
	// contains filtered or unexported fields
}

Replay replays a recorded workload against a Target. Values and block payloads are regenerated from their recorded lengths; a block keeps one deterministic payload, so its replay reference is stable across operations even though it differs from the recorded one.

func NewReplay

func NewReplay(records []Record) (*Replay, error)

NewReplay prepares a replay of records, regenerating every block payload and finding the state the workload reads before writing it.

func ReadTrace

func ReadTrace(path string) (*Replay, error)

ReadTrace prepares a replay of the Go execution trace file at path.

func (*Replay) Run

func (r *Replay) Run(ctx context.Context, t Target) (*Result, error)

Run replays the workload against t in record order on one goroutine, with no think time, and reports its timing.

func (*Replay) Seed

func (r *Replay) Seed(ctx context.Context, t Target) error

Seed writes the state the workload reads before writing it, then syncs.

type Result

type Result struct {
	// Ops is the number of records replayed.
	Ops int
	// Wall is the replay's elapsed time.
	Wall time.Duration
	// Latency holds each timed operation's latencies in replay order: commit,
	// sync, put, put-batch, get-block, journal-append, and journal-replay.
	Latency map[Op][]time.Duration
	// CommitErrors counts commits the target rejected. A replay that commits
	// transactions the recording interleaved may conflict where it did not.
	CommitErrors int
	// OrderedCommits counts commits and journal appends made with write
	// ordering only.
	OrderedCommits int
	// BlockBytes is the payload written by block puts.
	BlockBytes int64
	// ValueBytes is the payload written by key-value sets.
	ValueBytes int64
}

Result reports one replay.

func (*Result) Percentile

func (r *Result) Percentile(op Op, p float64) time.Duration

Percentile returns the p-th percentile latency of op, or zero when op was never timed.

type Target

type Target interface {
	kvtx.Store
	block.StoreOps
	// AppendJournal durably journals reference graph changes.
	AppendJournal(ctx context.Context, adds, removes []block_gc.RefEdge) error
	// ReplayJournal passes every journaled change to apply, then removes it.
	ReplayJournal(ctx context.Context, apply func(adds, removes []block_gc.RefEdge) error) error
}

Target is the storage engine surface a replay drives: the key-value store and block store a Volume serves, and its garbage collection journal.

Jump to

Keyboard shortcuts

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