Repository navigation
fix(move): make --force re-validate before wiping and cover definitive unresumable checkpoints - #1038
Conversation
…e unresumable checkpoints --force's wipe-and-restart recovery had two holes: 1. It wiped the target FIRST and re-ran the post-setup checks AFTER. RunChecks iterates a map, so the triggering failure may equally have been source-side (rename_safety's leftover _old table, source_schema_consistency drift, table_compatibility) — failures that wiping the target cannot cure. A multi-hundred-GB partial copy plus a valid checkpoint could be destroyed only for the rerun to fail on the same source-side error. Now the post-setup checks minus target_state (the one check wiping cures) are re-run BEFORE the wipe, and the wipe is refused if any still fail. 2. When the resume probe passed but resumeFromCheckpoint's deeper validations found the checkpoint definitively unusable — older than --checkpoint-max-age, positions that do not parse (e.g. a row written by the migration runner into the same _spirit_checkpoint table name), or a source missing from the positions map — the run hard-failed even with --force set, despite the flag's contract covering exactly "cannot resume from a checkpoint". These states are now tagged with typed sentinels (status.ErrCheckpointTooOld, new errCheckpointUnresumable) and fall through to the same validate-then-wipe path. Possibly-transient errors keep hard-failing: classification is strictly by errors.Is, never by string. resumeFromCheckpoint now performs all checkpoint-record validation before its first side effect (chunker subscriptions, runner state), so a definitive validation failure leaves the runner clean for the fall-through to rebuild everything via newCopy(). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
The changes are safety-focused, localized, and accompanied by targeted integration tests covering the newly introduced failure and recovery paths.
Pull request overview
This PR hardens move --force recovery by ensuring source-side validation happens before any destructive target wipe, and by making certain checkpoint failures eligible for forced restart rather than aborting after partial validation.
Changes:
- Gate
--forcetarget wipes behind a pre-wipe revalidation of all post-setup checks excepttarget_state, preventing wipes when failures are source-side. - Treat specific checkpoint-resume failures (e.g., too-old checkpoints, malformed/missing per-source positions) as definitively unresumable so
--forcecan restart safely. - Add a shared
dbconnguard to reject source/target database aliases usingDATABASE()+@@server_uuid, plus integration tests for new recovery and alias behavior.
File summaries
| File | Description |
|---|---|
| pkg/move/runner.go | Reorders validation vs wipe behavior for --force, adds definitive-unresumable checkpoint handling, and enforces source/target identity checks early. |
| pkg/move/runner_test.go | Adds regression coverage for pre-wipe validation, forced restart on definitive checkpoint failures, and source/target alias rejection. |
| pkg/move/check/target_state.go | Exposes a stable check name constant so the runner can exclude only target_state in pre-wipe validation. |
| pkg/move/check/check.go | Introduces RunChecksExcluding to support pre-wipe validation that intentionally omits specific checks. |
| pkg/dbconn/database_identity.go | Adds RequireDifferentDatabase helper for robust source/target alias prevention across differing DSNs. |
| pkg/dbconn/database_identity_test.go | Verifies alias detection works for same DB and for distinct DSNs pointing at the same DB. |
| docs/move.md | Updates operator guidance for --force, including which checkpoint failures are eligible and the source/target alias restriction. |
Review details
- Files reviewed: 7/7 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
🤖 Adversarial correctness review — The central insight is right and stated well: "wiping only cures target-side state, so a failure in any other (source-side) check must surface before the target is destroyed." Excluding exactly one check by name — with Restricting forced recovery to typed sentinels rather than "any resume error" is the other good call. ⭐ The reordered watermark assignment is not cleanup — it's what makes the new force path safe, and that coupling is worth stating in the PR. Moving copierWatermark := rec.CopierWatermark
r.checksumWatermark = rec.ChecksumWatermarkbelow the validations reads as tidying, but I verified the property that makes it hold, since it isn't local:
1 — the PR reasons about which check failed, over a randomly-ordered registry (low-med)
That was tolerable while nothing distinguished the checks — and you've already noticed it, in the comment at The fix already exists one package over.
and it goes further than ordering — (The unlocked map read is fine in practice — registration happens in 2 — the invariant that makes the sentinel safe isn't written down, and the obvious next extension violates it (low-med)// Only definitive checkpoint failures permit --force to discard a partial copy.
var errCheckpointUnresumable = errors.New("checkpoint is not resumable")The comment states the policy (definitive failures only). The property the code actually depends on is stronger and unstated: a force-eligible error must be raised before Consider the most natural future addition. Two things would keep this safe against that:
The first is what I'd actually want; the comment alone leaves a load-bearing ordering constraint enforced by nothing. 3 — the new pure logic is untested, and the indirection isn't needed (low)
While you're in there: 4 — the alias guard is quadratic, and sharded moves take the expensive branch (low) for si := range r.sources {
for ti := range r.targets {
if err := dbconn.RequireDifferentDatabase(ctx, r.sources[si].db, r.targets[ti].DB); err != nil {Each call issues two The part worth noting is which branch dominates. The cheap two-query path is taken when the schema names differ — but a sharded move typically has the same database name on both sides, on different servers. So the UUID reads fire on every pair, and the four-query path is the common case rather than the exception, re-reading the same handful of servers' UUIDs dozens of times. Startup-only, so this is a genuine low. But hoisting it is straightforward and reads better than the nested loop: resolve Practical note, not a finding: Verified — the ordering, and two attacks that dissolved⭐ Attack that dissolved: the pre-wipe run replaced the post-wipe run. If the new ⭐ Attack that dissolved: a past-cutover checkpoint becoming force-eligible. The most dangerous thing The alias guard runs before anything touches a target. The position check's new
Local: This review was generated by Claude Code (claude-opus-5). |
aparajon
left a comment
There was a problem hiding this comment.
🤖 Approved — validating source-side checks before the wipe is the right shape, and restricting forced recovery to typed sentinels keeps a transient read failure from becoming permission to destroy a partial copy. Worth calling out in the summary that the reordered watermark assignment is a co-requisite of the new force path rather than cleanup: without it, forced recovery would have opened the checksum chunker at the abandoned attempt's watermark. Findings in a separate comment.
This stamp was left by Claude Code (claude-opus-5).
|
🤖 Addressed the approval feedback in |
Move could wipe a partial target copy under
--forceand only afterward discover a source-side failure that wiping cannot fix. It also refused forced recovery when deeper checkpoint validation found an expired checkpoint or unusable source positions.Validate every post-setup check except target state before wiping, including automatic recovery from an empty move checkpoint. Allow forced recovery only for typed, definitive checkpoint failures; transient errors still abort. Checkpoint records are fully validated before the checksum watermark is assigned or change feeds are built, and the force fallback explicitly clears that watermark before starting fresh.
Post-setup checks now run in stable name order, so a target with several problems reports the same first failure on every run. The exclusion path is covered directly and shares the regular
RunChecksAPI.Reject source/target aliases before target operations by comparing selected schemas and server UUIDs through a shared
dbconnhelper. Different credentials or hostnames cannot bypass this guard. Multi-source and multi-target moves resolve each connection identity once instead of repeating queries for every pair.Validation against MySQL 8.0.43:
go test ./pkg/move/checkandgo test ./pkg/movegolangci-lint run: clean.