recovery

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 26 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 recovery rebuilds a cluster on a new server from its recovery storage (Phase 29c).

Index

Constants

View Source
const (
	HoldJobs       = "jobs"
	HoldAutoscale  = "autoscale"
	HoldRebalance  = "rebalance"
	HoldImageWatch = "imagewatch" // new images and commits deploy nothing
	HoldPools      = "pools"
	HoldRegMaint   = "regmaint"
	HoldProtect    = "protect"
	HoldPrune      = "prune" // nothing old is removed from the storage
	HoldNotify     = "notify"
	HoldCleanup    = "cleanup" // containers and volumes nobody here knows stay
	HoldBuilds     = "builds"  // held in a drill only: recovery rebuilds images
)

What the gate can hold.

View Source
const (
	KindDatabase  = "database"
	KindService   = "service"
	KindGitServer = "gitserver"
)

Item kinds the gate looks up.

View Source
const (
	PhaseClaim     = "claim"
	PhaseAddress   = "address"
	PhasePlatform  = "platform"
	PhaseDatabases = "databases"
	PhaseFiles     = "files"
	PhaseImages    = "images"
	PhaseServices  = "services"
	PhaseDNS       = "dns"
	PhaseDone      = "done"
)

Phases. Databases, files, images and services overlap: the phase shown is the first of them still open.

View Source
const (
	ItemWaiting    = "waiting"
	ItemRecovering = "recovering"
	ItemVerifying  = "verifying"
	ItemDone       = "done"
	ItemFailed     = "failed"
	// ItemLost: the storage holds nothing to bring it back from.
	ItemLost = "lost"
)

Item states.

View Source
const KindImage = "image"

More item kinds (see gate.go).

View Source
const SettingState = "recovery.state"

SettingState is where the recovery's progress is kept.

Variables

View Source
var (
	// ErrNoBackups: the storage holds no controller backup.
	ErrNoBackups = errors.New("no SynCloud backups found in the bucket")
	// ErrWrongKey: the key opens none of the newest backups.
	ErrWrongKey = errors.New("the recovery key does not open the newest backup in the storage")
)

Functions

func CheckStorage

func CheckStorage(ctx context.Context, c Candidate, recoveryKey, work string) error

CheckStorage reports whether this server can read the recovery storage a backup names. work is a folder for a temporary copy, removed again.

func CheckVersion

func CheckVersion(c Candidate, ours string) error

CheckVersion refuses a backup made by a newer release than this one.

func Inspect

func Inspect(ctx context.Context, c Candidate, recoveryKey, work string, look func(st *store.Store, box *secrets.Box, dir string) error) error

Inspect reads a backup without restoring it: it is opened in a folder under work (dir), removed again once look returns.

func MoveToken

func MoveToken(box *secrets.Box, m *Move) (string, error)

MoveToken reads a move's token.

func Sanitize

func Sanitize(ctx context.Context, st *store.Store) error

Sanitize makes a restored controller forget what is no longer safe to act on, since the backup is older than the cluster was: a move of the controller it was made on (it would think itself left), removals of database volumes (the volume may hold newer data by now; the containers are still stopped) and cloud servers it was waiting for (they may have joined since, and would be deleted).

func SaveState

func SaveState(ctx context.Context, st *store.Store, s State) error

SaveState stores it.

Types

type Apps

type Apps interface {
	Services(ctx context.Context) ([]Service, error)
	Serving(ctx context.Context, id string) bool
	Enqueue(id string)
}

Apps are the services.

type Candidate

type Candidate struct {
	// Bucket and Prefix are the folder it is in (empty for a file); Object
	// its name.
	Bucket, Prefix, Object string
	File                   bool
	CreatedAt              time.Time
	Meta                   backup.Meta
	Bundle                 []byte
	// Owner is the controller that owns the folder, when it says.
	Owner *backup.Owner
}

