workerupgrade

package
v0.211.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 11 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 workerupgrade is the server-side bookkeeping of remote worker binary upgrades (design 2026-10-03-worker-remote-upgrade, U1): it stages the binary a worker will download (one file per worker id under <run>/upgrade/) and records the outcome of the latest upgrade per worker. It knows nothing about HTTP or the websocket hub; httpapi serves the files and the hub reports into it.

Index

Constants

View Source
const (
	StatePending    = "pending"
	StateSucceeded  = "succeeded"
	StateRolledBack = "rolled_back"
	StateFailed     = "failed"
)

Upgrade states. Pending is the only non-terminal one.

View Source
const MaxBinaryBytes int64 = 512 << 20

MaxBinaryBytes caps one staged upload (a gofer binary is a few tens of MB).

Variables

View Source
var ErrInProgress = errors.New("an upgrade is already in progress for this worker")

ErrInProgress means the worker already has a pending upgrade.

View Source
var ErrNotStaged = errors.New("no upgrade binary staged for this worker")

ErrNotStaged means no binary has been staged for the worker.

Functions

This section is empty.

Types

type Manager

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

Manager stages upgrade binaries and tracks upgrade records. The most recent ten records are kept in memory and mirrored to <dir>/<worker>.json so history survives a server restart. Safe for concurrent use.

func New

func New(dir string) *Manager

New builds a Manager rooted at dir (created lazily).

func (*Manager) Begin

func (m *Manager) Begin(id, upgradeID, fromVersion, targetVersion, targetSHA string, force bool, staleAfter time.Duration) (Record, error)

Begin records a new pending upgrade for worker id. It refuses while a previous attempt is still pending (a stale pending record older than staleAfter is superseded so a lost worker cannot block upgrades forever).

func (*Manager) Finish

func (m *Manager) Finish(id, upgradeID, state, errMsg, version string) (Record, bool)

Finish moves the pending upgrade upgradeID of worker id to a terminal state. A stale report (different upgrade id) is ignored; so is one for an upgrade that is already terminal, except that a successful registration wins over a failed or rolled-back verdict (the new process being online is the ground truth). A record that already succeeded is never re-finished.

func (*Manager) History

func (m *Manager) History(id string) ([]Record, bool)

History returns the newest upgrade records first, capped at ten entries.

func (*Manager) Latest

func (m *Manager) Latest(id string) (Record, bool)

Latest returns the most recent upgrade record of worker id.

func (*Manager) Open

func (m *Manager) Open(id string) (*os.File, Staged, error)

Open opens the staged binary for reading, with its digest.

func (*Manager) SetClock

func (m *Manager) SetClock(now func() time.Time)

SetClock replaces the time source (tests).

func (*Manager) SetTargetVersion

func (m *Manager) SetTargetVersion(id, upgradeID, version string)

SetTargetVersion records the version the worker reported for the staged binary.

func (*Manager) Stage

func (m *Manager) Stage(id string, r io.Reader, max int64) (Staged, error)

Stage stores the stream as worker id's upgrade binary (replacing any previous one) and returns its server-computed digest. At most max bytes are accepted.

func (*Manager) StageFile

func (m *Manager) StageFile(id, path string) (Staged, error)

StageFile stages a copy of the local file at path (the server's own executable).

func (*Manager) Staged

func (m *Manager) Staged(id string) (Staged, error)

Staged returns the staged binary of worker id, digesting the stored bytes.

type Record

type Record struct {
	WorkerID      string `json:"worker_id"`
	UpgradeID     string `json:"upgrade_id"`
	State         string `json:"state"`
	FromVersion   string `json:"from_version,omitempty"`
	TargetVersion string `json:"target_version,omitempty"`
	TargetSHA256  string `json:"target_sha256,omitempty"`
	Force         bool   `json:"force,omitempty"`
	Error         string `json:"error,omitempty"`
	StartedAt     int64  `json:"started_at"`
	FinishedAt    int64  `json:"finished_at,omitempty"`
	DurationMS    int64  `json:"duration_ms,omitempty"`
}

Record is one upgrade attempt of one worker. Times are unix milliseconds.

type Staged

type Staged struct {
	WorkerID string `json:"worker_id"`
	Path     string `json:"-"`
	SHA256   string `json:"sha256"`
	Size     int64  `json:"size"`
}

Staged describes the binary staged for one worker. SHA256 and Size are computed by the server from the stored bytes, never taken from the uploader.

Jump to

Keyboard shortcuts

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