replica placement: log registry and incarnation failures (#1246)
Astra round 1, P2-1. A failed registry read left the worker backing off with no reason given, and a record whose incarnation could not be worked out was skipped in silence. The registry read is now a named step on the existing once-per-backoff-step path. The incarnation failure keeps its skip, which has no backoff to pace a log line, so it logs once for each assignment. Retry timing is unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+113
−7
docs/superpowers/notes/census-proposal-small-fixes-1246-1248.md+2 −2internal/host/replicaplacement.go+28 −1internal/host/replicaplacement_log_test.go+79 −0internal/provision/testdata/plan14-root-reads-chain.tsv+1 −1internal/provision/testdata/plan14-root-reads-small-fixes-1246-1248.tsv+3 −3
diff --git a/docs/superpowers/notes/census-proposal-small-fixes-1246-1248.md b/docs/superpowers/notes/census-proposal-small-fixes-1246-1248.md| index 27c73de59..14bdd42e4 100644 |
| --- a/docs/superpowers/notes/census-proposal-small-fixes-1246-1248.md |
| +++ b/docs/superpowers/notes/census-proposal-small-fixes-1246-1248.md |
| @@ -4,7 +4,7 @@ Ruling `census-ruling-small-fixes-1246-1248`. The independent reviewer approves |
| | unit | change | read sites | what changed | |
| |---|---|---|---| |
| -| `internal/host/replicaplacement.go` `replicaPlacementWorker.run` | body | unchanged (6) | Logs the retire, acquire and publish failures it used to drop, at most once per backoff step, outside the worker lock. The retry decision, backoff arithmetic, deadlines and read sites are unchanged (6); no read added. | |
| +| `internal/host/replicaplacement.go` `replicaPlacementWorker.run` | body | unchanged (6) | Logs the retire, acquire, publish, registry-read and incarnation failures it used to drop, throttled per backoff step (incarnation: per assignment), outside the worker lock. The retry decision, the incarnation skip, backoff arithmetic, deadlines and read sites are unchanged; no read added. | |
| Envelopes re-pinned: `internal/edge`, `internal/host`. |
| @@ -14,6 +14,6 @@ Recorded dispositions, which each change must still satisfy: |
| - `internal/host/replicaplacement.go` `replicaPlacementWorker.run`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-stateless-replicas-2;basis=Final fix I3: retain completed lifetime/revision observations and skip their work; only confirmed current binding publication after coordinator acquisition, or existing successful/fenced retirement ACK, completes work. Existing local registry read, authority and retirement checks, and 30-second request deadline remain. No new reads or polling.;rev3=census-ruling-staticcheck-sa4006;basis=SA4006 dead store: publishCurrent's error is discarded explicitly (done, _ =) with a comment; it was assigned to err and never read, and publishCurrent returns false with every error, so done and the retry backoff are exactly as before. No read added, read sites unchanged (6). |
| -Seal: `ec3c40098ec0a652c735d54925f334b9b9680c9e2b6cd0c3d9497b8a615fb86f` → `f4994de79e61619e4c6def7782e458518a5466a75ec484cdb921d85934653bb4`. |
| +Seal: `ec3c40098ec0a652c735d54925f334b9b9680c9e2b6cd0c3d9497b8a615fb86f` → `a87a05f32fa47b3cafd83bc9325e5665025f6a403ac424f44fc0be22e2e45de9`. |
| Overlay: `internal/provision/testdata/plan14-root-reads-small-fixes-1246-1248.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/internal/host/replicaplacement.go b/internal/host/replicaplacement.go| index 06f16797f..c145fadfd 100644 |
| --- a/internal/host/replicaplacement.go |
| +++ b/internal/host/replicaplacement.go |
| @@ -108,6 +108,11 @@ func (w *replicaPlacementWorker) run(ctx context.Context, now time.Time) { |
| } |
| inc, err := provision.Incarnation(rec.Account, rec.App, rec.Host, rec.CreatedAt) |
| if err != nil { |
| + // Skipped with no backoff, so every tick comes back here: one line |
| + // for each assignment. |
| + if w.firstSkipReport(rec) { |
| + logReplicaPlacementFailure(rec.Host, "incarnation", err) |
| + } |
| continue |
| } |
| id := replicas.Identity{Account: rec.Account, App: rec.App, Host: rec.Host, Incarnation: inc} |
| @@ -118,6 +123,9 @@ func (w *replicaPlacementWorker) run(ctx context.Context, now time.Time) { |
| // Serialize local removal/proof against reconcile minting a new lifetime. |
| reconcileMu.Lock() |
| rt, err := w.reg.Get(rec.Host) |
| + if err != nil { |
| + step, failure = "read route", err |
| + } |
| proven := false |
| if err == nil && slices.Contains(a.Retiring, w.box) && rt == nil && w.quiet != nil && w.quiet(rec.Host) && w.empty != nil { |
| proof := provision.RouteFor(rec, w.dataDir, "", false, nil) |
| @@ -169,11 +177,30 @@ func (w *replicaPlacementWorker) run(ctx context.Context, now time.Time) { |
| } |
| w.mu.Unlock() |
| if report { |
| - log.Printf("agent: replica placement %s: %s failed, will retry: %v", rec.Host, step, failure) |
| + logReplicaPlacementFailure(rec.Host, step, failure) |
| } |
| } |
| } |
| +// firstSkipReport says whether rec's assignment has yet to report a failure |
| +// that skips the attempt, and marks it reported. observe clears the mark when |
| +// the assignment changes. |
| +func (w *replicaPlacementWorker) firstSkipReport(rec provision.Record) bool { |
| + w.mu.Lock() |
| + defer w.mu.Unlock() |
| + current, ok := w.pending[rec.Host] |
| + if !ok || current.logged || current.rec.CreatedAt != rec.CreatedAt || current.rec.ReplicaAssignment == nil || current.rec.ReplicaAssignment.Revision != rec.ReplicaAssignment.Revision { |
| + return false |
| + } |
| + current.logged = true |
| + w.pending[rec.Host] = current |
| + return true |
| +} |
| + |
| +func logReplicaPlacementFailure(host, step string, err error) { |
| + log.Printf("agent: replica placement %s: %s failed, will retry: %v", host, step, err) |
| +} |
| + |
| func newReplicaPlacementWorker(ctx context.Context, reg *registry.Registry, svc *activator.Service, backend *activator.ExecBackend, publisher *statelessBindingPublisher, base, token, dataDir string) *replicaPlacementWorker { |
| ctx, cancel := context.WithCancel(ctx) |
| api := &replicaCoordinatorAPI{base: strings.TrimRight(base, "/"), fleet: publisher.fleet, box: publisher.box, token: token, client: &http.Client{Timeout: 30 * time.Second}} |
diff --git a/internal/host/replicaplacement_log_test.go b/internal/host/replicaplacement_log_test.go| index a48d081b4..c2b039c37 100644 |
| --- a/internal/host/replicaplacement_log_test.go |
| +++ b/internal/host/replicaplacement_log_test.go |
| @@ -122,6 +122,85 @@ func TestReplicaPlacementTightRetryLoopLogsOnce(t *testing.T) { |
| } |
| } |
| +// A registry that cannot answer is a failure of its own, not an absent route: |
| +// it is named once per backoff step, and the backoff runs as it always did. |
| +func TestReplicaPlacementLogsRegistryFailure(t *testing.T) { |
| + logs := captureLogBuffer(t) |
| + ctx := context.Background() |
| + w, rec := replicaRetiringWorker(t, func(context.Context, replicas.Identity, uint64) error { |
| + t.Error("retired with no route read") |
| + return nil |
| + }) |
| + if err := w.reg.Close(); err != nil { |
| + t.Fatal(err) |
| + } |
| + _, cause := w.reg.Get(rec.Host) |
| + if cause == nil { |
| + t.Fatal("a closed registry answered") |
| + } |
| + now := time.Now() |
| + for _, c := range []struct { |
| + at, delay, retry time.Duration |
| + lines int |
| + }{ |
| + {0, time.Second, time.Second, 1}, |
| + {0, time.Second, time.Second, 1}, // inside the first wait |
| + {time.Second, 2 * time.Second, 3 * time.Second, 2}, |
| + {2 * time.Second, 2 * time.Second, 3 * time.Second, 2}, // inside the second |
| + {3 * time.Second, 4 * time.Second, 7 * time.Second, 3}, |
| + } { |
| + w.run(ctx, now.Add(c.at)) |
| + if p := w.pending[rec.Host]; p.delay != c.delay || !p.retry.Equal(now.Add(c.retry)) { |
| + t.Fatalf("at +%s: delay %s, retry +%s, want %s and +%s", c.at, p.delay, p.retry.Sub(now), c.delay, c.retry) |
| + } |
| + if got := logs.count(replicaPlacementLogPrefix); got != c.lines { |
| + t.Fatalf("at +%s: %d lines, want %d:\n%s", c.at, got, c.lines, logs.String()) |
| + } |
| + } |
| + line, _, _ := strings.Cut(logs.String(), "\n") |
| + for _, want := range []string{rec.Host, "read route", cause.Error()} { |
| + if !strings.Contains(line, want) { |
| + t.Errorf("log line %q does not name %q", line, want) |
| + } |
| + } |
| +} |
| + |
| +// A record whose lifetime cannot be worked out is skipped on every tick, with |
| +// no backoff to pace a log line: it says so once for each assignment. |
| +func TestReplicaPlacementLogsIncarnationFailureOnce(t *testing.T) { |
| + logs := captureLogBuffer(t) |
| + ctx := context.Background() |
| + w, rec := replicaRetiringWorker(t, func(context.Context, replicas.Identity, uint64) error { |
| + t.Error("retired with no lifetime") |
| + return nil |
| + }) |
| + rec.Account, rec.CreatedAt = "NOT VALID", time.Time{} |
| + w.observe(rec) |
| + now := time.Now() |
| + for i := range 5 { |
| + w.run(ctx, now.Add(time.Duration(i)*time.Minute)) |
| + } |
| + if got := logs.count(replicaPlacementLogPrefix); got != 1 { |
| + t.Fatalf("%d lines for five skipped ticks, want 1:\n%s", got, logs.String()) |
| + } |
| + for _, want := range []string{rec.Host, "incarnation", provision.ErrMalformedIncarnation.Error()} { |
| + if !strings.Contains(logs.String(), want) { |
| + t.Errorf("log %q does not name %q", logs.String(), want) |
| + } |
| + } |
| + if p := w.pending[rec.Host]; p.delay != 0 || !p.retry.IsZero() { |
| + t.Fatalf("a skipped record gained a backoff: delay %s, retry %s", p.delay, p.retry) |
| + } |
| + next := *rec.ReplicaAssignment |
| + next.Revision++ |
| + rec.ReplicaAssignment = &next |
| + w.observe(rec) |
| + w.run(ctx, now) |
| + if got := logs.count(replicaPlacementLogPrefix); got != 2 { |
| + t.Fatalf("%d lines after a new revision, want 2:\n%s", got, logs.String()) |
| + } |
| +} |
| + |
| // What is not a failure to retry is not logged as one. |
| func TestReplicaPlacementQuietWhenNothingFailed(t *testing.T) { |
| t.Run("a fenced retirement is finished", func(t *testing.T) { |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index 75c2a6702..d3189e8ba 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -248,4 +248,4 @@ plan14-root-reads-mail-submission-followups.tsv c9cd3c8fdf31240b83affa0b2798422f |
| plan14-root-reads-staticcheck-sa4006.tsv 33e5eaaa9b2d80f6f8f5de8d04e908e39ecfc820c5fe7b44c870e671565e1063 |
| plan14-root-reads-aws-followups-1143.tsv 33e5eaaa9b2d80f6f8f5de8d04e908e39ecfc820c5fe7b44c870e671565e1063 |
| plan14-root-reads-fix-dbforward-reuse-1032.tsv ec3c40098ec0a652c735d54925f334b9b9680c9e2b6cd0c3d9497b8a615fb86f |
| -plan14-root-reads-small-fixes-1246-1248.tsv f4994de79e61619e4c6def7782e458518a5466a75ec484cdb921d85934653bb4 |
| +plan14-root-reads-small-fixes-1246-1248.tsv a87a05f32fa47b3cafd83bc9325e5665025f6a403ac424f44fc0be22e2e45de9 |
diff --git a/internal/provision/testdata/plan14-root-reads-small-fixes-1246-1248.tsv b/internal/provision/testdata/plan14-root-reads-small-fixes-1246-1248.tsv| index e31ebfa4e..69038081a 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-small-fixes-1246-1248.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-small-fixes-1246-1248.tsv |
| @@ -1,6 +1,6 @@ |
| # Census overlay small-fixes-1246-1248, written by census-propose (#369). census-ruling-small-fixes-1246-1248, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-small-fixes-1246-1248.md. |
| # 1 body, 0 sites, 2 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| -@legacy a21f3817e4d7592b66b0229a58c87f6f7a9c59ad30d6e65fe6c1dd84dfe34ce3 internal/host/replicaplacement.go replicaPlacementWorker.run legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-2;basis=Final fix I3: retain completed lifetime/revision observations and skip their work; only confirmed current binding publication after coordinator acquisition, or existing successful/fenced retirement ACK, completes work. Existing local registry read, authority and retirement checks, and 30-second request deadline remain. No new reads or polling.;rev3=census-ruling-staticcheck-sa4006;basis=SA4006 dead store: publishCurrent's error is discarded explicitly (done, _ =) with a comment; it was assigned to err and never read, and publishCurrent returns false with every error, so done and the retry backoff are exactly as before. No read added, read sites unchanged (6).;rev3=census-ruling-small-fixes-1246-1248;basis=Logs the retire, acquire and publish failures it used to drop, at most once per backoff step, outside the worker lock. The retry decision, backoff arithmetic, deadlines and read sites are unchanged (6); no read added. registry:ReplicaIncarnation@1337,registry:ReplicaRevision@1369,whole:Route@1049,whole:Route@1324,whole:Route@1843,whole:Route@897 8d4b85a98c41b8ad7736163024cd0cef3b0f0687e1e6f76fdee509cd56a27459 |
| -internal/host/replicaplacement.go replicaPlacementWorker.run legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-2;basis=Final fix I3: retain completed lifetime/revision observations and skip their work; only confirmed current binding publication after coordinator acquisition, or existing successful/fenced retirement ACK, completes work. Existing local registry read, authority and retirement checks, and 30-second request deadline remain. No new reads or polling.;rev3=census-ruling-staticcheck-sa4006;basis=SA4006 dead store: publishCurrent's error is discarded explicitly (done, _ =) with a comment; it was assigned to err and never read, and publishCurrent returns false with every error, so done and the retry backoff are exactly as before. No read added, read sites unchanged (6).;rev3=census-ruling-small-fixes-1246-1248;basis=Logs the retire, acquire and publish failures it used to drop, at most once per backoff step, outside the worker lock. The retry decision, backoff arithmetic, deadlines and read sites are unchanged (6); no read added. registry:ReplicaIncarnation@1337,registry:ReplicaRevision@1369,whole:Route@1049,whole:Route@1324,whole:Route@1843,whole:Route@897 8d4b85a98c41b8ad7736163024cd0cef3b0f0687e1e6f76fdee509cd56a27459 |
| +@legacy 829a818bbf74f19a8c6c55d2dd6bb0b4c3e3ecd52e95255ac3f4916d7f844d4c internal/host/replicaplacement.go replicaPlacementWorker.run legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-2;basis=Final fix I3: retain completed lifetime/revision observations and skip their work; only confirmed current binding publication after coordinator acquisition, or existing successful/fenced retirement ACK, completes work. Existing local registry read, authority and retirement checks, and 30-second request deadline remain. No new reads or polling.;rev3=census-ruling-staticcheck-sa4006;basis=SA4006 dead store: publishCurrent's error is discarded explicitly (done, _ =) with a comment; it was assigned to err and never read, and publishCurrent returns false with every error, so done and the retry backoff are exactly as before. No read added, read sites unchanged (6).;rev3=census-ruling-small-fixes-1246-1248;basis=Logs the retire, acquire, publish, registry-read and incarnation failures it used to drop, throttled per backoff step (incarnation: per assignment), outside the worker lock. The retry decision, the incarnation skip, backoff arithmetic, deadlines and read sites are unchanged; no read added. registry:ReplicaIncarnation@1591,registry:ReplicaRevision@1623,whole:Route@1151,whole:Route@1303,whole:Route@1578,whole:Route@2097 fa330ce1355ac7df5d298a300e768ecd647e0eb9927d853ebea3881b51b2d09b |
| +internal/host/replicaplacement.go replicaPlacementWorker.run legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-2;basis=Final fix I3: retain completed lifetime/revision observations and skip their work; only confirmed current binding publication after coordinator acquisition, or existing successful/fenced retirement ACK, completes work. Existing local registry read, authority and retirement checks, and 30-second request deadline remain. No new reads or polling.;rev3=census-ruling-staticcheck-sa4006;basis=SA4006 dead store: publishCurrent's error is discarded explicitly (done, _ =) with a comment; it was assigned to err and never read, and publishCurrent returns false with every error, so done and the retry backoff are exactly as before. No read added, read sites unchanged (6).;rev3=census-ruling-small-fixes-1246-1248;basis=Logs the retire, acquire, publish, registry-read and incarnation failures it used to drop, throttled per backoff step (incarnation: per assignment), outside the worker lock. The retry decision, the incarnation skip, backoff arithmetic, deadlines and read sites are unchanged; no read added. registry:ReplicaIncarnation@1591,registry:ReplicaRevision@1623,whole:Route@1151,whole:Route@1303,whole:Route@1578,whole:Route@2097 fa330ce1355ac7df5d298a300e768ecd647e0eb9927d853ebea3881b51b2d09b |
| @coverage internal/edge 5a957f25e2c8ec67ea1ee494bc3b12a4f9cfbe26f1db4890d5bf925da06eae39 |
| -@coverage internal/host 97ba6b1d1eb103f39aca148b55efad35e3aebec68614ac5462ea38fbff41391e |
| +@coverage internal/host 18c0b56671016a77b432c9d09a3b97fdb11e90897ec6aa010b30be314cd26518 |