edge: revert Task 10's purge across boxes (#186)
Reverts 1c9df470 and c3897881. Paul cut cross-box response caching under rule 2 after two Astra rounds in the shared-host cache authority family (spec §7.2 rev 5.1, plan Task 10 revised). Purge code and the structural guard's allowlists return to their pre-Task-10 state.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7 files changed,
+68
−674
internal/edge/cache.go+1 −1internal/edge/edge.go+2 −2internal/edge/linkpin_test.go+8 −14internal/edge/pagecache.go+16 −24internal/edge/pathselect.go+8 −25internal/edge/purge_across_test.go+0 −452internal/edge/purge_header.go+33 −156
diff --git a/internal/edge/cache.go b/internal/edge/cache.go| index a43c25011..ebdc1dda9 100644 |
| --- a/internal/edge/cache.go |
| +++ b/internal/edge/cache.go |
| @@ -122,7 +122,7 @@ type purgeBridge interface { |
| // a wildcard alias). |
| instanceHosts(owner registry.Route, cached []string) []string |
| // ownsHost reports whether owner still owns host in the live table, so |
| - // a purge acting for owner may touch host's LRU entries (purgeOwnsIn). |
| + // a purge acting for owner may touch host's LRU entries (purgeOwns). |
| ownsHost(owner registry.Route, host string) bool |
| } |
diff --git a/internal/edge/edge.go b/internal/edge/edge.go| index 3c7280cd3..59bd61717 100644 |
| --- a/internal/edge/edge.go |
| +++ b/internal/edge/edge.go |
| @@ -2983,10 +2983,10 @@ func (e *Edge) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| // (page cache design §5.3). This is the one place that rule is checked. |
| // |
| // A linked request is never cached, looked up or stored (ServeLinked), |
| - // as a forward row is not on the hub; nor a case 3 response under a front a catch-all shadows (caseThreeCacheable). |
| + // as a forward row is not on the hub. |
| cacheable := e.cache != nil && (r.Method == http.MethodGet || r.Method == http.MethodHead) && |
| up.route.Kind != "status" && up.route.Kind != "static" && up.route.ImportGate == "" && |
| - !up.route.IsForward() && !markedRequest(r) && !e.pagesOptedIn(up) && !pinned && (up.front == nil || caseThreeCacheable(e.table(), host)) |
| + !up.route.IsForward() && !markedRequest(r) && !e.pagesOptedIn(up) && !pinned |
| var key CacheKey |
| if cacheable { |
| key = CacheKey{Host: host, Method: r.Method, Path: r.URL.Path, RawQuery: r.URL.RawQuery} |
diff --git a/internal/edge/linkpin_test.go b/internal/edge/linkpin_test.go| index f5b7d9d08..59b230286 100644 |
| --- a/internal/edge/linkpin_test.go |
| +++ b/internal/edge/linkpin_test.go |
| @@ -52,10 +52,6 @@ var selectionEntrySites = map[string]map[string]string{ |
| "selectForUnservedFront": { |
| "selectAcross": "case 3, after the door and door-hop checks, with the remote map selectAcross read", |
| }, |
| - "unservedFrontTarget": { |
| - "selectForUnservedFront": "case 3's eligibility of a target served here", |
| - "frontPathOwns": "purge owner check; never dispatches: a route purges a front's pages exactly while case 3 would select it", |
| - }, |
| } |
| // The other ways to read the routing map by host, and where each may be |
| @@ -71,8 +67,7 @@ var mapReadSites = map[string]map[string]string{ |
| "pageRouteEligible": "the page cache's eligibility of the upstream already selected; never reached by a linked request", |
| "pageHostsFor": "the pages a purge declaration clears, from the response's own route", |
| "resolvePurgeOwnersIn": "validates the hosts a Carlos-Purge-Host names against the serving route's tenancy", |
| - "purgeOwnsIn": "the owner check of a purge target host", |
| - "caseThreeCacheable": "whether anything here answers a front's name, so a case 3 response may use the LRU under it and its target purge there; never picks an upstream", |
| + "purgeOwns": "the owner check of a purge target host", |
| }, |
| // lookupDemoAware(m, host): the demo zone's exact-only lookup. |
| "lookupDemoAware": { |
| @@ -87,13 +82,12 @@ var mapReadSites = map[string]map[string]string{ |
| "takeHost": "the HA take control path, an edge-owned handler a linked request never reaches", |
| }, |
| // routeTable.remote: the remote path map (pathremote.go), read or set. |
| + // The purge owner check for a front this box does not serve |
| + // (purgeOwnsIn, resolvePurgeOwnersIn) joins when it reads the map. |
| "routeTable.remote": { |
| - "selectAcross": "case 3 of the one selection, reached only from selectUpstream", |
| - "selectUpstream": "THE selection: whether a host it answers only through a catch-all has a remote map, so case 3 runs for it", |
| - "Reload": "the one publisher of the table (TestReloadIsTheOnlyPublisher) sets it beside hosts", |
| - "purgeOwnsIn": "the LRU owner check of a purge for a front this box does not serve (spec §7.2); it can only refuse or allow an eviction, never pick an upstream", |
| - "resolvePurgeOwnersIn": "accepts a Carlos-Purge-Host naming a front this box does not serve whose prefix selects the serving route (spec §7.2); never picks an upstream", |
| - "otherAccountFront": "denies a catch-all purge authority over a name another account's claim path-routes here (spec §7.2); can only refuse", |
| + "selectAcross": "case 3 of the one selection, reached only from selectUpstream", |
| + "selectUpstream": "THE selection: whether a host it answers only through a catch-all has a remote map, so case 3 runs for it", |
| + "Reload": "the one publisher of the table (TestReloadIsTheOnlyPublisher) sets it beside hosts", |
| }, |
| } |
| @@ -169,7 +163,7 @@ func TestSelectUpstreamIsTheOnlySite(t *testing.T) { |
| callers[fn.Name.Name] = append(callers[fn.Name.Name], fset.Position(ident.Pos()).String()) |
| case "lookupIn", "lookupDemoAware": |
| note(ident.Name, fn.Name.Name, ident.Pos()) |
| - case "pathMatch", "selectAcross", "selectFromServedFront", "selectForUnservedFront", "unservedFrontTarget": |
| + case "pathMatch", "selectAcross", "selectFromServedFront", "selectForUnservedFront": |
| if ident == n { |
| entries[ident.Name] = appendSite(entries[ident.Name], fn.Name.Name, fset.Position(ident.Pos()).String()) |
| } |
| @@ -185,7 +179,7 @@ func TestSelectUpstreamIsTheOnlySite(t *testing.T) { |
| if id, ok := n.(*ast.Ident); ok { |
| switch id.Name { |
| case "lookupUpstream", "lookupUpstreamPath", "lookupIn", "lookupDemoAware", |
| - "pathMatch", "selectAcross", "selectFromServedFront", "selectForUnservedFront", "unservedFrontTarget": |
| + "pathMatch", "selectAcross", "selectFromServedFront", "selectForUnservedFront": |
| t.Errorf("%s: %s referenced outside a function", fset.Position(id.Pos()), id.Name) |
| } |
| } |
diff --git a/internal/edge/pagecache.go b/internal/edge/pagecache.go| index e981c616f..7526d9e2f 100644 |
| --- a/internal/edge/pagecache.go |
| +++ b/internal/edge/pagecache.go |
| @@ -158,37 +158,29 @@ func (e *Edge) clearPages(owner registry.Route, host string, c pageindex.Clear) |
| x.Clear(routeScope(owner), c) |
| } |
| -// instanceHosts is instanceHostsIn over one snapshot of the live table, its |
| -// remote path map included (purgeBridge). |
| +// instanceHosts is instanceHostsIn over one snapshot of the live table |
| +// (purgeBridge). |
| func (e *Edge) instanceHosts(owner registry.Route, cached []string) []string { |
| - return instanceHostsIn(e.purgeTable(), owner, cached) |
| + return instanceHostsIn(e.current(), owner, cached) |
| } |
| -// ownsHost is purgeOwnsIn over one snapshot of the live table, its remote |
| -// path map included (purgeBridge). |
| +// ownsHost is purgeOwns over one snapshot of the live table (purgeBridge). |
| func (e *Edge) ownsHost(owner registry.Route, host string) bool { |
| - return e.purgeOwnsIn(e.purgeTable(), owner, host) |
| + return purgeOwns(e.current(), owner, host) |
| } |
| -// instanceHostsIn is every host t serves as owner's instance, sorted: each |
| -// key of t.hosts whose entry is that instance (the primary and every alias), |
| -// and each host in cached that t.hosts resolves (lookupIn) to that instance. |
| -// The second half finds the names served through a wildcard alias, which |
| -// the LRU keys by the name asked for and t.hosts cannot list; lookupIn lets |
| -// an exact key win over the wildcard, so a name another instance's route |
| -// takes is never among them. A wildcard key itself is a routing pattern, not |
| -// a name anything is cached under, and is left out. Nil when owner has no |
| -// host. |
| -// |
| -// A name another account's claim path-routes here (otherAccountFront) is |
| -// never among them either, though a catch-all of owner's resolves it: that |
| -// account's case 3 target has served it here (spec §7.2), and the catch-all |
| -// holds no authority over its pages. |
| -func instanceHostsIn(t *routeTable, owner registry.Route, cached []string) []string { |
| - if owner.Host == "" || t == nil { |
| +// instanceHostsIn is every host m serves as owner's instance, sorted: each |
| +// key whose entry is that instance (the primary and every alias), and each |
| +// host in cached that m resolves (lookupIn) to that instance. The second |
| +// half finds the names served through a wildcard alias, which the LRU keys |
| +// by the name asked for and m cannot list; lookupIn lets an exact key win |
| +// over the wildcard, so a name another instance's route takes is never |
| +// among them. A wildcard key itself is a routing pattern, not a name |
| +// anything is cached under, and is left out. Nil when owner has no host. |
| +func instanceHostsIn(m map[string]upstream, owner registry.Route, cached []string) []string { |
| + if owner.Host == "" { |
| return nil |
| } |
| - m := t.hosts |
| set := map[string]bool{} |
| for h, up := range m { |
| if !strings.HasPrefix(h, "*") && sameInstance(up.route, owner) { |
| @@ -196,7 +188,7 @@ func instanceHostsIn(t *routeTable, owner registry.Route, cached []string) []str |
| } |
| } |
| for _, h := range cached { |
| - if up, ok := lookupIn(m, h); ok && sameInstance(up.route, owner) && !otherAccountFront(t, h, owner) { |
| + if up, ok := lookupIn(m, h); ok && sameInstance(up.route, owner) { |
| set[h] = true |
| } |
| } |
diff --git a/internal/edge/pathselect.go b/internal/edge/pathselect.go| index 982b16085..4fefacc1b 100644 |
| --- a/internal/edge/pathselect.go |
| +++ b/internal/edge/pathselect.go |
| @@ -435,9 +435,14 @@ func (e *Edge) selectForUnservedFront(t *routeTable, host, urlPath string, rm re |
| // refusal; an unserved front's refusal reports what matched. |
| stay.Prefix, stay.Target = prefix, target |
| } |
| - if _, here := t.hosts[target]; here { |
| - tu, ok := unservedFrontTarget(t.hosts, target, rm.account) |
| - if !ok { |
| + if tu, here := t.hosts[target]; here { |
| + // A platform-alias target is its instance (selectedEntry), so the |
| + // box holding I's lease re-selects I for a hop another box sent |
| + // under I (spec §5.7.3); every other entry must be target's own. |
| + named := !tu.platformAlias |
| + tu, ok := selectedEntry(t.hosts, tu) |
| + if !ok || tu.alias || tu.regional != regionalNone || (named && tu.route.Host != target) || |
| + !registry.PathTarget(tu.route) || release.RouteAccount(tu.route) != rm.account { |
| e.pathSkip(host, fmt.Sprintf("prefix %q names %s, which this box serves but not as a ready instance or static route of account %s; sent to the host's home", prefix, target, rm.account)) |
| return stay |
| } |
| @@ -452,28 +457,6 @@ func (e *Edge) selectForUnservedFront(t *routeTable, host, urlPath string, rm re |
| return requestSelection{Remote: &remoteTarget{Target: target, Route: info}, Prefix: prefix, Target: target} |
| } |
| -// unservedFrontTarget is the entry case 3 dispatches a prefix of an unserved |
| -// front to when its target is served here: the target's own entry, or for a |
| -// platform-alias target its instance's (selectedEntry), so the box holding |
| -// I's lease re-selects I for a hop another box sent under I (spec §5.7.3). |
| -// ok only for a route of account satisfying registry.PathTarget that is not |
| -// an attached alias or a regional entry. The purge check for the front |
| -// (frontPathOwns) asks the same question, so a route purges the front's |
| -// pages exactly while a prefix of the front selects it. |
| -func unservedFrontTarget(hosts map[string]upstream, target, account string) (upstream, bool) { |
| - tu, here := hosts[target] |
| - if !here { |
| - return upstream{}, false |
| - } |
| - named := !tu.platformAlias |
| - tu, ok := selectedEntry(hosts, tu) |
| - if !ok || tu.alias || tu.regional != regionalNone || (named && tu.route.Host != target) || |
| - !registry.PathTarget(tu.route) || release.RouteAccount(tu.route) != account { |
| - return upstream{}, false |
| - } |
| - return tu, true |
| -} |
| - |
| // servedName is the key t.hosts answered host under: host itself, or its |
| // one-label catch-all. A log key, so it is never the request's own spelling |
| // of a name only a catch-all serves (logThrottled: never key from remote |
diff --git a/internal/edge/purge_across_test.go b/internal/edge/purge_across_test.go| deleted file mode 100644 |
| index 84e8c89d6..000000000 |
| --- a/internal/edge/purge_across_test.go |
| +++ /dev/null |
| @@ -1,452 +0,0 @@ |
| -package edge |
| - |
| -// Path routes across boxes (#186, spec §7.2): purge for a front host this box |
| -// does not serve. A prefix on hub.example.com (served on betty) selects |
| -// tenant.example.com, served here (case 3), so this box caches the tenant's |
| -// pages under hub.example.com. The tenant purges them by naming that host in |
| -// Carlos-Purge-Host, and the edge honours it only while this box's own |
| -// snapshot still says the prefix selects the purging route, the front is a |
| -// published front route of the claim's account and app, and the purging |
| -// route is the instance served here. |
| - |
| -import ( |
| - "net/http" |
| - "net/http/httptest" |
| - "slices" |
| - "sync/atomic" |
| - "testing" |
| - |
| - "github.com/carlosframework/platform/internal/registry" |
| -) |
| - |
| -// purgeAcrossBackend answers every request with the purge declaration |
| -// purge, naming the front host, after running before (when set) while the |
| -// request is in flight. |
| -type purgeAcrossBackend struct { |
| - purge string |
| - before func() |
| -} |
| - |
| -func (b *purgeAcrossBackend) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| - if b.before != nil { |
| - b.before() |
| - } |
| - w.Header().Set("Carlos-Purge-Host", selFront) |
| - w.Header().Set("Carlos-Purge", b.purge) |
| - w.WriteHeader(http.StatusOK) |
| -} |
| - |
| -// purgeAcrossScene builds this box: the target route tenant.example.com of |
| -// account (app "tenant") served by b, the claim's row acme -> |
| -// tenant.example.com for hub.example.com (account bae, app hub), and |
| -// hub.example.com published on betty as a front route of bae/hub. The cache |
| -// is armed. |
| -func purgeAcrossScene(t *testing.T, account string, b *purgeAcrossBackend) (*selScene, *Edge) { |
| - t.Helper() |
| - backend := httptest.NewServer(b) |
| - t.Cleanup(backend.Close) |
| - s := newSelScene(t) |
| - s.instance(selTarget, account, "tenant", func(r *registry.Route) { r.Addr = backend.Listener.Addr().String() }) |
| - s.path(selFront, "acme", selTarget, selAcct, "hub") |
| - s.publish("betty", selFront, frontRow(selAcct, "hub")) |
| - e := s.build() |
| - e.EnableCache(NewCache(DefaultCacheMaxEntries, DefaultCacheMaxBodyBytes)) |
| - return s, e |
| -} |
| - |
| -// postAcross sends a write on host+urlPath through ServeHTTP and wants it |
| -// served (200) with the purge headers stripped. |
| -func postAcross(t *testing.T, e *Edge, host, urlPath string) { |
| - t.Helper() |
| - rec := httptest.NewRecorder() |
| - e.ServeHTTP(rec, httptest.NewRequest(http.MethodPost, "http://"+host+urlPath, nil)) |
| - if rec.Code != http.StatusOK { |
| - t.Fatalf("POST %s%s = %d, want 200 (served by the target here); body %q", host, urlPath, rec.Code, rec.Body.String()) |
| - } |
| - if got := rec.Header().Get("Carlos-Purge-Host"); got != "" { |
| - t.Fatalf("Carlos-Purge-Host reached the client: %q", got) |
| - } |
| -} |
| - |
| -// wantCase3 pins the precondition: a request for the front's prefix is a |
| -// case 3 local target here, so its responses are cached under the front. |
| -func wantCase3(t *testing.T, s *selScene) { |
| - t.Helper() |
| - got := s.sel(selFront, "/acme/admin") |
| - wantLocal(t, got, selTarget, "acme", selTarget) |
| - if got.Up.front == nil { |
| - t.Fatalf("precondition: selection %s carries no front mark: not case 3", describeSel(got)) |
| - } |
| -} |
| - |
| -func wantCached(t *testing.T, e *Edge, host, path, rawQuery string, want bool, why string) { |
| - t.Helper() |
| - if got := cached(e.cache, host, path, rawQuery); got != want { |
| - t.Fatalf("%s%s?%s cached = %v, want %v: %s", host, path, rawQuery, got, want, why) |
| - } |
| -} |
| - |
| -func TestPurgeAcrossEvictsExactURL(t *testing.T) { |
| - s, e := purgeAcrossScene(t, selAcct, &purgeAcrossBackend{purge: "/acme/events/42?lang=fr"}) |
| - wantCase3(t, s) |
| - seed(t, e.cache, selFront, "/acme/events/42", "lang=fr", "stale") |
| - seed(t, e.cache, selFront, "/acme/events/42", "", "untouched") |
| - |
| - postAcross(t, e, selFront, "/acme/admin") |
| - |
| - wantCached(t, e, selFront, "/acme/events/42", "lang=fr", false, "the target could not purge its own page under the front host") |
| - wantCached(t, e, selFront, "/acme/events/42", "", true, "an exact-URL purge dropped another query") |
| -} |
| - |
| -func TestPurgeAcrossEvictsPath(t *testing.T) { |
| - s, e := purgeAcrossScene(t, selAcct, &purgeAcrossBackend{purge: "/acme/events/42"}) |
| - wantCase3(t, s) |
| - seed(t, e.cache, selFront, "/acme/events/42", "", "stale") |
| - seed(t, e.cache, selFront, "/acme/events/42", "lang=fr", "stale") |
| - seed(t, e.cache, selFront, "/acme/events/43", "", "untouched") |
| - |
| - postAcross(t, e, selFront, "/acme/admin") |
| - |
| - wantCached(t, e, selFront, "/acme/events/42", "", false, "the path purge missed the page") |
| - wantCached(t, e, selFront, "/acme/events/42", "lang=fr", false, "the path purge missed a query variant") |
| - wantCached(t, e, selFront, "/acme/events/43", "", true, "a path purge dropped another path") |
| -} |
| - |
| -func TestPurgeAcrossEvictsWholeHost(t *testing.T) { |
| - for _, purge := range []string{"*", "all"} { |
| - t.Run(purge, func(t *testing.T) { |
| - s, e := purgeAcrossScene(t, selAcct, &purgeAcrossBackend{purge: purge}) |
| - wantCase3(t, s) |
| - seed(t, e.cache, selFront, "/acme/events/42", "", "stale") |
| - seed(t, e.cache, selFront, "/acme/", "", "stale") |
| - seed(t, e.cache, "bystander.example.com", "/acme/events/42", "", "untouched") |
| - |
| - postAcross(t, e, selFront, "/acme/admin") |
| - |
| - wantCached(t, e, selFront, "/acme/events/42", "", false, "the whole-host purge missed a page") |
| - wantCached(t, e, selFront, "/acme/", "", false, "the whole-host purge missed a page") |
| - wantCached(t, e, "bystander.example.com", "/acme/events/42", "", true, "a whole-host purge reached a host nobody named") |
| - }) |
| - } |
| -} |
| - |
| -// The prefix moves to another target while the write is in flight: the |
| -// response was selected under the old table, but its purge is judged against |
| -// the table it lands in, where no prefix of the front selects the purging |
| -// route any more. |
| -func TestPurgeAcrossRefusedAfterPrefixMoves(t *testing.T) { |
| - for _, tc := range []struct { |
| - name string |
| - move func(*registry.Registry) error |
| - }{ |
| - {"moved to another target", func(reg *registry.Registry) error { |
| - return reg.UpsertPath(registry.RoutePath{Host: selFront, Prefix: "acme", Target: "moved.example.com", Account: selAcct, App: "hub"}) |
| - }}, |
| - {"removed", func(reg *registry.Registry) error { |
| - if err := reg.UpsertPath(registry.RoutePath{Host: selFront, Prefix: "other", Target: "moved.example.com", Account: selAcct, App: "hub"}); err != nil { |
| - return err |
| - } |
| - return reg.DeletePath(selFront, "acme") |
| - }}, |
| - {"target instance replaced", func(reg *registry.Registry) error { |
| - return reg.Upsert(registry.Route{Host: selTarget, Account: selAcct, App: "tenant2", Kind: "instance", Status: "ready", Addr: "127.0.0.1:1"}) |
| - }}, |
| - } { |
| - t.Run(tc.name, func(t *testing.T) { |
| - b := &purgeAcrossBackend{purge: "*"} |
| - s, e := purgeAcrossScene(t, selAcct, b) |
| - wantCase3(t, s) |
| - seed(t, e.cache, selFront, "/acme/events/42", "", "cached") |
| - var moveErr error |
| - b.before = func() { |
| - if moveErr = tc.move(s.reg); moveErr == nil { |
| - moveErr = e.Reload() |
| - } |
| - } |
| - |
| - postAcross(t, e, selFront, "/acme/admin") |
| - |
| - if moveErr != nil { |
| - t.Fatalf("move: %v", moveErr) |
| - } |
| - wantCached(t, e, selFront, "/acme/events/42", "", true, "a route no prefix of the front selects any more purged its pages") |
| - }) |
| - } |
| -} |
| - |
| -// The front's published row no longer names a front route of the claim's |
| -// account and app: the remote map alone grants nothing. The write arrives on |
| -// the target's own host, so the purge check is pinned whatever selection |
| -// does with the front. |
| -func TestPurgeAcrossRefusedWhenFrontNotPublished(t *testing.T) { |
| - for _, tc := range []struct { |
| - name, row string // "" unpublishes the front |
| - }{ |
| - {"control", frontRow(selAcct, "hub")}, |
| - {"another app", frontRow(selAcct, "other")}, |
| - {"another account", frontRow(selOther, "hub")}, |
| - {"not a front", homeRow(selAcct, "hub", false, true)}, |
| - {"unpublished", ""}, |
| - } { |
| - t.Run(tc.name, func(t *testing.T) { |
| - backend := httptest.NewServer(&purgeAcrossBackend{purge: "*"}) |
| - t.Cleanup(backend.Close) |
| - s := newSelScene(t) |
| - s.instance(selTarget, selAcct, "tenant", func(r *registry.Route) { r.Addr = backend.Listener.Addr().String() }) |
| - s.path(selFront, "acme", selTarget, selAcct, "hub") |
| - s.publish("cindy", "unrelated.example.com", frontRow(selAcct, "hub")) |
| - if tc.row != "" { |
| - s.publish("betty", selFront, tc.row) |
| - } |
| - e := s.build() |
| - e.EnableCache(NewCache(DefaultCacheMaxEntries, DefaultCacheMaxBodyBytes)) |
| - seed(t, e.cache, selFront, "/acme/events/42", "", "cached") |
| - |
| - postAcross(t, e, selTarget, "/admin") |
| - |
| - wantCached(t, e, selFront, "/acme/events/42", "", tc.name != "control", "the front's published row decides whether its pages are purgeable here") |
| - }) |
| - } |
| -} |
| - |
| -// The account boundary holds across boxes too. A row naming a target in |
| -// another account (written by an older binary, or by hand) never lets that |
| -// target purge the front's pages: selection refuses it (so the write |
| -// arrives on the target's own host), and so does the purge check. |
| -func TestPurgeAcrossRefusedForOtherAccount(t *testing.T) { |
| - for _, tc := range []struct { |
| - account string |
| - purged bool |
| - }{ |
| - {selAcct, true}, // control: the same write in the claim's account |
| - {selOther, false}, |
| - } { |
| - t.Run(tc.account, func(t *testing.T) { |
| - _, e := purgeAcrossScene(t, tc.account, &purgeAcrossBackend{purge: "*"}) |
| - seed(t, e.cache, selFront, "/acme/events/42", "", "cached") |
| - |
| - postAcross(t, e, selTarget, "/admin") |
| - |
| - wantCached(t, e, selFront, "/acme/events/42", "", !tc.purged, "the account boundary decides") |
| - }) |
| - } |
| -} |
| - |
| -// Scoped to the route a prefix selects: another route of the claim's account |
| -// on this box, which no prefix names, cannot purge the front. |
| -func TestPurgeAcrossRefusedForAnUnselectedRoute(t *testing.T) { |
| - backend := httptest.NewServer(&purgeAcrossBackend{purge: "*"}) |
| - t.Cleanup(backend.Close) |
| - s := newSelScene(t) |
| - s.instance(selTarget, selAcct, "tenant") |
| - s.instance("bystander.example.com", selAcct, "tenant", func(r *registry.Route) { r.Addr = backend.Listener.Addr().String() }) |
| - s.path(selFront, "acme", selTarget, selAcct, "hub") |
| - s.publish("betty", selFront, frontRow(selAcct, "hub")) |
| - e := s.build() |
| - e.EnableCache(NewCache(DefaultCacheMaxEntries, DefaultCacheMaxBodyBytes)) |
| - seed(t, e.cache, selFront, "/acme/events/42", "", "cached") |
| - |
| - postAcross(t, e, "bystander.example.com", "/admin") |
| - |
| - wantCached(t, e, selFront, "/acme/events/42", "", true, "a route no prefix selects purged the front") |
| -} |
| - |
| -// A platform-alias target is its instance (selectedEntry): the instance, |
| -// whose route serves the front's prefix, purges its pages under the front, |
| -// and the alias row itself never acts for it. |
| -func TestPurgeAcrossPlatformAliasTarget(t *testing.T) { |
| - s := newSelScene(t) |
| - const inst, alias = "a.bae.oncarlos.com", "shop.bae.oncarlos.com" |
| - s.instance(inst, selAcct, "shop", func(r *registry.Route) { r.Addr, r.Socket = "", "/s/a.sock" }) |
| - s.instance(alias, selAcct, "shop", func(r *registry.Route) { r.Addr, r.Socket, r.Platform = "", "/s/a.sock", true }) |
| - s.path(selFront, "shop", alias, selAcct, "hub") |
| - s.publish("betty", selFront, frontRow(selAcct, "hub")) |
| - e := s.build() |
| - e.EnableCache(NewCache(DefaultCacheMaxEntries, DefaultCacheMaxBodyBytes)) |
| - got := s.sel(selFront, "/shop/x") |
| - wantLocal(t, got, inst, "shop", alias) |
| - |
| - seed(t, e.cache, selFront, "/shop/x", "", "cached") |
| - h := http.Header{} |
| - h.Set("Carlos-Purge-Host", selFront) |
| - h.Set("Carlos-Purge", "/shop/x") |
| - e.applyPurgeHeader(got.Up.route, selFront, "", h) |
| - wantCached(t, e, selFront, "/shop/x", "", false, "the platform alias's instance could not purge its page under the front") |
| -} |
| - |
| -// The control channel (ownsHost) and the header's execution guard are one |
| -// rule: purgeOwnsIn answers both from one table. |
| -func TestPurgeAcrossOwnsHostFromOneTable(t *testing.T) { |
| - s, e := purgeAcrossScene(t, selAcct, &purgeAcrossBackend{purge: "*"}) |
| - tenant := e.current()[selTarget].route |
| - if !e.ownsHost(tenant, selFront) { |
| - t.Fatal("ownsHost refuses the front host whose prefix selects the tenant here") |
| - } |
| - other := registry.Route{Host: "bystander.example.com", Account: selAcct, App: "tenant"} |
| - if e.ownsHost(other, selFront) { |
| - t.Fatal("ownsHost lets a route no prefix selects own the front host") |
| - } |
| - s.path(selFront, "acme", "moved.example.com", selAcct, "hub") |
| - if err := e.Reload(); err != nil { |
| - t.Fatal(err) |
| - } |
| - if e.ownsHost(tenant, selFront) { |
| - t.Fatal("ownsHost still grants the front after its prefix moved") |
| - } |
| -} |
| - |
| -// ---- a front shadowed here by a catch-all (fix round 1) -------------------- |
| -// |
| -// The catch-all *.example.com of the route wild.example.net also answers |
| -// hub.example.com here, while hub.example.com's claim (account bae) sends |
| -// /acme to tenant.example.com here (case 3). Both tenancies would share one |
| -// LRU namespace, hub.example.com. The rule: a case 3 response uses the LRU |
| -// under a front only while nothing here answers that front |
| -// (caseThreeCacheable), and a catch-all never purges a name another |
| -// account's claim path-routes here (otherAccountFront). |
| - |
| -const shadowWild = "wild.example.net" |
| - |
| -// shadowBackend answers a GET with a cacheable body, counting them, and a |
| -// POST with the purge declaration set on it. |
| -type shadowBackend struct { |
| - gets atomic.Int64 |
| - purgeHost, purge string |
| -} |
| - |
| -func (b *shadowBackend) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| - if r.Method == http.MethodGet { |
| - b.gets.Add(1) |
| - w.Header().Set("Cache-Control", "public, max-age=600") |
| - w.Write([]byte(r.Host + r.URL.Path)) |
| - return |
| - } |
| - if b.purgeHost != "" { |
| - w.Header().Set("Carlos-Purge-Host", b.purgeHost) |
| - } |
| - w.Header().Set("Carlos-Purge", b.purge) |
| - w.WriteHeader(http.StatusOK) |
| -} |
| - |
| -// shadowScene is purgeAcrossScene's box plus the catch-all route |
| -// wild.example.net of wildAccount (app "wild"), aliased as *.example.com. |
| -func shadowScene(t *testing.T, wildAccount string) (s *selScene, e *Edge, tenant, wild *shadowBackend) { |
| - t.Helper() |
| - tenant, wild = &shadowBackend{}, &shadowBackend{} |
| - tsrv, wsrv := httptest.NewServer(tenant), httptest.NewServer(wild) |
| - t.Cleanup(tsrv.Close) |
| - t.Cleanup(wsrv.Close) |
| - s = newSelScene(t) |
| - s.instance(selTarget, selAcct, "tenant", func(r *registry.Route) { r.Addr = tsrv.Listener.Addr().String() }) |
| - s.instance(shadowWild, wildAccount, "wild", func(r *registry.Route) { r.Addr = wsrv.Listener.Addr().String() }) |
| - if err := s.reg.UpsertAlias(registry.RouteAlias{Alias: "*.example.com", Host: shadowWild, Account: wildAccount, App: "wild"}); err != nil { |
| - t.Fatal(err) |
| - } |
| - s.path(selFront, "acme", selTarget, selAcct, "hub") |
| - s.publish("betty", selFront, frontRow(selAcct, "hub")) |
| - e = s.build() |
| - e.EnableCache(NewCache(DefaultCacheMaxEntries, DefaultCacheMaxBodyBytes)) |
| - got := s.sel(selFront, "/acme/page") |
| - wantLocal(t, got, selTarget, "acme", selTarget) |
| - if got.Up.front == nil { |
| - t.Fatalf("fixture: %s is not a case 3 selection", describeSel(got)) |
| - } |
| - if !s.sel(selFront, "/other").OK || s.sel(selFront, "/other").Up.route.Host != shadowWild { |
| - t.Fatalf("fixture: the catch-all does not answer %s", selFront) |
| - } |
| - return s, e, tenant, wild |
| -} |
| - |
| -func getAcross(t *testing.T, e *Edge, host, urlPath string) { |
| - t.Helper() |
| - rec := httptest.NewRecorder() |
| - e.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "http://"+host+urlPath, nil)) |
| - if rec.Code != http.StatusOK { |
| - t.Fatalf("GET %s%s = %d, want 200; body %q", host, urlPath, rec.Code, rec.Body.String()) |
| - } |
| -} |
| - |
| -// A case 3 response under a shadowed front is neither stored nor answered |
| -// from the LRU, and its target's purge of that front is a no-op: the |
| -// catch-all's entry under the same name stays. Once the catch-all is gone, |
| -// case 3 responses cache and purge again. |
| -func TestPurgeAcrossShadowedFrontNotStored(t *testing.T) { |
| - s, e, tenant, wild := shadowScene(t, selOther) |
| - |
| - getAcross(t, e, selFront, "/acme/page") |
| - getAcross(t, e, selFront, "/acme/page") |
| - if n := tenant.gets.Load(); n != 2 { |
| - t.Fatalf("the target saw %d GETs for a shadowed front, want 2 (never answered from the LRU)", n) |
| - } |
| - wantCached(t, e, selFront, "/acme/page", "", false, "a case 3 response was stored under a front a catch-all shadows") |
| - |
| - getAcross(t, e, selFront, "/other") |
| - getAcross(t, e, selFront, "/other") |
| - if n := wild.gets.Load(); n != 1 { |
| - t.Fatalf("control: the catch-all saw %d GETs, want 1 (its own answer is cached)", n) |
| - } |
| - wantCached(t, e, selFront, "/other", "", true, "control: the catch-all's answer is cached under the front") |
| - |
| - tenant.purgeHost, tenant.purge = selFront, "*" |
| - postAcross(t, e, selFront, "/acme/admin") |
| - wantCached(t, e, selFront, "/other", "", true, "the case 3 target purged a shadowed front, the catch-all's entry included") |
| - |
| - if err := s.reg.DeleteAlias("*.example.com"); err != nil { |
| - t.Fatal(err) |
| - } |
| - if err := e.Reload(); err != nil { |
| - t.Fatal(err) |
| - } |
| - getAcross(t, e, selFront, "/acme/page") |
| - getAcross(t, e, selFront, "/acme/page") |
| - if n := tenant.gets.Load(); n != 3 { |
| - t.Fatalf("after the catch-all left, the target saw %d GETs, want 3 (the second answered from the LRU)", n) |
| - } |
| - wantCached(t, e, selFront, "/acme/page", "", true, "an unshadowed case 3 response was not stored") |
| - postAcross(t, e, selFront, "/acme/admin") |
| - wantCached(t, e, selFront, "/acme/page", "", false, "the target could not purge its page under an unshadowed front") |
| -} |
| - |
| -// A catch-all never purges a name another account's claim path-routes here: |
| -// not by Carlos-Purge-Host (a path, "*" or "all") and not by "all"'s |
| -// expansion over the names it answers, on the response header or the |
| -// control channel. A catch-all of the claim's own account keeps today's |
| -// authority. The claim's entries are seeded: one stored before the |
| -// catch-all appeared (a shadowed front stores none, as above). |
| -func TestPurgeAcrossCatchAllCannotPurgeAnotherAccountsFront(t *testing.T) { |
| - for _, tc := range []struct { |
| - name, purgeHost, purge string |
| - }{ |
| - {"named path", selFront, "/acme/events/42"}, |
| - {"named *", selFront, "*"}, |
| - {"named all", selFront, "all"}, |
| - {"own all", "", "all"}, |
| - } { |
| - for _, account := range []string{selOther, selAcct} { |
| - t.Run(tc.name+"/"+account, func(t *testing.T) { |
| - _, e, _, wild := shadowScene(t, account) |
| - seed(t, e.cache, selFront, "/acme/events/42", "", "the claim's page") |
| - wild.purgeHost, wild.purge = tc.purgeHost, tc.purge |
| - |
| - postAcross(t, e, shadowWild, "/write") |
| - |
| - same := account == selAcct |
| - wantCached(t, e, selFront, "/acme/events/42", "", !same, "a catch-all's purge authority over a path-routed name follows the claim's account") |
| - }) |
| - } |
| - } |
| - for _, account := range []string{selOther, selAcct} { |
| - t.Run("control channel/"+account, func(t *testing.T) { |
| - _, e, _, _ := shadowScene(t, account) |
| - seed(t, e.cache, selFront, "/acme/events/42", "", "the claim's page") |
| - wild := e.current()[shadowWild].route |
| - got := slices.Contains(e.instanceHosts(wild, e.cache.cachedHosts()), selFront) |
| - if same := account == selAcct; got != same { |
| - t.Fatalf("instanceHosts lists %s = %v, want %v", selFront, got, same) |
| - } |
| - if got := e.ownsHost(wild, selFront); got != (account == selAcct) { |
| - t.Fatalf("ownsHost(catch-all, %s) = %v", selFront, got) |
| - } |
| - }) |
| - } |
| -} |
diff --git a/internal/edge/purge_header.go b/internal/edge/purge_header.go| index 165ba87b4..d6bcfdea0 100644 |
| --- a/internal/edge/purge_header.go |
| +++ b/internal/edge/purge_header.go |
| @@ -143,7 +143,7 @@ const purgeInstanceTarget = "all" |
| // - It redirects EVERY target in the same response, "*" and the cap-degrade |
| // path included, to EVERY accepted host. The override decides WHICH |
| // hosts; §6.1 still decides which entries of each. |
| -// - Resolved against the CURRENT route table at response time (e.table()), |
| +// - Resolved against the CURRENT route table at response time (e.current()), |
| // never a snapshot taken when the proxy was built — a sibling added by the |
| // very reload that rebuilt this proxy must still validate. |
| // - Stripped from the response UNCONDITIONALLY, in the same place |
| @@ -309,9 +309,9 @@ func scrubInboundPurgeHeader(pr *httputil.ProxyRequest) { |
| // time the response comes back. |
| // |
| // The OVERRIDE side is deliberately the other way round: the named host is |
| -// looked up in e.table() at response time (see resolvePurgeHosts), because |
| +// looked up in e.current() at response time (see resolvePurgeHosts), because |
| // the route table is live and a sibling added since this proxy was built must |
| -// still validate. e.table() is an atomic pointer load, so reading it from |
| +// still validate. e.current() is an atomic pointer load, so reading it from |
| // this hook needs no lock and cannot tear against a concurrent Reload. |
| func (e *Edge) purgeModifier(rt registry.Route) func(*http.Response) error { |
| return func(resp *http.Response) error { |
| @@ -367,17 +367,17 @@ func (e *Edge) applyPurgeHeader(rt registry.Route, asked, public string, h http. |
| } |
| // ONE snapshot of the route table for the whole declaration: the hosts |
| // it reaches, the instance each acts for, and the hosts "all" expands to |
| - // are all judged against the same table, its remote path map included. |
| - t := e.purgeTable() |
| - owned, ok := e.resolvePurgeOwnersIn(t, rt, public, declared) |
| + // are all judged against the same table. |
| + cur := e.current() |
| + owned, ok := e.resolvePurgeOwnersIn(cur, rt, public, declared) |
| if !ok { |
| return |
| } |
| pages := owned |
| if len(declared) == 0 { |
| - pages = pageHostsFor(t.hosts, rt, asked) |
| + pages = pageHostsFor(cur, rt, asked) |
| } |
| - e.applyPurgeTargets(t, rt.Host, owned, pages, joined) |
| + e.applyPurgeTargets(cur, rt.Host, owned, pages, joined) |
| } |
| // purgeHost is one host a purge declaration reaches, with the instance it |
| @@ -430,7 +430,7 @@ func pageHostsFor(m map[string]upstream, rt registry.Route, asked string) []purg |
| // |
| // declared is every Carlos-Purge-Host LINE, already removed from the response. |
| func (e *Edge) resolvePurgeHosts(rt registry.Route, declared []string) ([]string, bool) { |
| - owned, ok := e.resolvePurgeOwnersIn(e.purgeTable(), rt, "", declared) |
| + owned, ok := e.resolvePurgeOwnersIn(e.current(), rt, "", declared) |
| if !ok { |
| return nil, false |
| } |
| @@ -441,14 +441,11 @@ func (e *Edge) resolvePurgeHosts(rt registry.Route, declared []string) ([]string |
| return hosts, true |
| } |
| -// resolvePurgeOwnersIn is resolvePurgeHosts against the snapshot t, with |
| +// resolvePurgeOwnersIn is resolvePurgeHosts against the snapshot cur, with |
| // the instance each accepted host acts for (purgeHost). public, when not |
| // empty, is the public host a linked request was served under |
| -// (ServeLinked): naming it is naming rt's own host. A host t.hosts does not |
| -// serve is accepted, for rt, only as a front whose prefix selects rt here |
| -// (frontPathOwns); any other is skipped as unserved. |
| -func (e *Edge) resolvePurgeOwnersIn(t *routeTable, rt registry.Route, public string, declared []string) ([]purgeHost, bool) { |
| - cur := t.hosts |
| +// (ServeLinked): naming it is naming rt's own host. |
| +func (e *Edge) resolvePurgeOwnersIn(cur map[string]upstream, rt registry.Route, public string, declared []string) ([]purgeHost, bool) { |
| if len(declared) == 0 { |
| return []purgeHost{{rt.Host, rt}}, true |
| } |
| @@ -499,10 +496,10 @@ func (e *Edge) resolvePurgeOwnersIn(t *routeTable, rt registry.Route, public str |
| return nil, false |
| } |
| } |
| - // cur is t.hosts, from e.table(), not a captured map: the route table is |
| - // live, and a sibling added after this proxy was built must still |
| - // validate. ONE snapshot for the whole list, its remote path map |
| - // included, so every entry is judged against the same table. |
| + // cur is e.current(), not a captured map: the route table is live, and a |
| + // sibling added after this proxy was built must still validate. ONE |
| + // snapshot for the whole list, so every entry is judged against the same |
| + // table. |
| hosts := make([]purgeHost, 0, len(vals)) |
| var unserved []string |
| servingChecked := false |
| @@ -528,20 +525,11 @@ func (e *Edge) resolvePurgeOwnersIn(t *routeTable, rt registry.Route, public str |
| // the name listed here. An exact key, another tenant's included, |
| // still wins over the wildcard, and either way the route found is the |
| // one judged below. |
| - if caseThreeCacheable(t, host) { |
| - // A front host this box does not serve (path routes across |
| - // boxes, case 3): rt's pages under it are rt's own while a |
| - // prefix of it selects rt here, judged in t. Anything else, |
| - // another account's front included, is skipped as unserved, |
| - // exactly as before: this box holds no route for it to judge. |
| - if rm, mapped := t.remote[host]; mapped && e.frontPathOwns(cur, rm, rt, host) { |
| - hosts = append(hosts, purgeHost{host, rt}) |
| - continue |
| - } |
| + up, ok := lookupIn(cur, host) |
| + if !ok { |
| unserved = append(unserved, host) |
| continue |
| } |
| - up, _ := lookupIn(cur, host) |
| if !servingChecked { |
| // The SERVING side is a value captured when this proxy was built, |
| // and a reload can land between that capture and this response — |
| @@ -566,15 +554,6 @@ func (e *Edge) resolvePurgeOwnersIn(t *routeTable, rt registry.Route, public str |
| } |
| servingChecked = true |
| } |
| - if otherAccountFront(t, host, rt) { |
| - // Served here only through a catch-all, while another account's |
| - // claim path-routes it: that account's pages may be cached |
| - // under it (spec §7.2), and a catch-all never purges them. |
| - e.logPurgeIssue("override-tenancy", rt.Host, fmt.Sprintf( |
| - "%s (account %q) declared Carlos-Purge-Host %q, which another account's path routes send to this box — a purge never crosses an account boundary; the whole declaration is ignored", |
| - rt.Host, rt.Account, truncateForLog(host))) |
| - return nil, false |
| - } |
| if !purgeHostInTenancy(rt, up) { |
| e.logPurgeIssue("override-tenancy", rt.Host, fmt.Sprintf( |
| "%s (app %q, account %q) declared Carlos-Purge-Host %q, which belongs to app %q, account %q — a purge crosses an app boundary only when %q path-routes to the serving route, and never crosses an account boundary; the whole declaration is ignored", |
| @@ -748,12 +727,12 @@ func validPurgeOverrideHost(h string) bool { |
| // both, wiping a host nobody asked about while leaving the stale pages the app |
| // was trying to invalidate. |
| // |
| -// Every LRU purge is of a host its owner still owns in t (purgeOwnsIn, ledger |
| +// Every LRU purge is of a host its owner still owns in cur (purgeOwns, ledger |
| // R10): a response whose hostname moved to another instance while it was in |
| // flight purges nothing of that instance's from the LRU, its primary host |
| // included. Page clears need no such test: they are pinned to the owner's |
| // own scope (clearPages). |
| -func (e *Edge) applyPurgeTargets(t *routeTable, from string, hosts, pageHosts []purgeHost, joined string) { |
| +func (e *Edge) applyPurgeTargets(cur map[string]upstream, from string, hosts, pageHosts []purgeHost, joined string) { |
| if len(hosts) == 0 { |
| return |
| } |
| @@ -765,7 +744,7 @@ func (e *Edge) applyPurgeTargets(t *routeTable, from string, hosts, pageHosts [] |
| // lru is the hosts whose LRU entries this declaration may purge. |
| lru := make([]purgeHost, 0, len(hosts)) |
| for _, p := range hosts { |
| - if e.purgeOwnsIn(t, p.owner, p.host) { |
| + if purgeOwns(cur, p.owner, p.host) { |
| lru = append(lru, p) |
| } |
| } |
| @@ -800,17 +779,17 @@ func (e *Edge) applyPurgeTargets(t *routeTable, from string, hosts, pageHosts [] |
| // would refuse a target that is not a path. |
| // |
| // Each host is purged as "*" would purge it, and the expansion is to the |
| - // hosts t serves as that host's OWNER (purgeHost), never to whatever |
| + // hosts cur serves as that host's OWNER (purgeHost), never to whatever |
| // instance holds the hostname now: a response still in flight when its |
| // hostname moved to another instance cannot reach that instance's |
| // aliases or pages. |
| if slices.Contains(targets, purgeInstanceTarget) { |
| cached := e.cache.cachedHosts() |
| for _, p := range hosts { |
| - if e.purgeOwnsIn(t, p.owner, p.host) { |
| + if purgeOwns(cur, p.owner, p.host) { |
| e.cache.PurgeHost(p.host) |
| } |
| - for _, h := range instanceHostsIn(t, p.owner, cached) { |
| + for _, h := range instanceHostsIn(cur, p.owner, cached) { |
| if h != p.host { |
| e.cache.PurgeHost(h) |
| } |
| @@ -875,34 +854,16 @@ func (e *Edge) applyPurgeTargets(t *routeTable, from string, hosts, pageHosts [] |
| } |
| } |
| -// purgeOwnsIn reports whether a purge acting for owner may touch the LRU |
| -// entries cached under host, judged in the one routing snapshot t (ledger |
| -// R10, purge authority): t.hosts resolves host (lookupIn) to owner's |
| -// instance, or host path-routes to owner while t.hosts still serves owner's |
| -// primary host as owner's instance (the path-routing exception: the pages |
| -// owner serves under host are its own). A hostname that has moved to another |
| -// instance is that instance's, so a purge still on its way from the old one, |
| -// by a response or a control listener built before the move, leaves its LRU |
| +// purgeOwns reports whether a purge acting for owner may touch the LRU |
| +// entries cached under host, judged in the one routing snapshot m (ledger |
| +// R10, purge authority): m resolves host (lookupIn) to owner's instance, or |
| +// host path-routes to owner while m still serves owner's primary host as |
| +// owner's instance (the path-routing exception: the pages owner serves |
| +// under host are its own). A hostname that has moved to another instance is |
| +// that instance's, so a purge still on its way from the old one, by a |
| +// response or a control listener built before the move, leaves its LRU |
| // entries alone. |
| -// |
| -// A host t.hosts does not resolve at all (caseThreeCacheable) is owner's |
| -// only as a front another box serves whose prefix selects owner here |
| -// (frontPathOwns, spec §7.2). A host t.hosts resolves only through a |
| -// catch-all while another account's claim path-routes it is never owner's |
| -// unless owner is in that account (otherAccountFront). Every other host is |
| -// judged as before path routes crossed boxes. |
| -func (e *Edge) purgeOwnsIn(t *routeTable, owner registry.Route, host string) bool { |
| - if t == nil { |
| - return false |
| - } |
| - m := t.hosts |
| - if caseThreeCacheable(t, host) { |
| - rm, mapped := t.remote[host] |
| - return mapped && e.frontPathOwns(m, rm, owner, host) |
| - } |
| - if otherAccountFront(t, host, owner) { |
| - return false |
| - } |
| +func purgeOwns(m map[string]upstream, owner registry.Route, host string) bool { |
| up, ok := lookupIn(m, host) |
| if !ok { |
| return false |
| @@ -917,90 +878,6 @@ func (e *Edge) purgeOwnsIn(t *routeTable, owner registry.Route, host string) boo |
| return ok && sameInstance(primary.route, owner) |
| } |
| -// frontPathOwns reports whether owner's pages under host, a front this box |
| -// does not serve, are owner's to purge (path routes across boxes, case 3, |
| -// spec §7.2), judged in one snapshot: hosts and rm, host's remote path map, |
| -// come from the same routeTable. Each of these must hold: |
| -// |
| -// - owner is in the claim's account (rm.account, as release.RouteAccount |
| -// names a route's account); |
| -// - the home map's exact row for host is a front route of the claim's |
| -// account and app, as selection requires before it reads rm |
| -// (selectForUnservedFront); |
| -// - a prefix of rm selects owner here: its target is one unservedFrontTarget |
| -// answers with owner's instance, which is hosts[owner.Host] (a |
| -// platform-alias target is its instance). So owner is still the instance |
| -// served here, and a prefix that moved, or an owner replaced while its |
| -// response was in flight, grants nothing. |
| -// |
| -// Selection and purge ask the same question of the same functions, so a |
| -// route purges a front's pages exactly while a request for one of its |
| -// prefixes would be served by that route here. |
| -// |
| -// A linear scan of rm's prefixes, as pathRoutesTo is, for the same reason: |
| -// it runs only for a purge naming such a host, and a claim's map is capped |
| -// (domains.MaxPathsPerClaim). The cheap name test runs first, so only a |
| -// prefix naming owner's own host or a platform alias of it is judged. |
| -func (e *Edge) frontPathOwns(hosts map[string]upstream, rm remotePathMap, owner registry.Route, host string) bool { |
| - if owner.Host == "" || release.RouteAccount(owner) != rm.account { |
| - return false |
| - } |
| - fi, ok := e.homes.Load().exactPathRoute(host) |
| - if !ok || !fi.Front || fi.Account != rm.account || fi.App != rm.app { |
| - return false |
| - } |
| - for _, target := range rm.prefixes { |
| - if target != owner.Host { |
| - if tu, here := hosts[target]; !here || !tu.platformAlias || tu.route.Host != owner.Host { |
| - continue |
| - } |
| - } |
| - if tu, ok := unservedFrontTarget(hosts, target, rm.account); ok && sameInstance(tu.route, owner) { |
| - return true |
| - } |
| - } |
| - return false |
| -} |
| - |
| -// caseThreeCacheable reports whether nothing on this box answers host in t: |
| -// no exact entry and no catch-all (lookupIn misses). It is the one rule for |
| -// a front host's cache namespace (spec §7.2): a case 3 response (up.front |
| -// set) is looked up in and stored to the response LRU under host only then |
| -// (ServeHTTP), and a case 3 target purges host only then (purgeOwnsIn, |
| -// resolvePurgeOwnersIn). So a front shadowed here by a catch-all never |
| -// shares its LRU entries between the catch-all's tenancy and the target's: |
| -// the target stores nothing under it and purges nothing under it. Nil t (no |
| -// table yet) answers false. |
| -func caseThreeCacheable(t *routeTable, host string) bool { |
| - if t == nil { |
| - return false |
| - } |
| - _, served := lookupIn(t.hosts, host) |
| - return !served |
| -} |
| - |
| -// otherAccountFront reports whether a claim of another account than owner's |
| -// path-routes host from this box: t.remote holds host's map, whose account |
| -// is not release.RouteAccount(owner). The remote map never holds a name this |
| -// box serves exactly (buildRemotePaths), so host is answered here, if at |
| -// all, through a catch-all, and that catch-all holds no purge authority over |
| -// it: not by Carlos-Purge-Host, "*" or "all" (purgeOwnsIn, |
| -// resolvePurgeOwnersIn, instanceHostsIn). A catch-all of the claim's own |
| -// account keeps today's authority. |
| -func otherAccountFront(t *routeTable, host string, owner registry.Route) bool { |
| - rm, ok := t.remote[host] |
| - return ok && rm.account != release.RouteAccount(owner) |
| -} |
| - |
| -// purgeTable is the published routing snapshot, or an empty one before the |
| -// first Reload, so a purge judged then finds nothing to own. |
| -func (e *Edge) purgeTable() *routeTable { |
| - if t := e.table(); t != nil { |
| - return t |
| - } |
| - return &routeTable{} |
| -} |
| - |
| // logPurgeIssue rate-limits one class of purge complaint for one host, using |
| // the same first-then-every-300th shape as the registry watcher in edge.go. |
| // |