directsource

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 22 Imported by: ? 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 directsource lets a relay run straight from flag files: it computes the manifest itself.

A Source is a manifestreader.ObjectStore for one virtual manifest key. A read of that key runs a round: it lists the prefixes of the discovered sources, reads the objects whose marker moved, validates what it read with the code of the publisher (package controlplane) and returns the manifest that a publisher would have written for the same objects. The manifest reader polls it like a stored manifest, so the polling, the backoff, the state directory, the last known good content, the swap and the readiness are the ones of the published way.

A round is all or nothing: any failure keeps the previous generation (see Source.Get).

Index

Constants

View Source
const (
	// DefaultConcurrency is the number of objects read at the same time.
	DefaultConcurrency = 8

	// DefaultMaxSetFileBytes is the largest flag set file: they are small documents.
	DefaultMaxSetFileBytes = 1 << 20
)

Defaults of Config.

View Source
const (
	// VirtualConnection is the connection name of the objects that exist only in memory (the flag-set documents the
	// relay builds from flag set files). It cannot clash with a connection of the bootstrap file: their names start
	// with a letter.
	VirtualConnection = "$direct"
	// ManifestKey is the key of the computed manifest in the virtual connection.
	ManifestKey = "manifest.yaml"
	// Channel is the channel of every computed manifest.
	Channel = "direct"
)

Names of the virtual connection and objects of a Source.

Variables

View Source
var (
	// ErrInvalidSpec is returned for a [Spec] that cannot be used.
	ErrInvalidSpec = errors.New("directsource: invalid specification")
	// ErrNoLister is returned when a source names a connection whose kind cannot list a prefix.
	ErrNoLister = errors.New("directsource: the connection cannot list keys")
	// ErrUnknownConnection is returned for a connection that is not one of the backends.
	ErrUnknownConnection = errors.New("directsource: unknown connection")
	// ErrRound is the cause of every failed round: the previous generation stays.
	ErrRound = errors.New("directsource: round failed")
)

Errors of a Spec or of a round. Test them with errors.Is.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	// Store reads one object.
	Store manifestreader.ObjectStore
	// Lister lists a prefix; nil when the kind cannot list.
	Lister manifestreader.Lister
	// ReadTwice makes the round read an object that changed twice and compare the two reads: a writer that is
	// still writing (a local file) changes the bytes between them. A remote store replaces an object atomically and
	// does not need it.
	ReadTwice bool
}

Backend is what a round needs from one connection of the bootstrap file. The connection layer builds it from the kind of the connection: a kind that cannot list a prefix has no Lister, so a source on it is refused when the spec is set, never found out by a type assertion.

type Cached

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

Cached is the store of a connection for the reader, see Source.Wrap.

func (*Cached) Get

Get implements manifestreader.ObjectStore.

type Config

type Config struct {
	// Backends are the connections the spec may name, by name.
	Backends map[string]Backend
	// Logger receives one line per distinct failure; nil discards.
	Logger *slog.Logger
	// Spec says what to read.
	Spec Spec
	// MaxObjects is the largest number of objects of a manifest (default controlplane.DefaultMaxObjects).
	MaxObjects int
	// MaxObjectBytes is the largest object (default controlplane.DefaultMaxObjectBytes).
	MaxObjectBytes int64
	// MaxTotalBytes is the largest sum of the distinct objects (default controlplane.DefaultMaxTotalBytes).
	MaxTotalBytes int64
	// MaxSetFileBytes is the largest flag set file (default [DefaultMaxSetFileBytes]).
	MaxSetFileBytes int64
	// Concurrency is the number of objects read at the same time (default [DefaultConcurrency]).
	Concurrency int
}

Config configures a Source.

type FileRef

type FileRef struct {
	Connection string
	Key        string
}

FileRef names one object: a connection of the bootstrap file and a key in it.

type Problem

