From 9172eccbc47da0716b3ffc9a03f5c07a61f748e2 Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 16:52:28 +0100 Subject: [PATCH] selfcompose: only what the node needs of another node's placement is asked, beside the pass The trunk build is asked, and a placed module laid, only for the store's holder (a store seat's holding on that node) and the providers this node's modules are bound to; never every module placed elsewhere. The asks run beside the pass, three at a time, and an answer asks a pass; a module that waits is only the one needing that address. Builds: design 47 G-22 A-461, A-461d, A-461e --- internal/selfcompose/entries.go | 80 ++++++++++++++++++++++------ internal/selfcompose/entries_test.go | 40 +++++++++++++- internal/selfcompose/selfcompose.go | 2 + 3 files changed, 103 insertions(+), 19 deletions(-) diff --git a/internal/selfcompose/entries.go b/internal/selfcompose/entries.go index f5801ffe..18015852 100644 --- a/internal/selfcompose/entries.go +++ b/internal/selfcompose/entries.go @@ -12,6 +12,7 @@ import ( "slices" "sort" "strings" + "sync" "time" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds" @@ -21,6 +22,7 @@ import ( "git.novox.be/novox/mesh-sdk/go/catalogue" "github.com/novox/mesh-host/internal/agent" + "github.com/novox/mesh-host/internal/compose/resolution" engcomp "github.com/novox/mesh-host/internal/compositions" ) @@ -287,7 +289,7 @@ func (c *Composer) wantedBuilds() map[string]bool { // none is heard (A-461, A-461d). for node, p := range c.assignments { for _, pm := range p.Modules { - if built := c.placedBuild(node, pm.Module); c.lacksEntry(node, pm.Module) && strings.HasPrefix(built, meshcatalogclient.SourcePrefix2) { + if built := c.placedBuild(node, pm.Module); c.needsAddressOf(node, pm.Module) && c.lacksEntry(node, pm.Module) && strings.HasPrefix(built, meshcatalogclient.SourcePrefix2) { if _, named := out[built]; !named { out[built] = false } @@ -433,7 +435,7 @@ func (c *Composer) layModules() { continue } for _, pm := range c.assignments[node].Modules { - if _, laid := modules[pm.Module]; laid || !c.lacksEntry(node, pm.Module) { + if _, laid := modules[pm.Module]; laid || !c.needsAddressOf(node, pm.Module) || !c.lacksEntry(node, pm.Module) { continue } if built := c.placedBuild(node, pm.Module); built != "" { @@ -510,39 +512,83 @@ func (c *Composer) lacksEntry(node, module string) bool { return !ok || k.entry.Module == "" } +// needsAddressOf says whether this node needs the address of module on node (c.mu held): it holds a store seat there (the image +// seats' holders), or a module placed here is bound to it as the provider of a requirement (A-461). +func (c *Composer) needsAddressOf(node, module string) bool { + for _, h := range c.assignments[node].Holds { + if h.Module == module && slices.Contains(resolution.StoreSeats, h.Claim) { + return true + } + } + for _, pm := range c.assignments[c.env.Node].Modules { + for _, b := range pm.Bindings { + if b.Module == module && b.Node == node { + return true + } + } + } + return false +} + // askTrunkBuilds asks, for each module another node runs at a build with no entry and whose placement names no build, the trunk // build by the seat's verb `module`, once per running build (A-461b). Called before the lock is taken: the verb is a call. -func (c *Composer) askTrunkBuilds() { +func (c *Composer) askTrunkBuilds() (wait func()) { type ask struct{ node, module, running string } var asks []ask c.mu.Lock() for node, p := range c.assignments { for _, pm := range p.Modules { module := pm.Module - if pm.Build != "" || !c.lacksEntry(node, module) { + // Only a module this node needs the address of (A-461): the store's holder, the provider of a requirement. + if pm.Build != "" || !c.needsAddressOf(node, module) || !c.lacksEntry(node, module) || c.trunkAsking[module] { continue } running := c.heard[node][module].fingerprint if had, asked := c.trunkBuilds[module]; !asked || had.running != running { asks = append(asks, ask{node, module, running}) + if c.trunkAsking == nil { + c.trunkAsking = map[string]bool{} + } + c.trunkAsking[module] = true } } } c.mu.Unlock() - for _, a := range asks { - fp, why := c.trunkFp(a.module) - if fp == "" { - // Said with its reason, and asked again on the next pass: nothing is kept of an answer that was none (A-461e). - c.env.Say(fmt.Sprintf("the trunk build of %s, placed on %s, could not be had, and is asked again: %s", a.module, a.node, why)) - continue - } - c.mu.Lock() - if c.trunkBuilds == nil { - c.trunkBuilds = map[string]trunkBuild{} - } - c.trunkBuilds[a.module] = trunkBuild{running: a.running, fp: fp} - c.mu.Unlock() + // Asked beside the pass, a few at a time: no pass waits on the catalog half's answer, and a module that waits for it is only + // the one needing that address (A-461e). An answer asks a pass. + var all sync.WaitGroup + work := make(chan ask) + for i := 0; i < 3 && i < len(asks); i++ { + all.Add(1) + go func() { + defer all.Done() + for a := range work { + fp, why := c.trunkFp(a.module) + c.mu.Lock() + delete(c.trunkAsking, a.module) + if fp != "" { + if c.trunkBuilds == nil { + c.trunkBuilds = map[string]trunkBuild{} + } + c.trunkBuilds[a.module] = trunkBuild{running: a.running, fp: fp} + } + c.mu.Unlock() + if fp == "" { + // Said with its reason, and asked again on the next pass: nothing is kept of an answer that was none (A-461e). + c.env.Say(fmt.Sprintf("the trunk build of %s, placed on %s, could not be had, and is asked again: %s", a.module, a.node, why)) + continue + } + c.askRehand() + } + }() } + go func() { + for _, a := range asks { + work <- a + } + close(work) + }() + return all.Wait } // entryManifest is an entry's manifest as a reader takes it, with its digest: the one the indexer set at take-in, or, where it set diff --git a/internal/selfcompose/entries_test.go b/internal/selfcompose/entries_test.go index 6bb5f7b3..5d857781 100644 --- a/internal/selfcompose/entries_test.go +++ b/internal/selfcompose/entries_test.go @@ -375,7 +375,8 @@ func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) { }) c := New(env) c.mu.Lock() - c.assignments[tc.node] = meshmoduleassigner.Assignments{Node: tc.node, Modules: []meshmoduleassigner.PlacedModule{{Module: "distribution", Build: tc.build}}} + c.assignments[tc.node] = meshmoduleassigner.Assignments{Node: tc.node, Modules: []meshmoduleassigner.PlacedModule{{Module: "distribution", Build: tc.build}}, + Holds: []meshmoduleassigner.Holding{{Claim: "container-image-registry", Module: "distribution", Scope: "mesh"}}} c.heard = map[string]map[string]heardRun{tc.node: {"distribution": {fingerprint: old}}} switch tc.heard { case "none": @@ -389,7 +390,7 @@ func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) { if tc.holds { c.holdEntry(t, "distribution", placedFp, `{"module":"distribution","version":"2"}`) } - c.askTrunkBuilds() + c.askTrunkBuilds()() c.mu.Lock() _, kept := c.trunkBuilds["distribution"] c.mu.Unlock() @@ -410,3 +411,38 @@ func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) { }) } } + +// A-461, A-461e: a node asks the trunk build only of what it needs of another node's placement (the store's holder, the provider +// it is bound to), never of every module placed there, and beside the pass. +func TestOnlyWhatTheNodeNeedsOfAnotherNodesPlacementIsAsked(t *testing.T) { + env := newFakeBus().env() + env.Node = "n1" + var mu sync.Mutex + asked := map[string]int{} + env.Entry = EntryCall(func(_ context.Context, _, verb string, in any) (json.RawMessage, error) { + if verb == meshcatalog.VerbModule { + mu.Lock() + asked[in.(meshcatalog.ModuleInput).Module]++ + mu.Unlock() + } + return nil, errors.New("not held") + }) + c := New(env) + var unrelated []meshmoduleassigner.PlacedModule + for i := 0; i < 40; i++ { + unrelated = append(unrelated, meshmoduleassigner.PlacedModule{Module: fmt.Sprintf("unrelated%d", i)}) + } + c.mu.Lock() + c.assignments["n2"] = meshmoduleassigner.Assignments{Node: "n2", + Modules: append(unrelated, meshmoduleassigner.PlacedModule{Module: "distribution"}, meshmoduleassigner.PlacedModule{Module: "provider"}), + Holds: []meshmoduleassigner.Holding{{Claim: "container-image-registry", Module: "distribution", Scope: "mesh"}}} + c.assignments["n1"] = meshmoduleassigner.Assignments{Node: "n1", Modules: []meshmoduleassigner.PlacedModule{ + {Module: "app", Bindings: map[string]meshmoduleassigner.Provider{"postgres-database": {Module: "provider", Node: "n2"}}}}} + c.mu.Unlock() + c.askTrunkBuilds()() + mu.Lock() + defer mu.Unlock() + if len(asked) != 2 || asked["distribution"] != 1 || asked["provider"] != 1 { + t.Errorf("the trunk builds asked are %v, want the store's holder and the bound provider alone", asked) + } +} diff --git a/internal/selfcompose/selfcompose.go b/internal/selfcompose/selfcompose.go index 994205c4..cf5e4408 100644 --- a/internal/selfcompose/selfcompose.go +++ b/internal/selfcompose/selfcompose.go @@ -212,6 +212,8 @@ type Composer struct { heard map[string]map[string]heardRun // trunkBuilds is, by module, the trunk build asked for another node's module whose placement names none, with the running build it was asked for (A-461b). trunkBuilds map[string]trunkBuild + // trunkAsking is, by module, a trunk build being asked beside the pass (askTrunkBuilds), under mu. + trunkAsking map[string]bool heardRead bool // ends is, by module, the last build end naming no branch the builder said of it (NoteBuildEnded), its newest build that // ended, under mu; endsRead is whether the first read of the builder's stream ended (BuildEndsRead) (design 47 G A-293).