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

pds migrate-blobs moves blobs between the data directory and a bucket

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/monolith:migrate-blobs

pds migrate-blobs --to bucket|disk moves a data directory's blobs into an S3 bucket or back out, with the server stopped. It is safe to kill at any point, and re-running finishes the move or reverses it. pds serve refuses a directory mid-move, and the data directory is now held by one process at a time. The reference has no such command; its operators copy files by hand.

Claude Opus 5.5 · high

What changes

spec/.

  • BLOBS.md gains "Moving them":
    • Order of steps: the environment and usage checks, the refusal of a held directory, and a no-op when the blobs are already in place. Then a durable "moving" mark, during which pds serve refuses the directory and names the command to run.
    • Copy: every blob held is copied, each checked against its CID. A missing or wrong one stops the move with its DID and CID.
    • Finish: the switch, deleting the old copies (and objects still owed), then {"moved":N,"bytes":B}.
    • Interruptions: run again with the same --to to finish, or the other --to to move back.
    • The section also says how --migrate checks it.
  • COMMANDS.md lists the command, and says pds serve and pds migrate-blobs each hold the data directory while they run. A second process exits 1 before writing anything.

harness/. checks/migrate.mjs, the --migrate run, goes in the gates' compare suite:

  • Steps: blob steps compared with the reference, on disk, then in the bucket, then on disk again.
  • Refusals: pds serve and migrate-blobs must refuse to start beside a running server, usage errors exit 2, and a move to where the blobs already are does nothing.
  • Kills: each move is killed at random within 600 ms of its first store request, the store answering 100 ms late, then run again. The first kill checks that pds serve refuses the directory, then turns the move back and serves from disk before going on.
  • Object gone: a move out of the bucket with one object deleted must exit 1 naming it.
  • After each move: every blob read as the reference's, then the bucket and data directory checked as --s3 checks them.

crates/.

  • pds-server/src/migrate_blobs.rs: mark, copy (16 at a time, verified), switch, clean up, finish.
  • blobstore.rs: the blobstore-moving mark, and pds serve refusing it.
  • store::hold: a flock on <data dir>/lock, taken by both commands before anything else.
  • The account log gains blobObjectsDeleted for a move out of the bucket.
  • pds/src/main.rs dispatches the command.

Why

Without it, a data directory could never change where its blobs are kept. The reference's way is a manual copy and a restart, and it starts on a half-copied bucket without complaint, serving 500 for every blob missed. This command checks every blob before switching, and the lock closes an older gap: two pds serve processes could share one data directory.

How it was checked

  • --migrate failed against the server before this change: a second pds serve started beside a running one.
  • Bugs planted, each seen failing, then put back:
    • a move to disk that leaves objects behind ("the bucket, moved back to disk… differs");
    • pds serve starting on a directory mid-move ("pds serve on a data directory whose blobs are moving differs").
  • Here: --migrate at seeds 71 and 3 (killed mid-move up to 3 times, turned back), --steps 400 --seed 61 --crash-every 25 --s3 and --steps 600 --seed 51 --crash-every 40 --store all agree.
  • The implementing agent also ran --steps 400 --seed 24 --crash-every 15 --firehose and --upgrade, with cargo test -p pds-server (335 tests) and clippy clean. fmt is clean.

Shortcomings

  • Offline only: the server is down for as long as the copy takes.
  • A blob missing at its source stops the move, with no way to skip it. The operator must restore it, or move back.
  • The command needs the bucket's variables in both directions. Without them it exits 1, a choice the spec leaves open.
Approved

This adds pds migrate-blobs --to bucket|disk. It also adds a flock on <data dir>/lock, held by both pds serve and pds migrate-blobs, and a --migrate harness run in the compare gates. I read all 14 changed files and found nothing that must change.

  • Spec: BLOBS.md "Moving them" and COMMANDS.md describe what the code does. That covers the order of steps, the refusals, the {"moved":N,"bytes":B} line, and resuming with the same or the other --to. The README says what is built, not how. The new account-log entry and the marks are internal formats, and the spec doesn't list those for the existing marks or entries either.
  • Server: the resume cases hold up from the code: killed before the switch, killed after it, then the same --to or the other one. The blobstore-moving mark is written first and removed last, and check_dir refuses a directory that has it, including when a power cut lost the mark's bytes. A blob that is missing or doesn't match its CID is collected and named with its DID and CID, and the move stops. The unit tests cover these paths. I found no atproto or MCP crates added and no sign of reference or SDK source being used.
  • Harness: the checks are strict and compare against the reference. They are refusals beside a live server, usage errors exiting 2, kills at random moments, an object gone, and every blob read as the reference's after each move. I found nothing loosened, and no conformance.yaml change.

Two small points in harness/checks/migrate.mjs, neither blocking:

  • A run that draws no kill on its first attempts skips the first-kill checks without saying so. Those are the serveRefused check and the turn-back.
  • stoppedByObjectGone returns silently when no account holds a blob.

Both depend on the seed. Failing loudly would be stricter, but the pinned seed 71 in the gates already exercises them.

harness/checks/migrate.mjsline 112
killed += 1
// Unfinished, the data directory is not served, whichever way.
if (killed === 1) await serveRefused(pick(['bucket', 'disk']), 'on a data directory whose blobs are moving')
if (back && killed === 1) {
review.knotless.dev

The turn-back (back) and the first-kill serveRefused run only if the first attempt is killed. A run whose first attempt isn't killed (a 20% draw, or the move finishing before the kill) passes without checking either, and nothing says so. Counting those checks as ran or skipped, or failing when back was asked for and never ran, would keep a lucky seed from skipping them.

Merged as ec9b399