diff --git a/internal/selfcompose/entries.go b/internal/selfcompose/entries.go index c5eb2705..9b003c16 100644 --- a/internal/selfcompose/entries.go +++ b/internal/selfcompose/entries.go @@ -274,15 +274,20 @@ func (c *Composer) wantedBuilds() map[string]bool { } } } - for node, mods := range c.heard { - for module, run := range mods { + for _, mods := range c.heard { + for _, run := range mods { if !run.stopped && strings.HasPrefix(run.fingerprint, meshcatalogclient.SourcePrefix2) { if _, named := out[run.fingerprint]; !named { out[run.fingerprint] = false } } - // The build the assignment places for another node's module stands for its want where the running build has no entry (A-461). - if built := c.placedBuild(node, module); c.lacksEntry(node, module, run) && strings.HasPrefix(built, meshcatalogclient.SourcePrefix2) { + } + } + // The build the assignment places for another node's module stands for its want where the running build has no entry, or + // 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 _, named := out[built]; !named { out[built] = false } @@ -416,6 +421,26 @@ func (c *Composer) layModules() { } } } + // A module placed on another node and not heard running is one whose running build has no entry (A-461d): laid from the build + // its placement names, or its trunk build (A-461b). + placedOn := make([]string, 0, len(c.assignments)) + for node := range c.assignments { + placedOn = append(placedOn, node) + } + sort.Strings(placedOn) + for _, node := range placedOn { + if node == c.env.Node { + continue + } + for _, pm := range c.assignments[node].Modules { + if _, heard := c.heard[node][pm.Module]; heard { + continue + } + if built := c.placedBuild(node, pm.Module); built != "" { + lay(pm.Module, built) + } + } + } for module, w := range c.wants { if module == agent.NodeModule || w.Fp == "" { continue @@ -471,12 +496,19 @@ func (c *Composer) placedBuild(node, module string) string { return "" } -// lacksEntry says whether the build another node's module runs has no entry held (c.mu held): the only case the placed build stands -// in (A-461b). It is never so for this node's own modules. -func (c *Composer) lacksEntry(node, module string, run heardRun) bool { - if node == c.env.Node || run.stopped || run.fingerprint == "" { +// lacksEntry says whether the build another node's module runs has no entry held, or none is heard (c.mu held): the only cases the +// placed build stands in (A-461b, A-461d). It is never so for this node's own modules. +func (c *Composer) lacksEntry(node, module string) bool { + if node == c.env.Node { return false } + run, heard := c.heard[node][module] + if heard && run.stopped { + return false + } + if !heard || run.fingerprint == "" { + return true // placed there, and not heard running (A-461d) + } k, ok := c.keptEnt[run.fingerprint] return !ok || k.entry.Module == "" } @@ -487,15 +519,15 @@ func (c *Composer) askTrunkBuilds() { type ask struct{ node, module, running string } var asks []ask c.mu.Lock() - for node, mods := range c.heard { - for module, run := range mods { - if !c.lacksEntry(node, module, run) { + for node, p := range c.assignments { + for _, pm := range p.Modules { + module := pm.Module + if pm.Build != "" || !c.lacksEntry(node, module) { continue } - for _, pm := range c.assignments[node].Modules { - if pm.Module == module && pm.Build == "" && c.trunkBuilds[module].running != run.fingerprint { - asks = append(asks, ask{node, module, run.fingerprint}) - } + running := c.heard[node][module].fingerprint + if had, asked := c.trunkBuilds[module]; !asked || had.running != running { + asks = append(asks, ask{node, module, running}) } } } diff --git a/internal/selfcompose/entries_test.go b/internal/selfcompose/entries_test.go index 30e89a7c..dbc82d67 100644 --- a/internal/selfcompose/entries_test.go +++ b/internal/selfcompose/entries_test.go @@ -351,12 +351,16 @@ func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) { node string build, trunk string holds, laid bool + notHeard bool // A-461d: nothing of what the node runs is heard }{ - {"placed build has an entry", "n2", placedFp, "", true, true}, - {"neither build has an entry", "n2", placedFp, "", false, false}, - {"placement names no build, trunk build has an entry", "n2", "", placedFp, true, true}, - {"placement names no build, trunk names none", "n2", "", "", false, false}, - {"this node's own module is not laid from a placement", "n1", placedFp, "", true, false}, + {"placed build has an entry", "n2", placedFp, "", true, true, false}, + {"neither build has an entry", "n2", placedFp, "", false, false, false}, + {"placement names no build, trunk build has an entry", "n2", "", placedFp, true, true, false}, + {"placement names no build, trunk names none", "n2", "", "", false, false, false}, + {"this node's own module is not laid from a placement", "n1", placedFp, "", true, false, false}, + {"placed, not heard, placement names no build, trunk build has an entry (A-461d)", "n2", "", placedFp, true, true, true}, + {"placed, not heard, placed build has an entry (A-461d)", "n2", placedFp, "", true, true, true}, + {"placed, not heard, trunk names none (A-461d)", "n2", "", "", false, false, true}, } { t.Run(tc.name, func(t *testing.T) { env := newFakeBus().env() @@ -371,6 +375,9 @@ func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) { c.mu.Lock() c.assignments[tc.node] = meshmoduleassigner.Assignments{Node: tc.node, Modules: []meshmoduleassigner.PlacedModule{{Module: "distribution", Build: tc.build}}} c.heard = map[string]map[string]heardRun{tc.node: {"distribution": {fingerprint: old}}} + if tc.notHeard { + c.heard = map[string]map[string]heardRun{} + } c.mu.Unlock() if tc.holds { c.holdEntry(t, "distribution", placedFp, `{"module":"distribution","version":"2"}`)