Candidate is the backup a recovery would start from.

func Find

func Find(ctx context.Context, src Source, recoveryKey string) (Candidate, error)

Find picks the newest backup the recovery key opens. Only the newest of each folder counts: an older one is never used without saying so.

func FromBundle

func FromBundle(bundle []byte, name, recoveryKey string) (Candidate, error)

FromBundle is the candidate of a backup file a person downloaded.

func (Candidate) Where

func (c Candidate) Where() string

Where is the folder or file the backup is from.

type DNS

type DNS interface {
	Repoint(ctx context.Context, from, to string) (changed, manual []string, err error)
}

DNS repoints the provider records that held the old address.

type Databases

type Databases interface {
	RecoveryList(ctx context.Context) ([]dbs.RecoveryDatabase, error)
	PlanRecovery(ctx context.Context, id string, nodes dbs.NodeReport) (dbs.Plan, error)
	UseSurvivor(ctx context.Context, id string, ordinal int) error
	StartRebuild(ctx context.Context, id string, since time.Time, target *time.Time) error
	KeepData(ctx context.Context, id string) error
	RebuildValkey(ctx context.Context, id string, since time.Time) error
	Rebuilt(ctx context.Context, id string, since time.Time) (healthy, backedUp bool, recoveredTo *time.Time, err error)
	BackupNow(ctx context.Context, id string) error
	ResetLostEtcd(ctx context.Context, nodes dbs.NodeReport, since time.Time) (bool, error)
	Reached(ctx context.Context, id string, p dbs.Position) error
	AdoptCopy(ctx context.Context, id string, since time.Time, lsn string) error
}

Databases are the managed databases.

type Gate

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

Gate says what is held. A nil gate holds nothing. It is the only writer of the recovery state while the controller runs.

func NewGate

func NewGate(ctx context.Context, st *store.Store) (*Gate, error)

NewGate reads the recovery state.

func (*Gate) Active

func (g *Gate) Active() bool

Active reports whether a recovery is running.

func (*Gate) BackupHeld

func (g *Gate) BackupHeld(kind, id string) bool

BackupHeld: an item is not backed up until its data is back, and never in a drill.

func (*Gate) DatabaseHeld

func (g *Gate) DatabaseHeld(id string) bool

DatabaseHeld: nothing is done with a database before its turn.

func (*Gate) Drill

func (g *Gate) Drill() bool

Drill reports whether it is a rehearsal.

func (*Gate) Held

func (g *Gate) Held(kind string) bool

Held reports whether a kind of work waits for the recovery.

func (*Gate) ServiceHeld

func (g *Gate) ServiceHeld(_ context.Context, id string) (string, bool)

ServiceHeld reports whether a service must not be touched yet, and why.

func (*Gate) State

func (g *Gate) State() State

State is a copy of the recovery's progress.

func (*Gate) Update

func (g *Gate) Update(ctx context.Context, change func(*State)) error

Update changes the state and saves it.

type Git

type Git interface {
	Enabled() bool
	Answers() bool
	// RestoreDump loads a dump, the newest when name is "".
	RestoreDump(ctx context.Context, name string) error
	Dump(ctx context.Context) error
}

Git is the built-in Git server.

type Images

type Images interface {
	// Present reports whether a service's image can be pulled.
	Present(ctx context.Context, serviceID string) (bool, error)
	// Rebuild builds it again; false when it was not built here.
	Rebuild(ctx context.Context, serviceID string) (bool, error)
}

Images are the images services run.

type Item

type Item struct {
	Kind        string     `json:"kind"`
	ID          string     `json:"id,omitempty"`
	Name        string     `json:"name"`
	State       string     `json:"state"`
	Detail      string     `json:"detail,omitempty"`
	Attempts    int        `json:"attempts,omitempty"`
	RetryAt     *time.Time `json:"retryAt,omitempty"`
	RecoveredTo *time.Time `json:"recoveredTo,omitempty"`
	TargetTime  *time.Time `json:"targetTime,omitempty"`
	// Action and Since are the runner's notes: how the item is brought back,
	// and since when.
	Action string `json:"action,omitempty"`
	// Note is kept with the outcome: what the person should know about it.
	Note  string     `json:"note,omitempty"`
	Since *time.Time `json:"since,omitempty"`
}

