durable

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 6 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 durable records that a multi-step operation is in flight, so a process death cannot lose the knowledge that the work must be finished or undone.

The vocabulary here is intent and resolution. There is deliberately no key, value, shard, or workflow in it: a backend that stores intents as rows in the metadata cluster and one that hands them to a workflow engine implement the same interface. The package imports no infrastructure so any adapter can depend on it without depending on ours.

What this package does NOT do is interpret an intent. It stores and returns them; deciding what "the entry was written but the row was not" MEANS belongs to the component that owns those steps (docs/SPEC.md "Durable intent").

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("durable: intent not found")

ErrNotFound is returned when an intent is absent. Callers treat it as "already resolved" rather than as a failure: forgetting an intent twice is normal when two resolvers race.

Functions

This section is empty.

Types

type ID

type ID string

ID identifies one in-flight operation. Callers assign it, so an operation that is retried under the same ID resolves to the same intent rather than accumulating duplicates.

type Intent

type Intent struct {
	ID        ID
	Kind      Kind
	Scope     Scope
	Subject   string
	Reached   []StepName
	Guard     []byte
	StartedAt time.Time
}

Intent is the durable record of an operation that started and has not been confirmed finished.

Subject is what the operation acts on (for a paste, its slug). Guard is the payload a compensating delete must still find in place before removing anything, so cleanup cannot eat a fresh retry's work; an empty Guard means the step has no value to compare against.

func (Intent) HasReached

func (i Intent) HasReached(s StepName) bool

Reached reports whether the operation recorded that step before stopping.

type Kind

type Kind string

Kind names the operation, so a resolver can dispatch without guessing from the step list.

const (
	KindCreatePaste Kind = "create_paste"
	KindDeploySite  Kind = "deploy_site"
)

type Log

type Log interface {
	// Begin records the intent. Once it returns nil the intent is durable, and
	// the caller may start doing the work it describes.
	Begin(ctx context.Context, in Intent) error

	// Advance records that a step completed, so a later resolver knows how far
	// the work got. Advancing past a step already recorded is a no-op.
	Advance(ctx context.Context, id ID, scope Scope, step StepName) error

	// Complete forgets the intent: the operation finished and needs no
	// resolution. Completing an absent intent is a no-op, not an error.
	Complete(ctx context.Context, id ID, scope Scope) error

	// Outstanding returns the scope's intents that were never completed, oldest
	// first. It is the only read, and it is scoped deliberately.
	Outstanding(ctx context.Context, scope Scope) ([]Intent, error)
}

Log durably remembers in-flight operations.

Every method must be safe to call twice with the same argument. Concurrent resolvers are expected, and they converge only if repetition is harmless.

type MemLog

type MemLog struct {

	// FailBegin, when set, makes Begin return it. Crash-boundary tests use this
	// to stop an operation at T0 without killing the process.
	FailBegin error
	// contains filtered or unexported fields
}

MemLog is an in-memory Log for tests and for backends that have no dual write to protect. It is safe for concurrent use, which matters because the concurrency tests drive two resolvers at once through it.

func NewMemLog

func NewMemLog() *MemLog

func (*MemLog) Advance

func (m *MemLog) Advance(_ context.Context, id ID, scope Scope, step StepName) error

func (*MemLog) Begin

func (m *MemLog) Begin(_ context.Context, in Intent) error

func (*MemLog) Complete

func (m *MemLog) Complete(_ context.Context, id ID, scope Scope) error

func (*MemLog) Outstanding

func (m *MemLog) Outstanding(_ context.Context, scope Scope) ([]Intent, error)

type Scope

type Scope string

Scope is the recovery unit: the subject whose outstanding intents are listed together. Keeping it a single subject rather than offering a global "everything outstanding" is load-bearing - a global enumeration would force a keyspace-wide scan on a sharded store and an unbounded query on a workflow engine. Scoped, both are cheap.

type StepName

type StepName string

StepName names one step of an operation. Steps are recorded as DATA, never as closures: resolution may run in a different process from the one that began the work, so what was attempted has to survive without the original stack.

Jump to

Keyboard shortcuts

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