Skip to content

feat(registrar,agent): write-behind external-registry writes - #145

Merged
bpalermo merged 1 commit into
mainfrom
feat/registrar-write-behind
Jun 11, 2026
Merged

bpalermo merged 1 commit into
mainfrom
feat/registrar-write-behind

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

The real fix for the Cloud Map registration race the rev-68 e2e exposed (and the default panic threshold had been silently masking since the beginning). Per the design decision: discovery moves at watch latency; the external registry — and therefore cross-cluster visibility — is eventually consistent. panic_threshold stays 0 (#144 closed unmerged); this PR is the fix that has to carry it.

Registrar: snapshot-first writes + pending-shielding

  • RegisterEndpoint/UnregisterEndpoint apply to the snapshot and broadcast immediately; the RPC never fails on external-registry errors. The Cloud Map write goes to a per-replica write-behind queue (1s→30s backoff, 5m max age with loud drop + metric).
  • Pending-shielding — the part that keeps this from re-creating fix(agent,registrar): close the agent-roll 404 gaps #142's bug from the write side: the sync loop calls Overlay(fetchedState) before Diff/Replace, patching the fetched state with still-pending intents (registers injected, unregisters tombstoned). The wholesale Replace was the trap: filtering events alone wouldn't have stopped the snapshot itself from regressing. An op is released only when its write succeeded and a subsequent sync observes the intent (handles Cloud Map read-after-write lag).
  • Supersede semantics: newest op per (service, protocol, ip) wins; a register followed by unregister flushes only the unregister; mid-flight flushes can't clobber newer intents.
  • Metrics: aether.registrar.writebehind.{queue_depth,flush_failures,drops,shielded_intents}.

Agent: re-assertion on watch reconnect

The watch client signals each successful (re)connection (registry.ReconnectNotifier); the CNI server runs an immediate ghost sweep on it. A failed-over/restarted replica that lost queued intents is repaired at reconnect speed instead of the 60s sweep — this is the durability story (deliberately no persistent queue).

Multi-replica (2 replicas now the default, per directive)

Chart replicaCount 1→2 — both replicas serve gRPC and sync independently (verified: both the gRPC server and Syncer set NeedLeaderElection: false), so the split topology is permanently exercised. Interim semantics: an RPC-driven change is visible instantly on the receiving replica, converging on the peer via Cloud Map (write-flush + peer's sync interval). Phase 2 (separate PR): replicas peer-watch each other over the existing WatchEndpoints protocol with origin tagging (apply + re-broadcast to agents; never forward to peers; never write the external registry for peer-sourced events), restoring watch-latency visibility cluster-wide.

Testing

  • Queue: retry-until-success, overlay shield/release for register (incl. flushed-but-unobserved) and unregister tombstones, supersede.
  • RPC boundary: failing external registry → RPC succeeds, snapshot updated immediately, write queued.
  • Client: reconnect signal coalescing.
  • Full suite 38/38.

Validation criterion on talos (the one that matters): svc-1 rolling restart under load with panic still 0 → ~0 fails. Rev-68 baseline: 352/439.

🤖 Generated with Claude Code

Closes the Cloud Map registration race that the rev-68 e2e exposed (and
that the default panic threshold had been silently masking): a failed
external-registry write left a serving pod invisible to the mesh for up
to the 60s reconciliation sweep, driving the recorded healthy fraction of
a rolling service to zero while real capacity existed. Per the design
decision (2026-06-11): discovery moves at watch latency; the external
registry — and therefore cross-cluster visibility — is eventually
consistent. panic_threshold stays 0 (#144 closed unmerged); this is the
fix that has to carry it.

Registrar:
- RegisterEndpoint/UnregisterEndpoint are now snapshot-first: apply +
  broadcast immediately, never fail the RPC on external-registry errors.
  The external write goes to a per-replica write-behind queue (1s..30s
  backoff, 5m max age with loud drop).
- Pending-shielding: the sync loop overlays still-pending intents onto
  the fetched external state BEFORE Diff/Replace, so neither the
  broadcast events nor the wholesale snapshot replacement can regress an
  intent the external registry has not materialized yet (the rev-66
  partial-view bug, approached from the write side). An op is released
  only after its write succeeded AND a sync observes the intent.
- Metrics: writebehind.queue_depth / flush_failures / drops /
  shielded_intents.

Agent:
- The registry watch client signals each successful (re)connection
  (registry.ReconnectNotifier); the CNI server runs an immediate ghost
  sweep on it, re-asserting this node's registrations. A failed-over or
  restarted registrar replica that lost queued intents is repaired at
  reconnect speed instead of the sweep interval.

Chart:
- registrar replicaCount default 1 -> 2 (directive: always exercise the
  multi-replica topology). With 2 replicas, both serve gRPC and sync
  independently; an RPC-driven change is visible instantly on the
  receiving replica and converges on the peer via the external registry —
  peer-watch (origin-tagged replica-to-replica subscriptions over the
  existing WatchEndpoints protocol) is the planned phase 2 that closes
  that skew.

Validation criterion on talos: svc-1 rolling restart under load with
panic still 0 -> ~0 fails (rev-68 baseline: 352/439).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@bpalermo
bpalermo merged commit 9733134 into main Jun 11, 2026
10 checks passed
@bpalermo
bpalermo deleted the feat/registrar-write-behind branch June 11, 2026 18:25
bpalermo added a commit that referenced this pull request Jun 11, 2026
… not the watch cache (#149)

The reconnect re-assert (#145) reused the ghost sweep, which listed
endpoints via the registrar client's ListAllEndpoints — served from the
watch-fed local cache. A fresh or failed-over registrar with an EMPTY
snapshot emits no FULL_SNAPSHOT events, so that cache is never cleared:
it remains a stale superset claiming every pod is registered, the diff
concludes nothing is missing, and the re-assert silently no-ops —
defeating exactly the state-loss repair it exists to provide.

Observed in vivo (2026-06-11, backend-comparison e2e): switching the
registrar's external backend left the new registry with zero services
while every agent kept serving stale EDS; only restarting the agents
(fresh cache = server truth) healed it. A registrar fleet replacement
or backend data loss would hit the same latent gap.

Fix: new registry.AuthoritativeLister capability — list from the
authoritative source, bypassing any cache. The registrar client
implements it via the existing ListAllEndpoints RPC; the ghost sweep
prefers it when present. Cost: one RPC per sweep/reconnect per node,
served from the registrar's in-memory snapshot. Regression test
reproduces the stale-superset trap.

Co-authored-by: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant