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
- Variables
- type Manager
- func (m *Manager) Begin(id, upgradeID, fromVersion, targetVersion, targetSHA string, force bool, ...) (Record, error)
- func (m *Manager) Finish(id, upgradeID, state, errMsg, version string) (Record, bool)
- func (m *Manager) History(id string) ([]Record, bool)
- func (m *Manager) Latest(id string) (Record, bool)
- func (m *Manager) Open(id string) (*os.File, Staged, error)
- func (m *Manager) SetClock(now func() time.Time)
- func (m *Manager) SetTargetVersion(id, upgradeID, version string)
- func (m *Manager) Stage(id string, r io.Reader, max int64) (Staged, error)
- func (m *Manager) StageFile(id, path string) (Staged, error)
- func (m *Manager) Staged(id string) (Staged, error)
- type Record
- type Staged
Constants ¶
const ( StatePending = "pending" StateSucceeded = "succeeded" StateRolledBack = "rolled_back" StateFailed = "failed" )
Upgrade states. Pending is the only non-terminal one.
const MaxBinaryBytes int64 = 512 << 20
MaxBinaryBytes caps one staged upload (a gofer binary is a few tens of MB).
Variables ¶
var ErrInProgress = errors.New("an upgrade is already in progress for this worker")
ErrInProgress means the worker already has a pending upgrade.
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 (*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 ¶
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) SetTargetVersion ¶
SetTargetVersion records the version the worker reported for the staged binary.
func (*Manager) Stage ¶
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.
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.