Fleet public routes review R1 finding 1: the edge's change poll sees route identity and a forward row's inertness
Fingerprint keyed rows by rowid and hashed neither host, kind, account nor app. PutForward's conflict update rewrites account and app in place, and a DeleteForward plus a PutForward of another hostname can reuse the rowid, so the edge's watcher saw no change: an account-only correction after a fleet owner change stayed refused, and a replaced forward host kept serving its old name while the new one never appeared. Every row now also hashes host, kind, account and app (tagged, quoted), platform when set (the platform-alias fold reads it), and a forward row that is not inert carries one bit computed in the same SELECT from ForwardForbidden (fingerprintForwardInert), since admission reads every forbidden column and most are hashed nowhere else. Still one SELECT per table on one fresh connection, no new table, no bucket read; the new terms move only on real routing or ownership writes. The fleets table's owner was already hashed: a fleet owner change converged before and has a regression now. Regressions through the production writers and the real watcher, no explicit Reload: an account-only correction, a delete and re-put on a reused rowid, and a fleet owner change. Registry tests pin each identity column, the rowid reuse, and each forbidden column of a forward row. The three Fingerprint switch-off goldens are re-pinned once (identity joined every row); the guarded terms still add nothing while unset.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/edge/fleetforward_watch_test.go+161 −0internal/registry/forward.go+16 −0internal/registry/forward_inventory_test.go+1 −0internal/registry/hold_test.go+5 −1internal/registry/identity_fingerprint_test.go+166 −0internal/registry/policycols_test.go+5 −1internal/registry/ratelimit_fingerprint_test.go+5 −1internal/registry/registry.go+41 −3
Intent
OK, go ahead.
<task-notification> <task-id>bgq1k5334</task-id> <tool-use-id>toolu_01RA1hvcHvHHCdwMDboEozNE</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/bgq1k5334.output</output-file> <status>completed</status> <summary>Background command "Wait for CI on the branch tip" completed (exit code 0)</summary> </task-notification>
<task-notification> <task-id>bakam0cte</task-id> <tool-use-id>toolu_01EyGBSR6DRqyGVAQoCznuJR</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/bakam0cte.output</output-file> <status>completed</status> <summary>Background command "Run Astra's whole-branch and census review round 1" completed (exit code 0)</summary> </task-notification>
diff --git a/internal/edge/fleetforward_watch_test.go b/internal/edge/fleetforward_watch_test.go| new file mode 100644 |
| index 000000000..0d718d47a |
| --- /dev/null |
| +++ b/internal/edge/fleetforward_watch_test.go |
| @@ -0,0 +1,161 @@ |
| +package edge |
| + |
| +// Fleet public routes, whole-branch review round 1, finding 1: every change |
| +// to a row's routing identity or to an input of fleet admission reaches the |
| +// serving map through the edge's own watcher (Watch's 2s Fingerprint poll), |
| +// never only through an explicit Reload. Each test writes with the |
| +// production registry writers (PutForward, DeleteForward, UpsertFleet, Upsert) |
| +// and calls no Reload after its watcher starts: convergence is the watcher's. |
| + |
| +import ( |
| + "database/sql" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/registry" |
| +) |
| + |
| +// watchConvergeBound is how long a test waits for the watcher: the 2s poll |
| +// and a reload, with room for a loaded machine. |
| +const watchConvergeBound = 12 * time.Second |
| + |
| +// startWatch runs hub's watcher until the test ends. |
| +func startWatch(t *testing.T, hub *Edge) { |
| + t.Helper() |
| + stop := make(chan struct{}) |
| + done := make(chan struct{}) |
| + go func() { defer close(done); hub.Watch(stop) }() |
| + t.Cleanup(func() { close(stop); <-done }) |
| +} |
| + |
| +// servedByBox reports whether host answers through the fleet as box-1. |
| +func servedByBox(t *testing.T, hubURL string, hub *Edge, host string) bool { |
| + t.Helper() |
| + if !hub.Allowed(host) { |
| + return false |
| + } |
| + resp, body := fwdDo(t, hubURL, "GET", host, "/", "", nil) |
| + return resp.StatusCode == 200 && string(body) == "box-1" |
| +} |
| + |
| +// waitServed waits for host's service to become want, failing with what when |
| +// the watcher does not get there within watchConvergeBound. |
| +func waitServed(t *testing.T, hubURL string, hub *Edge, host string, want bool, what string) { |
| + t.Helper() |
| + deadline := time.Now().Add(watchConvergeBound) |
| + for { |
| + if servedByBox(t, hubURL, hub, host) == want { |
| + return |
| + } |
| + if time.Now().After(deadline) { |
| + t.Fatalf("%s: %s served = %v after %s, want %v (the watcher never reloaded)", what, host, !want, watchConvergeBound, want) |
| + } |
| + time.Sleep(100 * time.Millisecond) |
| + } |
| +} |
| + |
| +// baselineWatch starts hub's watcher and returns once it has reloaded at |
| +// least once after starting: a fresh accountless fleet hand row, written |
| +// after the watcher started, is served. A change written after this returns |
| +// is one the watcher must notice by its fingerprint, not by its first tick. |
| +func baselineWatch(t *testing.T, hubURL string, hub *Edge) { |
| + t.Helper() |
| + startWatch(t, hub) |
| + sentinel := registry.Route{Host: "sentinel.example.com", Kind: "instance", Status: "ready", Region: registry.PlacementTarget("home")} |
| + if err := hub.reg.Upsert(sentinel); err != nil { |
| + t.Fatal(err) |
| + } |
| + waitServed(t, hubURL, hub, sentinel.Host, true, "the watcher's baseline") |
| +} |
| + |
| +// rowidOf is host's rowid in the registry file at path. |
| +func rowidOf(t *testing.T, path, host string) int64 { |
| + t.Helper() |
| + db, err := sql.Open("sqlite", path) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + defer db.Close() |
| + var id int64 |
| + if err := db.QueryRow(`SELECT rowid FROM routes WHERE host = ?`, host).Scan(&id); err != nil { |
| + t.Fatalf("rowid of %s: %v", host, err) |
| + } |
| + return id |
| +} |
| + |
| +// (c) A fleet owner change converges: the forward row of the old owner's |
| +// account stops being served when the fleet passes to another account, and |
| +// is served again when it passes back. |
| +func TestWatchConvergesAFleetOwnerChange(t *testing.T) { |
| + const host = "shop.example.com" |
| + hubURL, hub, _ := forwardHubAndBox(t, []registry.Route{forwardRow(host, "home", fwdOwner)}, nil, namedHandler("box-1")) |
| + if !servedByBox(t, hubURL, hub, host) { |
| + t.Fatalf("fixture: %s not served before the owner change", host) |
| + } |
| + baselineWatch(t, hubURL, hub) |
| + |
| + if err := hub.reg.UpsertFleet(registry.Fleet{Name: "home", Account: fwdOther, Bucket: "home-data"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + waitServed(t, hubURL, hub, host, false, "fleet home passed to another account") |
| + |
| + if err := hub.reg.UpsertFleet(registry.Fleet{Name: "home", Account: fwdOwner, Bucket: "home-data"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + waitServed(t, hubURL, hub, host, true, "fleet home passed back") |
| +} |
| + |
| +// (a) An account-only correction converges (the finding's first scenario): |
| +// the fleet passes to another account, the watcher refuses the old account's |
| +// forward row, and the forward phase's PutForward then corrects only the |
| +// row's Account (an in-place conflict update, rowid and every other |
| +// fingerprinted column unchanged). The new owner's row is served. |
| +func TestWatchConvergesAForwardRowsAccountCorrection(t *testing.T) { |
| + const host = "shop.example.com" |
| + hubURL, hub, _ := forwardHubAndBox(t, []registry.Route{forwardRow(host, "home", fwdOwner)}, nil, namedHandler("box-1")) |
| + baselineWatch(t, hubURL, hub) |
| + |
| + if err := hub.reg.UpsertFleet(registry.Fleet{Name: "home", Account: fwdOther, Bucket: "home-data"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + waitServed(t, hubURL, hub, host, false, "fleet home passed to another account") |
| + |
| + before := rowidOf(t, hub.reg.Path(), host) |
| + if err := hub.reg.PutForward(forwardRow(host, "home", fwdOther)); err != nil { |
| + t.Fatal(err) |
| + } |
| + if after := rowidOf(t, hub.reg.Path(), host); after != before { |
| + t.Fatalf("PutForward moved %s from rowid %d to %d; the test needs the in-place update", host, before, after) |
| + } |
| + waitServed(t, hubURL, hub, host, true, "the forward row's account corrected to the new owner") |
| +} |
| + |
| +// (b) A forward host replaced by another reusing its rowid converges (the |
| +// finding's second scenario): DeleteForward of the highest-rowid row and |
| +// PutForward of another hostname with the same declared fields, before the |
| +// next poll. SQLite gives the new row the old one's rowid. The old name is |
| +// retired and the new one served. |
| +func TestWatchRetiresAForwardHostReplacedOnItsRowid(t *testing.T) { |
| + const old, next = "old.example.com", "new.example.com" |
| + hubURL, hub, _ := forwardHubAndBox(t, nil, nil, namedHandler("box-1")) |
| + startWatch(t, hub) |
| + // Written after the watcher started, and served once it has reloaded: the |
| + // old row is in the watcher's baseline and holds the highest rowid. |
| + if err := hub.reg.PutForward(forwardRow(old, "home", fwdOwner)); err != nil { |
| + t.Fatal(err) |
| + } |
| + waitServed(t, hubURL, hub, old, true, "the old forward row") |
| + |
| + oldID := rowidOf(t, hub.reg.Path(), old) |
| + if deleted, err := hub.reg.DeleteForward(old); err != nil || !deleted { |
| + t.Fatalf("DeleteForward(%s) = %v, %v", old, deleted, err) |
| + } |
| + if err := hub.reg.PutForward(forwardRow(next, "home", fwdOwner)); err != nil { |
| + t.Fatal(err) |
| + } |
| + if id := rowidOf(t, hub.reg.Path(), next); id != oldID { |
| + t.Fatalf("the new row took rowid %d, not the old row's %d; the test needs the reuse", id, oldID) |
| + } |
| + waitServed(t, hubURL, hub, next, true, "the replacement forward host") |
| + waitServed(t, hubURL, hub, old, false, "the retired forward host") |
| +} |
diff --git a/internal/registry/forward.go b/internal/registry/forward.go| index 437c16cfa..b10fe4f1f 100644 |
| --- a/internal/registry/forward.go |
| +++ b/internal/registry/forward.go |
| @@ -236,6 +236,22 @@ func (t Route) InertForward() bool { |
| t.ClaimRowID == "" |
| } |
| +// fingerprintForwardInert is InertForward as a column of Fingerprint's |
| +// SELECT: 1 for a row that is not a forward row or is an inert one, 0 for a |
| +// forward row with any ForwardForbidden column set. It is built from |
| +// ForwardForbidden, so a forbidden column added there is read here too. |
| +var fingerprintForwardInert = func() string { |
| + zero := make([]string, 0, len(ForwardForbidden)) |
| + for _, c := range ForwardForbidden { |
| + if c.Type == "INTEGER" { |
| + zero = append(zero, c.Column+" = 0") |
| + } else { |
| + zero = append(zero, c.Column+" = ''") |
| + } |
| + } |
| + return "CASE WHEN kind <> 'forward' OR (" + strings.Join(zero, " AND ") + ") THEN 1 ELSE 0 END" |
| +}() |
| + |
| // putForwardSQL is PutForward's one statement. The INSERT binds every column |
| // through routeArgs (the forbidden ones zero). The conflict arm names every |
| // column too: declared ones from the call, CreatedAt and the observational |
diff --git a/internal/registry/forward_inventory_test.go b/internal/registry/forward_inventory_test.go| index cb87de604..4ec12e1a0 100644 |
| --- a/internal/registry/forward_inventory_test.go |
| +++ b/internal/registry/forward_inventory_test.go |
| @@ -47,6 +47,7 @@ var unresolvedRouteSQL = map[string]unresolvedSQL{ |
| "fleets.go:migrateFleets": {false, "ALTER TABLE fleets ADD COLUMN: a schema migration of the fleets table"}, |
| "registry.go:Get": {false, "SELECT <readCols> FROM routes WHERE host = ?: a read"}, |
| "registry.go:List": {false, "SELECT <readCols> FROM routes ORDER BY host: a read"}, |
| + "registry.go:Fingerprint": {false, "SELECT ... <fingerprintForwardInert> FROM routes ORDER BY rowid: the edge's change poll, a read"}, |
| "claimrows.go:RetireClaimRows": {true, "DELETE FROM routes|timers built at run time; the routes arm carries kind <> 'forward', and the forward check runs before archive"}, |
| "registry.go:applyRegistryPragmas": {false, "the connection pragmas (registryPragmas): busy_timeout, journal_mode, synchronous"}, |
| "registry.go:migrate": {false, "ALTER TABLE routes ADD COLUMN from routeAddedColumns: a schema migration, writes no row"}, |
diff --git a/internal/registry/hold_test.go b/internal/registry/hold_test.go| index 473a98762..4d689b418 100644 |
| --- a/internal/registry/hold_test.go |
| +++ b/internal/registry/hold_test.go |
| @@ -415,6 +415,10 @@ func TestFingerprintSeesHoldOpChangeAndIgnoresUnheld(t *testing.T) { |
| // Switch-off contract: an unheld registry hashes byte-for-byte as it did |
| // before hold_op existed. The goldens were produced by the same two rows on |
| // the parent commit's registry.go (8437004c^). |
| +// Fingerprint's golden was re-pinned once, when every row's identity (host, |
| +// kind, account, app) joined its encoding (fleet public routes review R1, |
| +// finding 1); hold_op still adds nothing while unset. SnapshotFingerprint's is |
| +// as produced. |
| func TestFingerprintsUnchangedForUnheldRows(t *testing.T) { |
| u := openTestRegistry(t) |
| if err := u.Upsert(Route{Host: "u", Kind: "instance", Socket: "/s", App: "a", CreatedAt: 1700000000}); err != nil { |
| @@ -423,7 +427,7 @@ func TestFingerprintsUnchangedForUnheldRows(t *testing.T) { |
| if err := u.Upsert(Route{Host: "v", Kind: "static", Status: "starting", Hibernate: true, CreatedAt: 1700000001}); err != nil { |
| t.Fatal(err) |
| } |
| - const wantF = "2:f1013971d496e9401cd6a9928a1f4e18669deda40089d2c2a8b84263b32f34c6" |
| + const wantF = "2:ffab25437b4e089489344a477b12149c3b7b10d4fd8ae82b3a2e5cd53975878f" |
| const wantS = "2:149e8f668771c7493bdb7d4245fdabe03e957b0909c4daa1d037484b11064b80" |
| if got, _ := u.Fingerprint(); got != wantF { |
| t.Fatalf("Fingerprint = %s, want %s", got, wantF) |
diff --git a/internal/registry/identity_fingerprint_test.go b/internal/registry/identity_fingerprint_test.go| new file mode 100644 |
| index 000000000..34140f310 |
| --- /dev/null |
| +++ b/internal/registry/identity_fingerprint_test.go |
| @@ -0,0 +1,166 @@ |
| +package registry |
| + |
| +import ( |
| + "strings" |
| + "testing" |
| +) |
| + |
| +// Fleet public routes, whole-branch review round 1, finding 1: Fingerprint |
| +// moves on every change to a row's routing identity (host, kind, account, |
| +// app, platform) and on every change to a forward row's inertness, so the |
| +// edge's watcher reloads on each; a row's rowid alone does not identify it. |
| + |
| +func fingerprintOf(t *testing.T, reg *Registry) string { |
| + t.Helper() |
| + fp, err := reg.Fingerprint() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return fp |
| +} |
| + |
| +// PutForward's conflict update rewrites Account and App in place: same |
| +// rowid, every other fingerprinted column unchanged. Each must move the |
| +// digest. |
| +func TestFingerprintSeesAForwardRowsAccountAndApp(t *testing.T) { |
| + reg := openTestRegistry(t) |
| + rt := validForward("shop.example.com", "home") |
| + if err := reg.PutForward(rt); err != nil { |
| + t.Fatal(err) |
| + } |
| + prev := fingerprintOf(t, reg) |
| + for _, step := range []struct { |
| + name string |
| + edit func(*Route) |
| + }{ |
| + {"account", func(r *Route) { r.Account = "baj" }}, |
| + {"app", func(r *Route) { r.App = "blog" }}, |
| + } { |
| + step.edit(&rt) |
| + if err := reg.PutForward(rt); err != nil { |
| + t.Fatal(err) |
| + } |
| + fp := fingerprintOf(t, reg) |
| + if fp == prev { |
| + t.Errorf("a PutForward that changed only %s left the fingerprint at %s", step.name, fp) |
| + } |
| + prev = fp |
| + } |
| +} |
| + |
| +// DeleteForward of the highest-rowid row and PutForward of another hostname |
| +// with the same declared fields reuses the rowid; the digest must still move. |
| +func TestFingerprintSeesAHostReplacedOnItsRowid(t *testing.T) { |
| + reg := openTestRegistry(t) |
| + if err := reg.PutForward(validForward("a.example.com", "home")); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := reg.PutForward(validForward("old.example.com", "home")); err != nil { |
| + t.Fatal(err) |
| + } |
| + rowid := func(host string) int64 { |
| + t.Helper() |
| + var id int64 |
| + if err := reg.sql.QueryRow(`SELECT rowid FROM routes WHERE host = ?`, host).Scan(&id); err != nil { |
| + t.Fatal(err) |
| + } |
| + return id |
| + } |
| + oldID := rowid("old.example.com") |
| + before := fingerprintOf(t, reg) |
| + if deleted, err := reg.DeleteForward("old.example.com"); err != nil || !deleted { |
| + t.Fatalf("DeleteForward = %v, %v", deleted, err) |
| + } |
| + if err := reg.PutForward(validForward("new.example.com", "home")); err != nil { |
| + t.Fatal(err) |
| + } |
| + if id := rowid("new.example.com"); id != oldID { |
| + t.Fatalf("the new row took rowid %d, not %d; the test needs the reuse", id, oldID) |
| + } |
| + if after := fingerprintOf(t, reg); after == before { |
| + t.Fatalf("replacing old.example.com by new.example.com on rowid %d left the fingerprint at %s", oldID, after) |
| + } |
| +} |
| + |
| +// Each identity column, changed alone by raw SQL behind every writer, moves |
| +// the digest, and each change is distinct from the others. |
| +func TestFingerprintSeesEachIdentityColumn(t *testing.T) { |
| + reg := openTestRegistry(t) |
| + if err := reg.Upsert(Route{Host: "h.example.com", Kind: "instance", Socket: "/s", App: "shop", Account: "bah", Status: "ready", CreatedAt: 1000}); err != nil { |
| + t.Fatal(err) |
| + } |
| + base := fingerprintOf(t, reg) |
| + seen := map[string]string{base: "the base row"} |
| + for _, c := range []struct{ column, set, reset string }{ |
| + {"host", "host = 'g.example.com'", "host = 'h.example.com'"}, |
| + {"kind", "kind = 'service'", "kind = 'instance'"}, |
| + {"account", "account = 'baj'", "account = 'bah'"}, |
| + {"app", "app = 'blog'", "app = 'shop'"}, |
| + {"platform", "platform = 1", "platform = 0"}, |
| + } { |
| + if _, err := reg.sql.Exec(`UPDATE routes SET ` + c.set); err != nil { |
| + t.Fatal(err) |
| + } |
| + fp := fingerprintOf(t, reg) |
| + if prev, dup := seen[fp]; dup { |
| + t.Errorf("%s changed: fingerprint %s is the same as %s's", c.column, fp, prev) |
| + } |
| + seen[fp] = c.column |
| + if _, err := reg.sql.Exec(`UPDATE routes SET ` + c.reset); err != nil { |
| + t.Fatal(err) |
| + } |
| + if fp := fingerprintOf(t, reg); fp != base { |
| + t.Fatalf("%s reset: fingerprint %s, want the base %s", c.column, fp, base) |
| + } |
| + } |
| +} |
| + |
| +// A forward row's admission reads every forbidden column (InertForward), so |
| +// each one, set alone on a stored forward row, moves the digest: the edge |
| +// must reload and refuse the row. Steering, pool and the rest are not |
| +// otherwise hashed for a row of any other kind. |
| +func TestFingerprintSeesEachForbiddenColumnOfAForwardRow(t *testing.T) { |
| + reg := openTestRegistry(t) |
| + const host = "shop.example.com" |
| + if err := reg.PutForward(validForward(host, "home")); err != nil { |
| + t.Fatal(err) |
| + } |
| + base := fingerprintOf(t, reg) |
| + for _, c := range ForwardForbidden { |
| + var v, zero any = "x", "" |
| + if c.Type == "INTEGER" { |
| + v, zero = 1, 0 |
| + } |
| + if _, err := reg.sql.Exec(`UPDATE routes SET `+c.Column+` = ? WHERE host = ?`, v, host); err != nil { |
| + t.Fatalf("%s: %v", c.Column, err) |
| + } |
| + if fp := fingerprintOf(t, reg); fp == base { |
| + t.Errorf("forbidden %s set on a forward row left the fingerprint at the inert row's %s", c.Column, fp) |
| + } |
| + if _, err := reg.sql.Exec(`UPDATE routes SET `+c.Column+` = ? WHERE host = ?`, zero, host); err != nil { |
| + t.Fatalf("%s: %v", c.Column, err) |
| + } |
| + } |
| + if fp := fingerprintOf(t, reg); fp != base { |
| + t.Fatalf("every forbidden column back at zero: fingerprint %s, want %s", fp, base) |
| + } |
| +} |
| + |
| +// The inertness term is a forward row's only: steering on a row of another |
| +// kind still does not move the digest (Route.Steering's exclusion). |
| +func TestFingerprintInertnessTermIsForwardRowsOnly(t *testing.T) { |
| + reg := openTestRegistry(t) |
| + if err := reg.Upsert(Route{Host: "h.example.com", Kind: "instance", Socket: "/s", Status: "ready", CreatedAt: 1000}); err != nil { |
| + t.Fatal(err) |
| + } |
| + before := fingerprintOf(t, reg) |
| + if _, err := reg.sql.Exec(`UPDATE routes SET steering = 'x'`); err != nil { |
| + t.Fatal(err) |
| + } |
| + if after := fingerprintOf(t, reg); after != before { |
| + t.Fatalf("steering on an instance row moved the fingerprint %s -> %s", before, after) |
| + } |
| + if !strings.HasPrefix(before, "1:") { |
| + t.Fatalf("fingerprint %s does not count one route", before) |
| + } |
| +} |
diff --git a/internal/registry/policycols_test.go b/internal/registry/policycols_test.go| index 4078c5931..950ea8cbf 100644 |
| --- a/internal/registry/policycols_test.go |
| +++ b/internal/registry/policycols_test.go |
| @@ -80,13 +80,17 @@ func TestPolicyColumns(t *testing.T) { |
| // the three columns existed, so upgrading does not force a snapshot on every |
| // box. The goldens were produced by this fixture on d3757ae7, the parent of |
| // the commit that added the columns. |
| +// Fingerprint's golden was re-pinned once, when every row's identity (host, |
| +// kind, account, app) joined its encoding (fleet public routes review R1, |
| +// finding 1); the three columns still add nothing while unset. |
| +// SnapshotFingerprint's is as produced. |
| func TestPolicyColumnsUnsetDigestsAsBefore(t *testing.T) { |
| reg := openTestRegistry(t) |
| if err := reg.Upsert(Route{Host: policyHost, Kind: "instance", Socket: "/s", Account: "abc", App: "shop", CreatedAt: 1700000000}); err != nil { |
| t.Fatal(err) |
| } |
| wantPolicy(t, policyRow(t, reg), "", "", "") |
| - const wantF = "1:a38d2c4eaed5e64549201160a19193bcfabd1bc370b46a24eca47e51d9733b01" |
| + const wantF = "1:2d07eed81f95d5b97b3b8f0acf2bdd96039d99dc1bbfd4339028b8701de6768a" |
| const wantS = "1:8246d576d9fbce7acc7e07ee2ecb17e59e828a0e0313cb467b515038e5f71a87" |
| f, s := claimFingerprints(t, reg) |
| if f != wantF { |
diff --git a/internal/registry/ratelimit_fingerprint_test.go b/internal/registry/ratelimit_fingerprint_test.go| index beb485a43..f6402ef9f 100644 |
| --- a/internal/registry/ratelimit_fingerprint_test.go |
| +++ b/internal/registry/ratelimit_fingerprint_test.go |
| @@ -7,6 +7,10 @@ import "testing" |
| // The digests are hard-coded from the encoding before the column was added, |
| // for a fixed fixture; they must never be re-pinned to follow a change to the |
| // rate_limit term. |
| +// Fingerprint's golden was re-pinned once, when every row's identity (host, |
| +// kind, account, app) joined its encoding (fleet public routes review R1, |
| +// finding 1); rate_limit still adds nothing while unset. SnapshotFingerprint's is |
| +// as produced. |
| func TestFingerprintsUnchangedWithoutRateLimit(t *testing.T) { |
| reg := openTestRegistry(t) |
| for _, rt := range []Route{ |
| @@ -27,7 +31,7 @@ func TestFingerprintsUnchangedWithoutRateLimit(t *testing.T) { |
| if err != nil { |
| t.Fatal(err) |
| } |
| - const wantFP, wantSnap = "3:d5ce261390a371e30d5096af5f99d0f8db77ac9ea6b8a7a8ff779585b9a20051", "3:b0eafec28c73c277183b73cd69ec5fe9d443781ebde4ce3c795ce51ec5ddc79d" |
| + const wantFP, wantSnap = "3:eb320047f70557ed38dca3e3d8737eedd9dde9eaeab6d06b3087c35a254a7d5b", "3:b0eafec28c73c277183b73cd69ec5fe9d443781ebde4ce3c795ce51ec5ddc79d" |
| if fp != wantFP { |
| t.Errorf("Fingerprint = %s, want %s", fp, wantFP) |
| } |
diff --git a/internal/registry/registry.go b/internal/registry/registry.go| index e7f84787a..22484b87d 100644 |
| --- a/internal/registry/registry.go |
| +++ b/internal/registry/registry.go |
| @@ -3730,6 +3730,22 @@ func (r *Registry) DeletePath(host, prefix string) error { |
| // database must reach a running edge, or the activator keeps waking the host |
| // on the stale cached path. |
| // |
| +// A row's identity is hashed too (fleet public routes, whole-branch review |
| +// round 1): host, kind, account and app on every row, platform when set, and |
| +// for a forward row whether every ForwardForbidden column is zero |
| +// (fingerprintForwardInert). Rows are keyed by rowid, and a rowid is not a |
| +// route: a delete and an insert of another hostname can reuse it, and |
| +// PutForward's conflict update rewrites account and app in place. These are |
| +// what fleet admission reads (FleetArmVerdict: kind, status, region, tunnel, |
| +// account, a forward row's inertness, the platform-alias fold's platform, |
| +// app and socket, all by host) beside the fleets table below, so each of |
| +// their changes reloads the edge. They change only on a real routing or |
| +// ownership write, so they add no reload and no edges-file publication on |
| +// any cadence. Adding them changed every digest once; no digest is |
| +// persisted (Watch and the edges-file loop keep theirs in memory and start |
| +// afresh with the process), so that costs nothing past the restart the new |
| +// binary brings. |
| +// |
| // `addrs` and `health` are hashed too (issue #152, multi-upstream routing): a |
| // SetUpstreams call that resizes or reshuffles a route's upstream set, or |
| // changes its probe config, is exactly as reload-relevant as an addr rewrite |
| @@ -3814,7 +3830,9 @@ func (r *Registry) Fingerprint() (string, error) { |
| SELECT rowid, status, socket, addr, version, hibernate, channel, backing, tunnel, |
| db_path, region, fleet_box, addrs, health, gate, hold_op, import_gate, rate_limit, |
| claim_incarnation, claim_stamp, claim_owner, claim_row_id, |
| - assets_off, asset_gen, incarnation, serving_seq |
| + assets_off, asset_gen, incarnation, serving_seq, |
| + host, kind, account, app, platform, |
| + ` + fingerprintForwardInert + ` |
| FROM routes ORDER BY rowid`) |
| if err != nil { |
| return "", err |
| @@ -3823,20 +3841,40 @@ FROM routes ORDER BY rowid`) |
| h := sha256.New() |
| n := 0 |
| for rows.Next() { |
| - var rowid, hibernate, assetsOff int64 |
| + var rowid, hibernate, assetsOff, platform, forwardInert int64 |
| var pair Pair |
| var claim ClaimOwnership |
| var assetGen string |
| var status, socket, addr, version, channel, backing, tunnel, dbPath, region, fleetBox, addrs, health, gate, holdOp, importGate, rateLimit string |
| + var host, kind, account, app string |
| if err := rows.Scan(&rowid, &status, &socket, &addr, &version, &hibernate, |
| &channel, &backing, &tunnel, &dbPath, ®ion, &fleetBox, &addrs, &health, &gate, &holdOp, &importGate, &rateLimit, |
| &claim.ClaimIncarnation, &claim.ClaimStamp, &claim.ClaimOwner, &claim.ClaimRowID, |
| - &assetsOff, &assetGen, &pair.Incarnation, &pair.ServingSeq); err != nil { |
| + &assetsOff, &assetGen, &pair.Incarnation, &pair.ServingSeq, |
| + &host, &kind, &account, &app, &platform, &forwardInert); err != nil { |
| return "", err |
| } |
| fmt.Fprintf(h, "%d\x1f%s\x1f%s\x1f%s\x1f%s\x1f%d\x1f%s\x1f%s\x1f%s\x1f%s\x1f%s\x1f%s\x1f%s\x1f%s\x1f%s", |
| rowid, status, socket, addr, version, hibernate, channel, backing, tunnel, |
| dbPath, region, fleetBox, addrs, health, gate) |
| + // The row's identity, always: a rowid is not a route. A delete and an |
| + // insert of another hostname can reuse it, and PutForward's conflict |
| + // update rewrites account and app in place, so without these the |
| + // digest of a replaced or re-owned row matches the old one and the |
| + // edge keeps serving its old map. Each is tagged and quoted. |
| + fmt.Fprintf(h, "\x1fhost=%q\x1fkind=%q\x1faccount=%q\x1fapp=%q", host, kind, account, app) |
| + // The platform mark decides the platform-alias fold (PlatformAliasFold), |
| + // and a refused source refuses its alias with it; folded only when set. |
| + if platform != 0 { |
| + fmt.Fprint(h, "\x1fplatform=1") |
| + } |
| + // A forward row's admission reads every ForwardForbidden column |
| + // (InertForward), most of which no other term hashes: one bit says |
| + // whether they are all zero, so a stray value refuses the row on the |
| + // next poll. Only a forward row that is not inert carries it. |
| + if forwardInert == 0 { |
| + fmt.Fprint(h, "\x1fforward_inert=0") |
| + } |
| // Only a held row carries the extra field: an unheld registry's digest |
| // is byte-identical to the pre-hold_op encoding (switch-off contract), |
| // while a hold handed to another op with the status unchanged still |