provision: an offline start pins its target box (#413)
move.target_box is the one box in the region the move goes to that can hold the row, written by OfflineTargeted in the same write as the start (direct or staged). Later steps wait on that box alone. An empty box, or a mut that does not leave the move in offline-stopping, is a malformed start and writes nothing. The field is additive and omitempty; a move started before it reads empty.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+89
−0
internal/provision/offline_move.go+23 −0internal/provision/offline_move_test.go+58 −0internal/provision/provision.go+8 −0
diff --git a/internal/provision/offline_move.go b/internal/provision/offline_move.go| index 9176e8f99..be6f9ac6f 100644 |
| --- a/internal/provision/offline_move.go |
| +++ b/internal/provision/offline_move.go |
| @@ -250,6 +250,29 @@ func OfflineStartStaged(id, by string, now time.Time) func(*Record) error { |
| } |
| } |
| +// OfflineTargeted is a start that also pins the move's target box: the one |
| +// box in the region the move goes to that can hold the row, as the start |
| +// door found it (amadan #413). start is OfflineStart or OfflineStartStaged, |
| +// so the pin is written in the same write that takes the instance offline, |
| +// and every later step waits on that box alone. An empty box, or a mut that |
| +// does not leave the move in offline-stopping (a stage is not a start), is a |
| +// malformed start and writes nothing. |
| +func OfflineTargeted(box string, start func(*Record) error) func(*Record) error { |
| + return func(rec *Record) error { |
| + if box == "" { |
| + return fmt.Errorf("%w: %s", ErrMoveConflict, refusedMalformedStart) |
| + } |
| + if err := start(rec); err != nil { |
| + return err |
| + } |
| + if !rec.Move.Offline() || rec.Move.State != OfflineStopping { |
| + return fmt.Errorf("%w: %s", ErrMoveConflict, refusedMalformedStart) |
| + } |
| + rec.Move.TargetBox = box |
| + return nil |
| + } |
| +} |
| + |
| // OfflineRestage is staging to staging: the operator asked for another |
| // pre-copy round. It moves staged_at to now (always forward), which is the |
| // request the stager answers with exactly one round (the stager report's |
diff --git a/internal/provision/offline_move_test.go b/internal/provision/offline_move_test.go| index 1e52c760b..e3becc2e1 100644 |
| --- a/internal/provision/offline_move_test.go |
| +++ b/internal/provision/offline_move_test.go |
| @@ -1058,3 +1058,61 @@ func TestMoveSeqExhaustionAtEveryTransition(t *testing.T) { |
| t.Fatalf("start one below the ceiling: %v %+v", err, got) |
| } |
| } |
| + |
| +// The start pins the one box in the target region that can hold the row |
| +// (amadan #413): every later step waits on that box alone, so a box beside |
| +// it that serves only another pool never holds the move up. Both starts pin |
| +// it, the direct one and a staged move's; an empty box is a malformed start |
| +// and writes nothing; and a mut that does not leave the move in stopping |
| +// (a stage) is not a start and writes nothing. |
| +func TestOfflineTargetedPinsTheTargetBox(t *testing.T) { |
| + ctx := context.Background() |
| + now := time.Date(2026, 11, 13, 9, 0, 0, 0, time.UTC) |
| + st := StageTarget{Stager: offSealer, Bucket: "data-uk", Region: "eu-west-2"} |
| + t.Run("direct start", func(t *testing.T) { |
| + s := release.NewDirStore(t.TempDir()) |
| + rec := offlineRecord(t, s) |
| + got, err := SetRecordMove(ctx, s, rec.Account, rec.App, rec.Host, OfflineTargeted("uk-box", OfflineStart(offID, "", "uk", "ops@example.com", now))) |
| + if err != nil || got.Move.TargetBox != "uk-box" || got.Move.State != OfflineStopping { |
| + t.Fatalf("start = %v %+v", err, got.Move) |
| + } |
| + }) |
| + t.Run("staged start", func(t *testing.T) { |
| + s := release.NewDirStore(t.TempDir()) |
| + rec := offlineRecord(t, s) |
| + if _, err := SetRecordMove(ctx, s, rec.Account, rec.App, rec.Host, OfflineStage(offID, "", "uk", "ops@example.com", st, now)); err != nil { |
| + t.Fatal(err) |
| + } |
| + got, err := SetRecordMove(ctx, s, rec.Account, rec.App, rec.Host, OfflineTargeted("uk-box", OfflineStartStaged(offID, "ops@example.com", now.Add(time.Minute)))) |
| + if err != nil || got.Move.TargetBox != "uk-box" || got.Move.State != OfflineStopping { |
| + t.Fatalf("staged start = %v %+v", err, got.Move) |
| + } |
| + }) |
| + for name, mut := range map[string]func(*Record) error{ |
| + "no box": OfflineTargeted("", OfflineStart(offID, "", "uk", "ops@example.com", now)), |
| + "a stage": OfflineTargeted("uk-box", OfflineStage(offID, "", "uk", "ops@example.com", st, now)), |
| + } { |
| + t.Run(name, func(t *testing.T) { |
| + s := release.NewDirStore(t.TempDir()) |
| + rec := offlineRecord(t, s) |
| + key := RecordKey(rec.Account, rec.App, rec.Host) |
| + before, _, _ := s.Get(ctx, key) |
| + if _, err := SetRecordMove(ctx, s, rec.Account, rec.App, rec.Host, mut); !errors.Is(err, ErrMoveConflict) || !strings.Contains(err.Error(), refusedMalformedStart) { |
| + t.Fatalf("%s = %v, want the malformed start", name, err) |
| + } |
| + if after, _, _ := s.Get(ctx, key); !bytes.Equal(before, after) { |
| + t.Fatalf("%s wrote the record", name) |
| + } |
| + }) |
| + } |
| + // The pin is additive on the wire: a journal without it reads empty, and |
| + // one with it round-trips. |
| + const pinned = `{"schema":1,"host":"a.go.example.com","slug":"s","app":"app","account":"bab","region":"ie","channel":"stable","created_at":"2026-09-01T08:00:00Z","move":{"id":"mv_abcdefghijklmnopqrstuvwxyz","from":"ie","to":"uk","state":"offline-stopping","requested_by":"ops@example.com","requested_at":"2026-10-21T09:00:00Z","updated_at":"2026-10-21T09:00:00Z","kind":"offline","target_box":"uk-box","seq":1}}` |
| + rec, err := DecodeRecord([]byte(pinned)) |
| + if err != nil || rec.Move.TargetBox != "uk-box" { |
| + t.Fatalf("pinned journal: %v %+v", err, rec.Move) |
| + } |
| + if out, _ := json.Marshal(rec); string(out) != pinned { |
| + t.Errorf("pinned journal did not round-trip:\n got %s\nwant %s", out, pinned) |
| + } |
| +} |
diff --git a/internal/provision/provision.go b/internal/provision/provision.go| index 5a8d307ef..17d2f5ed0 100644 |
| --- a/internal/provision/provision.go |
| +++ b/internal/provision/provision.go |
| @@ -1339,6 +1339,14 @@ type MoveState struct { |
| // Additive and omitempty. |
| StageBucket string `json:"stage_bucket,omitempty"` |
| StageRegion string `json:"stage_region,omitempty"` |
| + // TargetBox is the one box in the region the move goes to that can |
| + // hold the row, pinned by the start (OfflineTargeted) from the edges |
| + // files the start door read. That box alone lands, and the doors read |
| + // that box's target report alone: a box beside it that serves only |
| + // another pool never gets the row, so a wait on it never ends (amadan |
| + // #413). Empty on a move started before the pin. Additive and |
| + // omitempty. |
| + TargetBox string `json:"target_box,omitempty"` |
| // Seq is the record's move_seq as the transition that produced this |
| // state left it (self-serve moves plan 1 Task 7, offline_move.go): the |
| // hold's for a held row, open's for the target, the abort's for the |