From fbd75dfac47ffcd3d12c9f440d8e6d0c84bf340a Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 20 Nov 2026 05:32:16 +0100 Subject: [PATCH] indexer: what nothing reads goes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit packageEntries, manifestBytes, writtenModules, WriteHeard, heldOldSections, keepOldSections, the overlay's written and changed, moduleOfDir with moduleAt, EncodeSeriesPackage, InputDigest, HoldSeats and the barBlock shape's functions are referenced by no file of the repository; with HoldSeats gone the seat list's lock is a plain mutex WithSeats takes. barShows and barOption stay: a judge test reads them. Builds: design 47 H §764; lead answer H-A-48 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy --- .../internal/index/artifacts.go | 16 ---- .../internal/index/catalog_revisions.go | 12 --- .../internal/index/control_records.go | 10 --- .../internal/index/heard.go | 12 --- .../internal/index/oldsections.go | 37 -------- .../internal/index/overlay.go | 16 ---- .../internal/index/own.go | 27 ------ .../internal/index/packages_values.go | 11 +-- .../internal/index/run_inputs.go | 6 -- modules/mesh-delivery-indexer/judge/rules.go | 89 ------------------- .../mesh-delivery-indexer/judge/seatsover.go | 16 +--- 11 files changed, 5 insertions(+), 247 deletions(-) diff --git a/modules/mesh-delivery-indexer/internal/index/artifacts.go b/modules/mesh-delivery-indexer/internal/index/artifacts.go index e12e23e1..0473a654 100644 --- a/modules/mesh-delivery-indexer/internal/index/artifacts.go +++ b/modules/mesh-delivery-indexer/internal/index/artifacts.go @@ -2,7 +2,6 @@ package index import ( "context" - "maps" "slices" "strings" @@ -83,18 +82,3 @@ func (ix *Indexer) packageOf(ctx context.Context, e meshcatalog.CatalogEntry, a } return &meshcatalog.ArtifactPackage{Ecosystem: ecosystem, Name: name} } - -// packageEntries is the entry of each module whose manifest decodes, with its artifacts' package names as the take-in reads -// them, for the judge of §491 to read the names from. -func (ix *Indexer) packageEntries(ctx context.Context, held map[string]meshcatalog.ModulesByModuleValue, raws map[string][]byte) []meshcatalog.CatalogEntry { - var out []meshcatalog.CatalogEntry - for _, name := range slices.Sorted(maps.Keys(raws)) { - m, err := catalogue.Decode(raws[name]) - if err != nil { - continue - } - cur := held[name] - out = append(out, ix.withArtifacts(ctx, meshcatalog.CatalogEntry{Module: name, Repository: cur.Repository, Path: cur.Path, Commit: cur.Commit}, m)) - } - return out -} diff --git a/modules/mesh-delivery-indexer/internal/index/catalog_revisions.go b/modules/mesh-delivery-indexer/internal/index/catalog_revisions.go index b76627a4..e584f836 100644 --- a/modules/mesh-delivery-indexer/internal/index/catalog_revisions.go +++ b/modules/mesh-delivery-indexer/internal/index/catalog_revisions.go @@ -770,18 +770,6 @@ func (m markSource) Get(state string) (*views.Entry, bool, error) { return &views.Entry{Value: data, Revision: uint64(at)}, true, nil } -// manifestBytes is the manifest the module's value names by its digest, as the forge answered it; empty when it is not kept. -func (ix *Indexer) manifestBytes(ctx context.Context, digest string) string { - if digest == "" || ix.Manifests == nil { - return "" - } - raw, _, err := ix.manifestRaw(ctx, digest) - if err != nil { - return "" - } - return raw -} - // NewestRevision is the number of the newest catalog graph revision kept for the watched branch, 0 when none is kept: the // revision a take-in has just made, said with its take-in.taken (design 47 G §476, A-448). func (ix *Indexer) NewestRevision(ctx context.Context, branch string) int64 { diff --git a/modules/mesh-delivery-indexer/internal/index/control_records.go b/modules/mesh-delivery-indexer/internal/index/control_records.go index d1ccb81b..f9725a1e 100644 --- a/modules/mesh-delivery-indexer/internal/index/control_records.go +++ b/modules/mesh-delivery-indexer/internal/index/control_records.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "errors" - "strings" "time" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" @@ -65,13 +64,4 @@ func (ix *Indexer) now() time.Time { return time.Now() } -// writtenModules are the modules a merged message wrote, from its written keys (`modules.`). -func writtenModules(written []string) []string { - var out []string - for _, k := range written { - out = append(out, strings.TrimPrefix(k, "modules.")) - } - return out -} - func ptr[T any](v T) *T { return &v } diff --git a/modules/mesh-delivery-indexer/internal/index/heard.go b/modules/mesh-delivery-indexer/internal/index/heard.go index 6a55f6b8..39a942de 100644 --- a/modules/mesh-delivery-indexer/internal/index/heard.go +++ b/modules/mesh-delivery-indexer/internal/index/heard.go @@ -1,8 +1,6 @@ package index import ( - "context" - "encoding/json" "time" ) @@ -48,13 +46,3 @@ type Applied struct { Written []string Late string } - -// WriteHeard writes h as the newest value of heard.forge. -func WriteHeard(ctx context.Context, st Store, h Heard) error { - h.V = 1 - data, err := json.Marshal(h) - if err != nil { - return err - } - return write(ctx, st, HeardKey, func([]byte, bool) ([]byte, bool, error) { return data, false, nil }) -} diff --git a/modules/mesh-delivery-indexer/internal/index/oldsections.go b/modules/mesh-delivery-indexer/internal/index/oldsections.go index 67d80c40..a3885ace 100644 --- a/modules/mesh-delivery-indexer/internal/index/oldsections.go +++ b/modules/mesh-delivery-indexer/internal/index/oldsections.go @@ -1,12 +1,8 @@ package index import ( - "context" "encoding/json" "fmt" - "maps" - - "mesh-delivery-indexer/judge" ) // How many accepted modules use each old section (issue 1966 D4; novox/hq ADR 0595 §11): the indexer counts them, the @@ -41,36 +37,3 @@ func DecodeOldSections(value []byte) (OldSectionsCount, error) { } return c, nil } - -// heldOldSections is the count the last pass wrote (the accepted set it held): a module that keeps using a section was -// accepted with it, so it is counted, and a fresh manifest changes nothing in it. Nil when none is held yet or it cannot be -// read; a failed read is said, never taken as 0 (issue 1966 D4). -func (ix *Indexer) heldOldSections(ctx context.Context) judge.OldSectionCounts { - value, _, found, err := ix.OldSections.Get(ctx, OldSectionsKey) - if err == nil && found { - var c OldSectionsCount - if c, err = DecodeOldSections(value); err == nil { - return c.Counts - } - } - if err != nil { - ix.logf("judge: the count of the old sections cannot be read (%v), so the zero rule is not applied in this pass", err) - } - return nil -} - -// keepOldSections writes the counts under OldSectionsKey when they differ from the ones held. -func (ix *Indexer) keepOldSections(ctx context.Context, counts judge.OldSectionCounts, reads map[string]int) error { - if ix.OldSections == nil { - return nil - } - return write(ctx, ix.OldSections, OldSectionsKey, func(value []byte, found bool) ([]byte, bool, error) { - if found { - if cur, err := DecodeOldSections(value); err == nil && maps.Equal(cur.Counts, counts) && maps.Equal(cur.Reads, reads) { - return nil, false, nil - } - } - next, err := json.Marshal(OldSectionsCount{V: 1, Counts: counts, Reads: reads}) - return next, false, err - }) -} diff --git a/modules/mesh-delivery-indexer/internal/index/overlay.go b/modules/mesh-delivery-indexer/internal/index/overlay.go index 6405f0a4..67702978 100644 --- a/modules/mesh-delivery-indexer/internal/index/overlay.go +++ b/modules/mesh-delivery-indexer/internal/index/overlay.go @@ -2,7 +2,6 @@ package index import ( "context" - "maps" "slices" "sync" ) @@ -93,18 +92,3 @@ func (o *overlayStore) Keys(ctx context.Context) ([]string, error) { slices.Sort(keys) return keys, nil } - -// written is what the overlay holds of key: its value, and whether it wrote or deleted it at all. -func (o *overlayStore) written(key string) (value []byte, deleted, ok bool) { - o.mu.Lock() - defer o.mu.Unlock() - v, ok := o.vals[key] - return slices.Clone(v.value), v.deleted, ok -} - -// changed is every key the overlay wrote or deleted, in order. -func (o *overlayStore) changed() []string { - o.mu.Lock() - defer o.mu.Unlock() - return slices.Sorted(maps.Keys(o.vals)) -} diff --git a/modules/mesh-delivery-indexer/internal/index/own.go b/modules/mesh-delivery-indexer/internal/index/own.go index c008596f..020fe5c0 100644 --- a/modules/mesh-delivery-indexer/internal/index/own.go +++ b/modules/mesh-delivery-indexer/internal/index/own.go @@ -4,12 +4,9 @@ import ( "context" "encoding/json" "fmt" - "path" - "strings" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/trunk" ) // From R4e the indexer lists a repository's modules from what it holds itself (novox/hq ADR 0501 clause 6, issue 1851): @@ -57,27 +54,3 @@ func (ix *Indexer) heldModules(ctx context.Context) (map[string]meshcatalog.Modu } return out, nil } - -// moduleAt is the module whose directory in the repository is dir, as the modules bucket holds it. -func moduleAt(held map[string]meshcatalog.ModulesByModuleValue, repository, dir string) (string, bool) { - want := pathOf(strings.Trim(dir, "/")) - for name, m := range held { - if m.Path == want && trunk.SameRepository(m.Repository, repository) { - return name, true - } - } - return "", false -} - -// moduleOfDir is the module of a changed directory of a pull request: the module its manifest in the message names, else -// the one the modules bucket holds at that directory of the repository, else the directory's last element (the -// catalogue's rule for nearly every manifest). -func moduleOfDir(held map[string]meshcatalog.ModulesByModuleValue, f whole, dir string) string { - if name := manifestModule(f.Manifests[dir]); name != "" { - return name - } - if name, ok := moduleAt(held, f.Repository, dir); ok { - return name - } - return path.Base(strings.Trim(dir, "/")) -} diff --git a/modules/mesh-delivery-indexer/internal/index/packages_values.go b/modules/mesh-delivery-indexer/internal/index/packages_values.go index 9f64525e..bc511574 100644 --- a/modules/mesh-delivery-indexer/internal/index/packages_values.go +++ b/modules/mesh-delivery-indexer/internal/index/packages_values.go @@ -146,16 +146,7 @@ func checkSeries(s meshcatalog.PackagesByPackageSeriesValue) error { return nil } -// EncodeSeriesPackage is s as JSON at the kept values' version; it refuses what a reader could not take. -func EncodeSeriesPackage(s meshcatalog.PackagesByPackageSeriesValue) ([]byte, error) { - if err := checkSeries(s); err != nil { - return nil, err - } - s.V = keys.Version - return json.Marshal(s) -} - -// DecodeSeriesPackage reads a series key's value; it refuses an unknown version and what EncodeSeriesPackage refuses. +// DecodeSeriesPackage reads a series key's value; it refuses an unknown version and what checkSeries refuses. func DecodeSeriesPackage(data []byte) (meshcatalog.PackagesByPackageSeriesValue, error) { if err := keys.CheckVersion(data); err != nil { return meshcatalog.PackagesByPackageSeriesValue{}, err diff --git a/modules/mesh-delivery-indexer/internal/index/run_inputs.go b/modules/mesh-delivery-indexer/internal/index/run_inputs.go index 8043a8d6..ca681ea4 100644 --- a/modules/mesh-delivery-indexer/internal/index/run_inputs.go +++ b/modules/mesh-delivery-indexer/internal/index/run_inputs.go @@ -39,12 +39,6 @@ const ( InputsAskPrefix = "ask." ) -// InputDigest is the sha256 of an input's exact bytes, as "sha256:" and its hex digits. -func InputDigest(body []byte) string { - sum := sha256.Sum256(body) - return "sha256:" + hex.EncodeToString(sum[:]) -} - // runDigest is the digest a run ask names its input by (buildstep.RunInput.Digest): the 64 hex digits of its sha256, which are also // the digest of the key's form, a name a state's key may hold (a ':' may not be). func runDigest(body []byte) string { diff --git a/modules/mesh-delivery-indexer/judge/rules.go b/modules/mesh-delivery-indexer/judge/rules.go index 00774d62..d675cb5f 100644 --- a/modules/mesh-delivery-indexer/judge/rules.go +++ b/modules/mesh-delivery-indexer/judge/rules.go @@ -8060,95 +8060,6 @@ func withEnum(s map[string]any, property string, values ...string) map[string]an return s } -// barBlockShape is the shape of a block (novox/hq ADR 0255): which bar, where on it, in what order, -// what it shows, and that kind's options. -// -// - bar: top or bottom; -// - place: resources (beside the processor, memory and disks) or status (beside the sound, before the -// clock) — the two places every holder keeps for contributed blocks; -// - order: 0–99 within the place, 50 when absent; -// - shows: battery or command; options: what that kind takes. -func barBlockShape() *catalogue.Shape { - return &catalogue.Shape{ - Text: true, - Places: []catalogue.PlaceField{{Field: "bar", Values: []string{"bottom", "top"}}, - {Field: "place", Values: []string{"resources", "status"}}}, - Order: "order", - Check: barBlockProblems, - Reads: barBlockReads, - Examples: []map[string]any{ - {"bar": "bottom", "place": "status", "shows": "battery"}, - {"bar": "bottom", "place": "status", "shows": "battery", "options": map[string]any{"device": "BAT0"}}, - {"bar": "bottom", "place": "status", "shows": "command", - "options": map[string]any{"command": "echo \"a line\"", "interval": float64(5)}}, - {"bar": "bottom", "place": "status", "shows": "state", "options": map[string]any{"state": "power.draw"}}, - {"bar": "bottom", "place": "status", "shows": "state", - "options": map[string]any{"state": "power.draw", "key": "a-machine"}}, - }, - } -} - -func barBlockProblems(data map[string]any) []string { - var problems []string - for field := range data { - if !oneOf([]string{"bar", "place", "order", "shows", "options"}, field) { - problems = append(problems, fmt.Sprintf("a block has no field %q; it has bar, place, order, shows and options", field)) - } - } - shows, _ := data["shows"].(string) - takes, known := barShows[shows] - if !known { - return append(problems, fmt.Sprintf("a block shows %v; it shows one of %s", data["shows"], - strings.Join(sortedKeys(barShows), ", "))) - } - options := map[string]any{} - if raw, has := data["options"]; has { - o, ok := raw.(map[string]any) - if !ok { - return append(problems, "a block's options are an object") - } - options = o - } - for name, v := range options { - opt, ok := takes[name] - if !ok { - problems = append(problems, fmt.Sprintf("a %s block has no option %q; it takes %s", shows, name, - orNothing(sortedKeys(takes)))) - continue - } - switch opt.kind { - case "text": - if t, isText := v.(string); !isText || strings.TrimSpace(t) == "" { - problems = append(problems, fmt.Sprintf("a %s block's %s is text", shows, name)) - } - case "seconds": - if _, whole := wholeIn(v, 1, 86400); !whole { - problems = append(problems, fmt.Sprintf("a %s block's %s is a whole number of seconds from 1 to 86400", shows, name)) - } - } - } - for _, name := range sortedKeys(takes) { - if _, has := options[name]; takes[name].required && !has { - problems = append(problems, fmt.Sprintf("a %s block needs the option %s", shows, name)) - } - } - return problems -} - -// barBlockReads is the state and key a block shows, if any; an empty key is the machine's own. -func barBlockReads(data map[string]any) []catalogue.StateRead { - if data["shows"] != "state" { - return nil - } - options, _ := data["options"].(map[string]any) - s, ok := options["state"].(string) - if !ok || s == "" { - return nil - } - key, _ := options["key"].(string) - return []catalogue.StateRead{{Read: s, Key: key}} -} - var barShows = map[string]map[string]barOption{ // The machine's battery: its charge, and how long it lasts or takes to fill. "battery": {"device": {kind: "text"}}, diff --git a/modules/mesh-delivery-indexer/judge/seatsover.go b/modules/mesh-delivery-indexer/judge/seatsover.go index 99b80f60..e991d3ba 100644 --- a/modules/mesh-delivery-indexer/judge/seatsover.go +++ b/modules/mesh-delivery-indexer/judge/seatsover.go @@ -28,19 +28,11 @@ func merged(base, over []catalogue.Seat) []catalogue.Seat { } // seatsMu keeps the seat list the catalogue holds (a list of the process, fed from the bus by the seat list reader) still -// while one pass judges with another: WithSeats takes it whole; a judge pass of the running indexer that uses the list as it -// stands takes it shared. -var seatsMu sync.RWMutex +// while one pass judges with another: WithSeats takes it. +var seatsMu sync.Mutex -// HoldSeats keeps the catalogue's seat list as it stands until the returned function is called, so a pass that judges -// with it never sees another's (WithSeats). The one pass inside WithSeats does not take it. -func HoldSeats() func() { - seatsMu.RLock() - return seatsMu.RUnlock -} - -// WithSeats runs fn with seats put over the catalogue's seat list (merged), and puts the list back after. Nothing -// else judges meanwhile (HoldSeats). fn must not call HoldSeats. No seats runs fn as it is, without the exclusion. +// WithSeats runs fn with seats put over the catalogue's seat list (merged), and puts the list back after. No other +// WithSeats runs meanwhile. No seats runs fn as it is, without the exclusion. func WithSeats(seats []catalogue.Seat, fn func()) { if len(seats) == 0 { fn()