Item is one thing being recovered.

type Move

type Move struct {
	// From is the old controller; Pin its certificate's key while it is
	// self-signed.
	From string `json:"from"`
	Pin  string `json:"pin,omitempty"`
	// Token is the move token, sealed with the master key. Receiver is what
	// this server is to the old one.
	Token    string `json:"token,omitempty"`
	Receiver string `json:"receiver"`
	// AllowHTTP: the old controller is reached without TLS (a private
	// network, asked for with SYNCLOUD_MOVE_ALLOW_HTTP).
	AllowHTTP bool         `json:"allowHttp,omitempty"`
	Finals    []move.Final `json:"finals,omitempty"`
	// Copied are the databases whose data was copied here ahead of the
	// switch, and how far each copy got.
	Copied map[string]string `json:"copied,omitempty"`
	// SwitchedAt: the old controller handed the cluster over.
	SwitchedAt *time.Time `json:"switchedAt,omitempty"`
	// Cancelled: the move was cancelled there; nothing more is done here.
	Cancelled bool `json:"cancelled,omitempty"`
}

Move is the planned move a recovery carries out.

type MoveSource

type MoveSource struct {
	From, Pin, Token, Receiver string
	AllowHTTP                  bool
	// Copied are the finished copies on this server (Phase 29e).
	Copied map[string]string
}

MoveSource is the controller being moved away from.

type Node

type Node struct{ ID, Name string }

Node is a server.

type NodeTracker

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

NodeTracker remembers which data volumes each node said it holds.

func (*NodeTracker) Hooks

func (t *NodeTracker) Hooks() agentgw.Hooks

Hooks follow the agents' connections.

func (*NodeTracker) Report

func (t *NodeTracker) Report(all []nodes.View) dbs.NodeReport

Report is what the nodes say now.

type Options

type Options struct {
	DataDir string
	// EnvFile is the controller's settings file, written from the backup's.
	EnvFile string
	// Source is the storage as given; empty when recovering from a file, whose
	// own settings then apply.
	Source   Source
	PublicIP string
	Drill    bool
	// Version is this release.
	Version string
	// Rejoin writes the token the local agent joins again with.
	Rejoin func(dataDir string) error
	// Move: the backup comes from a controller that is being left (Phase
	// 29d). The recovery starts as a drill, until it is verified.
	Move *MoveSource
}

Options say how this server is set up for the recovery.

type Platform

type Platform interface {
	// Claim returns nil once this controller owns the recovery storage.
	Claim(ctx context.Context) error
	// Publish tells the workers where the controller is now.
	Publish(ctx context.Context) error
	// Ready returns nil once the platform's own parts answer.
	Ready(ctx context.Context) error
}

Platform is what everything else needs first.

type Report

type Report struct {
	// Resumed: an earlier run of this recovery had already restored.
	Resumed bool
	Files   int
}

Report is what Prepare did.

func Prepare

func Prepare(ctx context.Context, c Candidate, recoveryKey string, o Options) (Report, error)

Prepare restores a backup into the data directory and sets it up to recover: nothing is left behind when it fails. Running it again resumes.

type Runner

type Runner struct {
	Gate      *Gate
	Platform  Platform
	Databases Databases
	Apps      Apps
	Images    Images
	Git       Git
	DNS       DNS
	// Nodes reports the connected nodes and their volumes.
	Nodes func(ctx context.Context) dbs.NodeReport
	// NodeWait is how long a node that may hold data is waited for.
	NodeWait time.Duration
	// Finished runs once when everything is back.
	Finished func(ctx context.Context)
	// Switch is set for a planned move; Switched runs once the cluster is
	// this controller's.
	Switch   Switch
	Switched func(ctx context.Context)
	Log      *slog.Logger
	// contains filtered or unexported fields
}

