Files
mesh-delivery/modules/mesh-delivery-indexer/internal/index/control_records.go
T
jschoubben fbd75dfac4 indexer: what nothing reads goes
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
2026-11-20 05:32:16 +01:00

68 lines
2.5 KiB
Go

package index
import (
"context"
"encoding/json"
"errors"
"time"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
"git.novox.be/novox/mesh-sdk/go/keys"
"git.novox.be/novox/mesh-sdk/go/process"
)
// The indexer's control record (novox/hq ADR 0565 §2, issue 1953 D2): the catalogue's predefined list, read from the forge
// bridge's merged message. mesh-config reads it in place of the controller's mirror; a key's write is its event, nothing
// polls. A pull request's config declarations are no longer kept: the mesh knows no pull request (design 47 G, ADR 0565 §2
// and §3 ended by the operator's word, record pending).
// writePredefined keeps the predefined list a merged message carries, unless the key names a later merge: a merge older
// than the one it names never replaces it (ADR 0348 §7). The same list at the same merge writes nothing (ADR 0289 §1).
func (ix *Indexer) writePredefined(ctx context.Context, f whole) error {
if ix.Predefined == nil || len(f.Predefined) == 0 {
return nil
}
return ix.notYet(PredefinedState, write(ctx, ix.Predefined, PredefinedListKey, func(value []byte, found bool) ([]byte, bool, error) {
if found {
var cur struct { // the list is compared as it was kept, byte for byte
Commit string `json:"commit"`
List json.RawMessage `json:"list"`
}
if err := json.Unmarshal(value, &cur); err == nil {
if cur.Commit == f.Merge && string(cur.List) == string(f.Predefined) {
return nil, false, nil
}
older, err := ix.older(ctx, f.Repository, f.Merge, cur.Commit)
if err != nil {
return nil, false, err
}
if older {
ix.logf("%s: the predefined list of %.12s is older than the one kept (%.12s): left", f.Repository, f.Merge, cur.Commit)
return nil, false, nil
}
}
}
next, err := json.Marshal(meshcatalog.PredefinedByListValue{V: keys.Version, Commit: f.Merge, At: ptr(ix.now()), List: f.Predefined})
return next, false, err
}))
}
// notYet says a state not on the bus yet (it comes with this delivery, bound when it appears) and lets the message go:
// what it would have written is written at the next message that carries it.
func (ix *Indexer) notYet(state string, err error) error {
if errors.Is(err, process.ErrNotYet) {
ix.logf("the state %s is not on the bus yet: nothing is written to it for this message", state)
return nil
}
return err
}
func (ix *Indexer) now() time.Time {
if ix.Now != nil {
return ix.Now()
}
return time.Now()
}
func ptr[T any](v T) *T { return &v }