Capture and restore Geo pairs and Praefect rigs as a unit

What this changes

A Geo pair snapshotted member by member, minutes apart, restored diverged: the secondary was ahead of the restored primary and replication never resumed. The only health check, pg_is_in_recovery, read t throughout. A Praefect rig has the same shape across Rails, the Praefect database and the repositories on node B.

Closes the issue filed alongside this MR; link it by full path when posting.

Item Change Test, red on origin/main and green here
geo snapshot Gates on streaming, stops GitLab on the secondary, snapshots it, then snapshots the running primary. A trap starts the secondary again on any exit. stop, snapshot, start order; secondary restarted when the primary's snapshot fails
geo restore Restores the primary and waits until it serves, then the secondary. Passes the streaming gate, then creates a project and waits up to 120 s for it on the secondary. primary restored before the secondary
Per-instance refusal snapshot and restore refuse a member named in a geo*.json or praefect-*.json state file and name the rig verb. A two-plane member still works. Geo member, praefect member, two-plane member
geo verify Runs the streaming gate. slot active=f fails the gate
snapshot_at Records the start of the snapshot, not its finish. read before the create call
praefect snapshot and restore Stops Rails and Praefect on node A, snapshots both nodes, restarts in a trap. Restore brings node B back, then node A, and waits for the database, node B and Rails before praefect verify. order; node A restarted on failure

The streaming gate is two facts: the primary's slot for the secondary is active, and the secondary's pg_stat_wal_receiver reports streaming.

Deletion and release stay record-keyed and owner-filtered. No deletion by name is added.

Order

With the secondary stopped, its slot is frozen at or below the position of its snapshot, and the primary, still running, has flushed at least that far. Restoring the primary first, with the secondary down, then the secondary, returns them to a state the slot can resume from.

sequenceDiagram
    participant O as Operator
    participant S as Secondary
    participant P as Primary
    O->>P: slot active, secondary receiver streaming
    O->>S: stop GitLab and its database
    O->>S: snapshot disk
    O->>P: snapshot disk, primary still running
    O->>S: start GitLab (trap restarts it on any exit)
    Note over S,P: Secondary position is at or behind the primary snapshot
    O->>P: restore, wait until it serves
    O->>S: restore, wait until it serves
    O->>P: streaming gate: slot active, receiver streaming
    O->>P: create a project
    P-->>S: project appears within 120 s

Found while proving it

  • replicate-geo-database ends with its own gitlab-ctl start, which exits 1 when gitlab-kas misses runit's start window although kas is up seconds later. geo up stopped there twice on a fresh pair. It now continues when that is the only failure; the standby assertion that follows still decides.
  • A member recreated from a snapshot gets new host keys, and the rig's raw SSH path kept the old pin and refused it. recreate_vm now drops the instance's pinned key, as create_vm does.
  • A restore hint named just lab restore --instance <member>, which now refuses. Hints name the rig verb for a member.
  • Restored Praefect nodes serve their Gitaly socket before PostgreSQL has finished recovery, so the restore waits on the database, node B and Rails.

Failure paths

  • geo snapshot and praefect snapshot record that they hold the node before they stop it. A stop that half ran and then failed (a service survived, ssh dropped, Ctrl-C) left the EXIT trap nothing to release, and the node stayed stopped. Starting a node that is already running is harmless.
  • Under a pair verb, a member's snapshot keeps its previous one. The pair verb deletes the replaced snapshots only once its own state names both new ones; a failed delete logs and continues.
  • When a pair snapshot fails, or is killed before the pair state names the new snapshots, each member that captured goes back to its saved record (id, time, size, seconds) and its new snapshot is deleted, so the old pair stays restorable. The pair state writes its three snapshot fields in one update.
  • Tests in the "captured and restored as a unit" block cover each path: a surviving service is followed by a start, a second-member failure or a kill leaves the old pair restorable, and success deletes the replaced snapshots.

Live proof

Geo pair, SIM_OWNER=fix-geosnap, c2d-standard-8 pair in us-central1-a:

  • Before the snapshot: slot sim_gs_s active=t, receiver status=streaming.
  • geo snapshot took the secondary (94 s) then the primary (125 s) and recorded the start, 2026-11-20T08:20:00Z. GitLab on the secondary was started again and the gate passed.
  • geo down --keep-snapshot, then geo restore: primary serving first, secondary recreated second, streaming again, and the new project was visible on the secondary within 0 s of the poll starting.
  • geo verify passed the streaming gate and ran to the end. geo down removed both members and their snapshots.
  • us-central1-a returned stockouts for c2d-standard-8 during the restore. The restore resumes from the failed start, so a retry did not repeat finished work.

Praefect rig, sim-gs-pf and sim-gs-pf-gitaly: up, verify, praefect snapshot, praefect down --keep-snapshot, restore --instance refused with the rig verb named, praefect restore, praefect verify ("All checks passed"), praefect down.

Teardown: no VM, disk, snapshot, address or firewall rule named sim-gs, no sim-rig-* service account, project ssh-keys entries unchanged at [4].

Checks

word-budget 40488 against 40489, vale-check, lint, ruby-check, provider-gate and commit-trailers pass. The permission manifest is unchanged: no provider verb was added.

Closes #62 (closed)

Merge request reports

Loading
Loading