stream

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package stream owns the C-S2 visibility watermark and C-S7 retention machinery for the transactional change-event outbox.

Index

Constants

This section is empty.

Variables

View Source
var ErrLeaseHeld = errors.New("stream watermark lease is held")

ErrLeaseHeld means another watermarker owns the unexpired singleton lease.

Functions

This section is empty.

Types

type Retention

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

Retention prunes change events without consulting consumer cursors and advances per-stream horizons in the same transaction as each delete batch.

func NewRetention

func NewRetention(
	pool *pgxpool.Pool,
	options RetentionOptions,
) (*Retention, error)

NewRetention validates the locked seven-day C-S7 floor.

func (*Retention) Prune

func (r *Retention) Prune(
	ctx context.Context,
) (total int64, resultErr error)

Prune deletes every expired event in bounded C-S7 batches and returns the number removed. Cursor positions never participate in eligibility.

func (*Retention) Run

func (r *Retention) Run(ctx context.Context) error

Run prunes on startup and periodically thereafter. It is intentionally independent of River granularity and consumer cursor state (C-S7).

type RetentionOptions

type RetentionOptions struct {
	Age       time.Duration
	Period    time.Duration
	BatchSize int
	Now       func() time.Time
	OnPrune   func(context.Context, string, int64)
	Tracer    trace.Tracer
}

RetentionOptions configures independent C-S7 change-event pruning.

type WatermarkObserver

type WatermarkObserver interface {
	WatermarkStep(context.Context, WatermarkProgress)
}

WatermarkObserver is M6's C-S2 progress seam.

type WatermarkOptions

type WatermarkOptions struct {
	RefreshInterval  time.Duration
	LeaseTTL         time.Duration
	FenceLockTimeout time.Duration
	Owner            string
	Observer         WatermarkObserver
	InstallationID   int64
}

WatermarkOptions configures the leased C-S2 maintenance loop.

type WatermarkProgress

type WatermarkProgress struct {
	SafeSeq      int64
	MaxSeq       int64
	CandidateSeq *int64
	Advanced     bool
	// FenceTimedOut is a bounded, retryable step outcome rather than a
	// watermarker failure. Observers meter it separately from advances.
	FenceTimedOut bool
}

WatermarkProgress is one observed state of the public stream watermark.

type Watermarker

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

Watermarker advances stream_watermark.safe_seq while holding the exclusive side of the outbox writer fence.

func NewWatermarker

func NewWatermarker(
	pool *pgxpool.Pool,
	options WatermarkOptions,
) (*Watermarker, error)

NewWatermarker constructs a leader-coordinated C-S2 watermarker.

func (*Watermarker) Close

func (w *Watermarker) Close(ctx context.Context) error

Close releases this runtime's singleton lease. It does not alter the safe watermark.

func (*Watermarker) Run

func (w *Watermarker) Run(ctx context.Context) error

Run maintains the watermark at approximately RefreshInterval. Standby processes keep attempting the expiring lease, so failover needs no external coordinator (C-O2).

func (*Watermarker) Step

func (w *Watermarker) Step(
	ctx context.Context,
) (WatermarkProgress, error)

Step renews or acquires the singleton lease, waits for all registered outbox writers, and publishes the greatest committed sequence. Read-only snapshots and unrelated transactions do not participate in this fence.

Jump to

Keyboard shortcuts

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