host

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 30 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 host wires the whole Go overlay host: storage, chain tracker, modules, the engine, the pipeline, readiness, root reconciliation, retention, GASP catch-up and the HTTP surface. The binary and the integration test both build it here, so the test exercises exactly what runs.

Index

Constants

This section is empty.

Variables

View Source
var CoalesceDynamic = time.Second

CoalesceDynamic is how long a reload an application's ask calls for waits for others to share it.

View Source
var ErrAssert = errors.New("startup assertion failed")

ErrAssert is a startup assertion that failed: a misconfiguration.

Functions

This section is empty.

Types

type Host

type Host struct {
	Handler  http.Handler
	Engine   *engine.Engine
	Store    *store.Store
	Pipeline *pipeline.Pipeline
	Metrics  *metrics.Metrics
	Tracker  *tracker.Bridge
	// Syncer is the GASP catch-up (internal/catchup); it pulls only with
	// peers configured.
	Syncer *catchup.Syncer
	// Gate is the catch-up hold (nil when off: no OVERLAY_GASP_SHED_URL,
	// no peers, or OVERLAY_CATCHUP_HOLD=false).
	Gate *catchup.Gate
	// contains filtered or unexported fields
}

Host is one running overlay host.

func New

func New(ctx context.Context, cfg *config.Config, version string, log *slog.Logger) (*Host, error)

New builds a host whose modules read the process environment. It opens storage; Close releases it.

func NewFrom added in v0.19.0

func NewFrom(ctx context.Context, cfg *config.Config, getenv func(string) string, version string, log *slog.Logger) (*Host, error)

NewFrom is New with the modules' settings read through getenv: the settings source a reload reads again (config.Source).

func (*Host) Checkpoint added in v0.2.0

func (h *Host) Checkpoint(ctx context.Context, name string, blobs bool) (store.CheckpointResult, error)

Checkpoint writes a checkpoint under the configured backup directory as <dir>/<name> (name is one path component): the index and every module state directory at one instant, admissions held for it, and with blobs the blob snapshot.

func (*Host) Close

func (h *Host) Close(context.Context) error

Close stops the modules' background work, waiting for it (at most 10 s) so that none of it reaches the storage after, and releases storage.

func (*Host) Config added in v0.19.0

func (h *Host) Config() *config.Config

Config is the configuration the host was built on.

func (*Host) Instances added in v0.19.0

func (h *Host) Instances() []*module.Instance

Instances are the module instances this host mounted.

func (*Host) Probe

func (h *Host) Probe(ctx context.Context) bool

Probe re-checks readiness: storage and the chain tracker both answer.

func (*Host) Ready

func (h *Host) Ready() bool

Ready reports the last readiness probe.

func (*Host) Reconcile

func (h *Host) Reconcile(ctx context.Context) error

Reconcile runs one root reconciliation pass now.

func (*Host) Retire added in v0.19.0

func (h *Host) Retire(wait time.Duration) bool

Retire stops this host's work without closing the storage, for a reload that builds the next host on the same storage: what Start started, and the modules' background work (at most wait; their rows journals close). Its pipeline should be held by the caller, so nothing is admitted meanwhile. It reports whether the modules stopped in time.

func (*Host) RetireKeeping added in v0.19.0

func (h *Host) RetireKeeping(wait time.Duration, keep map[string]*module.Instance) bool

RetireKeeping is Retire leaving the module instances in keep running, for a reload that hands them to the next host: only the others' background work stops.

func (*Host) Start

func (h *Host) Start(ctx context.Context)

Start runs readiness probing, root reconciliation, retention and GASP catch-up until ctx ends.

type ReloadResult added in v0.19.0

type ReloadResult struct {
	Changed bool     `json:"changed"`
	Added   []string `json:"added,omitempty"`
	Removed []string `json:"removed,omitempty"`
	Modules []string `json:"modules,omitempty"`
	// Rebuilt are the modules stopped, built and restored; the others were
	// kept as they ran.
	Rebuilt []string `json:"rebuilt,omitempty"`
	// InPlace are the modules that took the change without being built
	// again (TakeChanges): their running index changed by the change alone.
	InPlace []string `json:"in_place,omitempty"`
	// Restart names settings that changed and need a restart to apply.
	Restart []string `json:"restart,omitempty"`
	// HeldMS is how long admissions waited.
	HeldMS int64 `json:"held_ms"`
	// RolledBack: the next host failed to build and the previous
	// settings serve again.
	RolledBack bool `json:"rolled_back,omitempty"`
}

