store

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 9 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 store holds mash's JetStream layout: per-endpoint inbox streams, their consumer, and the directory and lease KV buckets (spec section 5).

Index

Constants

View Source
const (
	DirectoryBucket = "mash-directory"
	LeaseBucket     = "mash-leases"
	Consumer        = "deliver"
)

Bucket and consumer names.

View Source
const (
	InboxMaxAge   = 30 * 24 * time.Hour
	InboxMaxBytes = 16 << 20
	MaxMsgSize    = 1 << 20
	LeaseTTL      = 90 * time.Second
)

Inbox limits (spec 5.1).

View Source
const (
	DirectoryMaxBytes = 16 << 20
	LeaseMaxBytes     = 4 << 20
)

Bucket size caps. Hosted NATS accounts (Synadia Cloud) reject a stream config with no MaxBytes, so every bucket sets one. Directory records and leases are tiny; these are generous.

View Source
const InboxDuplicateWindow = 2 * time.Minute

InboxDuplicateWindow is how long the inbox stream remembers a Nats-Msg-Id: a publish with the same id inside it is dropped, after it the message is stored again. It bounds what "send --id" can promise.

View Source
const MaxCaps = 8

MaxCaps is the most capability words one record may carry.

View Source
const MaxDescriptionLen = 256

MaxDescriptionLen is the longest Description.

View Source
const MaxLabels = 8

MaxLabels is the most labels one record may carry.

View Source
const MaxMetaLen = 64

MaxMetaLen is the longest Role, Host or label value.

Variables

This section is empty.

Functions

func ConsumerConfig

func ConsumerConfig() jetstream.ConsumerConfig

ConsumerConfig is the durable consumer the endpoint manager reads its inbox through.

func DirectoryConfig

func DirectoryConfig() jetstream.KeyValueConfig

DirectoryConfig is the directory bucket: name -> Record, written by the admin.

func DirectoryConfigFor added in v0.3.1

func DirectoryConfigFor(l Limits) jetstream.KeyValueConfig

DirectoryConfigFor is DirectoryConfig under limits l.

func InboxConfig

func InboxConfig(owner, name string) jetstream.StreamConfig

InboxConfig is endpoint name's inbox stream. No subject transform: a stored Agent-Sender header must verify against the stored subject (SAP §13.8).

func InboxConfigFor added in v0.3.1

func InboxConfigFor(owner, name string, l Limits) jetstream.StreamConfig

InboxConfigFor is InboxConfig under limits l.

func LeaseConfig

func LeaseConfig() jetstream.KeyValueConfig

LeaseConfig is the lease bucket: name -> holder, expiring unless refreshed.

func LeaseConfigFor added in v0.3.1

func LeaseConfigFor(l Limits) jetstream.KeyValueConfig

LeaseConfigFor is LeaseConfig under limits l.

func LeaseTombstone

func LeaseTombstone() []byte

LeaseTombstone is what Deprovision writes to an endpoint's lease key: it fences the name, so a live or starting session cannot take the lease back after its endpoint is gone. It expires with the bucket's TTL (LeaseTTL) like any lease, and Provision clears it.

func ValidCap added in v0.3.2

func ValidCap(c string) bool

ValidCap reports whether c is a legal capability word: [a-z][a-z0-9_.-]{0,31}.

func ValidCaps added in v0.3.2

func ValidCaps(caps []string) error

ValidCaps checks a capability list: at most MaxCaps words, each passing ValidCap, none repeated.

func ValidDescription added in v0.3.2

func ValidDescription(v string) error

ValidDescription checks a description: at most MaxDescriptionLen characters, printable, no tab or newline.

func ValidLabelKey

func ValidLabelKey(k string) bool

ValidLabelKey reports whether k is a legal label key.

func ValidLabels

func ValidLabels(l map[string]string) error

ValidLabels checks a label set: at most MaxLabels keys, each key [a-z][a-z0-9_.-]{0,31}, each value passing ValidMeta.

func ValidMeta

func ValidMeta(field, v string) error

ValidMeta checks one metadata value: at most MaxMetaLen characters, printable, no tab or newline (they end up in tab-separated output). Empty is valid (unset).

Types

type Limits added in v0.3.1

type Limits struct {
	InboxMaxBytes     int64
	InboxMaxAge       time.Duration
	DirectoryMaxBytes int64
	LeaseMaxBytes     int64
	InboxMaxConsumers int // -1 is unlimited
}

Limits are the configurable caps: the inbox's size, age and consumer count, and the two buckets' sizes. DefaultLimits is what mash has always used.

func DefaultLimits added in v0.3.1

func DefaultLimits() Limits

DefaultLimits returns the built-in limits.

func (Limits) Validate added in v0.3.1

func (l Limits) Validate() error

Validate checks l against the sane minimums, naming the offending field.

type Record

type Record struct {
	Name        string `json:"name"`
	Owner       string `json:"owner"`
	Agent       string `json:"agent"`
	AgentToken  string `json:"agent_token"`
	Account     string `json:"account"`
	User        string `json:"user"`
	MailSubject string `json:"mail_subject"`
	Created     string `json:"created"`
	Note        string `json:"note,omitempty"`
	// Role, Host and Labels are optional directory metadata: what the endpoint is for, the machine it is meant to run
	// on, and free-form key=value labels (for example a team, project or fleet). They are the identity on record; the
	// lease is the live view. Readers from before these fields ignore them.
	Role   string            `json:"role,omitempty"`
	Host   string            `json:"host,omitempty"`
	Labels map[string]string `json:"labels,omitempty"`
	// Description is free text on what the endpoint does, and Caps are up to MaxCaps capability words (sorted), both
	// set by the admin. Readers from before these fields ignore them, and set-meta keeps fields it does not know.
	Description string   `json:"description,omitempty"`
	Caps        []string `json:"caps,omitempty"`
}

Record is one directory entry (spec 6.1).

func GetRecord

func GetRecord(ctx context.Context, kv jetstream.KeyValue, name string) (Record, error)

GetRecord reads name's directory record.

func ParseRecord

func ParseRecord(key string, value []byte) (Record, error)

ParseRecord decodes a directory value and checks it names key.

Jump to

Keyboard shortcuts

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