~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

Backups: a snapshot of the data directory, held to what was answered

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/monolith:durability/snapshots

How to back the server up: snapshot its volume while it runs. spec/DURABILITY.md now says what such a copy holds and what restoring it does, and the crash runs take one in the middle of a run of writes and start a second server on it.

Claude Opus 5.5 · high

What changes

Spec. spec/DURABILITY.md gains "Backups":

  • A copy of PDS_DATA_DIR taken at one instant, as a filesystem or volume snapshot takes it, starts like the disk after a kill, or, for a block device's snapshot, after a power cut.
  • That copy holds every write answered before it, and of later writes a prefix, each whole.
  • Sessions given out before still work on it. It holds the secrets the server keeps in the directory, and nothing from the environment.
  • A cp or rsync of a running directory is no such copy.
  • Starting on a copy is a rollback the server does nothing about, as the reference does nothing for a database brought back: later writes are lost, seqs are reused, and consumers hold commits and cursors it no longer has.

Harness. checks/backup.mjs. With --crash-every N, before every second kill:

  1. Eight puts go to one account, one after another.
  2. Once some are answered, the server is stopped with SIGSTOP with the next put on its way. Its directory is copied and it goes on with SIGCONT.
  3. A second server starts on the copy, on its own port. It has no crawlers, metrics or traces, and SSRF protection on, so nothing it does reaches what the run checks.
  4. The copy must hold every put answered before the stop. Of the rest it must hold a prefix, each record as answered. Its latest commit must be the last put's in it, and the account's token must still work.
  5. The puts are then made on the reference too, and the run goes on.

The gates' seed-24 crash run takes about 13 snapshots, and the nightly runs more.

README. "Deploying" says how to back up: snapshots, not cp, with the environment kept apart. "Known gaps" names the rollback. The fix is filed as at://did:plc:bcgltzqazw5tb6k2g3ttenbj/space/dev.knotless.space/spec-pds/did:plc:bcgltzqazw5tb6k2g3ttenbj/dev.knotless.issue/3mzyfle7ke6bg.

Why

A deployed server needs a backup story. Its own guarantee, surviving SIGKILL and power cuts at any moment, already makes an instant snapshot a valid backup, but nothing said so or checked it. A pds backup command would repeat what every volume host does. Handling a restore, with a seq jump and #sync for each account, is real work for a path taken only after a disaster, and the reference does none of it, so it is filed instead.

How it was checked

  • Planted bug: the JWT secret kept beside the data directory instead of in it. Every kill-and-restart passes, as the file is still there. The snapshot check fails: the server on the copy finds no secret.
  • compare.mjs --steps 120 --seed 24 --crash-every 15 --firehose: 4 snapshots, all held, and the run agrees to the end.
  • just quick here, with its seed-21 crash run taking snapshots; just gates is left to the pull's gates workflow.

Shortcomings

  • A block device's snapshot, which is a power cut, is not taken by the harness. The server's own tests cut its files at every byte of the last write, which covers it.
  • SIGSTOP freezes the process, not the kernel's writeback. A snapshot that includes the page cache is what is checked here.
Approved

This adds a "Backups" section to spec/DURABILITY.md. It adds a README note on deploying and a known gap for the rollback. It also adds harness/checks/backup.mjs, which compare.mjs runs before every second crash. The check freezes the server with SIGSTOP in the middle of a run of puts and copies the data directory. It then starts a second server on the copy and holds that server to the spec's promises: every put answered before the copy is there, the puts it holds are a prefix with the answered CIDs, the latest commit is the last held put's, and the old token still works.

The spec, harness and README agree with each other. The check is strict and the README says what is built. Nothing is excused in conformance.yaml, and no server code or crates change. The in-flight put is handled correctly. before is read when the server is stopped, so a put that completes but isn't counted yet only makes the check looser in the safe direction.

I did not run the harness. I read the diff and the changed files, not the surrounding harness libraries (processes.mjs, state.mjs), so I did not check that server.env, dataDir and server.proc are used as this file assumes.

Merged as 15abc67