ReloadResult is what a reload did.

type Reloader added in v0.19.0

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

A Reloader serves one host and, asked to (SIGHUP, POST /admin/reload), builds the next one on the topic settings read afresh, without a restart: a topic added to or dropped from the host (OVERLAY_TOPICS, OVERLAY_MODULES and every module's own settings, as config.Source reads them) takes effect while the process, its port and its storage stay up, and a bridge in front (overlay-bridge -topics-from engine) follows within its next ask.

The next host is built the way the first was, on the same open storage: its modules mount and restore their indexes from the rows. The swap is made under the old host's hold, so no admission falls between a module's restore and the swap:

  1. hold the old host's admissions and stop its work (each module's rows journal closes before the next instance opens it);
  2. build and restore the next host;
  3. serve it, retire the old pipeline (an object that waited at its door answers 503 with Retry-After, and its sender sends it again) and release the hold.

A next host that fails to build is not served: the old settings are built again and served instead, and the reload answers the error. Admissions wait for the whole of steps 1 and 2, the time a module restore takes, which a start pays too; lookups go on answering from the old host meanwhile.

Settings other than topics and modules (storage, ports, peers, the verifier) are read but not applied: a change to one is named as needing a restart.

func NewReloader added in v0.19.0

func NewReloader(base context.Context, h *Host, src *config.Source, version string, log *slog.Logger, wire func(*Host)) *Reloader

NewReloader serves h, which runs under base, and reads src on a reload. wire, when not nil, is called with every host before it serves, including h.

func (*Reloader) Close added in v0.19.0

func (r *Reloader) Close(ctx context.Context) error

Close stops the current host and releases the storage. It waits for a reload in progress, and a reload after it is refused.

func (*Reloader) Delete added in v0.19.0

func (r *Reloader) Delete(ctx context.Context, id string) (any, error)

Delete withdraws an ask and answers once the reload is done (DELETE /admin/topics/{id}).

func (*Reloader) Dynamic added in v0.19.0

func (r *Reloader) Dynamic() *config.Dynamic

Dynamic is the topics local applications asked for.

func (*Reloader) Host added in v0.19.0

func (r *Reloader) Host() *Host

Host is the host serving now.

func (*Reloader) List added in v0.19.0

func (r *Reloader) List() any

List answers the asks (GET /admin/topics).

func (*Reloader) Put added in v0.19.0

func (r *Reloader) Put(ctx context.Context, ask httpapi.TopicsAsk) (any, error)

Put keeps a local application's ask and answers once the reload that serves it is done (POST /admin/topics). Asking again with the same id refreshes its lifetime and replaces its settings.

The ask is kept only if the host's settings with it load; and if the reload it shares fails or rolls back, it is taken back (its previous version put back), so an ask that does not build never stays to block the next. The reload's outcome is judged whether or not the caller is still waiting.

func (*Reloader) Reload added in v0.19.0

func (r *Reloader) Reload(ctx context.Context) (ReloadResult, error)

Reload reads the settings again and, if the topics or the modules' settings changed, builds and serves the next host.

func (*Reloader) ReloadSoon added in v0.19.0

func (r *Reloader) ReloadSoon(ctx context.Context) (ReloadResult, error)

ReloadSoon runs a reload shared by every caller within CoalesceDynamic of the first, and answers its result once it is done (or ctx ends).

func (*Reloader) RunExpiry added in v0.19.0

func (r *Reloader) RunExpiry(ctx context.Context, every time.Duration)

RunExpiry drops the asks whose lifetime ran out, every interval, with a reload when any did, until ctx ends.

func (*Reloader) ServeHTTP added in v0.19.0

func (r *Reloader) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP serves the current host's routes.

func (*Reloader) SetDynamic added in v0.19.0

func (r *Reloader) SetDynamic(dyn *config.Dynamic)

SetDynamic lays dyn over the settings at every later reload.

type TopicsResult added in v0.19.0

type TopicsResult struct {
	Entry   *config.DynamicEntry `json:"entry,omitempty"`
	Removed bool                 `json:"removed,omitempty"`
	Reload  ReloadResult         `json:"reload"`
}

TopicsResult is what an ask did: the entry kept and the reload it shared.

Jump to

Keyboard shortcuts

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