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
- Variables
- type Log
- func (l *Log) Append(ctx context.Context, execID string, expected uint64, evs []event.Event) (uint64, error)
- func (l *Log) Decode(ctx context.Context, m jetstream.Msg) ([]event.Event, error)
- func (l *Log) DecodeEach(ctx context.Context, m jetstream.Msg) ([]event.Event, error)
- func (l *Log) FirstSeq(ctx context.Context, execID string) (uint64, error)
- func (l *Log) LastSeq(ctx context.Context, execID string) (uint64, error)
- func (l *Log) Purge(ctx context.Context, execID string) error
- func (l *Log) PurgeBefore(ctx context.Context, execID string, seq uint64) error
- func (l *Log) Read(ctx context.Context, execID string, from, to uint64) ([]event.Event, error)
- func (l *Log) Scan(ctx context.Context, execID string, from uint64, fn func(event.Event) bool) error
- func (l *Log) ScanDecisions(ctx context.Context, execID string, from uint64, fn func([]event.Event) bool) error
Constants ¶
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 ¶
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 (*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) DecodeEach ¶
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 ¶
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) PurgeBefore ¶
PurgeBefore removes the events of execID stored before sequence seq (they were archived by a continuation).
func (*Log) Read ¶
Read returns the events of execID with stream sequence in [from, to] (to = 0: up to the end), with Seq and DecisionEnd set.