journal

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCorrupt = errors.New("snapshot: corrupt")

ErrCorrupt marks a snapshot file that exists but cannot be decoded. Callers (and the journal itself) treat this as "fall back", not "fail".

Functions

This section is empty.

Types

type BranchJournal

type BranchJournal interface {
	Get(ctx context.Context, runID, sourceNode string) ([]BranchRecord, bool, error)
	Put(ctx context.Context, runID, sourceNode string, records []BranchRecord) error
}

type BranchRecord

type BranchRecord struct {
	RunID       string       `json:"run_id"`
	SourceNode  string       `json:"source_node"`
	From        string       `json:"from"`
	To          string       `json:"to"`
	When        string       `json:"when,omitempty"`
	Otherwise   bool         `json:"otherwise,omitempty"`
	Status      BranchStatus `json:"status"`
	Reason      string       `json:"reason"`
	DecisionSeq int          `json:"decision_seq"`
	CreatedAt   time.Time    `json:"created_at"`
}

type BranchStatus

type BranchStatus string
const (
	BranchSelected BranchStatus = "selected"
	BranchSkipped  BranchStatus = "skipped"
)

type FileSnapshotJournal added in v0.4.0

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

FileSnapshotJournal is a durable, filesystem-backed SnapshotJournal.

Layout:

<baseDir>/<runID>/step_00042.json   immutable per-step snapshots
<baseDir>/<runID>/latest.json       most recent snapshot (pointer)

Every write is atomic + durable: temp file -> fsync -> rename -> fsync(dir). Readers take no lock: rename() is atomic, so Recover observes either the previous or the new file, never a torn one. This keeps the read path cheap and eliminates reader/writer contention.

The writer mutex serializes the shared latest.json rename target. Under contention this is the correct trade-off: the critical section is dominated by kernel I/O, not the lock itself.

func NewFileSnapshotJournal added in v0.4.0

func NewFileSnapshotJournal(baseDir string) (*FileSnapshotJournal, error)

NewFileSnapshotJournal creates or opens a journal rooted at baseDir.

func (*FileSnapshotJournal) Recover added in v0.4.0

func (f *FileSnapshotJournal) Recover(ctx context.Context, runID string) (*Snapshot, bool, error)

Recover loads the most recent snapshot for runID. The bool is false when no snapshot exists (not an error). Missing or corrupt latest.json transparently falls back to the highest step.

func (*FileSnapshotJournal) Save added in v0.4.0

Save durably persists s. Safe for concurrent use.

type MemoryBranchJournal

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

func NewMemoryBranchJournal

func NewMemoryBranchJournal() *MemoryBranchJournal

func (*MemoryBranchJournal) Get

func (j *MemoryBranchJournal) Get(_ context.Context, runID, sourceNode string) ([]BranchRecord, bool, error)

func (*MemoryBranchJournal) Put

func (j *MemoryBranchJournal) Put(_ context.Context, runID, sourceNode string, records []BranchRecord) error

type SQLBranchJournal

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

func NewSQLBranchJournal

func NewSQLBranchJournal(db *sql.DB) *SQLBranchJournal

func (*SQLBranchJournal) EnsureSchema

func (j *SQLBranchJournal) EnsureSchema(ctx context.Context) error

func (*SQLBranchJournal) Get

func (j *SQLBranchJournal) Get(ctx context.Context, runID, sourceNode string) ([]BranchRecord, bool, error)

func (*SQLBranchJournal) Put

func (j *SQLBranchJournal) Put(ctx context.Context, runID, sourceNode string, records []BranchRecord) error

type Snapshot added in v0.4.0

type Snapshot struct {
	RunID       string         `json:"run_id"`
	StepIndex   int            `json:"step_index"`
	StateData   map[string]any `json:"state_data"`
	SpentMicros int64          `json:"spent_micros"`
	Timestamp   time.Time      `json:"timestamp"`
}

Snapshot captures the resumable state of a run at a given step.

type SnapshotJournal added in v0.4.0

type SnapshotJournal interface {
	Save(ctx context.Context, s Snapshot) error
	Recover(ctx context.Context, runID string) (*Snapshot, bool, error)
}

SnapshotJournal persists and recovers run snapshots.

Jump to

Keyboard shortcuts

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