Merge remote-tracking branch 'origin/main' into sqlite-integrity-safe
# Conflicts: # internal/provision/testdata/plan14-root-reads-chain.tsv
30 files changed,
+958
−53
.amadan/code-health.tsv+1 −1docs/superpowers/notes/census-proposal-1682-fleet-door-walk.md+11 −0docs/superpowers/notes/census-proposal-1682-floor-slow-line.md+11 −0docs/superpowers/reviews/ASTRA-REVIEW-BRIEF-1682-fleet-door-walk-R1.md+40 −0docs/superpowers/reviews/ASTRA-REVIEW-BRIEF-1682-floor-slow-line-R1.md+32 −0internal/console/claim_invariant_test.go+3 −1internal/edge/fleetdoor_walk_e2e_test.go+90 −0internal/fleetapi/fleetapi.go+8 −0internal/fleetapi/fleetapi_test.go+17 −0internal/host/agent.go+1 −25internal/host/instancesfloor.go+96 −0internal/host/instancesfloor_test.go+48 −0internal/host/startupmeasure_e2e_test.go+16 −3internal/host/startuptiming.go+9 −2internal/host/startuptiming_door_test.go+81 −0internal/host/startuptiming_test.go+11 −1internal/host/walkshare_e2e_test.go+14 −6internal/hostops/listdirs_shape_test.go+30 −0internal/hostops/mutation_boundary.go+2 −1internal/hostops/record_writes.go+3 −0internal/mail/claim_gate.go+3 −1internal/mail/listdirs_shape_test.go+22 −0internal/provision/applisting_door.go+90 −0internal/provision/applisting_door_test.go+263 −0internal/provision/reconcile.go+15 −7internal/provision/testdata/plan14-root-reads-1682-fleet-door-walk.tsv+7 −0internal/provision/testdata/plan14-root-reads-1682-floor-slow-line.tsv+3 −0internal/provision/testdata/plan14-root-reads-chain.tsv+2 −1internal/provision/walkshare.go+6 −4internal/release/store.go+23 −0
diff --git a/.amadan/code-health.tsv b/.amadan/code-health.tsv| index ec6509e54..fe9c4b513 100644 |
| --- a/.amadan/code-health.tsv |
| +++ b/.amadan/code-health.tsv |
| @@ -2216,7 +2216,7 @@ file-lines . apimode_test.go - 3530 # raised: fdc912b (batch 2, #1123) landed be |
| file-lines internal/activator activator.go - 3785 # raised: the Service.ConfigBeforeWake field and doWakeOnce's one call to it (the body lives in configbeforewake.go); before it, #1290 step 2c |
| file-lines internal/activator activator_test.go - 5471 |
| file-lines internal/console server.go - 4051 # raised: public shares, Config.Shares (one field; the settings type and every share function live in shares.go) |
| -file-lines internal/host agent.go - 3118 # raised: runAgent's one-line publication of the edge's backhaul refusal counters (#1535); their helpers live in backhaulshed.go |
| +file-lines internal/host agent.go - 3097 # raised: runAgent's one-line publication of the edge's backhaul refusal counters (#1535); their helpers live in backhaulshed.go |
| file-lines internal/provision reconcile_test.go - 3094 |
| file-lines internal/registry registry_test.go - 3261 |
| release-importers internal/release - - 66 # raised: scripts/pathmapcheck reads claims and edges files from the store (#186 pre-roll check) |
diff --git a/docs/superpowers/notes/census-proposal-1682-fleet-door-walk.md b/docs/superpowers/notes/census-proposal-1682-fleet-door-walk.md| new file mode 100644 |
| index 000000000..5bf41c65f |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-1682-fleet-door-walk.md |
| @@ -0,0 +1,11 @@ |
| +# Census approval: 1682-fleet-door-walk |
| + |
| +Ruling `census-ruling-1682-fleet-door-walk`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| + |
| +Envelopes re-pinned: `internal/fleetapi`, `internal/host`, `internal/hostops`, `internal/provision`, `internal/release`. |
| + |
| +Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner. |
| + |
| +Seal: `dc00dc6bab094e8c81ab4e083a0b6a122ea886a70f8dca4885b5cf8a2bc3b177` → `dc00dc6bab094e8c81ab4e083a0b6a122ea886a70f8dca4885b5cf8a2bc3b177`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-1682-fleet-door-walk.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/docs/superpowers/notes/census-proposal-1682-floor-slow-line.md b/docs/superpowers/notes/census-proposal-1682-floor-slow-line.md| new file mode 100644 |
| index 000000000..4a14ee989 |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-1682-floor-slow-line.md |
| @@ -0,0 +1,11 @@ |
| +# Census approval: 1682-floor-slow-line |
| + |
| +Ruling `census-ruling-1682-floor-slow-line`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| + |
| +Envelopes re-pinned: `internal/host`. |
| + |
| +Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner. |
| + |
| +Seal: `dc00dc6bab094e8c81ab4e083a0b6a122ea886a70f8dca4885b5cf8a2bc3b177` → `dc00dc6bab094e8c81ab4e083a0b6a122ea886a70f8dca4885b5cf8a2bc3b177`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-1682-floor-slow-line.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/docs/superpowers/reviews/ASTRA-REVIEW-BRIEF-1682-fleet-door-walk-R1.md b/docs/superpowers/reviews/ASTRA-REVIEW-BRIEF-1682-fleet-door-walk-R1.md| new file mode 100644 |
| index 000000000..fd0435014 |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/ASTRA-REVIEW-BRIEF-1682-fleet-door-walk-R1.md |
| @@ -0,0 +1,40 @@ |
| +# Review brief: branch fix/1682-fleet-door-walk, round 1 of 3 |
| + |
| +Repo carlos/platform, branch `fix/1682-fleet-door-walk`, commit 68019416886d4568c84c68e949512b4be90073a3. |
| +Under review: the diff `origin/main..fix/1682-fleet-door-walk` (base 991bbe8000a078d41237b44931581dd87f86f983), plus the census card `docs/superpowers/notes/census-proposal-1682-fleet-door-walk.md`. |
| +Authorities on main: `internal/edge/storedoor.go` (aclListScope, aclDir, serveListing: the door's listing contract), `internal/provision/reconcile.go` (listAppSubtree and its doc comment), `internal/provision/walkshare.go`, AGENTS.md ("The census", "Stopping rules"). |
| + |
| +You are an independent reviewer. Read the diff, then the code it names, and check every claim against that code. |
| + |
| +## Context |
| + |
| +Discussion #1682. Tito's fleet boxes (v0.43.11) take 55–80 s per serial pass: reconcile ~25 s and moves ~25 s. Diagnosis: a fleet box has no bucket and reads through the edge's store door (fleetapi). listAppSubtree walks per app only on a store that promises bucket-shaped ListDirs. The door doesn't (its ListDirs("apps/") is the account's APP dirs), so it listed apps/ whole. The door maps that to apps/<sqid>/, which on Tito's bucket is 315,087 keys, 308,617 of them logs, for 103 records. The change index is ignored on fleet boxes, so the moves pass walks too. |
| + |
| +The change: an opt-in `release.AccountListDirs` shape that fleetapi declares; `listDoorApps` (one ListDirs("apps/"), shape-checked, then one List per app); WalkShare keys door listings per sub; the hostops and mail wrappers forward the shape as they forward BucketShapedListDirs. |
| + |
| +## What to check |
| + |
| +1. **No false absence.** Can the door walk return fewer records than the flat listing of the same account, in any reachable case, without reporting partial or an error? A silently short record set is read by reconcile as routes retired, and by the moves pass as hosts gone. Check doorAppDir's shape test, the empty-answer fallback, the unknown-account skip, and what the real door (serveListing + aclDir) can return for ListDirs("apps/"), including an old edge. |
| +2. **Failure semantics** match listAppSubtree's documented two sizes: the top-level ListDirs failing is an error; one app's List failing is partial. Confirm every caller treats them as before (recordhost.go, rootrecord.go, seedrollback.go, recordview.go, walkshare.go). |
| +3. **WalkShare.** With the door now per sub, is there any path where a listing made for one sub, or under one account set, is reused for another? And when listDoorApps falls back to the flat listing, is caching it under the sub id still correct? |
| +4. **Shape plumbing.** Is there any store on a fleet box's reconcile, moves, sidecar or root-record path that wraps the fleetapi store without forwarding AccountScopedListDirs (so the fix silently doesn't apply), or any store that now claims the shape wrongly (so a bucket-shaped or DirStore store is walked as the door)? prefixStore deliberately doesn't forward it; say whether that is right. walkStore (record view) doesn't either; the record view is never armed on a fleet box (host/changeindex.go); say whether that holds. |
| +5. **Census.** Envelopes re-pinned: internal/fleetapi, internal/hostops, internal/provision, internal/release; no unit changed class. Give a verdict per envelope per AGENTS.md "The census": does the change let root open, run, query or follow anything new from an input a tenant, an app or a box agent can create, write or name, or weaken a check root relies on? |
| +6. **Tests bite.** applisting_door_test.go, internal/edge/fleetdoor_walk_e2e_test.go, fleetapi and wrapper tests: would each fail without the change? (The author checked the provision, walkshare and e2e tests by disabling the hook, the walkshare change and the fleetapi declaration in turn.) |
| + |
| +## Severity |
| + |
| +- **P1**: unsafe, would not compile, a test fails, or it would not work. Blocks merge. |
| +- **P2**: wrong or missing. Fixed without reopening this review. (The census, and review of any newly changed security, root, termination or production-storage behaviour, still check the fix; see AGENTS.md, "Stopping rules".) |
| +- **P3**: clarity or polish. Goes on a follow-up list; never a reason for another round. |
| + |
| +A P1 states its failure scenario and the evidence (file:line). Do not raise a P2 to P1 to keep the review open. |
| + |
| +## Output |
| + |
| +Findings ranked P1, P2, P3. Each gives the section or task, the problem, the evidence (file:line, verified), the failure scenario, a concrete fix and the invariant or trust boundary it breaks (that is its fault family). Then the census verdict per envelope. End with exactly one verdict: |
| + |
| +- **READY**: no P1 and no P2. |
| +- **READY AFTER FIXES**: no P1. The listed P2s are fixed without another round. |
| +- **NOT READY**: one or more P1s, listed. |
| + |
| +Do not edit files. Do not spawn reviewers or subagents of your own. Do not run the full test suites. |
diff --git a/docs/superpowers/reviews/ASTRA-REVIEW-BRIEF-1682-floor-slow-line-R1.md b/docs/superpowers/reviews/ASTRA-REVIEW-BRIEF-1682-floor-slow-line-R1.md| new file mode 100644 |
| index 000000000..2cbbbc059 |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/ASTRA-REVIEW-BRIEF-1682-floor-slow-line-R1.md |
| @@ -0,0 +1,32 @@ |
| +# Review brief: branch fix/1682-floor-slow-line, round 1 of 3 |
| + |
| +Repo carlos/platform, branch `fix/1682-floor-slow-line`, base 0ed99fd883ea8b369e1dbb4b592edf4f2cddf578 (main). |
| +Under review: the diff `0ed99fd88..HEAD`, plus the census card `docs/superpowers/notes/census-proposal-1682-floor-slow-line.md`. |
| +Authorities on main: `internal/host/agent.go` (instancesLoop), `internal/host/changeindex.go` (passLegs.run, the fast loop's slow-pass line this mirrors), AGENTS.md ("The census", "Stopping rules", "Writing Go here"). |
| + |
| +You are an independent reviewer. Read the diff, then the code it names, and check every claim against that code. |
| + |
| +## Context |
| + |
| +Discussion #1682, follow-up (a) agreed with Tito: the 5-minute instances floor runs the same reconcile + moves as the fast loop's serial pass, but logs nothing about its time. On Tito's fleet it ran ~55 s every 5 minutes, invisibly. This branch moves instancesLoop's per-pass body, unchanged in order and calls, into instancesFloorPass (new file, because agent.go is over the file-lines ratchet), and times each stage with a small stageTimes helper. A pass over slowLegAfter (5 s) logs one line: "agent: instances floor stages took <d> (<stage> <d>, ...)". |
| + |
| +## What to check |
| + |
| +1. **Behaviour preserved.** The floor pass makes exactly the same calls in the same order with the same arguments and error handling as before (backfill, reconcileSerialized, bs.refreshAll, telemetryPass, plansPass, runMovesPass, runRunsPass, runInteractivePass, aliasPassReporting, ReconcileFleetBindings on the hub). Nothing moved out of or into the loop beyond that. |
| +2. **The line.** Correct durations per stage (each mark closes the stage since the previous mark), logged once per pass and only when slow, no log per pass otherwise. Conditional stages (build states, fleet bindings) are marked only when they ran. |
| +3. **Census.** Envelope re-pinned: internal/host; no unit changed class. Verdict per AGENTS.md "The census". |
| +4. **Ratchets and tests.** The code-health record lowered one line; the tests use an injected clock, not sleeps. |
| + |
| +## Severity |
| + |
| +- **P1**: unsafe, would not compile, a test fails, or it would not work. Blocks merge. |
| +- **P2**: wrong or missing. Fixed without reopening this review. |
| +- **P3**: clarity or polish. Goes on a follow-up list; never a reason for another round. |
| + |
| +A P1 states its failure scenario and the evidence (file:line). Do not raise a P2 to P1 to keep the review open. |
| + |
| +## Output |
| + |
| +Findings ranked P1, P2, P3, each with evidence (file:line), failure scenario, fix and fault family. Then the census verdict for internal/host. End with exactly one verdict: **READY**, **READY AFTER FIXES**, or **NOT READY**. |
| + |
| +Do not edit files. Do not spawn reviewers or subagents of your own. Do not run the full test suites. |
diff --git a/internal/console/claim_invariant_test.go b/internal/console/claim_invariant_test.go| index ff810e20b..7a5fdf9d1 100644 |
| --- a/internal/console/claim_invariant_test.go |
| +++ b/internal/console/claim_invariant_test.go |
| @@ -777,7 +777,9 @@ func claimWriterInventory(s *Server) map[string]bool { |
| } |
| // ListWithCount and ListDirsWithCount are List and ListDirs with their |
| // request counts, forwarded to the store underneath (#1653): reads. |
| - methods("bucket/", s.cfg.Releases, "Get", "List", "ListDirs", "Open", "ListMod", "ListSizes", "ListPage", "BucketShapedListDirs", "GetIfChanged", "ListETags", |
| + // AccountScopedListDirs, like BucketShapedListDirs, only says how |
| + // ListDirs answers (#1682). |
| + methods("bucket/", s.cfg.Releases, "Get", "List", "ListDirs", "Open", "ListMod", "ListSizes", "ListPage", "BucketShapedListDirs", "AccountScopedListDirs", "GetIfChanged", "ListETags", |
| "ListWithCount", "ListDirsWithCount") |
| methods("versioned/", s.cfg.DBVersions, "ListVersions", "OpenVersion", "GetVersion", "OpenVersionRange") |
| for _, b := range []struct { |
diff --git a/internal/edge/fleetdoor_walk_e2e_test.go b/internal/edge/fleetdoor_walk_e2e_test.go| new file mode 100644 |
| index 000000000..470dafe4d |
| --- /dev/null |
| +++ b/internal/edge/fleetdoor_walk_e2e_test.go |
| @@ -0,0 +1,90 @@ |
| +package edge_test |
| + |
| +import ( |
| + "context" |
| + "fmt" |
| + "strings" |
| + "sync" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/applog" |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// doorListingStore is the bucket as the store door reaches it, recording |
| +// every List prefix the door asks of it. |
| +type doorListingStore struct { |
| + *release.DirStore |
| + mu sync.Mutex |
| + lists []string |
| +} |
| + |
| +func (s *doorListingStore) List(ctx context.Context, prefix string) ([]string, error) { |
| + s.mu.Lock() |
| + s.lists = append(s.lists, prefix) |
| + s.mu.Unlock() |
| + return s.DirStore.List(ctx, prefix) |
| +} |
| + |
| +func (s *doorListingStore) take() []string { |
| + s.mu.Lock() |
| + defer s.mu.Unlock() |
| + out := s.lists |
| + s.lists = nil |
| + return out |
| +} |
| + |
| +// A fleet box's record readers walk its account per app through the real |
| +// door, never listing the account whole, and find exactly its records |
| +// (#1682: on Tito's fleet the account was 98% logs, and each flat listing |
| +// through the door took ~25 s). |
| +func TestFleetBoxRecordReadersWalkTheDoorPerApp(t *testing.T) { |
| + ctx := context.Background() |
| + var ls *doorListingStore |
| + w := newFleetDoorWorldWith(t, func(d *release.DirStore) release.Store { |
| + ls = &doorListingStore{DirStore: d} |
| + return ls |
| + }) |
| + w.put(t, "accounts/"+w.sqid+"/account.json", fapiAccountManifest(fapiAcctID, w.sqid, "Orchard")) |
| + if err := provision.PutManifest(ctx, w.store, w.sqid, fapiApp, provision.Manifest{ |
| + Schema: 1, App: fapiApp, Domain: fapiDomain, Regions: []string{fapiRegion}, Seed: []string{"serve"}, |
| + }); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := provision.CreateRecord(ctx, w.store, provision.Record{ |
| + Schema: 1, Host: fapiHost, Slug: "acme", App: fapiApp, Account: w.sqid, |
| + Region: fapiRegion, Channel: fapiChannel, CreatedAt: time.Now(), |
| + }); err != nil { |
| + t.Fatal(err) |
| + } |
| + for i := range 20 { |
| + key, err := applog.ChunkKey(w.sqid, fapiApp, fapiBoxA, applog.HourOf(time.Now()), uint64(i+1), 9) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + w.put(t, key, fmt.Sprintf("log %d", i)) |
| + } |
| + ls.take() |
| + |
| + recs, err := provision.ListAllRecords(ctx, w.boxA) |
| + if err != nil { |
| + t.Fatalf("ListAllRecords through the door: %v", err) |
| + } |
| + if len(recs) != 1 || recs[0].Host != fapiHost { |
| + t.Fatalf("ListAllRecords through the door = %+v, want the one %s record", recs, fapiHost) |
| + } |
| + acct := "apps/" + w.sqid + "/" |
| + for _, p := range ls.take() { |
| + if !strings.HasPrefix(p, "apps/") { |
| + continue // accounts/, the record reader's account manifest listing |
| + } |
| + if p == acct || p == "apps/" { |
| + t.Fatalf("the door listed %q whole for a record read", p) |
| + } |
| + if !strings.HasSuffix(p, "/instances/") { |
| + t.Fatalf("the door listed %q; a record read lists only apps/<acct>/<app>/instances/", p) |
| + } |
| + } |
| +} |
diff --git a/internal/fleetapi/fleetapi.go b/internal/fleetapi/fleetapi.go| index df0203718..af42c679e 100644 |
| --- a/internal/fleetapi/fleetapi.go |
| +++ b/internal/fleetapi/fleetapi.go |
| @@ -181,6 +181,14 @@ func (s *store) Open(ctx context.Context, key string) (io.ReadCloser, string, er |
| var _ release.Opener = (*store)(nil) |
| +// AccountScopedListDirs: the door scopes a box to its own account, and its |
| +// ListDirs("apps/") is that account's app directories (storedoor.go, |
| +// aclListScope), so record readers walk the account per app rather than |
| +// list every key under it, logs included (provision.listDoorApps, #1682). |
| +func (s *store) AccountScopedListDirs() bool { return true } |
| + |
| +var _ release.AccountListDirs = (*store)(nil) |
| + |
| // absentHeader is the door's mark on a 404 that means "absent" rather than |
| // "refused" (internal/edge/storedoor.go, storeAbsentHeader). The door sets it |
| // only on a GET of an app policy key it would have served. |
diff --git a/internal/fleetapi/fleetapi_test.go b/internal/fleetapi/fleetapi_test.go| index f7e5bd483..547cbf868 100644 |
| --- a/internal/fleetapi/fleetapi_test.go |
| +++ b/internal/fleetapi/fleetapi_test.go |
| @@ -564,3 +564,20 @@ func TestPolicyETagsThroughTheDoor(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// The door's ListDirs("apps/") is the box's own account's app directories |
| +// (storedoor.go, aclListScope), and the client says so, so record readers |
| +// walk the account per app instead of listing its logs (#1682). It is not |
| +// the bucket's shape, and must never claim it. |
| +func TestStoreDeclaresTheDoorsListDirsShape(t *testing.T) { |
| + s, err := fleetapi.New("https://tunnel.example.com", "pi/box-a", "tok") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if !release.HasAccountListDirs(s) { |
| + t.Error("the door client does not declare the account-scoped ListDirs shape") |
| + } |
| + if release.HasBucketListDirs(s) { |
| + t.Error("the door client claims the bucket's ListDirs shape") |
| + } |
| +} |
diff --git a/internal/host/agent.go b/internal/host/agent.go| index 6910a89d0..1137e4170 100644 |
| --- a/internal/host/agent.go |
| +++ b/internal/host/agent.go |
| @@ -4606,31 +4606,7 @@ func instancesLoop(reg *registry.Registry, writes hostwrite.Config, bs *buildSta |
| for { |
| time.Sleep(delay) |
| delay = 5*time.Minute + rand.N(time.Minute) |
| - if err := backfill(ctx); err != nil { |
| - log.Printf("agent: claim backfill: %v", err) |
| - } |
| - if err := reconcileSerialized(ctx, store, reg, cfg); err != nil { |
| - log.Printf("agent: instances pass: %v", err) |
| - } |
| - // Every reconcile refreshes the build-state copies (settings spec |
| - // §4.2), this 5-minute one too: the fast leg above runs only on a |
| - // serial move. |
| - if bs != nil { |
| - bs.refreshAll(ctx) |
| - } |
| - telemetryPass(ctx, store, reg) |
| - plansPass(ctx, store, reg, os.Getenv) |
| - runMovesPass(ctx, store) |
| - runRunsPass(ctx) |
| - runInteractivePass(ctx) |
| - if err := aliasPassReporting(ctx, store, reg, &aliasClaimCache, boxAssetAuthority, cfg.Region); err != nil { |
| - log.Printf("agent: instances alias pass: %v", err) |
| - } |
| - if hub { |
| - if err := ReconcileFleetBindings(ctx, store, reg); err != nil { |
| - log.Printf("agent: fleet bindings reconcile: %v", err) |
| - } |
| - } |
| + instancesFloorPass(ctx, store, reg, cfg, bs, backfill, hub) |
| } |
| } |
diff --git a/internal/host/instancesfloor.go b/internal/host/instancesfloor.go| new file mode 100644 |
| index 000000000..e43f5de77 |
| --- /dev/null |
| +++ b/internal/host/instancesfloor.go |
| @@ -0,0 +1,96 @@ |
| +package host |
| + |
| +import ( |
| + "context" |
| + "fmt" |
| + "log" |
| + "os" |
| + "strings" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// stageTimes times a pass's stages for one slow-pass line, the way the fast |
| +// loop's pass set does (passLegs.run): each mark closes a stage, and line |
| +// speaks only when the whole pass took longer than slowLegAfter. |
| +type stageTimes struct { |
| + now func() time.Time |
| + start, cur time.Time |
| + took []string |
| +} |
| + |
| +func newStageTimes(now func() time.Time) *stageTimes { |
| + t := now() |
| + return &stageTimes{now: now, start: t, cur: t} |
| +} |
| + |
| +// mark closes the stage that began at the last mark (or the start). |
| +func (s *stageTimes) mark(name string) { |
| + t := s.now() |
| + s.took = append(s.took, fmt.Sprintf("%s %s", name, t.Sub(s.cur).Round(100*time.Millisecond))) |
| + s.cur = t |
| +} |
| + |
| +// line is the journal line for a pass named what, and whether it is slow |
| +// enough to log. |
| +func (s *stageTimes) line(what string) (string, bool) { |
| + d := s.now().Sub(s.start) |
| + if d <= slowLegAfter { |
| + return "", false |
| + } |
| + return fmt.Sprintf("agent: %s took %s (%s)", what, d.Round(100*time.Millisecond), strings.Join(s.took, ", ")), true |
| +} |
| + |
| +// instancesFloorPass is one pass of the 5-minute instances floor |
| +// (instancesLoop), with its stages timed. A pass slower than slowLegAfter |
| +// logs one line naming each stage, like the fast loop's serial pass: the |
| +// floor runs the same reconcile and moves pass on every box, and before |
| +// #1682 its time was in no journal (on Tito's fleet, ~55 s every five |
| +// minutes, holding reconcileMu in front of the fast loop's passes). |
| +func instancesFloorPass(ctx context.Context, store release.Store, reg *registry.Registry, cfg provision.ReconcileConfig, |
| + bs *buildStates, backfill func(context.Context) error, hub bool) { |
| + st := newStageTimes(time.Now) |
| + defer func() { |
| + if line, slow := st.line("instances floor stages"); slow { |
| + log.Print(line) |
| + } |
| + }() |
| + if err := backfill(ctx); err != nil { |
| + log.Printf("agent: claim backfill: %v", err) |
| + } |
| + st.mark("backfill") |
| + if err := reconcileSerialized(ctx, store, reg, cfg); err != nil { |
| + log.Printf("agent: instances pass: %v", err) |
| + } |
| + st.mark("reconcile") |
| + // Every reconcile refreshes the build-state copies (settings spec |
| + // §4.2), this 5-minute one too: the fast leg runs only on a serial |
| + // move. |
| + if bs != nil { |
| + bs.refreshAll(ctx) |
| + st.mark("build states") |
| + } |
| + telemetryPass(ctx, store, reg) |
| + st.mark("telemetry") |
| + plansPass(ctx, store, reg, os.Getenv) |
| + st.mark("plans") |
| + runMovesPass(ctx, store) |
| + st.mark("moves") |
| + runRunsPass(ctx) |
| + st.mark("runs") |
| + runInteractivePass(ctx) |
| + st.mark("interactive") |
| + if err := aliasPassReporting(ctx, store, reg, &aliasClaimCache, boxAssetAuthority, cfg.Region); err != nil { |
| + log.Printf("agent: instances alias pass: %v", err) |
| + } |
| + st.mark("aliases") |
| + if hub { |
| + if err := ReconcileFleetBindings(ctx, store, reg); err != nil { |
| + log.Printf("agent: fleet bindings reconcile: %v", err) |
| + } |
| + st.mark("fleet bindings") |
| + } |
| +} |
diff --git a/internal/host/instancesfloor_test.go b/internal/host/instancesfloor_test.go| new file mode 100644 |
| index 000000000..26006376f |
| --- /dev/null |
| +++ b/internal/host/instancesfloor_test.go |
| @@ -0,0 +1,48 @@ |
| +package host |
| + |
| +import ( |
| + "testing" |
| + "time" |
| +) |
| + |
| +// floorClock advances only when told to. |
| +type floorClock struct{ t time.Time } |
| + |
| +func (c *floorClock) now() time.Time { return c.t } |
| +func (c *floorClock) step(d time.Duration) { c.t = c.t.Add(d) } |
| +func newFakeClock() *floorClock { return &floorClock{t: time.Date(2026, 12, 3, 12, 0, 0, 0, time.UTC)} } |
| + |
| +// A slow floor pass gets one journal line naming every stage's time, like |
| +// the fast loop's serial pass line, so the 5-minute floor's cost is no |
| +// longer invisible (#1682: on Tito's fleet it ran ~55 s every 5 minutes |
| +// and logged nothing). |
| +func TestStageTimesNamesEveryStageWhenSlow(t *testing.T) { |
| + c := newFakeClock() |
| + st := newStageTimes(c.now) |
| + c.step(100 * time.Millisecond) |
| + st.mark("backfill") |
| + c.step(25 * time.Second) |
| + st.mark("reconcile") |
| + c.step(26 * time.Second) |
| + st.mark("moves") |
| + line, slow := st.line("instances floor stages") |
| + if !slow { |
| + t.Fatal("a 51 s pass was not slow") |
| + } |
| + want := "agent: instances floor stages took 51.1s (backfill 100ms, reconcile 25s, moves 26s)" |
| + if line != want { |
| + t.Fatalf("line = %q\nwant %q", line, want) |
| + } |
| +} |
| + |
| +// A pass inside slowLegAfter says nothing: the floor runs every 5 minutes on |
| +// every box, and a quiet one is the normal case. |
| +func TestStageTimesQuietWhenFast(t *testing.T) { |
| + c := newFakeClock() |
| + st := newStageTimes(c.now) |
| + c.step(slowLegAfter) |
| + st.mark("reconcile") |
| + if line, slow := st.line("instances floor stages"); slow { |
| + t.Fatalf("a pass of exactly slowLegAfter logged %q", line) |
| + } |
| +} |
diff --git a/internal/host/startupmeasure_e2e_test.go b/internal/host/startupmeasure_e2e_test.go| index 7195c377b..90f5105df 100644 |
| --- a/internal/host/startupmeasure_e2e_test.go |
| +++ b/internal/host/startupmeasure_e2e_test.go |
| @@ -97,6 +97,7 @@ func TestStartupMeasure(t *testing.T) { |
| // how many ops were in flight when it began. |
| type slowDoor struct { |
| inner release.Store // a DirStore: Opener and ETagLister both |
| + acct string // the box's account: apps/ is scoped to it, as the door scopes it |
| lat time.Duration |
| inflight atomic.Int32 |
| @@ -143,14 +144,26 @@ func (d *slowDoor) Put(ctx context.Context, key string, body []byte, ifMatch str |
| func (d *slowDoor) List(ctx context.Context, prefix string) ([]string, error) { |
| defer d.begin(opList, prefix)() |
| - return d.inner.List(ctx, prefix) |
| + return d.inner.List(ctx, d.scoped(prefix)) |
| } |
| func (d *slowDoor) ListDirs(ctx context.Context, prefix string) ([]string, error) { |
| defer d.begin(opDirs, prefix)() |
| - return d.inner.ListDirs(ctx, prefix) |
| + return d.inner.ListDirs(ctx, d.scoped(prefix)) |
| } |
| +// scoped maps apps/ to the box's own account, as the door does |
| +// (storedoor.go, aclListScope). |
| +func (d *slowDoor) scoped(prefix string) string { |
| + if prefix == "apps/" && d.acct != "" { |
| + return "apps/" + d.acct + "/" |
| + } |
| + return prefix |
| +} |
| + |
| +// AccountScopedListDirs: the door's shape (#1682). |
| +func (d *slowDoor) AccountScopedListDirs() bool { return d.acct != "" } |
| + |
| func (d *slowDoor) Delete(ctx context.Context, key string) error { |
| defer d.begin(opDelete, key)() |
| return d.inner.Delete(ctx, key) |
| @@ -224,7 +237,7 @@ func measureStartup(t *testing.T, n int, lat time.Duration) string { |
| } |
| armMeasuredBox(t, b, getenv, judge) |
| ctx = provision.WithLifetimes(ctx, judge) |
| - door := &slowDoor{inner: w.store, lat: lat} |
| + door := &slowDoor{inner: w.store, acct: w.acct, lat: lat} |
| if storeExts(door) != doorShape { |
| t.Fatal("fixture: the fake door is not the fleet door's shape") |
| } |
diff --git a/internal/host/startuptiming.go b/internal/host/startuptiming.go| index 5004ed6d6..7bd87e389 100644 |
| --- a/internal/host/startuptiming.go |
| +++ b/internal/host/startuptiming.go |
| @@ -167,9 +167,13 @@ func (s *opCountingStore) listETags(ctx context.Context, prefix string) ([]relea |
| } |
| // doorCountingStore is the shape of the fleet store door (fleetapi): Store, |
| -// Opener and ETagLister. |
| +// Opener, ETagLister and AccountListDirs. |
| type doorCountingStore struct{ *opCountingStore } |
| +// AccountScopedListDirs answers as the door does: hiding it would send the |
| +// boot walk and the first full pass back to listing the whole account (#1682). |
| +func (s doorCountingStore) AccountScopedListDirs() bool { return release.HasAccountListDirs(s.inner) } |
| + |
| func (s doorCountingStore) Open(ctx context.Context, key string) (io.ReadCloser, string, error) { |
| return s.open(ctx, key) |
| } |
| @@ -259,13 +263,14 @@ const ( |
| extVersionDirLister |
| extBucketListDirs |
| extAppMutationRunner |
| + extAccountListDirs |
| ) |
| type storeExt uint32 |
| const ( |
| plainShape = storeExt(0) |
| - doorShape = extOpener | extETagLister |
| + doorShape = extOpener | extETagLister | extAccountListDirs |
| dirShape = extOpener | extPutStreamer | extPageLister | extModLister | extSizeLister | |
| extConditionalGetter | extETagLister | extConditionalDeleter | extIndexedDeleter | extBatchDeleter |
| ) |
| @@ -311,6 +316,8 @@ func storeExts(s release.Store) storeExt { |
| has(extBucketListDirs, ok) |
| _, ok = s.(release.AppMutationRunner) |
| has(extAppMutationRunner, ok) |
| + _, ok = s.(release.AccountListDirs) |
| + has(extAccountListDirs, ok) |
| return e |
| } |
diff --git a/internal/host/startuptiming_door_test.go b/internal/host/startuptiming_door_test.go| new file mode 100644 |
| index 000000000..760dea3ff |
| --- /dev/null |
| +++ b/internal/host/startuptiming_door_test.go |
| @@ -0,0 +1,81 @@ |
| +package host |
| + |
| +import ( |
| + "context" |
| + "strings" |
| + "sync" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/domains" |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// accountDoor answers like the fleet door: ListDirs("apps/") and List("apps/") |
| +// are scoped to one account, and it records every List. |
| +type accountDoor struct { |
| + doorShapedStore |
| + acct string |
| + mu sync.Mutex |
| + lists []string |
| +} |
| + |
| +func (s *accountDoor) List(ctx context.Context, p string) ([]string, error) { |
| + s.mu.Lock() |
| + s.lists = append(s.lists, p) |
| + s.mu.Unlock() |
| + if p == "apps/" { |
| + p = "apps/" + s.acct + "/" |
| + } |
| + return s.inner.List(ctx, p) |
| +} |
| + |
| +func (s *accountDoor) ListDirs(ctx context.Context, p string) ([]string, error) { |
| + if p == "apps/" { |
| + p = "apps/" + s.acct + "/" |
| + } |
| + return s.inner.ListDirs(ctx, p) |
| +} |
| + |
| +// The startup timing wrapper keeps the door's walk: the boot walk and the |
| +// first full pass read through countStore, and a wrapper that hid the shape |
| +// sent them back to listing the whole account (#1682, Astra R1). |
| +func TestCountedDoorStillWalksPerApp(t *testing.T) { |
| + ctx := context.Background() |
| + dir := release.NewDirStore(t.TempDir()) |
| + sqid := domains.Sqid(2) |
| + manifest := []byte(`{"id":2,"sqid":"` + sqid + `","name":"Eleven","created_at":"2026-08-02T09:00:00Z"}`) |
| + if _, err := dir.Put(ctx, "accounts/"+sqid+"/account.json", manifest, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := provision.CreateRecord(ctx, dir, provision.Record{ |
| + Schema: 1, Host: "acme.eleven.example.com", Slug: "acme", App: "eleven", Account: sqid, |
| + Region: "ie", Channel: "stable", CreatedAt: time.Now(), |
| + }); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := dir.Put(ctx, "apps/"+sqid+"/eleven/logs/2026/12/03/chunk-1.jsonl", []byte("log"), ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + door := &accountDoor{doorShapedStore: doorShapedStore{dir}, acct: sqid} |
| + counted, c := countStore(door) |
| + if c == nil { |
| + t.Fatal("the door was not counted") |
| + } |
| + recs, err := provision.ListAllRecords(ctx, counted) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if len(recs) != 1 || recs[0].Host != "acme.eleven.example.com" { |
| + t.Fatalf("records through the counted door = %+v", recs) |
| + } |
| + for _, p := range door.lists { |
| + if p == "apps/" || p == "apps/"+sqid+"/" { |
| + t.Fatalf("the counted door was listed whole (%q): %v", p, door.lists) |
| + } |
| + if strings.HasPrefix(p, "apps/") && !strings.HasSuffix(p, "/instances/") { |
| + t.Fatalf("the counted door listed %q", p) |
| + } |
| + } |
| +} |
diff --git a/internal/host/startuptiming_test.go b/internal/host/startuptiming_test.go| index 7d1c9ed03..2153b6721 100644 |
| --- a/internal/host/startuptiming_test.go |
| +++ b/internal/host/startuptiming_test.go |
| @@ -18,7 +18,8 @@ import ( |
| // plainShapedStore is a Store with none of release's optional interfaces. |
| type plainShapedStore struct{ release.Store } |
| -// doorShapedStore has the fleet door's shape: Store, Opener and ETagLister. |
| +// doorShapedStore has the fleet door's shape: Store, Opener, ETagLister and |
| +// AccountListDirs. |
| type doorShapedStore struct{ inner *release.DirStore } |
| func (s doorShapedStore) Get(ctx context.Context, k string) ([]byte, string, error) { |
| @@ -34,6 +35,7 @@ func (s doorShapedStore) ListDirs(ctx context.Context, p string) ([]string, erro |
| return s.inner.ListDirs(ctx, p) |
| } |
| func (s doorShapedStore) Delete(ctx context.Context, k string) error { return s.inner.Delete(ctx, k) } |
| +func (s doorShapedStore) AccountScopedListDirs() bool { return true } |
| func (s doorShapedStore) Open(ctx context.Context, k string) (io.ReadCloser, string, error) { |
| return s.inner.Open(ctx, k) |
| } |
| @@ -173,6 +175,14 @@ func TestCountingStoreKeepsTheStoreShape(t *testing.T) { |
| if !tc.counted && got != tc.s { |
| t.Errorf("%s: an uncounted store was wrapped", name) |
| } |
| + // The shape answers by value too: a wrapper that has the method but |
| + // answers differently changes how the record walk lists (#1682). |
| + if release.HasAccountListDirs(got) != release.HasAccountListDirs(tc.s) || |
| + release.HasBucketListDirs(got) != release.HasBucketListDirs(tc.s) { |
| + t.Errorf("%s: wrapper answers account %v bucket %v, store's %v %v", name, |
| + release.HasAccountListDirs(got), release.HasBucketListDirs(got), |
| + release.HasAccountListDirs(tc.s), release.HasBucketListDirs(tc.s)) |
| + } |
| if storeExts(got) != storeExts(tc.s) { |
| t.Errorf("%s: wrapper extensions %b, store's %b", name, storeExts(got), storeExts(tc.s)) |
| } |
diff --git a/internal/host/walkshare_e2e_test.go b/internal/host/walkshare_e2e_test.go| index ea9de08c5..4d172db4f 100644 |
| --- a/internal/host/walkshare_e2e_test.go |
| +++ b/internal/host/walkshare_e2e_test.go |
| @@ -83,7 +83,7 @@ func newWalkWorld(t *testing.T, n int) *walkWorld { |
| t.Fatal("fixture: no lifetime judge, as a claims-off fleet box has") |
| } |
| armMeasuredBox(t, b, getenv, judge) |
| - door := &slowDoor{inner: w.store} |
| + door := &slowDoor{inner: w.store, acct: w.acct} |
| if storeExts(door) != doorShape { |
| t.Fatal("fixture: the fake door is not the fleet door's shape") |
| } |
| @@ -172,7 +172,13 @@ func (ww *walkWorld) calls(ops []doorOp) walkCalls { |
| var c walkCalls |
| for _, o := range ops { |
| switch { |
| - case o.op == opList && o.key == "apps/": |
| + // A walk for instance records. Over the door that is its own walk |
| + // (listDoorApps, #1682), which lists every app's instances/ and so |
| + // shop's, the app every world has; listed whole, it is List("apps/"). |
| + // The sidecar scan's walk is its own over the door (one sub per |
| + // listing) and is not counted here: these tests are about who |
| + // shares the instance listing. |
| + case o.op == opList && (o.key == "apps/" || o.key == "apps/"+ww.w.acct+"/shop/instances/"): |
| c.trees++ |
| case o.op == opList && o.key == "accounts/": |
| c.accounts++ |
| @@ -236,8 +242,10 @@ func (ww *walkWorld) grow(t *testing.T, apps, perApp, junk int) { |
| // and after, for a small account (one app), a mid one (~20 apps) and a big |
| // one (many apps, many non-record objects): whole-tree and accounts |
| // listings, record GETs across every app, slot GETs. Nothing goes up for |
| -// any size, and the whole apps/ listings go from 5 to 2 (first) and 3 to 2 |
| -// (steady state). |
| +// any size, and the instance walks go from 4 to 2 (first) and stay at 2 |
| +// (steady state). Before the door had its own walk (#1682) the sidecar |
| +// scan shared the whole apps/ listing too, and the counts were 5 to 2 and |
| +// 3 to 2; over the door it walks sidecars/ per app, which is not counted. |
| func TestSharedWalkStoreCallsPerPass(t *testing.T) { |
| sizes := []struct { |
| name string |
| @@ -271,8 +279,8 @@ func TestSharedWalkStoreCallsPerPass(t *testing.T) { |
| before, after walkCalls |
| trees [2]int |
| }{ |
| - {"first", before.first, after.first, [2]int{5, 2}}, |
| - {"steady", before.steady, after.steady, [2]int{3, 2}}, |
| + {"first", before.first, after.first, [2]int{4, 2}}, |
| + {"steady", before.steady, after.steady, [2]int{2, 2}}, |
| } { |
| if c.before.trees != c.trees[0] || c.after.trees != c.trees[1] { |
| t.Errorf("%s pass: whole apps/ listings before %d after %d, want %d and %d", c.name, c.before.trees, c.after.trees, c.trees[0], c.trees[1]) |
diff --git a/internal/hostops/listdirs_shape_test.go b/internal/hostops/listdirs_shape_test.go| new file mode 100644 |
| index 000000000..bad5fa302 |
| --- /dev/null |
| +++ b/internal/hostops/listdirs_shape_test.go |
| @@ -0,0 +1,30 @@ |
| +package hostops |
| + |
| +import ( |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +type doorShapedStore struct{ release.Store } |
| + |
| +func (doorShapedStore) AccountScopedListDirs() bool { return true } |
| + |
| +// The record-write wrappers keep the fleet door's ListDirs shape, as they keep |
| +// the bucket's: a wrapped door that lost it would be listed whole again, logs |
| +// and all (#1682). |
| +func TestWrappersKeepTheDoorsListDirsShape(t *testing.T) { |
| + door := doorShapedStore{release.NewDirStore(t.TempDir())} |
| + plain := release.NewDirStore(t.TempDir()) |
| + for name, c := range map[string]struct{ door, plain release.Store }{ |
| + "mutationBoundary": {&mutationBoundary{raw: door}, &mutationBoundary{raw: plain}}, |
| + "conditionalRecordStore": {conditionalRecordStore{raw: door}, conditionalRecordStore{raw: plain}}, |
| + } { |
| + if !release.HasAccountListDirs(c.door) { |
| + t.Errorf("%s over the door lost its shape", name) |
| + } |
| + if release.HasAccountListDirs(c.plain) { |
| + t.Errorf("%s over a plain store claims the door's shape", name) |
| + } |
| + } |
| +} |
diff --git a/internal/hostops/mutation_boundary.go b/internal/hostops/mutation_boundary.go| index 493abc29a..0b33e1168 100644 |
| --- a/internal/hostops/mutation_boundary.go |
| +++ b/internal/hostops/mutation_boundary.go |
| @@ -129,7 +129,8 @@ func (s *mutationBoundary) ListWithCount(ctx context.Context, prefix string) ([] |
| func (s *mutationBoundary) ListDirsWithCount(ctx context.Context, prefix string) ([]string, int, error) { |
| return release.ListDirsCounted(ctx, s.raw, prefix) |
| } |
| -func (s *mutationBoundary) BucketShapedListDirs() bool { return release.HasBucketListDirs(s.raw) } |
| +func (s *mutationBoundary) BucketShapedListDirs() bool { return release.HasBucketListDirs(s.raw) } |
| +func (s *mutationBoundary) AccountScopedListDirs() bool { return release.HasAccountListDirs(s.raw) } |
| func (s *mutationBoundary) Open(ctx context.Context, key string) (io.ReadCloser, string, error) { |
| return release.OpenObject(ctx, s.raw, key) |
| } |
diff --git a/internal/hostops/record_writes.go b/internal/hostops/record_writes.go| index 5197f09dd..57b5f942d 100644 |
| --- a/internal/hostops/record_writes.go |
| +++ b/internal/hostops/record_writes.go |
| @@ -63,6 +63,9 @@ func (s conditionalRecordStore) ListDirs(ctx context.Context, prefix string) ([] |
| return s.raw.ListDirs(ctx, prefix) |
| } |
| func (s conditionalRecordStore) BucketShapedListDirs() bool { return release.HasBucketListDirs(s.raw) } |
| +func (s conditionalRecordStore) AccountScopedListDirs() bool { |
| + return release.HasAccountListDirs(s.raw) |
| +} |
| func (s conditionalRecordStore) Open(ctx context.Context, key string) (io.ReadCloser, string, error) { |
| return release.OpenObject(ctx, s.raw, key) |
| } |
diff --git a/internal/mail/claim_gate.go b/internal/mail/claim_gate.go| index f9394201c..1fb190293 100644 |
| --- a/internal/mail/claim_gate.go |
| +++ b/internal/mail/claim_gate.go |
| @@ -86,6 +86,7 @@ var ( |
| _ release.PageLister = ClaimMailStore{} |
| _ release.SizeLister = ClaimMailStore{} |
| _ release.BucketListDirs = ClaimMailStore{} |
| + _ release.AccountListDirs = ClaimMailStore{} |
| ) |
| func NewClaimMailStore(data release.Store, gate ClaimMailGate, admitter ClaimMailAdmitter, owner ClaimMailOwner) (ClaimMailStore, error) { |
| @@ -104,7 +105,8 @@ func (s ClaimMailStore) List(ctx context.Context, prefix string) ([]string, erro |
| func (s ClaimMailStore) ListDirs(ctx context.Context, prefix string) ([]string, error) { |
| return s.data.ListDirs(ctx, prefix) |
| } |
| -func (s ClaimMailStore) BucketShapedListDirs() bool { return release.HasBucketListDirs(s.data) } |
| +func (s ClaimMailStore) BucketShapedListDirs() bool { return release.HasBucketListDirs(s.data) } |
| +func (s ClaimMailStore) AccountScopedListDirs() bool { return release.HasAccountListDirs(s.data) } |
| func (s ClaimMailStore) Open(ctx context.Context, key string) (io.ReadCloser, string, error) { |
| return release.OpenObject(ctx, s.data, key) |
| } |
diff --git a/internal/mail/listdirs_shape_test.go b/internal/mail/listdirs_shape_test.go| new file mode 100644 |
| index 000000000..0ef0e4802 |
| --- /dev/null |
| +++ b/internal/mail/listdirs_shape_test.go |
| @@ -0,0 +1,22 @@ |
| +package mail |
| + |
| +import ( |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +type doorShapedStore struct{ release.Store } |
| + |
| +func (doorShapedStore) AccountScopedListDirs() bool { return true } |
| + |
| +// ClaimMailStore keeps the fleet door's ListDirs shape, as it keeps the |
| +// bucket's (#1682). |
| +func TestClaimMailStoreKeepsTheDoorsListDirsShape(t *testing.T) { |
| + if !release.HasAccountListDirs(ClaimMailStore{data: doorShapedStore{release.NewDirStore(t.TempDir())}}) { |
| + t.Error("over the door it lost the shape") |
| + } |
| + if release.HasAccountListDirs(ClaimMailStore{data: release.NewDirStore(t.TempDir())}) { |
| + t.Error("over a plain store it claims the door's shape") |
| + } |
| +} |
diff --git a/internal/provision/applisting_door.go b/internal/provision/applisting_door.go| new file mode 100644 |
| index 000000000..8917c3f40 |
| --- /dev/null |
| +++ b/internal/provision/applisting_door.go |
| @@ -0,0 +1,90 @@ |
| +package provision |
| + |
| +import ( |
| + "context" |
| + "log" |
| + "slices" |
| + "strings" |
| + "sync" |
| + |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// listDoorApps is listAppSubtree over the fleet door (#1682): one |
| +// ListDirs("apps/"), which the door answers with its account's app |
| +// directories, then one small List of apps/<acct>/<app>/<sub> per app. ok |
| +// false means the answer was not in the door's shape and nothing was |
| +// listed: the caller lists the old way, whole. |
| +// |
| +// Why: a fleet box reads through the door, and listed whole, the account's |
| +// apps/ is mostly logs. On Tito's fleet (2026-12-03) it was 315,087 keys, |
| +// 308,617 of them logs, for 103 instance records: about 316 S3 list pages |
| +// per walk, ~25 s, and reconcile and the moves pass each walked once per |
| +// pass. That is what held `carlos console` sessions back by a minute or more. |
| +// |
| +// The shape is checked, not assumed. Every directory must be |
| +// apps/<acct>/<app>/ with both segments non-empty, and there must be at least |
| +// one. Anything else (an empty answer, an account directory, a deeper one) is |
| +// listed the old way, so a door that answers differently can never make the |
| +// records look absent, which reconcile would read as every route retired. |
| +// An app directory of an account not in known is skipped: the parsers refuse |
| +// its records in the flat listing too. |
| +// |
| +// Failure has the same two sizes as the bucket walk. ListDirs("apps/") |
| +// failing is an error, as the flat List failing was. One app's listing |
| +// failing is partial. |
| +func listDoorApps(ctx context.Context, s release.Store, known map[string]bool, sub string) (keys []string, partial, ok bool, err error) { |
| + dirs, err := s.ListDirs(ctx, "apps/") |
| + if err != nil { |
| + return nil, false, true, err |
| + } |
| + if len(dirs) == 0 { |
| + return nil, false, false, nil |
| + } |
| + var prefixes []string |
| + for _, d := range dirs { |
| + acct, isApp := doorAppDir(d) |
| + if !isApp { |
| + log.Printf("provision: the store's ListDirs(apps/) answered %q, not an app directory; listing apps/ whole", d) |
| + return nil, false, false, nil |
| + } |
| + if known[acct] { |
| + prefixes = append(prefixes, d+sub) |
| + } |
| + } |
| + var ( |
| + mu sync.Mutex |
| + out []string |
| + ) |
| + forEach(prefixes, func(p string) { |
| + got, err := s.List(ctx, p) |
| + mu.Lock() |
| + defer mu.Unlock() |
| + if err != nil { |
| + log.Printf("provision: listing %s: %v — its records are unseen this pass", p, err) |
| + partial = true |
| + return |
| + } |
| + out = append(out, got...) |
| + }) |
| + slices.Sort(out) |
| + return out, partial, true, nil |
| +} |
| + |
| +// doorAppDir reports whether d is an app directory, apps/<acct>/<app>/ with |
| +// both segments non-empty and nothing below, and returns its account. |
| +func doorAppDir(d string) (acct string, ok bool) { |
| + rest, ok := strings.CutPrefix(d, "apps/") |
| + if !ok { |
| + return "", false |
| + } |
| + rest, ok = strings.CutSuffix(rest, "/") |
| + if !ok { |
| + return "", false |
| + } |
| + acct, app, ok := strings.Cut(rest, "/") |
| + if !ok || acct == "" || app == "" || strings.Contains(app, "/") { |
| + return "", false |
| + } |
| + return acct, true |
| +} |
diff --git a/internal/provision/applisting_door_test.go b/internal/provision/applisting_door_test.go| new file mode 100644 |
| index 000000000..2c76b0072 |
| --- /dev/null |
| +++ b/internal/provision/applisting_door_test.go |
| @@ -0,0 +1,263 @@ |
| +package provision |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "reflect" |
| + "strings" |
| + "sync" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// doorShaped answers the way the fleet door does (internal/edge storedoor.go, |
| +// aclListScope): ListDirs("apps/") is the app directories of the store's one |
| +// account, and anything under apps/<acct>/ is listed as the bucket would. It |
| +// says so (release.AccountListDirs), and records every listing asked of it. |
| +// dirsAnswer, when set, replaces the door's answer to ListDirs("apps/"). |
| +type doorShaped struct { |
| + release.Store |
| + acct string |
| + |
| + mu sync.Mutex |
| + lists []string |
| + dirs []string |
| + |
| + failDirs, failList string |
| + dirsAnswer []string |
| +} |
| + |
| +func (s *doorShaped) AccountScopedListDirs() bool { return true } |
| + |
| +func (s *doorShaped) List(ctx context.Context, prefix string) ([]string, error) { |
| + s.mu.Lock() |
| + s.lists = append(s.lists, prefix) |
| + s.mu.Unlock() |
| + if prefix == s.failList { |
| + return nil, errors.New("list refused") |
| + } |
| + if prefix == "apps/" { |
| + prefix = "apps/" + s.acct + "/" |
| + } |
| + return s.Store.List(ctx, prefix) |
| +} |
| + |
| +func (s *doorShaped) ListDirs(ctx context.Context, prefix string) ([]string, error) { |
| + s.mu.Lock() |
| + s.dirs = append(s.dirs, prefix) |
| + s.mu.Unlock() |
| + if prefix == s.failDirs { |
| + return nil, errors.New("listdirs refused") |
| + } |
| + if prefix == "apps/" { |
| + if s.dirsAnswer != nil { |
| + return s.dirsAnswer, nil |
| + } |
| + prefix = "apps/" + s.acct + "/" |
| + } |
| + return s.Store.ListDirs(ctx, prefix) |
| +} |
| + |
| +func (s *doorShaped) listedAllOfApps() bool { |
| + s.mu.Lock() |
| + defer s.mu.Unlock() |
| + for _, p := range s.lists { |
| + if p == "apps/" { |
| + return true |
| + } |
| + } |
| + return false |
| +} |
| + |
| +// The door's account, listed whole: what the old flat listing found. |
| +func doorFlatListing(t *testing.T, s release.Store, acct string) []string { |
| + t.Helper() |
| + all, err := s.List(context.Background(), "apps/"+acct+"/") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return all |
| +} |
| + |
| +// On the fleet door the walk is per app: it finds exactly the records the |
| +// flat listing of the account found, for both record kinds, and lists only |
| +// apps/<acct>/<app>/<sub> prefixes, never the account's logs (#1682: on Tito's |
| +// fleet 98% of the account's 315,087 keys were logs, and listing them took |
| +// ~25 s per walk). |
| +func TestAppSubtreeWalksTheFleetDoorPerApp(t *testing.T) { |
| + inner := seedAppListingBucket(t) |
| + known := map[string]bool{"bab": true} |
| + all := doorFlatListing(t, inner, "bab") |
| + for _, c := range []struct { |
| + sub string |
| + parse func(string) bool |
| + }{ |
| + {"instances/", func(k string) bool { _, _, _, ok := ParseRecordKey(k, known); return ok }}, |
| + {"sidecars/", func(k string) bool { _, _, _, ok := ParseSidecarKey(k, known); return ok }}, |
| + } { |
| + s := &doorShaped{Store: inner, acct: "bab"} |
| + got, partial, err := listAppSubtree(context.Background(), s, known, c.sub) |
| + if err != nil || partial { |
| + t.Fatalf("%s: partial=%v err=%v", c.sub, partial, err) |
| + } |
| + if g, w := parsedRecords(got, c.parse), parsedRecords(all, c.parse); !reflect.DeepEqual(g, w) { |
| + t.Fatalf("%s: the walk found %v, the flat listing %v", c.sub, g, w) |
| + } |
| + if len(s.lists) == 0 { |
| + t.Fatalf("%s: listed nothing", c.sub) |
| + } |
| + for _, p := range s.lists { |
| + if !strings.HasPrefix(p, "apps/bab/") || !strings.HasSuffix(p, "/"+c.sub) { |
| + t.Fatalf("%s: listed %q; the door walk lists only apps/bab/<app>/%s", c.sub, p, c.sub) |
| + } |
| + } |
| + } |
| +} |
| + |
| +// The walk trusts the door's ListDirs("apps/") only in the shape it promises. |
| +// An empty answer, or any directory that is not apps/<acct>/<app>/, is listed |
| +// the old way, whole, so a door that answers differently can never make the |
| +// records look absent (which reconcile would read as every route retired). |
| +func TestAppSubtreeListsTheOldWayWhenTheDoorAnswersOffShape(t *testing.T) { |
| + known := map[string]bool{"bab": true} |
| + parse := func(k string) bool { _, _, _, ok := ParseRecordKey(k, known); return ok } |
| + want := []string{ |
| + "apps/bab/blog/instances/c.example.com.json", |
| + "apps/bab/shop/instances/a.example.com.json", |
| + "apps/bab/shop/instances/b.example.com.json", |
| + } |
| + for _, c := range []struct { |
| + name string |
| + answer []string |
| + }{ |
| + {"empty", []string{}}, |
| + {"account directories", []string{"apps/bab/"}}, |
| + {"one too deep", []string{"apps/bab/shop/", "apps/bab/shop/instances/"}}, |
| + {"outside apps/", []string{"apps/bab/shop/", "fleets/x/"}}, |
| + {"no trailing slash", []string{"apps/bab/shop"}}, |
| + {"empty segment", []string{"apps/bab//"}}, |
| + } { |
| + s := &doorShaped{Store: seedAppListingBucket(t), acct: "bab", dirsAnswer: c.answer} |
| + got, partial, err := listAppSubtree(context.Background(), s, known, "instances/") |
| + if err != nil || partial { |
| + t.Fatalf("%s: partial=%v err=%v", c.name, partial, err) |
| + } |
| + if g := parsedRecords(got, parse); !reflect.DeepEqual(g, want) { |
| + t.Fatalf("%s: records = %v, want %v", c.name, g, want) |
| + } |
| + if !s.listedAllOfApps() { |
| + t.Fatalf("%s: an off-shape answer was walked, not listed whole: %v", c.name, s.lists) |
| + } |
| + } |
| +} |
| + |
| +// An app directory of an account the box does not know is not walked: the |
| +// flat listing's parsers refuse its records too. |
| +func TestAppSubtreeDoorSkipsUnknownAccounts(t *testing.T) { |
| + s := &doorShaped{Store: seedAppListingBucket(t), acct: "bab", |
| + dirsAnswer: []string{"apps/bab/shop/", "apps/bad/site/"}} |
| + known := map[string]bool{"bab": true} |
| + if _, _, err := listAppSubtree(context.Background(), s, known, "instances/"); err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, p := range s.lists { |
| + if strings.HasPrefix(p, "apps/bad/") { |
| + t.Fatalf("listed %q under an account the box does not know", p) |
| + } |
| + } |
| +} |
| + |
| +// One app's listing failing through the door is partial, as on a bucket; the |
| +// door's ListDirs("apps/") failing is an error, as the flat List failing was. |
| +func TestAppSubtreeDoorFailures(t *testing.T) { |
| + known := map[string]bool{"bab": true} |
| + parse := func(k string) bool { _, _, _, ok := ParseRecordKey(k, known); return ok } |
| + s := &doorShaped{Store: seedAppListingBucket(t), acct: "bab", failList: "apps/bab/blog/instances/"} |
| + got, partial, err := listAppSubtree(context.Background(), s, known, "instances/") |
| + if err != nil { |
| + t.Fatalf("one failed app listing failed the walk: %v", err) |
| + } |
| + if !partial { |
| + t.Fatal("a failed app listing was not reported as partial") |
| + } |
| + want := []string{"apps/bab/shop/instances/a.example.com.json", "apps/bab/shop/instances/b.example.com.json"} |
| + if g := parsedRecords(got, parse); !reflect.DeepEqual(g, want) { |
| + t.Fatalf("records = %v, want %v", g, want) |
| + } |
| + |
| + s = &doorShaped{Store: seedAppListingBucket(t), acct: "bab", failDirs: "apps/"} |
| + if _, _, err := listAppSubtree(context.Background(), s, known, "instances/"); err == nil { |
| + t.Fatal("the door's ListDirs(apps/) failing came back without an error") |
| + } |
| +} |
| + |
| +// The record readers over the door: reconcile mints the same route it mints |
| +// off a plain store, and no reader lists the whole of apps/. |
| +func TestRecordReadersWalkTheFleetDoor(t *testing.T) { |
| + inner, sqid := setup(t) |
| + if err := CreateRecord(ctx, inner, acmeRecord(sqid)); err != nil { |
| + t.Fatal(err) |
| + } |
| + cfg := ReconcileConfig{Region: "ie", Pools: []string{"tito"}, DataDir: "/data"} |
| + plainReg := regWith(t) |
| + if err := Reconcile(ctx, inner, plainReg, cfg); err != nil { |
| + t.Fatal(err) |
| + } |
| + s := &doorShaped{Store: inner, acct: sqid} |
| + reg := regWith(t) |
| + if err := Reconcile(ctx, s, reg, cfg); err != nil { |
| + t.Fatal(err) |
| + } |
| + want, got := *mustGet(t, plainReg, "acme.go.tito.io"), *mustGet(t, reg, "acme.go.tito.io") |
| + want.CreatedAt, got.CreatedAt = 0, 0 |
| + if got != want { |
| + t.Fatalf("minted over the door walk = %+v, over the full listing %+v", got, want) |
| + } |
| + recs, err := ListAllRecords(ctx, s) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if len(recs) != 1 || recs[0].Host != "acme.go.tito.io" { |
| + t.Fatalf("ListAllRecords = %+v, want the one acme record", recs) |
| + } |
| + if err := ReconcileSidecars(ctx, s, reg, cfg); err != nil { |
| + t.Fatal(err) |
| + } |
| + if s.listedAllOfApps() { |
| + t.Fatalf("a record reader listed the whole of apps/ through the door: %v", s.lists) |
| + } |
| +} |
| + |
| +// Through a WalkShare the door is listed per sub, like a bucket: a listing of |
| +// instances/ is never handed back for sidecars/. |
| +func TestWalkShareDoorIsPerSub(t *testing.T) { |
| + s := &doorShaped{Store: seedAppListingBucket(t), acct: "bab"} |
| + known := map[string]bool{"bab": true} |
| + w := NewWalkShare() |
| + w.known = map[string]bool{"bab": true} |
| + if _, _, err := w.subtree(ctx, s, known, "instances/"); err != nil { |
| + t.Fatal(err) |
| + } |
| + side, _, err := w.subtree(ctx, s, known, "sidecars/") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + want, _, _ := listAppSubtree(ctx, s, known, "sidecars/") |
| + if !reflect.DeepEqual(side, want) { |
| + t.Fatalf("sidecars/ through the share = %v, want its own listing %v", side, want) |
| + } |
| +} |
| + |
| +// The interface is optional and not inherited from the bucket shape. |
| +func TestAccountListDirsIsOptIn(t *testing.T) { |
| + if release.HasAccountListDirs(release.NewDirStore(t.TempDir())) { |
| + t.Fatal("DirStore claims the door's shape") |
| + } |
| + if release.HasAccountListDirs(&bucketShaped{Store: release.NewDirStore(t.TempDir())}) { |
| + t.Fatal("a bucket-shaped store claims the door's shape") |
| + } |
| + if !release.HasAccountListDirs(&doorShaped{Store: release.NewDirStore(t.TempDir())}) { |
| + t.Fatal("the door-shaped fake does not") |
| + } |
| +} |
diff --git a/internal/provision/reconcile.go b/internal/provision/reconcile.go| index eb5bdba5f..a3254751a 100644 |
| --- a/internal/provision/reconcile.go |
| +++ b/internal/provision/reconcile.go |
| @@ -3408,13 +3408,16 @@ func readAllRecords(ctx context.Context, s release.Store, strict bool, w *WalkSh |
| // It finds the same records the full listing did. A record's account is |
| // always one of known (the parsers refuse any other), and its app is a |
| // directory directly under the account, so no record lives anywhere the walk |
| -// does not look — PROVIDED ListDirs answers in the bucket's shape. Only a |
| -// store that says so (release.HasBucketListDirs: the S3 store, and a prefix |
| -// store over one) is walked; the fleet door, whose ListDirs("apps/") is its |
| -// own account's app directories, and DirStore, which lists by walking its |
| -// whole root, are listed the old way. Assuming the shape on the fleet door |
| -// found no records at all, and the reconcile pass would have read that as |
| -// every route retired. |
| +// does not look — PROVIDED ListDirs answers in the shape the walk assumes. |
| +// A store that promises the bucket's shape (release.HasBucketListDirs: the |
| +// S3 store, and a prefix store over one) is walked by account and app. The |
| +// fleet door, whose ListDirs("apps/") is its own account's app directories, |
| +// promises that shape instead (release.HasAccountListDirs) and has a walk of |
| +// its own (listDoorApps, #1682), which lists the old way when the answer is |
| +// not in that shape. Walking the door as if it were a bucket found no records |
| +// at all, and the reconcile pass would have read that as every route |
| +// retired. Any other store (DirStore, which lists by walking its whole root) |
| +// is listed the old way. |
| // |
| // Failure comes in two sizes. The top-level listing failing is an error, as |
| // the single List failing was. One account's or one app's listing failing is |
| @@ -3425,6 +3428,11 @@ func readAllRecords(ctx context.Context, s release.Store, strict bool, w *WalkSh |
| // retired the rest", and one app's bad minute must not stop every other app's |
| // routes from being minted. |
| func listAppSubtree(ctx context.Context, s release.Store, known map[string]bool, sub string) (keys []string, partial bool, err error) { |
| + if !release.HasBucketListDirs(s) && release.HasAccountListDirs(s) { |
| + if keys, partial, ok, err := listDoorApps(ctx, s, known, sub); ok { |
| + return keys, partial, err |
| + } |
| + } |
| if !release.HasBucketListDirs(s) { |
| keys, err := s.List(ctx, "apps/") |
| slices.Sort(keys) // Store.List promises no order; the walk's is sorted |
diff --git a/internal/provision/testdata/plan14-root-reads-1682-fleet-door-walk.tsv b/internal/provision/testdata/plan14-root-reads-1682-fleet-door-walk.tsv| new file mode 100644 |
| index 000000000..6ed06431b |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-1682-fleet-door-walk.tsv |
| @@ -0,0 +1,7 @@ |
| +# Census overlay 1682-fleet-door-walk, written by census-propose (#369). census-ruling-1682-fleet-door-walk, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-1682-fleet-door-walk.md. |
| +# 0 body, 0 sites, 5 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +@coverage internal/fleetapi e9ba6216d4bd8b13aa89ea563df9153365016e1e2a47b3f0f8bf7d9089223f1f |
| +@coverage internal/host b7ccd4e9a679d321697b664b72afc26ddbe449583aebb7761ad9c370ecbf8f1a |
| +@coverage internal/hostops df19111eab0f9850262f62b8e4e06503d5482cabf7c8de045f1002d7a731b6a5 |
| +@coverage internal/provision 36321da7c9d18225a028de076970e3e9a7f90922b5324ac339f0ba35d334a547 |
| +@coverage internal/release d09a6cd3dffdff5c21c888c4d8662742d6b0871a40d218cea9cafd138585ee06 |
diff --git a/internal/provision/testdata/plan14-root-reads-1682-floor-slow-line.tsv b/internal/provision/testdata/plan14-root-reads-1682-floor-slow-line.tsv| new file mode 100644 |
| index 000000000..611a8539b |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-1682-floor-slow-line.tsv |
| @@ -0,0 +1,3 @@ |
| +# Census overlay 1682-floor-slow-line, written by census-propose (#369). census-ruling-1682-floor-slow-line, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-1682-floor-slow-line.md. |
| +# 0 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +@coverage internal/host eeaca7988e4bc3d4990419a877c3bec30a170b32ca63901dd77560fcf23217b0 |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index 3acdb7214..a8d92c92d 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -334,4 +334,5 @@ plan14-root-reads-alias-with-mint-1653.tsv ce9536904e10de3f5e5c582061f130f870515 |
| plan14-root-reads-private-store-scan-1653.tsv ce9536904e10de3f5e5c582061f130f870515ae0999de2946658ea49e4a17bf8 |
| plan14-root-reads-canary-retire-orphan-1634.tsv 83cd5238dcd073e8fc89934a72f9c60b96081f15054f32a168f6cd594c88f49c |
| plan14-root-reads-backhaul-streams-1535.tsv dc00dc6bab094e8c81ab4e083a0b6a122ea886a70f8dca4885b5cf8a2bc3b177 |
| -plan14-root-reads-sqlite-integrity-safe.tsv 69fc038fd570d1d7fe5e3cd6a733bacbcf6708499785e5d2c55a9c2c09c58806 |
| +plan14-root-reads-1682-fleet-door-walk.tsv dc00dc6bab094e8c81ab4e083a0b6a122ea886a70f8dca4885b5cf8a2bc3b177 |
| +plan14-root-reads-1682-floor-slow-line.tsv dc00dc6bab094e8c81ab4e083a0b6a122ea886a70f8dca4885b5cf8a2bc3b177 |
diff --git a/internal/provision/walkshare.go b/internal/provision/walkshare.go| index 5ee5440c4..c7246339e 100644 |
| --- a/internal/provision/walkshare.go |
| +++ b/internal/provision/walkshare.go |
| @@ -99,15 +99,17 @@ func (w *WalkShare) accounts(ctx context.Context, s release.Store) (known, faile |
| } |
| // subtree is listAppSubtree through w. A store listed whole answers every |
| -// sub from one listing; a bucket-shaped one is listed per sub, and its |
| -// listing depends on the account set, so it is shared only under the |
| -// share's own account set. |
| +// sub from one listing; a bucket-shaped one, or the fleet door, is listed |
| +// per sub, and its listing depends on the account set, so it is shared only |
| +// under the share's own account set. |
| func (w *WalkShare) subtree(ctx context.Context, s release.Store, known map[string]bool, sub string) (keys []string, partial bool, err error) { |
| if w == nil { |
| return listAppSubtree(ctx, s, known, sub) |
| } |
| id := wholeTree |
| - if release.HasBucketListDirs(s) { |
| + if release.HasBucketListDirs(s) || release.HasAccountListDirs(s) { |
| + // Walked per sub (the fleet door's walk too, listDoorApps): one |
| + // sub's listing never answers another's. |
| id = sub |
| } |
| w.mu.Lock() |
diff --git a/internal/release/store.go b/internal/release/store.go| index 83db0a19c..dade4d24e 100644 |
| --- a/internal/release/store.go |
| +++ b/internal/release/store.go |
| @@ -109,6 +109,29 @@ func HasBucketListDirs(s Store) bool { |
| return ok && b.BucketShapedListDirs() |
| } |
| +// AccountListDirs is the optional half of Store that says ListDirs answers in |
| +// the fleet door's shape (internal/edge storedoor.go, aclListScope): the |
| +// store is scoped to one account, ListDirs("apps/") is that account's APP |
| +// directories (apps/<acct>/<app>/), and List and ListDirs under |
| +// apps/<acct>/<app>/ answer as the bucket would. A record reader may then |
| +// walk the account per app instead of listing every key under it, logs |
| +// included (#1682). |
| +// |
| +// Separate from BucketListDirs, never implied by it: the two shapes answer |
| +// ListDirs("apps/") with different things, and walking one as the other |
| +// finds no records at all. prefixStore does not forward it: rebasing the |
| +// door would change what "apps/" names. |
| +type AccountListDirs interface { |
| + AccountScopedListDirs() bool |
| +} |
| + |
| +// HasAccountListDirs reports whether s promises the door's account-scoped |
| +// ListDirs (AccountListDirs). |
| +func HasAccountListDirs(s Store) bool { |
| + a, ok := s.(AccountListDirs) |
| + return ok && a.AccountScopedListDirs() |
| +} |
| + |
| // BucketShapedListDirs: rebasing keeps the shape of the store underneath. |
| func (p prefixStore) BucketShapedListDirs() bool { return HasBucketListDirs(p.Store) } |