eventlog

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package eventlog appends to and reads an execution's event log: the subject <ns>.ev.<partition>.<exec> of the events stream.

Append is the single-writer guarantee: it carries Nats-Expected-Last-Subject-Sequence, so two writers deciding on the same state can never both commit — the loser gets ErrConflict and re-decides on the fresh state. The events of one decision are written as one message (a JSON array), so a decision is stored all or nothing without a JetStream atomic batch, and the stream sequence identifies a decision.

Index

Constants

View Source
const (

	// MaxEvents bounds the events of one decision. NATS imposes no such
	// limit (a large decision is claim-checked); it is a guard against a
	// runaway decision.
	MaxEvents = 1000
)

NATS headers used by append and read.

Variables

View Source
var ErrConflict = errors.New("eventlog: concurrent append (expected sequence mismatch)")

ErrConflict means another writer appended first: reload and decide again.

Functions

This section is empty.

Types

type Log

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

Log reads and writes event logs.

func New

func New(in *infra.Infra) *Log

New returns a Log.

func (*Log) Append

func (l *Log) Append(ctx context.Context, execID string, expected uint64, evs []event.Event) (uint64, error)

Append writes the decision evs after expected (the stream sequence of the execution's last decision, 0 for a new execution) as one message and returns its sequence.

func (*Log) Decode

func (l *Log) Decode(ctx context.Context, m jetstream.Msg) ([]event.Event, error)

Decode decodes the decision delivered by a consumer (seq from its metadata).

func (*Log) DecodeEach

func (l *Log) DecodeEach(ctx context.Context, m jetstream.Msg) ([]event.Event, error)

DecodeEach decodes the events of a delivered decision one by one, keeping those that decode: a quarantined execution still needs its terminal event when another event of the same decision is unreadable.

func (*Log) FirstSeq

func (l *Log) FirstSeq(ctx context.Context, execID string) (uint64, error)

FirstSeq returns the sequence of the first event of execID still in the live log (a continuation purges what precedes it), 0 if none.

func (*Log) LastSeq

func (l *Log) LastSeq(ctx context.Context, execID string) (uint64, error)

LastSeq returns the sequence of the last event of execID, 0 if none.

func (*Log) Purge

func (l *Log) Purge(ctx context.Context, execID string) error

Purge removes every event of execID (archival).

func (*Log) PurgeBefore

func (l *Log) PurgeBefore(ctx context.Context, execID string, seq uint64) error

PurgeBefore removes the events of execID stored before sequence seq (they were archived by a continuation).

func (*Log) Read

func (l *Log) Read(ctx context.Context, execID string, from, to uint64) ([]event.Event, error)

Read returns the events of execID with stream sequence in [from, to] (to = 0: up to the end), with Seq and DecisionEnd set.

func (*Log) Scan

func (l *Log) Scan(ctx context.Context, execID string, from uint64, fn func(event.Event) bool) error

Scan calls fn for every event of execID from sequence from, in order, until fn returns false. It uses batched direct gets: no consumer is created.

func (*Log) ScanDecisions

func (l *Log) ScanDecisions(ctx context.Context, execID string, from uint64, fn func([]event.Event) bool) error

ScanDecisions calls fn for every decision of execID from sequence from, in order, until fn returns false.

Jump to

Keyboard shortcuts

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