infra

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package infra holds the NATS handles shared by every packtrail component — connection, JetStream context, resource names, partition count — and the provisioning of the streams, buckets and object stores they use.

Index

Constants

View Source
const (
	DefaultReadTimeout = 5 * time.Second
	DefaultBlobTimeout = 2 * time.Minute
)

Default timeouts (all configurable on the engine, client and worker).

View Source
const DedupWindow = dedupWindow

DedupWindow is how long the command and work streams remember a message id. Ids are derived from the execution id, so an execution id must not be used again before its last messages have left the window: a deleted execution is kept at least this long after it finished.

View Source
const DefaultPartitions = 64

DefaultPartitions is the partition count of a new deployment. The count is permanent, so the default leaves room to add engines (G5-08).

View Source
const MetaPartitions = "packtrail.partitions"

MetaPartitions is the command-stream metadata key holding the partition count: every process (engine, client, SDK) reads it from there, so all agree on where an execution's commands go.

View Source
const MetaProtocol = "packtrail.protocol"

MetaProtocol is the command-stream metadata key holding the wire protocol version.

View Source
const ProtocolVersion = "1"

ProtocolVersion is the version of the wire protocol.

Variables

View Source
var ErrNotProvisioned = apierr.ErrNotProvisioned

ErrNotProvisioned is returned by Attach when the deployment does not exist.

Functions

func DefaultBlobThreshold

func DefaultBlobThreshold(nc *nats.Conn) int

DefaultBlobThreshold derives the claim-check threshold from the server's max_payload minus a margin for headers and subject.

func Retry

func Retry(ctx context.Context, attempts int, fn func() error) error

Retry runs fn until it succeeds, ctx ends or attempts are exhausted, backing off between attempts. It is for transient NATS errors on idempotent calls.

Types

type Infra

type Infra struct {
	NC         *nats.Conn
	JS         jetstream.JetStream
	Names      names.Names
	Partitions int
	Logger     *slog.Logger
	// BlobThreshold is the body size above which a message body is moved to
	// the blobs object store (claim-check).
	BlobThreshold int
	// AckWait and PullExpiry configure the engine and dispatcher consumers.
	AckWait    time.Duration
	PullExpiry time.Duration
	// ReadTimeout bounds one batched read of an event log.
	ReadTimeout time.Duration
	// BlobTimeout bounds one blob transfer when the caller sets no deadline.
	BlobTimeout time.Duration
	// Replicas is the replication factor of every stream, bucket and object
	// store (0 = 1). Use 3 in production: the events stream is the source of
	// truth.
	Replicas int
	// contains filtered or unexported fields
}

Infra bundles the shared NATS handles.

func New

func New(nc *nats.Conn, ns names.Names, logger *slog.Logger) (*Infra, error)

New returns an Infra for an existing connection. Partitions and the blob threshold are resolved by Attach (from the deployed command stream) or Provision.

func (*Infra) Attach

func (i *Infra) Attach(ctx context.Context) error

Attach reads the partition count from a deployed command stream.

func (*Infra) CheckServer

func (i *Infra) CheckServer() error

CheckServer fails fast when the connected server is too old for packtrail (backlog: "require NATS >= 2.12 and fail at startup").

func (*Infra) CmdSubject

func (i *Infra) CmdSubject(execID string) string

CmdSubject returns the command subject of an execution.

func (*Infra) EraseKey added in v1.0.1

func (i *Infra) EraseKey(ctx context.Context, bucket, key string) error

EraseKey removes a key of a KV bucket without leaving a delete marker. Erasing a missing key is a no-op.

func (*Infra) EraseObject added in v1.0.1

func (i *Infra) EraseObject(ctx context.Context, bucket, name string) error

EraseObject removes an object of an object store without leaving a delete marker. Erasing a missing object is a no-op.

func (*Infra) EventSubject

func (i *Infra) EventSubject(execID string) string

EventSubject returns the event subject of an execution.

func (*Infra) KV

func (i *Infra) KV(ctx context.Context, bucket string) (jetstream.KeyValue, error)

KV returns (and caches) a key-value bucket handle.

func (*Infra) Object

func (i *Infra) Object(ctx context.Context, bucket string) (jetstream.ObjectStore, error)

Object returns (and caches) an object store handle.

func (*Infra) Partition

func (i *Infra) Partition(execID string) int

Partition returns the partition of an execution.

func (*Infra) Provision

func (i *Infra) Provision(ctx context.Context, partitions int) error

Provision creates or updates every resource of the namespace. partitions is the desired partition count for a new deployment (0 = DefaultPartitions or the deployed value); changing it on an existing deployment is refused, because it would re-route in-flight executions.

Jump to

Keyboard shortcuts

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