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 ¶
- Variables
- type Host
- func (h *Host) Checkpoint(ctx context.Context, name string, blobs bool) (store.CheckpointResult, error)
- func (h *Host) Close(context.Context) error
- func (h *Host) Config() *config.Config
- func (h *Host) Instances() []*module.Instance
- func (h *Host) Probe(ctx context.Context) bool
- func (h *Host) Ready() bool
- func (h *Host) Reconcile(ctx context.Context) error
- func (h *Host) Retire(wait time.Duration) bool
- func (h *Host) RetireKeeping(wait time.Duration, keep map[string]*module.Instance) bool
- func (h *Host) Start(ctx context.Context)
- type ReloadResult
- type Reloader
- func (r *Reloader) Close(ctx context.Context) error
- func (r *Reloader) Delete(ctx context.Context, id string) (any, error)
- func (r *Reloader) Dynamic() *config.Dynamic
- func (r *Reloader) Host() *Host
- func (r *Reloader) List() any
- func (r *Reloader) Put(ctx context.Context, ask httpapi.TopicsAsk) (any, error)
- func (r *Reloader) Reload(ctx context.Context) (ReloadResult, error)
- func (r *Reloader) ReloadSoon(ctx context.Context) (ReloadResult, error)
- func (r *Reloader) RunExpiry(ctx context.Context, every time.Duration)
- func (r *Reloader) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Reloader) SetDynamic(dyn *config.Dynamic)
- type TopicsResult
Constants ¶
This section is empty.
Variables ¶
var CoalesceDynamic = time.Second
CoalesceDynamic is how long a reload an application's ask calls for waits for others to share it.
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 ¶
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 ¶
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) Retire ¶ added in v0.19.0
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
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.
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"`
// 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:
- hold the old host's admissions and stop its work (each module's rows journal closes before the next instance opens it);
- build and restore the next host;
- 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
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
Delete withdraws an ask and answers once the reload is done (DELETE /admin/topics/{id}).
func (*Reloader) Put ¶ added in v0.19.0
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
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
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.