Documentation
¶
Overview ¶
Package recovery rebuilds a cluster on a new server from its recovery storage (Phase 29c).
Index ¶
- Constants
- Variables
- func CheckStorage(ctx context.Context, c Candidate, recoveryKey, work string) error
- func CheckVersion(c Candidate, ours string) error
- func Inspect(ctx context.Context, c Candidate, recoveryKey, work string, ...) error
- func MoveToken(box *secrets.Box, m *Move) (string, error)
- func Sanitize(ctx context.Context, st *store.Store) error
- func SaveState(ctx context.Context, st *store.Store, s State) error
- type Apps
- type Candidate
- type DNS
- type Databases
- type Gate
- func (g *Gate) Active() bool
- func (g *Gate) BackupHeld(kind, id string) bool
- func (g *Gate) DatabaseHeld(id string) bool
- func (g *Gate) Drill() bool
- func (g *Gate) Held(kind string) bool
- func (g *Gate) ServiceHeld(_ context.Context, id string) (string, bool)
- func (g *Gate) State() State
- func (g *Gate) Update(ctx context.Context, change func(*State)) error
- type Git
- type Images
- type Item
- type Move
- type MoveSource
- type Node
- type NodeTracker
- type Options
- type Platform
- type Report
- type Runner
- type Service
- type SeveralClustersError
- type Source
- type State
- type Switch
Constants ¶
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.
const ( KindDatabase = "database" KindService = "service" KindGitServer = "gitserver" )
Item kinds the gate looks up.
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.
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.
const KindImage = "image"
More item kinds (see gate.go).
const SettingState = "recovery.state"
SettingState is where the recovery's progress is kept.
Variables ¶
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 ¶
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 ¶
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 Sanitize ¶
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).
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 ¶
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 ¶
FromBundle is the candidate of a backup file a person downloaded.
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 (*Gate) BackupHeld ¶
BackupHeld: an item is not backed up until its data is back, and never in a drill.
func (*Gate) DatabaseHeld ¶
DatabaseHeld: nothing is done with a database before its turn.
func (*Gate) ServiceHeld ¶
ServiceHeld reports whether a service must not be touched yet, and why.
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 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.
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 ¶
Retry starts an item again now, a database optionally up to an earlier moment.
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.
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.