Skip to content

fix(registrar): name the snapshot by its contents (store revision); version only at consistent points - #1204

Merged
bpalermo merged 4 commits into
mainfrom
feat/1193-revisioned-snapshot-version
Oct 4, 2026
Merged

bpalermo merged 4 commits into
mainfrom
feat/1193-revisioned-snapshot-version

Conversation

@bpalermo

@bpalermo bpalermo commented Oct 4, 2026 •

Copy link
Copy Markdown
Owner

Problems

  1. Perf (registrar: every sync poll bumps the snapshot version even when nothing changed, so a reconnecting agent with last_version never matches and always gets the full snapshot #1193). The registrar's snapshot version was a per-process atomic.Uint64. Every replaceLocked bumped it, on every sync poll (changed or not), and so did every RPC apply batch. WatchEndpoints skips the full snapshot only when last_version == current. So any poll between a stream drop and the reconnect forced a full resend: in practice every reconnect.
  2. Correctness (registrar: every sync poll bumps the snapshot version even when nothing changed, so a reconnecting agent with last_version never matches and always gets the full snapshot #1193). talos runs 2 registrar replicas behind one Service, each with its own counter. A reconnect that lands on the other replica with a coincidentally equal counter skipped the snapshot even though the contents differed: a silent stale cache.
  3. Correctness (registrar/agent: the watch version is stamped on every event, so a stream truncated mid-snapshot or mid-batch leaves the agent with last_version = V and partial state — a reconnect that matches V skips the resend #1203, prerequisite). Every FULL_SNAPSHOT event and every event of a broadcast batch carried the version, and the agent adopts the last non-empty version it receives. A stream cut mid-snapshot (after the agent cleared its cache) or mid-batch left the agent presenting a version it did not fully hold. The per-poll bump hid this. Once versions are stable, a reconnect would match and skip the resend.

Design

  • Backend revision as the version. New optional capability registry.RevisionedLister (same pattern as DerivedEndpoints, fix(registrar): kubernetes backend releases an agent's write at the next sync, so every replica serves the Pod-derived endpoint (#1145) #1152).

    • etcd implements it. The sync reads every protocol in one prefix Get (it was 3) and takes resp.Header.Revision. The watch-response headers feed StoreRevision(). The per-protocol ListAllEndpoints API is unchanged.
    • The kubernetes backend deliberately does not implement it. Its listing is not a function of the Pod list's resourceVersion: podHealth depends on now() (the registrar (kubernetes backend): the agent's second drain step (UNHEALTHY ~1 s before SIGTERM) reaches only the receiving replica #1144 pool-close deadline), locality comes from a separately cached node list, and the list RV moves on any write in the cluster. The version there is content-addressed, and the lag metrics are etcd-only. This is stated in the capability doc and the runbook.
  • Version format. The content hash is always embedded, and only the hash decides currency. The revision is carried for the lag metrics and is never trusted for equality: a rebuilt etcd restarts at 1, and a binary that decodes a stored value differently derives different contents at the same revision.

    version meaning
    <rev>.<hash> exactly the etcd listing at rev
    <rev>+<hash> the listing plus a write-behind intent still overlaid, or an RPC applied since
    hash:<hash> no revision (kubernetes)

    <hash> is sha256 over sorted keys plus the deterministic proto encoding of each endpoint, truncated to 16 hex. It is computed in the mutation's critical section, at O(N) per sync and O(N log N) per mutation (documented in code). No form parses as a bare integer.

  • Resume decision (Snapshot.WatchStart, one critical section):

    • current: the token is the current version. The client gets SNAPSHOT_COMPLETE only.
    • renamed: the token's hash equals the current content hash under another name (the revision moved without a content change, a dirty token re-derived clean, another replica's name). The client gets the service catalog plus a SNAPSHOT_COMPLETE carrying the current version, with no endpoint events. The agent swaps in an identical catalog and adopts the fresh token.
    • resent: anything else. Full snapshot and catalog.
  • Agent token drop (review HIGH). processStream now clears lastVersion together with the cache on the first FULL_SNAPSHOT. A resend cut short therefore reconnects with no token, rather than with one that a lagging replica, reverted contents, or another replica could still match. Without this, that match served the marker alone onto an empty cache.

  • Version only at consistent points (registrar/agent: the watch version is stamped on every event, so a stream truncated mid-snapshot or mid-batch leaves the agent with last_version = V and partial state — a reconnect that matches V skips the resend #1203). FULL_SNAPSHOT and catalog events carry no version; SNAPSHOT_COMPLETE does. Broadcaster.Broadcast puts the batch version on the last event each watcher receives, with unversioned copies built once per event (not per watcher). Old agents already ignore empty versions, so they get the fix for free.

  • Generation. aether.registrar.snapshot.version keeps its series name (no dashboard or alert uses it, see below). It now records a generation that moves only when the content hash changes.

  • New metrics

    • aether.registrar.store_revision and aether.registrar.snapshot_revision (observable, etcd only).
    • aether.registrar.snapshot.content{content_hash}: an info gauge. It is observed, so exactly one series per replica is exported and a superseded hash stops being exported.
    • aether.registrar.watch.starts{resume=resent|current|renamed}: the measurement instrument, kept because it is the fast-path hit rate.
  • Agent. The last_version gauge parses the part before . or +. hash: never parses.

  • Wire compat. No proto change. Nothing parses the version semantically; the only numeric parses were the two gauges, both handled.

    • Rolling upgrade: an old counter token embeds no hash, so it never matches and the agent gets a full snapshot, which is safe.
    • Rollout caveat: agents older than this PR keep their old token across a cut resend. Until the agent DaemonSet has rolled they remain exposed to an empty-cache match on that reconnect. The window is milliseconds per reconnect.

Red, then green

Each test was red on main before the change:

New coverage:

Existing tests that pinned counter values (TestVersion, TestReplace, TestApply, TestFullSnapshotEvents, TestGetAllWithVersion, TestSyncer_Start_NoEventsAfterInitialSync, the metrics tests) were rewritten to assert the generation. No test case was removed.

A mutation check confirms the dirty and hash-match logic are load-bearing: removing either fails 3 tests. go_test targets under //registrar/... and //registry/..., including the agent registry client, are green under --config=race --runs_per_test=10. lint (fail_on_violation, //...) and format-check are clean.

kind measurement

Measured on the first revision of this branch (versions were bare <rev>). The drop scenario resolves the same way under the hash-embedded format: same contents give an identical version, so current.

e2e/drain-propagation.sh setup: etcd backend, 2 registrar replicas, client-a's 4 GET loops running. The source agent's registrar TCP connection was killed with ss -K 20× (the agent stays up). Replica attachment was read from conntrack before and after each drop. Full-snapshot sends were counted with aether.registrar.watch.starts{resume}, summed over both replicas.

Arms:

  • Before: main plus that counter only (instrumentation, no behaviour change).
  • After: this branch.

The agent image is this branch in both arms; its only change is the gauge parse.

arm placement reconnects full snapshot sends resumed (marker only)
before same replica 13 13 0
before cross replica 7 7 0
after same replica 13 0 13
after cross replica 7 0 7

After the runs both replicas reported snapshot_revision=20, store_revision=20, the same content_hash="e5ce0416ae6e28ea", and both agents reported last_version=20.

Lag metrics through a pod churn (one quic-a replica deleted at t=0, 15 s preStop). Rows are printed only when a value changed; sampling is about every 0.8 s.

t (s) cp agent last_version worker agent last_version replica A snapshot replica A store replica B snapshot replica B store
−3.16 20 20 20 20 20 20
+0.28 21 21 21 22 22 22
+1.11 21 21 22 22 22 22
+12.18 22 22 22 22 22 22
+13.01 22 22 23 23 23 23
+13.83 23 23 23 24 24 24
+14.71 23 24 24 24 24 24
+15.54 25 25 25 25 25 25
  • Store − snapshot (replica lag) closes within one sample (under 1 s).
  • Store − agent is an upper bound. Revision 22 changed no contents, so nothing was broadcast, and both agents stayed at 21 with a current cache until the next real change at +12 s. The gauge description and the runbook say so.

GitOps metric-name hits

/home/palermo/code/bpalermo/k8s-talos-main (read-only grep for aether_registrar_*, aether_agent_registry*, snapshot_version): none. No dashboard or alert depends on the redescribed series.

Docs

docs/runbook.md has a new section, "Stored vs in place vs applied". It covers the three version forms, the PromQL for replica lag, agent lag and divergence, the divergence rule (same revision with a different content_hash and no pending write-behind is a bug), and the kubernetes and upper-bound notes. No chart change.

Fixes #1193
Fixes #1203

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 3 commits October 4, 2026 11:34
…stent points

The registrar's snapshot version was a per-process counter bumped on every
sync and every RPC batch (#1193). A reconnecting agent's last_version went
stale on every 5 s poll, so every reconnect paid a full snapshot; and two
replicas behind one Service counted independently, so a reconnect landing on
the other replica with a coincidentally equal counter skipped a snapshot it
needed (silent stale cache).

The version now names the contents:
- "<rev>": the etcd listing at store revision rev. The sync reads every
  protocol in ONE Get (registry.RevisionedLister) and takes its header
  revision. Same revision => same contents on every replica.
- "<rev>+<hash>": the listing plus an overlaid write-behind intent or an RPC
  applied since; the suffix is the content hash, never another replica's
  clean revision.
- "hash:<hash>": backends without a revision. The kubernetes backend does not
  implement the capability: its listing derives health from the clock and
  locality from a separate node list, and the Pod list RV moves on any write.
The content hash (sha256 over sorted keys + deterministic endpoint encoding)
is computed in the mutation's critical section; a token whose embedded hash
matches the current contents is current (the marker echoes it).

Stamping the version only at consistent points (#1203): FULL_SNAPSHOT and
catalog events carry none, SNAPSHOT_COMPLETE does, and a broadcast batch
carries it on the last event each watcher receives. With stable versions a
stream cut mid-snapshot or mid-batch otherwise left the agent presenting a
version it did not fully hold, and the reconnect skipped the resend.

Metrics: snapshot.version keeps its series name as the content-change
generation; new store_revision, snapshot_revision and an info gauge
snapshot.content{content_hash} (one series per replica, observed). The
agent's last_version gauge parses the revision before '+'.

Fixes #1193
Fixes #1203

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
aether.registrar.watch.starts{resume} makes the reconnect fast path
observable: the share of agent reconnects that skip the full snapshot.
Also remembers the content hash of the last 64 clean revisions so a clean
"<rev>" token is current after the revision moved without a content change
(an agent's re-assert re-Puts what etcd already holds).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
Measured on kind: an agent learns a revision only from an event that reaches
it, so a no-op store write (or a change outside a demand-scoped filter) leaves
aether.agent.registry.last_version behind a current cache. Say so in the gauge
description and the runbook's stored/in-place/applied section.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
…send

Review of #1204.

HIGH: processStream cleared the cache on the first FULL_SNAPSHOT but kept the
resume token, and every non-DataLoss end returned it. With content-addressed
versions that token can match again -- a lagging replica, a reverted content,
or another replica's revision history -- and the reconnect is served the
marker alone onto an empty or partial cache. The agent now drops the token at
the cache clear; SNAPSHOT_COMPLETE hands it the new one.

Design: the version always embeds the hash -- "<rev>.<hash>" clean,
"<rev>+<hash>" dirty, "hash:<hash>" without a revision -- and only the hash
decides currency. The 64-revision ring is gone (it aged out under busy etcd
traffic, its echoed token never refreshed, and a bare revision assumed
revisions are never reused). A token with the current hash under another name
gets the catalog and a SNAPSHOT_COMPLETE carrying the CURRENT version (no
endpoint events): resume=renamed. The agent gauge parses before '.' or '+'.
Documents the O(N) per sync / O(N log N) per mutation hash cost.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit eef223a into main Oct 4, 2026
24 checks passed
@bpalermo
bpalermo deleted the feat/1193-revisioned-snapshot-version branch October 4, 2026 15:22
bpalermo added a commit that referenced this pull request Oct 4, 2026
…from the last two days (#1235)

- proxy-supervisor: drop "15 MiB / 24 modules" (it links 25 since the OTel
  1.47 bump, #1215) and name deps_test + check-proxy-supervisor-deps.sh as
  the source of truth; that guard asserts forbidden packages and a size
  ceiling, not a count.
- cni: the allow-list budget is 19, not 37 (#1185). Point at the guard's
  maxModules instead of repeating it; the build-graph script now forbids
  OpenTelemetry too. The plugin forwards timings to the agent.
- mesh-dns: same wording (its guard asserts 30, still correct).
- cni/internal: telemetry/ was removed by #1185.
- registrar/internal/server: the snapshot version is store revision +
  content hash since #1204.
- Add agent/internal/ownership (proposal 041), common/drain,
  common/referencegrant, and common/taint (in the node-taint entry).

Fixes #1224


Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

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