Runner runs a recovery.

func (*Runner) Retry

func (r *Runner) Retry(ctx context.Context, id string, target *time.Time) error

Retry starts an item again now, a database optionally up to an earlier moment.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context)

Run steps the recovery until it is finished or ctx ends.

func (*Runner) Tick

func (r *Runner) Tick(ctx context.Context)

Tick makes whatever progress can be made now.

func (*Runner) View

func (r *Runner) View() State

View is the recovery's progress.

type Service

type Service struct {
	ID, Name, EnvironmentID string
	Desired                 int
	// Env are the plain values of its variables (to find database names).
	Env []string
	// Nodes run its tasks.
	Nodes []Node
}

Service is a service as the recovery sees it.

type SeveralClustersError

type SeveralClustersError struct{ Prefixes []string }

SeveralClustersError: the key opens the backups of more than one cluster.

func (*SeveralClustersError) Error

func (e *SeveralClustersError) Error() string

type Source

type Source struct {
	URL, Region, AccessKeyID, SecretAccessKey string
	PathStyle                                 bool
	Bucket, Prefix                            string
}

Source is the recovery storage as a person gives it. Prefix is only needed when the bucket holds more than one cluster.

type State

type State struct {
	ID string `json:"id"`
	// Active until everything is recovered; a drill stays active.
	Active     bool       `json:"active"`
	Drill      bool       `json:"drill,omitempty"`
	StartedAt  time.Time  `json:"startedAt"`
	FinishedAt *time.Time `json:"finishedAt,omitempty"`
	// Source is the folder or file recovered from.
	Source     string    `json:"source"`
	OldAddress string    `json:"oldAddress,omitempty"`
	NewAddress string    `json:"newAddress,omitempty"`
	BackupAt   time.Time `json:"backupAt"` // when the restored backup was made
	Phase      string    `json:"phase"`
	// OldIP and NewIP are the controller's public addresses.
	OldIP       string    `json:"oldIp,omitempty"`
	NewIP       string    `json:"newIp,omitempty"`
	AddressedAt time.Time `json:"addressedAt,omitzero"` // when the new address was published
	// Problem is what stops the recovery as a whole, if anything.
	Problem string `json:"problem,omitempty"`
	// DNSDone, the records moved, and what a person has to change by hand.
	DNSDone    bool       `json:"dnsDone,omitempty"`
	DNSTries   int        `json:"dnsTries,omitempty"`
	DNSRetryAt *time.Time `json:"dnsRetryAt,omitempty"`
	DNSChanged []string   `json:"dnsChanged,omitempty"`
	Manual     []string   `json:"manual,omitempty"`
	Items      []Item     `json:"items,omitempty"`
	// Move: this server is taking over from a controller that is still there
	// (Phase 29d). It is a drill until what moved is verified.
	Move *Move `json:"move,omitempty"`
}

State is a recovery and how far it got. It survives restarts.

func Existing

func Existing(ctx context.Context, dataDir string) (State, bool)

Existing is the recovery a data directory already holds, if any.

func LoadState

func LoadState(ctx context.Context, st *store.Store) (State, bool, error)

LoadState reads the recovery state; ok is false when there never was one.

type Switch

type Switch interface {
	// Status is the move's state there.
	Status(ctx context.Context) (string, error)
	// Commit has the old controller hand the cluster over.
	Commit(ctx context.Context) error
	// TakeOver lets this controller claim the recovery storage.
	TakeOver() error
	Report(ctx context.Context, step, problem string) error
}

Switch is the old controller of a planned move, as this one sees it.

Jump to

Keyboard shortcuts

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