I1: the indexer hears imports-reported and keeps each module's import set
The indexer consumes node-build-go and node-build-node imports-reported; a report of the
fingerprint main's modules state holds for the module keeps the set on the module (Imports,
ImportForm, as the build log path did) and in the new state imports (one key per module,
{module, fingerprint, commit, imports: [{package, digest}]}, the digests the import form is
computed with), deleted with the module's modules key. A report of another fingerprint is
left; one naming no module or fingerprint is said and acknowledged.
Builds: design 47 H2 H-A-517, H-A-518, H-A-519, H-A-527, H-A-529, H-A-532 DQ-3, DQ-4, DQ-13, DMC-2
This commit is contained in:
@@ -26,6 +26,7 @@ import (
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildnode"
|
||||
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||
"github.com/nats-io/nats.go"
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
@@ -378,6 +379,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
BuildEdges: awaitedStore{b: process.AwaitBucket(ctx, js, conn, index.Bucket(cred.Module, index.BuildEdgesState), "no build of another watched branch keeps its edges", logger.Printf)},
|
||||
Pins: pinsStore, PinsPending: pendingOf(js, cred),
|
||||
Held: awaitedStore{b: process.AwaitBucket(ctx, js, conn, index.Bucket(cred.Module, index.HeldState), "no held take-in is kept, so indexer_pending reads none", logger.Printf)},
|
||||
Imports: awaitedStore{b: process.AwaitBucket(ctx, js, conn, index.Bucket(cred.Module, index.ImportsState), "no import set is kept, so every module keeps the version line", logger.Printf)},
|
||||
Inputs: inputsStore,
|
||||
InputObjects: inObjects,
|
||||
SayVersionReleased: sayVersionReleased(conn, cred), SayVersionsFilled: sayVersionsFilled(conn, cred),
|
||||
@@ -631,6 +633,12 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
if err := hub.Handle(nodebuildgo.SubjectStepEndedAll, func(m jetstream.Msg) { heardStepEnded(ctx, ix, m, logger.Printf) }); err != nil {
|
||||
return err
|
||||
}
|
||||
// A build's import set, said by its build module at its end (design 47 H2 H-A-517, H-A-532 DQ-2).
|
||||
for _, subject := range []string{nodebuildgo.SubjectImportsReportedAll, nodebuildnode.SubjectImportsReportedAll} {
|
||||
if err := hub.Handle(subject, func(m jetstream.Msg) { heardImportsReported(ctx, ix, m, logger.Printf) }); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := hub.Handle(decidedSubject(cred.Module), func(m jetstream.Msg) { heardDecided(ctx, registry, m, logger.Printf) }); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
@@ -179,6 +180,27 @@ func heardStepEnded(ctx context.Context, ix *index.Indexer, m jetstream.Msg, log
|
||||
_ = m.Ack()
|
||||
}
|
||||
|
||||
// heardImportsReported keeps a build's import set (design 47 H2 H-A-517, H-A-527): one that does not decode, or names no
|
||||
// module or fingerprint, is said and acknowledged; one that cannot be kept is left, so the bus gives it again.
|
||||
func heardImportsReported(ctx context.Context, ix *index.Indexer, m jetstream.Msg, logf func(string, ...any)) {
|
||||
var e nodebuildgo.ImportsReported
|
||||
if err := json.Unmarshal(m.Data(), &e); err != nil {
|
||||
logf("%s holds what is no imports-reported, left: %v", m.Subject(), err)
|
||||
_ = m.Ack()
|
||||
return
|
||||
}
|
||||
err := ix.HearImportsReported(ctx, e)
|
||||
switch {
|
||||
case errors.Is(err, index.ErrImportsUnreadable):
|
||||
logf("%s: %v, left", m.Subject(), err)
|
||||
case err != nil:
|
||||
logf("imports: the import set of %s at %s could not be kept, so the bus gives it again: %v", e.Module, e.Fingerprint, err)
|
||||
leftForBus(m, fmt.Sprintf("the imports-reported of %s at %s", e.Module, e.Fingerprint), err, logf)
|
||||
return
|
||||
}
|
||||
_ = m.Ack()
|
||||
}
|
||||
|
||||
// sayVersionsFilled says versions-filled (design 47 G §372) once, on the seat's stream that keeps it with no age limit.
|
||||
func sayVersionsFilled(conn *nats.Conn, cred process.Account) func(context.Context, meshcatalog.VersionsFilledEvent, string) error {
|
||||
return func(_ context.Context, e meshcatalog.VersionsFilledEvent, id string) error {
|
||||
|
||||
@@ -17,6 +17,7 @@ require (
|
||||
git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner v0.0.0-00010101000000-000000000000
|
||||
git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants v0.0.0-00010101000000-000000000000
|
||||
git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo v0.0.0-00010101000000-000000000000
|
||||
git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildnode v0.0.0-00010101000000-000000000000
|
||||
git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/npmpackageregistry v0.0.0-00010101000000-000000000000
|
||||
git.novox.be/novox/mesh-sdk/go v0.0.0-00010101000000-000000000000
|
||||
github.com/nats-io/nats-server/v2 v2.11.17
|
||||
|
||||
@@ -187,6 +187,8 @@ type Indexer struct {
|
||||
SayTakeIn func(ctx context.Context, event, id string, body any) error
|
||||
// Held is the state held: each watched branch's source-moved held unacknowledged (held.go, design 47 H §744); nil keeps none.
|
||||
Held Store
|
||||
// Imports is the state imports: each module's reported import set (importset.go, design 47 H2 H-A-527); nil keeps none.
|
||||
Imports Store
|
||||
// Runs is the state runs: the runs on request the indexer holds a candidate for (runcandidates.go, A-174); nil keeps none.
|
||||
Runs Store
|
||||
runMu sync.Mutex // one run event at a time (runcandidates.go)
|
||||
|
||||
@@ -76,7 +76,24 @@ func (ix *Indexer) applyBuildEnd(ctx context.Context, value []byte) (bool, error
|
||||
if e.Event != builds.BuildEndedEvent || e.Outcome != builds.BuildDone || len(e.Imports) == 0 || ix.Modules == nil || e.FP == "" {
|
||||
return false, nil
|
||||
}
|
||||
key, err := meshcatalogclient.ModulesKey(e.Module)
|
||||
return ix.keepImports(ctx, reported{module: e.Module, fp: e.FP, commit: e.Commit, imports: e.Imports})
|
||||
}
|
||||
|
||||
// reported is one build's import set as its build module reported it (design 47 H2 H-A-517): the module, the
|
||||
// fingerprint built, its commit and the imported mesh packages by import path.
|
||||
type reported struct {
|
||||
module, fp, commit string
|
||||
imports []string
|
||||
}
|
||||
|
||||
// keepImports keeps the import set e on its module when e's fingerprint is the one main's modules state holds for it
|
||||
// (H-A-532 DMC-2), with ImportForm, and writes it with each package's digest into the state imports (H-A-527, DQ-3,
|
||||
// DQ-4: the digests the import form is computed with). It reports whether it wrote the module.
|
||||
func (ix *Indexer) keepImports(ctx context.Context, e reported) (bool, error) {
|
||||
if ix.Modules == nil || e.fp == "" {
|
||||
return false, nil
|
||||
}
|
||||
key, err := meshcatalogclient.ModulesKey(e.module)
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
@@ -87,10 +104,10 @@ func (ix *Indexer) applyBuildEnd(ctx context.Context, value []byte) (bool, error
|
||||
return false, err
|
||||
}
|
||||
cur, err := meshcatalogclient.DecodeModule(raw)
|
||||
if err != nil || cur.Fp2 != e.FP || cur.Inputs2 == nil || cur.Manifest == "" {
|
||||
if err != nil || cur.Fp2 != e.fp || cur.Inputs2 == nil || cur.Manifest == "" {
|
||||
return false, nil // a build of a fingerprint the module no longer holds says nothing of its inputs now
|
||||
}
|
||||
if slices.Equal(cur.Inputs2.Imports, e.Imports) && cur.Inputs2.ImportForm != "" {
|
||||
if slices.Equal(cur.Inputs2.Imports, e.imports) && cur.Inputs2.ImportForm != "" && ix.importSetHeld(ctx, key, e) {
|
||||
return false, nil
|
||||
}
|
||||
_, m, err := ix.manifestRaw(ctx, cur.Manifest)
|
||||
@@ -101,20 +118,21 @@ func (ix *Indexer) applyBuildEnd(ctx context.Context, value []byte) (bool, error
|
||||
for artifact, language := range languagesOf(m) {
|
||||
used, ok := cur.Toolchains[language]
|
||||
if !ok {
|
||||
ix.logf("%s: its fingerprint names no %s toolchain, so the imports of its build are not kept", e.Module, language)
|
||||
ix.logf("%s: its fingerprint names no %s toolchain, so the imports of its build are not kept", e.module, language)
|
||||
return false, nil
|
||||
}
|
||||
toolchains[artifact] = meshcatalogclient.Toolchain2{Language: language, Version: used.Version, Recipe: used.Recipe}
|
||||
}
|
||||
kept := *cur.Inputs2
|
||||
kept.Imports, kept.ImportForm = slices.Clone(e.Imports), ""
|
||||
kept.Imports, kept.ImportForm = slices.Clone(e.imports), ""
|
||||
digests := map[string]string{}
|
||||
if built, err := ix.publishedAsBuilt(ctx, cur, e); err != nil {
|
||||
ix.logf("%s: the packages its build imported cannot be read as built (%v): its imports are kept, and its next recompute writes the import form", e.Module, err)
|
||||
} else if r := fingerprint.Resolve(cur.Repository, e.Imports, built); len(r.Missing) > 0 {
|
||||
ix.logf("%s: no published package holds %v: its imports are kept, and the recompute that resolves them writes the import form", e.Module, r.Missing)
|
||||
ix.logf("%s: the packages its build imported cannot be read as built (%v): its imports are kept, and its next recompute writes the import form", e.module, err)
|
||||
} else if r := fingerprint.Resolve(cur.Repository, e.imports, built); len(r.Missing) > 0 {
|
||||
ix.logf("%s: no published package holds %v: its imports are kept, and the recompute that resolves them writes the import form", e.module, r.Missing)
|
||||
} else {
|
||||
in := inputsFrom(e.Module, kept, toolchains)
|
||||
in.Imports, in.Requires = r.Digests, r.Requires
|
||||
in := inputsFrom(e.module, kept, toolchains)
|
||||
in.Imports, in.Requires, digests = r.Digests, r.Requires, r.Digests
|
||||
if fp, _ := fingerprint.Of(in); fp != "" {
|
||||
kept.ImportForm = fp
|
||||
}
|
||||
@@ -126,7 +144,7 @@ func (ix *Indexer) applyBuildEnd(ctx context.Context, value []byte) (bool, error
|
||||
return nil, false, nil
|
||||
}
|
||||
now, err := meshcatalogclient.DecodeModule(value)
|
||||
if err != nil || now.Fp2 != e.FP || now.Manifest != cur.Manifest || now.Inputs2 == nil {
|
||||
if err != nil || now.Fp2 != e.fp || now.Manifest != cur.Manifest || now.Inputs2 == nil {
|
||||
return nil, false, nil
|
||||
}
|
||||
in := *now.Inputs2
|
||||
@@ -136,16 +154,22 @@ func (ix *Indexer) applyBuildEnd(ctx context.Context, value []byte) (bool, error
|
||||
wrote = err == nil && !unchanged(data, false, value, found)
|
||||
return data, false, err
|
||||
})
|
||||
return wrote && err == nil, err
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if err := ix.writeImportSet(ctx, key, e, digests); err != nil {
|
||||
return wrote, err
|
||||
}
|
||||
return wrote, nil
|
||||
}
|
||||
|
||||
// publishedAsBuilt are the published Go modules holding the imports of build e of module cur, each as the build took
|
||||
// it: a module of the built module's own repository at the commit built, one of another repository at the version the
|
||||
// module's fingerprint pins (cur.Packages), else its latest published version. A module whose published commit is the
|
||||
// one built is taken from the packages state; any other is read from the forge's listing at that commit.
|
||||
func (ix *Indexer) publishedAsBuilt(ctx context.Context, cur meshcatalog.ModulesByModuleValue, e builds.BuildLogEntry) (map[string]meshcatalog.PackagesByModuleValue, error) {
|
||||
func (ix *Indexer) publishedAsBuilt(ctx context.Context, cur meshcatalog.ModulesByModuleValue, e reported) (map[string]meshcatalog.PackagesByModuleValue, error) {
|
||||
published := ix.publishedAll(ctx)
|
||||
if r := fingerprint.Resolve(cur.Repository, e.Imports, published); len(r.Missing) > 0 {
|
||||
if r := fingerprint.Resolve(cur.Repository, e.imports, published); len(r.Missing) > 0 {
|
||||
if err := ix.FillPackages(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -161,14 +185,14 @@ func (ix *Indexer) publishedAsBuilt(ctx context.Context, cur meshcatalog.Modules
|
||||
type at struct{ repository, commit string }
|
||||
reread := map[at][]string{}
|
||||
var asVersion map[string]meshcatalog.PackagesByModuleValue
|
||||
for _, imp := range e.Imports {
|
||||
for _, imp := range e.imports {
|
||||
r := fingerprint.Resolve(cur.Repository, []string{imp}, published)
|
||||
for mod := range r.Requires {
|
||||
p := published[mod]
|
||||
commit := p.Commit
|
||||
switch pin := cur.Packages[mod]; {
|
||||
case trunk.SameRepository(p.Repository, cur.Repository) && e.Commit != "":
|
||||
commit = e.Commit
|
||||
case trunk.SameRepository(p.Repository, cur.Repository) && e.commit != "":
|
||||
commit = e.commit
|
||||
case strings.HasPrefix(pin, "v"):
|
||||
if c, ok := byVersion[mod+"@"+pin]; ok {
|
||||
if asVersion == nil {
|
||||
@@ -176,7 +200,7 @@ func (ix *Indexer) publishedAsBuilt(ctx context.Context, cur meshcatalog.Modules
|
||||
}
|
||||
c.Commit, asVersion[mod] = pin, c
|
||||
} else {
|
||||
ix.logf("%s: the version %s of %s it was pinned to is no series' newest any more, so its imports are read at the latest published commit", e.Module, pin, mod)
|
||||
ix.logf("%s: the version %s of %s it was pinned to is no series' newest any more, so its imports are read at the latest published commit", e.module, pin, mod)
|
||||
}
|
||||
case pin != "":
|
||||
commit = pin
|
||||
|
||||
@@ -5,11 +5,10 @@ import (
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||
"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-contracts/go/seats/nodebuildgo"
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
|
||||
"mesh-delivery-indexer/internal/fingerprint"
|
||||
@@ -61,7 +60,7 @@ func TestImportsReportedMoveTheFingerprintOnlyWithAnImportedPackage(t *testing.T
|
||||
ix, mods := newFormIndexer(t, mod{"avahi", catalogueManifest(t, "avahi")})
|
||||
reportToolchain(t, ix, "mesh-build-go", "novox", "go", "go1.27.1")
|
||||
listings := forge{c1: sdkFiles("a1", "b1"), c2: sdkFiles("a1", "b2"), c3: sdkFiles("a2", "b2")}
|
||||
ix.Packages, ix.Files = newMem(), listings.files
|
||||
ix.Packages, ix.Files, ix.Imports = newMem(), listings.files, newMem()
|
||||
// avahi's go.sum names mesh-sdk (the version line), as every Go module's does; mesh-sdk's module is held at c1.
|
||||
setPackages(t, mods, "avahi", []string{meshSDK})
|
||||
sdkModule, err := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Repository: "novox/mesh-sdk", Path: ".", Commit: c1, None2: "a TypeScript package"})
|
||||
@@ -87,7 +86,7 @@ func TestImportsReportedMoveTheFingerprintOnlyWithAnImportedPackage(t *testing.T
|
||||
|
||||
// The build of that fingerprint ends, reporting its imports: kept, and the fingerprint does not move.
|
||||
end := buildEnd(t, "avahi", before.Fp2, meshSDK, meshSDK+"/announce")
|
||||
if err := ix.ApplyBuildEnd(ctx, end); err != nil {
|
||||
if err := ix.HearImportsReported(ctx, end); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := ix.Recompute(ctx); err != nil {
|
||||
@@ -98,6 +97,11 @@ func TestImportsReportedMoveTheFingerprintOnlyWithAnImportedPackage(t *testing.T
|
||||
t.Fatalf("after the build's imports: fp2 %q (was %q), imports %v, import form %q; want the same fingerprint and the imports kept",
|
||||
after.Fp2, before.Fp2, after.Inputs2.Imports, after.Inputs2.ImportForm)
|
||||
}
|
||||
// Design 47 H2 H-A-527, H-A-532 DQ-3, DQ-4: the set is kept in the state imports with each package's digest at that build.
|
||||
if set, found, err := ix.ImportSetOf(ctx, "avahi"); err != nil || !found || set.Fingerprint != before.Fp2 || set.Commit != cat1 || len(set.Imports) != 2 ||
|
||||
set.Imports[0].Package != meshSDK || set.Imports[0].Digest != digestIn(pub, meshSDK) || set.Imports[1].Digest != digestIn(pub, meshSDK+"/announce") || set.Imports[1].Digest == "" {
|
||||
t.Fatalf("imports.avahi = %+v, %v, %v; want the set at %s with each package's published digest %v", set, found, err, before.Fp2, pub.Packages)
|
||||
}
|
||||
|
||||
// mesh-sdk merges a change of buildstep only: avahi does not import it.
|
||||
held, _ = ix.heldModules(ctx)
|
||||
@@ -159,13 +163,21 @@ func TestImportsReportedMoveTheFingerprintOnlyWithAnImportedPackage(t *testing.T
|
||||
func buildOfAnOlderFingerprintKeepsNoImports(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ix, mods := newFormIndexer(t, mod{"avahi", catalogueManifest(t, "avahi")})
|
||||
ix.Imports = newMem()
|
||||
reportToolchain(t, ix, "mesh-build-go", "novox", "go", "go1.27.1")
|
||||
if err := ix.ApplyBuildEnd(ctx, buildEnd(t, "avahi", "src2:"+strings.Repeat("e", 64), meshSDK)); err != nil {
|
||||
if err := ix.HearImportsReported(ctx, buildEnd(t, "avahi", "src2:"+strings.Repeat("e", 64), meshSDK)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if m, _ := moduleOf(t, mods, "avahi"); m.Inputs2 == nil || len(m.Inputs2.Imports) != 0 {
|
||||
t.Fatalf("imports %v kept from a build of another fingerprint", m.Inputs2)
|
||||
}
|
||||
if _, found, _ := ix.ImportSetOf(ctx, "avahi"); found {
|
||||
t.Fatal("imports.avahi kept from a build of another fingerprint (H-A-519)")
|
||||
}
|
||||
// A report naming no module or fingerprint is unreadable: said and acknowledged, never kept (principle 3).
|
||||
if err := ix.HearImportsReported(ctx, buildEnd(t, "avahi", "", meshSDK)); !errors.Is(err, ErrImportsUnreadable) {
|
||||
t.Fatalf("a report with no fingerprint: %v, want ErrImportsUnreadable", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Review finding 2 (ADR 0593 §2 "never left stale", §3): avahi, with no reported import set, replaces a mesh Go module
|
||||
@@ -222,15 +234,19 @@ func aSiblingDirectoryAloneMovesItsImporter(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func buildEnd(t *testing.T, module, fp string, imports ...string) []byte {
|
||||
t.Helper()
|
||||
raw, err := builds.EncodeBuildLogEntry(builds.BuildLogEntry{Event: builds.BuildEndedEvent, Module: module, FP: fp,
|
||||
Repository: catalogueRepo, Directory: "modules/" + module, Commit: cat1, Ref: "main", Node: "n1", At: time.Now(),
|
||||
Outcome: builds.BuildDone, Imports: imports})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
// digestIn is the published digest of package pkg in p.
|
||||
func digestIn(p meshcatalog.PackagesByModuleValue, pkg string) string {
|
||||
for _, d := range p.Packages {
|
||||
if d.Package == pkg {
|
||||
return d.Digest
|
||||
}
|
||||
}
|
||||
return raw
|
||||
return ""
|
||||
}
|
||||
|
||||
func buildEnd(t *testing.T, module, fp string, imports ...string) nodebuildgo.ImportsReported {
|
||||
t.Helper()
|
||||
return nodebuildgo.ImportsReported{Node: "n1", Module: module, Fingerprint: fp, Commit: cat1, Imports: imports}
|
||||
}
|
||||
|
||||
// setPackages writes a module's version-line packages, as a merge reading its go.sum keeps them.
|
||||
@@ -291,7 +307,7 @@ func anAcceptedSeriesPinsItsNewest(t *testing.T) {
|
||||
t.Fatalf("with no series published, versions %v, want mesh-sdk kept with no pin, never the commit (H-A-161)", before.Packages)
|
||||
}
|
||||
step("the build reports its imports", func() error {
|
||||
return ix.ApplyBuildEnd(ctx, buildEnd(t, "avahi", before.Fp2, meshSDK, meshSDK+"/announce"))
|
||||
return ix.HearImportsReported(ctx, buildEnd(t, "avahi", before.Fp2, meshSDK, meshSDK+"/announce"))
|
||||
})
|
||||
pinned := step("0.1.15 published from c3", hear("0.1.15", c3))
|
||||
if pinned.Fp2 == before.Fp2 || pinned.Packages[meshSDK] != "v0.1.15" {
|
||||
@@ -337,7 +353,7 @@ func anUnreadPackagesStateWritesNoFingerprintAndFingerprintsAreComputedAgain(t *
|
||||
t.Fatal(err)
|
||||
}
|
||||
first, _ := moduleOf(t, mods, "avahi")
|
||||
if err := ix.ApplyBuildEnd(ctx, buildEnd(t, "avahi", first.Fp2, meshSDK, meshSDK+"/announce")); err != nil {
|
||||
if err := ix.HearImportsReported(ctx, buildEnd(t, "avahi", first.Fp2, meshSDK, meshSDK+"/announce")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
held, _ = ix.heldModules(ctx)
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
package index
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
|
||||
)
|
||||
|
||||
// ImportsState is the indexer's state imports (design 47 H2 H-A-527, H-A-532 DQ-3): one key per module, the module's
|
||||
// modules key, holding the import set main's last build of the module reported (H-A-517, H-A-519) with each package's
|
||||
// digest at that build (DQ-4). It is written only when an imports-reported is kept, and its key is deleted with the
|
||||
// module's modules key; the tool indexer_imports reads it.
|
||||
const ImportsState = "imports"
|
||||
|
||||
// ImportSet is a value of the state imports: the module, the fingerprint and commit of the build that reported the set,
|
||||
// and each imported mesh package with its digest; a package no published module held when it was kept has none.
|
||||
type ImportSet struct {
|
||||
Module string `json:"module"`
|
||||
Fingerprint string `json:"fingerprint"`
|
||||
Commit string `json:"commit"`
|
||||
Imports []ImportedPackage `json:"imports"`
|
||||
}
|
||||
|
||||
// ImportedPackage is one package of an import set, by import path, with its digest.
|
||||
type ImportedPackage struct {
|
||||
Package string `json:"package"`
|
||||
Digest string `json:"digest,omitempty"`
|
||||
}
|
||||
|
||||
// ErrImportsUnreadable says an imports-reported does not fit its shape: the message is said and acknowledged, never
|
||||
// given again.
|
||||
var ErrImportsUnreadable = errors.New("not an imports-reported the indexer can keep")
|
||||
|
||||
// HearImportsReported keeps the import set a build module reported at a build's end (design 47 H2 H-A-517), when its
|
||||
// fingerprint is the one main's modules state holds for the module (H-A-532 DMC-2); one of a fingerprint the module no
|
||||
// longer holds is left (H-A-519). A body naming no module or fingerprint is ErrImportsUnreadable.
|
||||
func (ix *Indexer) HearImportsReported(ctx context.Context, e nodebuildgo.ImportsReported) error {
|
||||
if e.Module == "" || e.Fingerprint == "" {
|
||||
return fmt.Errorf("%w: it names no module or no fingerprint", ErrImportsUnreadable)
|
||||
}
|
||||
_, err := ix.keepImports(ctx, reported{module: e.Module, fp: e.Fingerprint, commit: e.Commit, imports: slices.Clone(e.Imports)})
|
||||
return err
|
||||
}
|
||||
|
||||
// ImportSetOf is the import set the state imports keeps for the module key; found is false when it keeps none.
|
||||
func (ix *Indexer) ImportSetOf(ctx context.Context, key string) (set ImportSet, found bool, err error) {
|
||||
if ix.Imports == nil {
|
||||
return ImportSet{}, false, nil
|
||||
}
|
||||
v, _, found, err := ix.Imports.Get(ctx, key)
|
||||
if err != nil || !found {
|
||||
return ImportSet{}, false, err
|
||||
}
|
||||
if err := json.Unmarshal(v, &set); err != nil {
|
||||
return ImportSet{}, false, fmt.Errorf("%s.%s is not an import set: %w", ImportsState, key, err)
|
||||
}
|
||||
return set, true, nil
|
||||
}
|
||||
|
||||
// importSetHeld says whether the state imports already holds e for key, the same fingerprint and packages; a store that
|
||||
// keeps none holds it, so nothing is written for it.
|
||||
func (ix *Indexer) importSetHeld(ctx context.Context, key string, e reported) bool {
|
||||
if ix.Imports == nil {
|
||||
return true
|
||||
}
|
||||
set, found, err := ix.ImportSetOf(ctx, key)
|
||||
if err != nil || !found || set.Fingerprint != e.fp {
|
||||
return false
|
||||
}
|
||||
return slices.EqualFunc(set.Imports, e.imports, func(p ImportedPackage, imp string) bool { return p.Package == imp })
|
||||
}
|
||||
|
||||
// writeImportSet writes e with its packages' digests into the state imports at key.
|
||||
func (ix *Indexer) writeImportSet(ctx context.Context, key string, e reported, digests map[string]string) error {
|
||||
if ix.Imports == nil {
|
||||
return nil
|
||||
}
|
||||
set := ImportSet{Module: e.module, Fingerprint: e.fp, Commit: e.commit, Imports: []ImportedPackage{}}
|
||||
for _, imp := range e.imports {
|
||||
set.Imports = append(set.Imports, ImportedPackage{Package: imp, Digest: digests[imp]})
|
||||
}
|
||||
data, err := json.Marshal(set)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := write(ctx, ix.Imports, key, func([]byte, bool) ([]byte, bool, error) { return data, false, nil }); err != nil {
|
||||
return fmt.Errorf("%s.%s: %w", ImportsState, key, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// dropImportSet deletes the module key's import set, as its modules key is deleted (H-A-532 DQ-3).
|
||||
func (ix *Indexer) dropImportSet(ctx context.Context, key string) error {
|
||||
if ix.Imports == nil {
|
||||
return nil
|
||||
}
|
||||
if err := write(ctx, ix.Imports, key, func(_ []byte, found bool) ([]byte, bool, error) { return nil, found, nil }); err != nil {
|
||||
return fmt.Errorf("%s.%s: %w", ImportsState, key, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -276,6 +276,9 @@ func (ix *Indexer) dropRemoved(ctx context.Context, repository string, held map[
|
||||
return fmt.Errorf("modules.%s: %w", key, err)
|
||||
}
|
||||
ix.logf("modules.%s deleted: %s holds no module of that name at its trunk (issue 1900)", key, repository)
|
||||
if err := ix.dropImportSet(ctx, key); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, key := range handed {
|
||||
if err := ix.handOver(ctx, key); err != nil {
|
||||
|
||||
@@ -511,7 +511,8 @@ func TestAModuleMovesBetweenRepositoriesOnlyWhenItsTrunkDropsIt(t *testing.T) {
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
mods := &deletesSeen{memStore: newMem()}
|
||||
ix := &Indexer{Module: testSelf, Store: newMem(), Modules: mods, Builds: NewBuilds()}
|
||||
ix := &Indexer{Module: testSelf, Store: newMem(), Modules: mods, Builds: NewBuilds(), Imports: newMem()}
|
||||
ix.Imports.(*memStore).put("a", []byte(`{"module":"a","fingerprint":"f","commit":"c","imports":[]}`))
|
||||
var logs []string
|
||||
ix.Logf = func(format string, args ...any) { logs = append(logs, format) }
|
||||
if tc.heads {
|
||||
@@ -547,6 +548,10 @@ func TestAModuleMovesBetweenRepositoriesOnlyWhenItsTrunkDropsIt(t *testing.T) {
|
||||
if deleted := slices.Contains(mods.deleted, "a"); deleted != tc.deletedKeyA {
|
||||
t.Errorf("modules.a deleted %v, want %v", deleted, tc.deletedKeyA)
|
||||
}
|
||||
// Design 47 H2 H-A-532 DQ-3: the module's import set goes with its modules key.
|
||||
if _, kept, _ := ix.ImportSetOf(context.Background(), "a"); kept == tc.deletedKeyA {
|
||||
t.Errorf("imports.a kept %v, want %v", kept, !tc.deletedKeyA)
|
||||
}
|
||||
if _, ok := mods.vals["b"]; ok == tc.bGoneAtEnd {
|
||||
t.Errorf("modules.b held %v, want %v", ok, !tc.bGoneAtEnd)
|
||||
}
|
||||
|
||||
@@ -149,7 +149,8 @@ func TestManifestDeclarations(t *testing.T) { // 1238/AC1, 1444 (reads the build
|
||||
{Name: index.RequirementsState, History: 5, MaxMiB: 8}, {Name: index.SeatDefinitionsState, History: 5, MaxMiB: 32},
|
||||
{Name: index.EntryIndexState, History: 1, MaxMiB: 8}, {Name: index.NamedState, History: 1, MaxMiB: 4}, // design 47 G §695
|
||||
{Name: index.RegistrationsState, History: 1, MaxMiB: 8}, {Name: index.ProposalsState, History: 1, MaxMiB: 4},
|
||||
{Name: index.VersionsState, History: 1, MaxMiB: 64}, {Name: index.BuildEdgesState, History: 1, MaxMiB: 8}, {Name: index.InputsState, History: 1, MaxMiB: 8}, {Name: index.PinsState, History: 1, MaxMiB: index.PinsCapMiB}, {Name: index.HeldState, History: 1, MaxMiB: 8},
|
||||
{Name: index.VersionsState, History: 1, MaxMiB: 64}, {Name: index.BuildEdgesState, History: 1, MaxMiB: 8}, {Name: index.InputsState, History: 1, MaxMiB: 8}, {Name: index.PinsState, History: 1, MaxMiB: index.PinsCapMiB}, {Name: index.HeldState, History: 1, MaxMiB: 8}, {Name: index.ImportsState, History: 1, MaxMiB: 8}, // H-A-532 DQ-3
|
||||
|
||||
{Name: index.DryRunsState, History: 1, TTL: 3600, MaxMiB: 16}}; !reflect.DeepEqual(m.State, want) { // DLV-I7, DLV-I17; design 47 H2 §804, §820
|
||||
t.Errorf("state = %+v, want %+v", m.State, want)
|
||||
}
|
||||
@@ -186,7 +187,7 @@ func TestManifestDeclarations(t *testing.T) { // 1238/AC1, 1444 (reads the build
|
||||
// internal/broker/state.go:62-93).
|
||||
// The registry seats' published fill each (§413: no consume of version.numbered) package's series (DLV-I5, design 51 *The versions*).
|
||||
if want := []string{"go-package-registry.published", "mesh-build-go.toolchain.reported", "mesh-build-node.toolchain.reported", "mesh-builds.package-published", "mesh-builds.step-ended", "mesh-builds.toolchain-agreed", "mesh-builds.version-reserved", "mesh-catalog.catalog-revision", "mesh-catalog.registration-changed", "mesh-catalog.room", "mesh-conditions.findings-asked",
|
||||
"mesh-delivery.source-moved", "mesh-pipeline-runner.pipeline-ended", "mesh-pipeline-runner.pipeline-started", "mesh-pipeline-runner.run-started", "mesh-wants.pipeline-wanted", "mesh-wants.wait-ended", "mesh-wants.wanted", "node-build-go.step-ended", "node-engine.running", "npm-package-registry.published", "operator-channel.decided", "seat:mesh-module-assigner.views.assignments", "seat:mesh-module-assigner.views.seat-holders"}; !reflect.DeepEqual(sorted(m.Consumes), want) {
|
||||
"mesh-delivery.source-moved", "mesh-pipeline-runner.pipeline-ended", "mesh-pipeline-runner.pipeline-started", "mesh-pipeline-runner.run-started", "mesh-wants.pipeline-wanted", "mesh-wants.wait-ended", "mesh-wants.wanted", "node-build-go.imports-reported", "node-build-go.step-ended", "node-build-node.imports-reported", "node-engine.running", "npm-package-registry.published", "operator-channel.decided", "seat:mesh-module-assigner.views.assignments", "seat:mesh-module-assigner.views.seat-holders"}; !reflect.DeepEqual(sorted(m.Consumes), want) {
|
||||
t.Errorf("consumes = %v, want %v", m.Consumes, want)
|
||||
}
|
||||
if b, ok := m.OwnSecrets["broker"]; !ok || len(m.OwnSecrets) != 1 || b != "${dir:state}/broker" {
|
||||
|
||||
@@ -88,6 +88,8 @@
|
||||
"mesh-builds.step-ended",
|
||||
"mesh-builds.toolchain-agreed",
|
||||
"node-build-go.step-ended",
|
||||
"node-build-go.imports-reported",
|
||||
"node-build-node.imports-reported",
|
||||
"mesh-wants.wait-ended",
|
||||
"mesh-catalog.catalog-revision",
|
||||
"mesh-catalog.registration-changed",
|
||||
@@ -170,6 +172,7 @@
|
||||
{ "name": "inputs", "history": 1, "max-mib": 8 },
|
||||
{ "name": "pins", "history": 1, "max-mib": 4 },
|
||||
{ "name": "held", "history": 1, "max-mib": 8 },
|
||||
{ "name": "imports", "history": 1, "max-mib": 8 },
|
||||
{ "name": "dry-runs", "history": 1, "ttl-seconds": 3600, "max-mib": 16 }
|
||||
],
|
||||
"streams": [
|
||||
|
||||
Reference in New Issue
Block a user