journal

package
v1.45.13 Latest Latest
Warning

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

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

Documentation

Overview

Package journal implements durable admission only. Callers perform preflight between Lookup and Admit, and effects after Admit returns Fresh, outside locks. An error from Admit never permits an effect, even if a write reached disk.

Index

Constants

View Source
const MaxRate = 10000

MaxRate is the existing maximum record/JSON-array budget. Rate capacity does not reserve storage: the independent record, byte and retention limits apply.

View Source
const MinRetention uint64 = 7 * 24 * 60 * 60
View Source
const Protocol = "agent-notify/journal/v1"
View Source
const TrustedBootIDPath = "/proc/sys/kernel/random/boot_id"

TrustedBootIDPath is the kernel procfs boot identity. Production clocks inject this path explicitly; the zero PlatformClock never implies a filesystem root.

Variables

View Source
var (
	ErrRepair      = errors.New("state_repair_required")
	ErrFull        = errors.New("journal_full")
	ErrConflict    = errors.New("idempotency_conflict")
	ErrRate        = errors.New("rate_limited")
	ErrCAS         = errors.New("attempt_mismatch")
	ErrUnavailable = errors.New("journal_unavailable")
	ErrInvalid     = errors.New("invalid_journal_argument")
)

Functions

func LinuxBootSample

func LinuxBootSample(path string) (boot string, sec, nsec int64, ok bool)

LinuxBootSample reads an injected boot-id file and CLOCK_BOOTTIME. An empty path is unavailable and does not open any implicit filesystem root.

Types

type Admission

type Admission struct {
	Rates      RatePolicy
	Key        Key
	Digest     Digest
	TrackingID string
	Decision   Snapshot
}

type Clock

type Clock interface{ Sample() Sample }

Clock must return promptly and be safe for concurrent calls. Unavailable samples freeze collection and rate recovery; nil has the same behavior.

func DefaultClock

func DefaultClock() Clock

DefaultClock is the production Linux journal clock. Tests that need an unavailable clock still construct the zero PlatformClock.

type ClockFunc

type ClockFunc func() Sample

func (ClockFunc) Sample

func (f ClockFunc) Sample() Sample

type Digest

type Digest [32]byte

Digest is computed by the service from versioned normalized caller payload, never from mutable delivery configuration. No payload is accepted or stored.

type Key

type Key struct {
	Source, Session string
	Kind            KeyKind
	Request         string
}

type KeyKind

type KeyKind string
const (
	Explicit   KeyKind = "explicit"
	ClientCall KeyKind = "client_call"
	Generated  KeyKind = "generated"
)

type Limits

type Limits struct {
	Records   int    `json:"records"`
	Bytes     int    `json:"bytes"`
	Retention uint64 `json:"retention"`
}
type Navigation struct {
	Capability string `json:"capability"`
	Precision  string `json:"precision"`
	Scope      string `json:"scope"`
	Reason     string `json:"reason"`
}

type Options

type Options struct {
	Root   string
	Clock  Clock
	Limits Limits
}

type PlatformClock

type PlatformClock struct{ BootIDPath string }

PlatformClock requires an explicitly injected boot ID path on Linux (normally TrustedBootIDPath). No user HOME/config path is consulted. CLOCK_BOOTTIME includes elapsed suspend time and never uses wall time.

func (PlatformClock) Sample

func (c PlatformClock) Sample() Sample

type RatePolicy

type RatePolicy struct {
	SessionPerMinute int
	RuntimePerMinute int
	Burst            int
}

RatePolicy is a trusted configuration snapshot, never model payload. Windows are fixed at 60 seconds (session/runtime) and 2 seconds (runtime burst). The whole-zero value selects defaults; individual zero values never disable a limiter. Enablement and configuration generation fencing belong to callers.

func (RatePolicy) Normalize

func (p RatePolicy) Normalize() (RatePolicy, error)

Normalize validates a snapshot and resolves the backward-compatible default. Session and burst limits cannot exceed the enclosing runtime minute limit.

type Receipt

type Receipt struct {
	Status            string      `json:"status"`
	Reason            string      `json:"reason"`
	Backend           string      `json:"backend"`
	RequestID         *string     `json:"request_id"`
	TrackingID        string      `json:"tracking_id"`
	KeyKind           KeyKind     `json:"key_kind"`
	Decision          Snapshot    `json:"decision"`
	OutcomeNavigation *Navigation `json:"outcome_navigation,omitempty"`
}

type Record

type Record struct {
	Session string  `json:"session"`
	Digest  string  `json:"digest"`
	Attempt string  `json:"attempt"`
	Created uint64  `json:"created"`
	State   string  `json:"state"`
	Receipt Receipt `json:"receipt"`
}

type Result

type Result struct {
	// ScopedKey and Attempt let the service derive a stable native notification ID.
	ScopedKey string
	Found     bool
	Fresh     bool
	Record    Record
}

type Sample

type Sample struct {
	Boot      string
	Seconds   uint64
	Available bool
}

type Snapshot

type Snapshot struct {
	Target     Target     `json:"target"`
	Policy     string     `json:"policy"`
	Navigation Navigation `json:"navigation"`
}

type Store

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

func Initialize

func Initialize(ctx context.Context, o Options) (*Store, error)

Initialize is setup-only, for an explicitly never-initialized private root. The registry must remember initialization outside caches. Normal consumers must use Open; missing expected state must never trigger Initialize.

func Open

func Open(ctx context.Context, o Options) (*Store, error)

Open requires a complete existing namespace/journal/lock set. It never repairs or creates missing state, including when the entire expected root was lost.

func (*Store) Admit

func (s *Store) Admit(ctx context.Context, a Admission) (out Result, err error)

func (*Store) Collect

func (s *Store) Collect(ctx context.Context) error

Collect never affects OS notifications or callbacks. Unavailable/regressed clocks freeze GC. The logical clock baseline is persisted even when frozen.

func (*Store) Finalize

func (s *Store) Finalize(ctx context.Context, k Key, attempt, status, reason, backend string) error

Finalize only changes status/reason/backend; original identity and decision are immutable. On any error after the effect the caller reports unknown and must not retry delivery. A completed token cannot be finalized twice.

func (*Store) FinalizeOutcome

func (s *Store) FinalizeOutcome(ctx context.Context, k Key, attempt, status, reason, backend string, navigation *Navigation) error

FinalizeOutcome atomically records terminal navigation separately from the immutable admission. Nil preserves the legacy Finalize representation. This is draft unreleased v1 state: existing records remain readable, but old readers reject the optional field/new suppressed enum. Activation must fence older writers and rollback paths; never reset history or change namespace.

func (*Store) Lookup

func (s *Store) Lookup(ctx context.Context, k Key, digest Digest) (out Result, err error)

func (*Store) Namespace

func (s *Store) Namespace() string

type Target

type Target struct {
	Kind        string `json:"kind"`
	ID          string `json:"id"`
	Application string `json:"application"`
	Identity    string `json:"identity"`
}

Snapshot is a minimal immutable decision, not a callback dependency. The service maps these DTOs to the final notification receipt contract.

Jump to

Keyboard shortcuts

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