| index d81d42182..d2e9cfed9 100644 |
| --- a/internal/console/apidigests.go |
| +++ b/internal/console/apidigests.go |
| @@ -7,6 +7,7 @@ import ( |
| "log" |
| "net/http" |
| "slices" |
| + "sync" |
| "time" |
| |
| "github.com/carlosframework/platform/internal/release" |
| @@ -235,77 +236,112 @@ func (s *Server) handleAPISystemPointerDigests(w http.ResponseWriter, r *http.Re |
| sqids = append(sqids, sqid) |
| } |
| } |
| - type acctRow struct { |
| - Account string `json:"account"` |
| - On bool `json:"on"` |
| - Since string `json:"since,omitempty"` |
| - Error string `json:"error,omitempty"` |
| - // BucketOnly is an account the bucket holds and this console does |
| - // not: listed for its heads; a marker request never names it. |
| - BucketOnly bool `json:"bucket_only,omitempty"` |
| + // Accounts are walked digestWalkers at a time, each into its own slot, |
| + // so the report keeps the sequential walk's order under the deadline |
| + // (Fable R3 P2-1). |
| + walks := make([]digestAccountWalk, len(sqids)) |
| + sem := make(chan struct{}, digestWalkers) |
| + var wg sync.WaitGroup |
| + for i, sqid := range sqids { |
| + sem <- struct{}{} |
| + wg.Go(func() { |
| + defer func() { <-sem }() |
| + walks[i] = s.walkDigestAccount(ctx, sqid, !known[sqid]) |
| + }) |
| } |
| - type chRow struct { |
| - Account string `json:"account"` |
| - App string `json:"app"` |
| - Channel string `json:"channel"` |
| - Version string `json:"version"` |
| - Straggler bool `json:"straggler"` |
| + wg.Wait() |
| + acctRows, chRows, repRows := []digestAcctRow{}, []digestChRow{}, []digestRepRow{} |
| + for _, wk := range walks { |
| + acctRows = append(acctRows, wk.row) |
| + chRows = append(chRows, wk.channels...) |
| + repRows = append(repRows, wk.repairs...) |
| } |
| - // repRow is a channel whose head a fresh or replaced box would refuse |
| - // (release.ChannelDigestState.NeedsRepair), listed whatever the |
| - // account's marker says: the account binding's rollout waits on none. |
| - type repRow struct { |
| - Account string `json:"account"` |
| - App string `json:"app"` |
| - Channel string `json:"channel"` |
| - Version string `json:"version"` |
| - Unbound bool `json:"unbound,omitempty"` |
| - NoRecord bool `json:"no_record,omitempty"` |
| + writeJSON(w, http.StatusOK, map[string]any{"accounts": acctRows, "channels": chRows, "repairs": repRows}) |
| +} |
| + |
| +// digestWalkers is how many accounts the pointer digests report walks at once. |
| +const digestWalkers = 4 |
| + |
| +type digestAcctRow struct { |
| + Account string `json:"account"` |
| + On bool `json:"on"` |
| + Since string `json:"since,omitempty"` |
| + Error string `json:"error,omitempty"` |
| + // BucketOnly is an account the bucket holds and this console does |
| + // not: listed for its heads; a marker request never names it. |
| + BucketOnly bool `json:"bucket_only,omitempty"` |
| +} |
| + |
| +type digestChRow struct { |
| + Account string `json:"account"` |
| + App string `json:"app"` |
| + Channel string `json:"channel"` |
| + Version string `json:"version"` |
| + Straggler bool `json:"straggler"` |
| +} |
| + |
| +// digestRepRow is a channel whose head a fresh or replaced box would refuse |
| +// (release.ChannelDigestState.NeedsRepair), listed whatever the |
| +// account's marker says: the account binding's rollout waits on none. |
| +type digestRepRow struct { |
| + Account string `json:"account"` |
| + App string `json:"app"` |
| + Channel string `json:"channel"` |
| + Version string `json:"version"` |
| + Unbound bool `json:"unbound,omitempty"` |
| + NoRecord bool `json:"no_record,omitempty"` |
| +} |
| + |
| +// digestAccountWalk is one account's part of the pointer digests report. |
| +type digestAccountWalk struct { |
| + row digestAcctRow |
| + channels []digestChRow |
| + repairs []digestRepRow |
| +} |
| + |
| +// walkDigestAccount reads one account's marker and every app's channels |
| +// for handleAPISystemPointerDigests. A read that fails is the row's error, |
| +// never a shorter listing. |
| +func (s *Server) walkDigestAccount(ctx context.Context, sqid string, bucketOnly bool) digestAccountWalk { |
| + wk := digestAccountWalk{row: digestAcctRow{Account: sqid, BucketOnly: bucketOnly}} |
| + row := &wk.row |
| + m, err := release.ReadDigestMarker(ctx, s.cfg.Releases, s.cfg.ReleasePub, sqid) |
| + if err != nil { |
| + row.Error = err.Error() |
| + return wk |
| } |
| - acctRows, chRows, repRows := []acctRow{}, []chRow{}, []repRow{} |
| - for _, sqid := range sqids { |
| - row := acctRow{Account: sqid, BucketOnly: !known[sqid]} |
| - m, err := release.ReadDigestMarker(ctx, s.cfg.Releases, s.cfg.ReleasePub, sqid) |
| + if m != nil { |
| + row.On, row.Since = true, m.At.UTC().Format(time.RFC3339) |
| + } |
| + apps, err := release.BucketApps(ctx, s.cfg.Releases, sqid) |
| + if err != nil { |
| + row.Error = fmt.Sprintf(textBucketListApps, sqid, err) |
| + return wk |
| + } |
| + for _, app := range apps { |
| + states, _, err := release.DigestReport(ctx, s.cfg.Releases, s.cfg.ReleasePub, sqid, app) |
| if err != nil { |
| row.Error = err.Error() |
| - acctRows = append(acctRows, row) |
| - continue |
| - } |
| - if m != nil { |
| - row.On, row.Since = true, m.At.UTC().Format(time.RFC3339) |
| + break |
| } |
| - apps, err := release.BucketApps(ctx, s.cfg.Releases, sqid) |
| - if err != nil { |
| - row.Error = fmt.Sprintf(textBucketListApps, sqid, err) |
| - acctRows = append(acctRows, row) |
| - continue |
| - } |
| - for _, app := range apps { |
| - states, _, err := release.DigestReport(ctx, s.cfg.Releases, s.cfg.ReleasePub, sqid, app) |
| - if err != nil { |
| - row.Error = err.Error() |
| - break |
| - } |
| - for _, st := range states { |
| - switch { |
| - case st.Err != "": |
| - // Unknown, not "has digests": the account's report is |
| - // incomplete, so the CLI never calls the fleet ready. |
| - if row.Error == "" { |
| - row.Error = st.Err |
| - } |
| - case !st.HeadDigest: |
| - chRows = append(chRows, chRow{Account: sqid, App: app, Channel: st.Channel, Version: st.Version, Straggler: st.Straggler}) |
| - } |
| - if st.Err == "" && st.RecordErr != "" && row.Error == "" { |
| - row.Error = st.RecordErr // unknown whether it needs a repair |
| - } |
| - if st.Err == "" && st.NeedsRepair() { |
| - repRows = append(repRows, repRow{Account: sqid, App: app, Channel: st.Channel, Version: st.Version, Unbound: st.Unbound, NoRecord: st.NoRecord}) |
| + for _, st := range states { |
| + switch { |
| + case st.Err != "": |
| + // Unknown, not "has digests": the account's report is |
| + // incomplete, so the CLI never calls the fleet ready. |
| + if row.Error == "" { |
| + row.Error = st.Err |
| } |
| + case !st.HeadDigest: |
| + wk.channels = append(wk.channels, digestChRow{Account: sqid, App: app, Channel: st.Channel, Version: st.Version, Straggler: st.Straggler}) |
| + } |
| + if st.Err == "" && st.RecordErr != "" && row.Error == "" { |
| + row.Error = st.RecordErr // unknown whether it needs a repair |
| + } |
| + if st.Err == "" && st.NeedsRepair() { |
| + wk.repairs = append(wk.repairs, digestRepRow{Account: sqid, App: app, Channel: st.Channel, Version: st.Version, Unbound: st.Unbound, NoRecord: st.NoRecord}) |
| } |
| } |
| - acctRows = append(acctRows, row) |
| } |
| - writeJSON(w, http.StatusOK, map[string]any{"accounts": acctRows, "channels": chRows, "repairs": repRows}) |
| + return wk |
| } |