type Problem struct {
	// File is the connection and key of the flag set file.
	File string `json:"file"`
	// Reason names what is wrong, never a value or an API key.
	Reason string `json:"reason"`
	// KeptPrevious tells that the flag set still serves its last good version.
	KeptPrevious bool `json:"keptPrevious"`
}

Problem is a flag set file that cannot be served as it is now.

type Restored

type Restored struct {
	// ETag is the ETag of the restored manifest.
	ETag string
	// Manifest is the restored manifest.
	Manifest []byte
	// Objects are the bytes of the restored objects.
	Objects [][]byte
}

Restored is the state a restart brings back: the manifest the last run served and the objects it listed.

type Source

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

Source computes the manifest. It is safe for concurrent use; the rounds are serialised.

func New

func New(cfg *Config) (*Source, error)

New returns a source. It makes no request.

func (*Source) Get

Get implements manifestreader.ObjectStore for the virtual connection: the manifest key runs a round, and any other key is an in-memory flag-set document.

func (*Source) Seed

func (s *Source) Seed(restored *Restored)

Seed tells the source what a restored state holds: the generation and content checksum, so that unchanged content keeps the generation and changed content goes above it, and who held each flag set name, API key and public flag key, so that a restart does not hand a name or a key to another file than the one that held it.

func (*Source) SetSpec

func (s *Source) SetSpec(spec *Spec) error

SetSpec replaces what the source reads. The next round uses it. A spec that names a connection the source does not have, or a source on a connection that cannot list, is refused and nothing changes.

func (*Source) Status

func (s *Source) Status() Status

Status returns the state at the end of the last round.

func (*Source) Wrap

func (s *Source) Wrap(name string, inner manifestreader.ObjectStore) *Cached

Wrap returns the store of connection name for the reader: it answers from the objects the last rounds read, and asks inner for any other key. Every changed object is therefore read once, by the round.

type SourceSpec

type SourceSpec struct {
	Connection string
	// Prefix is the key prefix; empty means the whole connection. A prefix that does not end with a slash gets one.
	Prefix string
}

SourceSpec is a source: the flag set files found under a prefix of a connection.

type Spec

type Spec struct {
	Sources []SourceSpec
}

Spec is what the relay is told to read.

type Status

type Status struct {
	// LastRound is the time of the last successful round; zero when there was none.
	LastRound time.Time `json:"lastRound,omitzero"`
	// LastErrorAt is the time of the failure of LastError; zero when the last round succeeded.
	LastErrorAt time.Time `json:"lastErrorAt,omitzero"`
	// ContentChecksum is the sha256 of the computed manifest without its generation: relays that read the same
	// objects have the same one, whatever their generation numbers are.
	ContentChecksum string `json:"contentChecksum"`
	// LastError is the reason of the last failed round; empty when the last round succeeded. It names objects,
	// never values.
	LastError string `json:"lastError,omitempty"`
	// Manifest is the manifest the last successful round computed: what a publisher would have written for the
	// same files. It holds names, keys, sizes and checksums, never an API key or the content of an object.
	Manifest *controlplane.Manifest `json:"manifest,omitempty"`
	// Invalid lists the flag set files that are not usable now, at most 20, with the reason. A file that has a
	// previous version keeps serving it (KeptPrevious).
	Invalid []Problem `json:"invalid,omitempty"`
	// Generation is the generation of the computed manifest. It is the count of changes this relay saw, not
	// comparable between relays.
	Generation uint64 `json:"generation"`
	// Rounds counts the rounds, Failures the failed ones.
	Rounds   uint64 `json:"rounds"`
	Failures uint64 `json:"failures"`
	// Objects, FlagSets and Flags count what the last successful round computed.
	Objects  int `json:"objects"`
	FlagSets int `json:"flagSets"`
	Flags    int `json:"flags"`
}

Status is what the source knows about its rounds. It holds no API key and no object content.

Jump to

Keyboard shortcuts

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