move

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 18 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 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

View Source
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.

View Source
const (
	KindDatabase = "database"
	KindGit      = "gitserver"
)

Kinds of Final.

View Source
const SettingState = "cluster.move"

SettingState is where the move is kept. It travels in the controller's backup; a restored controller forgets it.

View Source
const TokenPrefix = "SYN-MOVE-"

TokenPrefix starts every move token.

Variables

View Source
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.

func (Client) Backup

func (c Client) Backup(ctx context.Context) ([]byte, error)

Backup downloads an encrypted controller backup, made now.

func (Client) Commit

func (c Client) Commit(ctx context.Context) error

Commit takes the cluster over.

func (Client) Copy

func (c Client) Copy(ctx context.Context, address string) error

Copy has the old controller wait while this server copies the databases.

func (Client) Prepare

func (c Client) Prepare(ctx context.Context, address string) error

Prepare asks the old controller to stop writes and back up.

func (Client) Report

func (c Client) Report(ctx context.Context, step, problem string) error

Report tells the old controller what this server is doing.

func (Client) Status

func (c Client) Status(ctx context.Context) (Status, error)

Status asks how far the move got.

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 New

func New(ctx context.Context, st *store.Store, log *slog.Logger) (*Mover, error)

New reads the move kept in the store. Resume must run once the dependencies are set.

func (*Mover) Authorize

func (m *Mover) Authorize(token, receiver string) (View, error)

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) Cancel

func (m *Mover) Cancel(ctx context.Context) error

Cancel ends the move and the cluster carries on here.

func (*Mover) ChangesBlocked

func (m *Mover) ChangesBlocked() (string, bool)

ChangesBlocked reports whether changes are refused, and why.

func (*Mover) Check

func (m *Mover) Check(ctx context.Context) (Report, error)

Check says what stands in the way of a move now.

func (*Mover) Commit

func (m *Mover) Commit(ctx context.Context, receiver string) error

Commit hands the cluster over to the new server, which has verified it.

func (*Mover) Copy

func (m *Mover) Copy(ctx context.Context, receiver, address string) error

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

func (m *Mover) DatabaseHeld(id string) bool

DatabaseHeld: a frozen database is left as it is.

func (*Mover) GitFrozen

func (m *Mover) GitFrozen() bool

GitFrozen reports whether the Git server takes no writes.

func (*Mover) Held

func (m *Mover) Held(kind string) bool

Held reports whether a kind of work waits for the move. Notifications go out throughout.

func (*Mover) Positions

func (m *Mover) Positions(ctx context.Context) (map[string]string, error)

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

func (m *Mover) Prepare(ctx context.Context, receiver, address string) error

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) Report

func (m *Mover) Report(ctx context.Context, receiver, step, problem string) error

Report keeps what the new server says about its work, for the person.

func (*Mover) Resume

func (m *Mover) Resume(ctx context.Context)

Resume deals with a move the controller was stopped in the middle of.

func (*Mover) Retired

func (m *Mover) Retired() bool

Retired reports whether the cluster was handed over.

func (*Mover) ServicePaused

func (m *Mover) ServicePaused(id string) bool

ServicePaused: a service that uses moved data runs no tasks.

func (*Mover) Start

func (m *Mover) Start(ctx context.Context) (string, View, error)

Start opens a move and returns its token, which is not kept.

func (*Mover) View

func (m *Mover) View() View

View is the move as it stands.

func (*Mover) Wait

func (m *Mover) Wait()

Wait returns when no background work of the move runs.

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.

func (Record) Open

func (r Record) Open() bool

Open reports whether the move still goes on.

type Report

type Report struct {
	Problems []string `json:"problems"`
	Warnings []string `json:"warnings"`
}

Report is what stands in the way, and what a person should know.

func Evaluate

func Evaluate(f Facts) Report

Evaluate judges whether a move can start.

type Service

type Service struct {
	ID, Name, EnvironmentID string
	Desired                 int
	Env                     []string
}

Service is a service as a move sees it.

type Status

type Status struct {
	Move    View   `json:"move"`
	Version string `json:"version"`
	// Positions are how far the writes of the databases to copy got, while
	// the move is copying.
	Positions map[string]string `json:"positions,omitempty"`
}

Status is how far the old controller got.

type View

type View = Record

View is a record without the token's hash.

Jump to

Keyboard shortcuts

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