Documentation
¶
Overview ¶
Package move hands a cluster over to a new server (Phase 29d). On the old controller it stops only the writes that live on this server, records where each of them stopped, backs the controller up and waits for the new server to verify its copy. Until the new server commits, a cancel gives everything back; from then on this controller is retired.
Index ¶
- Constants
- Variables
- type Apps
- type ChecksError
- type Client
- func (c Client) Backup(ctx context.Context) ([]byte, error)
- func (c Client) Commit(ctx context.Context) error
- func (c Client) Copy(ctx context.Context, address string) error
- func (c Client) Prepare(ctx context.Context, address string) error
- func (c Client) Report(ctx context.Context, step, problem string) error
- func (c Client) Status(ctx context.Context) (Status, error)
- type Cluster
- type Database
- type Databases
- type Facts
- type Final
- type Git
- type Mover
- func (m *Mover) Authorize(token, receiver string) (View, error)
- func (m *Mover) Cancel(ctx context.Context) error
- func (m *Mover) ChangesBlocked() (string, bool)
- func (m *Mover) Check(ctx context.Context) (Report, error)
- func (m *Mover) Commit(ctx context.Context, receiver string) error
- func (m *Mover) Copy(ctx context.Context, receiver, address string) error
- func (m *Mover) DatabaseHeld(id string) bool
- func (m *Mover) GitFrozen() bool
- func (m *Mover) Held(kind string) bool
- func (m *Mover) Positions(ctx context.Context) (map[string]string, error)
- func (m *Mover) Prepare(ctx context.Context, receiver, address string) error
- func (m *Mover) Report(ctx context.Context, receiver, step, problem string) error
- func (m *Mover) Resume(ctx context.Context)
- func (m *Mover) Retired() bool
- func (m *Mover) ServicePaused(id string) bool
- func (m *Mover) Start(ctx context.Context) (string, View, error)
- func (m *Mover) View() View
- func (m *Mover) Wait()
- type Record
- type Report
- type Service
- type Status
- type View
Constants ¶
const ( Waiting = "waiting" // for the new server Copying = "copying" // it copies the databases ahead; nothing is stopped Preparing = "preparing" // stopping writes Ready = "ready" // the new server restores and verifies Committed = "committed" // handed over Failed = "failed" Cancelled = "cancelled" )
States of a move.
const ( KindDatabase = "database" KindGit = "gitserver" )
Kinds of Final.
const SettingState = "cluster.move"
SettingState is where the move is kept. It travels in the controller's backup; a restored controller forgets it.
const TokenPrefix = "SYN-MOVE-"
TokenPrefix starts every move token.
Variables ¶
var ( ErrOpen = errors.New("a move is already open: cancel it first") ErrNotOpen = errors.New("the move is not open any more") ErrNoMove = errors.New("there is no move to cancel") ErrToken = errors.New("the move token is not valid") ErrExpired = errors.New("the move token has expired: start the move again") ErrOtherServer = errors.New("another server is already using this move token") ErrSwitched = errors.New("the cluster has already switched to the new server") ErrFailedOver = errors.New("a database failed over during the move: cancel it and start again") )
Functions ¶
This section is empty.
Types ¶
type Apps ¶
type Apps interface {
Services(ctx context.Context) ([]Service, error)
Running(ctx context.Context, id string) (int, error)
Enqueue(id string)
}
Apps are the services.
type ChecksError ¶
type ChecksError struct{ Problems []string }
ChecksError says why a move cannot start.
func (*ChecksError) Error ¶
func (e *ChecksError) Error() string
type Client ¶
type Client struct {
// URL is the old controller's dashboard.
URL, Token, Receiver string
// Pin is the old certificate's public key, while it is self-signed.
Pin string
AllowHTTP bool
}
Client is the new server's side of the handover.
type Cluster ¶
type Cluster interface {
Facts(ctx context.Context) (Facts, error)
// Backup writes a controller backup to the recovery storage.
Backup(ctx context.Context) error
// Retire runs once the cluster is handed over.
Retire(ctx context.Context)
}
Cluster is the controller itself.
type Database ¶
type Database struct {
ID, Name, Engine, EnvironmentID, Health string
Hosts []string
// Here: its primary is on this server. CanSwitch: a healthy replica
// elsewhere can take over. Cache: it keeps nothing on disk.
Here, CanSwitch, Cache bool
// BackedUp: backups are set up, which is how its data moves.
BackedUp bool
Primary int
}
Database is a database as a move sees it.
type Databases ¶
type Databases interface {
MoveList(ctx context.Context) ([]Database, error)
// SwitchAway makes a replica on another server the primary.
SwitchAway(ctx context.Context, id string) error
// Freeze stops a database taking writes and makes sure everything
// written is in the recovery storage.
Freeze(ctx context.Context, id string) (Final, error)
StopMembers(ctx context.Context, id string) error
// Release gives a frozen database back.
Release(ctx context.Context, id string) error
// Position is how far a database's writes got.
Position(ctx context.Context, id string) (string, error)
}
Databases are the managed databases.
type Facts ¶
type Facts struct {
// Standby is why this controller writes nothing outside ("" when it does).
Standby string
Recovering bool
// Offline nodes are not connected; Outdated ones cannot follow the
// controller to its new address.
Offline, Outdated []string
// AtRisk are the things that are not backed up, with the reason.
AtRisk []string
// Busy is work under way that a move would cut off.
Busy []string
Databases []Database
}
Facts are what a move checks before it starts, and again before it stops anything.
type Final ¶
type Final struct {
Kind string `json:"kind"`
ID string `json:"id,omitempty"`
Name string `json:"name"`
// LSN: PostgreSQL's last write position. Snapshot: Valkey's last
// snapshot. Dump: the Git server's last dump.
LSN string `json:"lsn,omitempty"`
Snapshot string `json:"snapshot,omitempty"`
Dump string `json:"dump,omitempty"`
}
Final is where moved data stopped. The new server must have all of it.
type Git ¶
type Git interface {
Enabled() bool
// Dump copies the frozen server into the recovery storage.
Dump(ctx context.Context) (string, error)
// Changed applies that it was frozen or thawed.
Changed()
}
Git is the built-in Git server.
type Mover ¶
type Mover struct {
Databases Databases
Apps Apps
Git Git
Cluster Cluster
// Uses reports whether a service uses a database.
Uses func(Database, Service) bool
// contains filtered or unexported fields
}
Mover runs the move on the old controller.
func (*Mover) Authorize ¶
Authorize checks a new server's token. It also answers for a move that has ended, so that the server hears of it.
func (*Mover) ChangesBlocked ¶
ChangesBlocked reports whether changes are refused, and why.
func (*Mover) Copy ¶
Copy binds the move to the new server, which copies the databases from the recovery storage before it asks for anything to stop.
func (*Mover) DatabaseHeld ¶
DatabaseHeld: a frozen database is left as it is.
func (*Mover) Held ¶
Held reports whether a kind of work waits for the move. Notifications go out throughout.
func (*Mover) Positions ¶
Positions are how far the writes of each database got that moves by way of the storage: what the new server's copies have to reach.
func (*Mover) Prepare ¶
Prepare binds the move to the new server and starts stopping writes; the steps run in the background. A server that copied ahead is told what stands in the way and asks again, rather than losing its copies.
func (*Mover) ServicePaused ¶
ServicePaused: a service that uses moved data runs no tasks.
type Record ¶
type Record struct {
ID string `json:"id,omitempty"`
State string `json:"state,omitempty"`
TokenHash string `json:"tokenHash,omitempty"`
CreatedAt time.Time `json:"createdAt,omitzero"`
ExpiresAt time.Time `json:"expiresAt,omitzero"`
// Receiver is the server the token is bound to; Address is where it is.
Receiver string `json:"receiver,omitempty"`
Address string `json:"address,omitempty"`
Step string `json:"step,omitempty"`
Problem string `json:"problem,omitempty"`
// What the new server reports about itself.
NewStep string `json:"newStep,omitempty"`
NewProblem string `json:"newProblem,omitempty"`
// Paused services, held databases and the frozen Git server.
Paused []string `json:"paused,omitempty"`
Databases []string `json:"databases,omitempty"`
GitFrozen bool `json:"gitFrozen,omitempty"`
Finals []Final `json:"finals,omitempty"`
// Primaries are the databases' primaries when the backup was made.
Primaries map[string]int `json:"primaries,omitempty"`
}
Record is a move and how far it got.