selfcompose: the manifest of the build a module runs here is answered in one place; every step reads it there (A-484)
Entry of the running build, else the composition this node runs of it, else the module's trunk manifest through the seat mesh-catalog's verb module; said once per module and source; words naming the three where none answers. Read there: a held module's offer (frombus Scope.RunningManifest), FormChanges (A-483), the store holder and the stand of a running module without an entry (A-461d, A-480a), and the tool composition. Builds: design 47 G A-484, A-480, A-480a, A-483, A-461d, A-482
This commit is contained in:
@@ -490,7 +490,7 @@ func (c *Composer) composeShadow(ctx context.Context, running []engcomp.Composed
|
||||
c.mu.Lock()
|
||||
c.wants = wants
|
||||
c.mu.Unlock()
|
||||
scope := frombus.Scope{Node: node, KeptAt: kept, InOwn: inOwn, Running: running, SameValue: c.sameValue, Heard: c.heardNow()}
|
||||
scope := frombus.Scope{Node: node, KeptAt: kept, InOwn: inOwn, Running: running, SameValue: c.sameValue, Heard: c.heardNow(), RunningManifest: c.runningFor(node)}
|
||||
if input != nil {
|
||||
input(scope, fps)
|
||||
}
|
||||
|
||||
+101
-95
@@ -296,14 +296,6 @@ func (c *Composer) wantedBuilds() map[string]bool {
|
||||
}
|
||||
}
|
||||
}
|
||||
// The trunk build of a module this node runs without an entry of its wanted or running build is asked too (A-480a).
|
||||
for module, tb := range c.trunkBuilds {
|
||||
if tb.fp != "" && c.runsWithoutEntry(module) {
|
||||
if _, named := out[tb.fp]; !named {
|
||||
out[tb.fp] = false
|
||||
}
|
||||
}
|
||||
}
|
||||
// The build each module runs here, as the node's own record of it says: its entry, kept in the composition state, stays held
|
||||
// for the judgement of a move's data forms though the catalog half dropped it and no event of the stream names it.
|
||||
for _, r := range running {
|
||||
@@ -391,6 +383,11 @@ func (c *Composer) layModules() {
|
||||
c.sayOnceEach(line)
|
||||
}
|
||||
}()
|
||||
// Read before the lock: what the node runs is the agent's, and a read of it may wait.
|
||||
var running []engcomp.Composed
|
||||
if c.env.Running != nil {
|
||||
running = c.env.Running()
|
||||
}
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
modules := map[string]meshcatalog.ModulesByModuleValue{}
|
||||
@@ -413,6 +410,19 @@ func (c *Composer) layModules() {
|
||||
c.manifests[digest] = raw
|
||||
return true
|
||||
}
|
||||
// layAnswer lays a module from the manifest the one place read of the build it runs (A-484): the entry's own fields, or the
|
||||
// trunk's answer, which holds none of an entry's checks.
|
||||
layAnswer := func(module string, a runningAnswer) bool {
|
||||
switch {
|
||||
case !a.Known:
|
||||
return false
|
||||
case a.Source == SourceTrunk:
|
||||
modules[module] = meshcatalog.ModulesByModuleValue{Fp2: a.FP, Manifest: a.Digest, Repository: a.Repository, Commit: a.Commit, Path: a.Path}
|
||||
c.manifests[a.Digest] = a.Raw
|
||||
return true
|
||||
}
|
||||
return lay(module, a.FP)
|
||||
}
|
||||
nodes := make([]string, 0, len(c.heard))
|
||||
for node := range c.heard {
|
||||
nodes = append(nodes, node)
|
||||
@@ -424,9 +434,7 @@ func (c *Composer) layModules() {
|
||||
// Where the running build has no entry, the module is laid from the entry of the build the assignment places
|
||||
// for that node, the mesh's truth of what it runs there (A-461); with neither it stays name-only below.
|
||||
if !lay(module, run.fingerprint) && node != c.env.Node {
|
||||
if built := c.placedBuild(node, module); built != "" && built != run.fingerprint {
|
||||
lay(module, built)
|
||||
}
|
||||
layAnswer(module, c.runningLocked(running, node, module, ""))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -446,9 +454,7 @@ func (c *Composer) layModules() {
|
||||
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 != "" {
|
||||
lay(pm.Module, built)
|
||||
}
|
||||
layAnswer(pm.Module, c.runningLocked(running, node, pm.Module, ""))
|
||||
}
|
||||
}
|
||||
for module, w := range c.wants {
|
||||
@@ -471,14 +477,19 @@ func (c *Composer) layModules() {
|
||||
}
|
||||
continue
|
||||
}
|
||||
// Running here with no entry of its wanted or running build and none of the newest: it stands, for resolution alone, as its
|
||||
// trunk build, so the module that requires what it provides is no "nothing provides" (A-480a); its want stays held.
|
||||
if _, laid := modules[module]; !laid && c.runsWithoutEntry(module) {
|
||||
if tb := c.trunkBuilds[module]; tb.fp != "" && lay(module, tb.fp) {
|
||||
// Running here with no entry of its wanted build and none of the newest: it stands, for resolution alone, as the manifest of
|
||||
// the build it runs, from the one place (A-484), so the module that requires what it provides is no "nothing provides";
|
||||
// its want stays held. A running build whose entry is held is laid where it is heard (above) and is read by a held module's offer
|
||||
// through the one place alone, so it is not laid again here.
|
||||
if _, laid := modules[module]; !laid && c.countsAsRunning(module) {
|
||||
if a := c.runningLocked(running, c.env.Node, module, ""); a.Source != SourceEntry && layAnswer(module, a) {
|
||||
m := modules[module]
|
||||
m.Fp2 = w.Fp
|
||||
modules[module] = m
|
||||
said = append(said, fmt.Sprintf("%s runs a build whose manifest the node does not hold, so it counts what the trunk build %s of %s provides; its want stays held", module, tb.fp, module))
|
||||
said = append(said, fmt.Sprintf("%s runs a build whose entry the node does not hold, so it counts the manifest read from %s; its want stays held", module, a.Source))
|
||||
if a.Said != "" {
|
||||
said = append(said, a.Said)
|
||||
}
|
||||
continue
|
||||
}
|
||||
}
|
||||
@@ -503,15 +514,12 @@ func (c *Composer) layModules() {
|
||||
c.modules = modules
|
||||
}
|
||||
|
||||
// placedBuild is the build the assignment places for module on node (c.mu held), the mesh's truth of what it runs there; where the
|
||||
// placement names none, the module's trunk build as syncEntries asked it (A-461b). Empty where neither is known.
|
||||
// placedBuild is the build the assignment places for module on node (c.mu held), the mesh's truth of what it runs there; empty
|
||||
// where the placement names none (the one place then asks the trunk's manifest, A-484).
|
||||
func (c *Composer) placedBuild(node, module string) string {
|
||||
for _, pm := range c.assignments[node].Modules {
|
||||
if pm.Module == module {
|
||||
if pm.Build != "" {
|
||||
return pm.Build
|
||||
}
|
||||
return c.trunkBuilds[module].fp
|
||||
return pm.Build
|
||||
}
|
||||
}
|
||||
return ""
|
||||
@@ -549,68 +557,40 @@ func (c *Composer) needsAddressOf(node, module string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// runsWithoutEntry says this node holds module on, as it runs it, and holds no entry of its wanted build nor of its running build
|
||||
// (c.mu held), and whose running event's manifest is not held (A-480a): the case where its
|
||||
// provisions are read from its trunk build (A-480a). A module built by hand before G says no running event (the engine says one only
|
||||
// of a build whose manifest it knows), so it counts as running when its have names a build in the phase running or held (A-482); one
|
||||
// wanted here that is heard running nowhere, runs nothing here and has no such have does not count.
|
||||
func (c *Composer) runsWithoutEntry(module string) bool {
|
||||
run := c.heard[c.env.Node][module]
|
||||
w, wanted := c.wants[module]
|
||||
if run.stopped || !wanted || w.Fp == "" || !(c.runsHere(module) || c.haveRuns[module]) {
|
||||
return false
|
||||
}
|
||||
// What is read decides (A-480a: "can be read from neither"): the manifest its running event names, where that digest is held;
|
||||
// a running composition's build is read as frombus ranOf reads it, only through the entry of the wanted fingerprint (the
|
||||
// loop below), so a composition at another build reads nothing.
|
||||
if _, read := c.manifests[run.manifest]; run.manifest != "" && read {
|
||||
return false
|
||||
}
|
||||
for _, fp := range []string{w.Fp, run.fingerprint} {
|
||||
if k, held := c.keptEnt[fp]; held && k.entry.Module != "" {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// 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() (wait func()) {
|
||||
type ask struct{ node, module, running string }
|
||||
var asks []ask
|
||||
var running []engcomp.Composed
|
||||
if c.env.Running != nil {
|
||||
running = c.env.Running()
|
||||
}
|
||||
c.mu.Lock()
|
||||
// The module whose running build's manifest the one place reads from the trunk, where neither its entry nor its composition
|
||||
// answers (A-484): the modules this node runs, and another node's module this node needs the address of (A-461, A-461d).
|
||||
for node, p := range c.assignments {
|
||||
for _, pm := range p.Modules {
|
||||
module := pm.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] {
|
||||
if 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{}
|
||||
if node == c.env.Node {
|
||||
if !c.countsAsRunning(module) {
|
||||
continue
|
||||
}
|
||||
c.trunkAsking[module] = true
|
||||
} else if !c.needsAddressOf(node, module) || !c.lacksEntry(node, module) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
// A module this node runs whose wanted build and running build have no entry stands as its trunk build, for resolution alone
|
||||
// (A-480a): asked once per running build, as another node's is.
|
||||
for _, pm := range c.assignments[c.env.Node].Modules {
|
||||
module := pm.Module
|
||||
if !c.runsWithoutEntry(module) || c.trunkAsking[module] {
|
||||
continue
|
||||
}
|
||||
running := c.heard[c.env.Node][module].fingerprint
|
||||
if had, asked := c.trunkBuilds[module]; !asked || had.running != running {
|
||||
asks = append(asks, ask{c.env.Node, module, running})
|
||||
if c.trunkAsking == nil {
|
||||
c.trunkAsking = map[string]bool{}
|
||||
if a := c.runningLocked(running, node, module, ""); a.NeedTrunk {
|
||||
if had, asked := c.trunkBuilds[module]; !asked || had.running != a.RunFP {
|
||||
asks = append(asks, ask{node, module, a.RunFP})
|
||||
if c.trunkAsking == nil {
|
||||
c.trunkAsking = map[string]bool{}
|
||||
}
|
||||
c.trunkAsking[module] = true
|
||||
}
|
||||
}
|
||||
c.trunkAsking[module] = true
|
||||
}
|
||||
}
|
||||
c.mu.Unlock()
|
||||
@@ -623,14 +603,22 @@ func (c *Composer) askTrunkBuilds() (wait func()) {
|
||||
go func() {
|
||||
defer all.Done()
|
||||
for a := range work {
|
||||
fp, why := c.trunkFp(a.module)
|
||||
t, why := c.trunkOf(a.module)
|
||||
fp := t.fp
|
||||
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}
|
||||
t.running = a.running
|
||||
c.trunkBuilds[a.module] = t
|
||||
delete(c.trunkWhy, a.module)
|
||||
} else {
|
||||
if c.trunkWhy == nil {
|
||||
c.trunkWhy = map[string]string{}
|
||||
}
|
||||
c.trunkWhy[a.module] = why
|
||||
}
|
||||
c.mu.Unlock()
|
||||
if fp == "" {
|
||||
@@ -823,23 +811,34 @@ func (c *Composer) FormChanges(_ context.Context, module, runningFp, appliedFp s
|
||||
}
|
||||
return catalogue.Decode(raw)
|
||||
}
|
||||
running, err := read(runningFp)
|
||||
if err != nil {
|
||||
// A running build with no entry (one from before G): what it keeps on the bus is read from the composition it runs on this
|
||||
// node, as what it provides is (A-480). Where neither that composition nor the wanted build's manifest keeps data, no form
|
||||
// can change; where either does, the module still waits for the entry (A-113, A-483).
|
||||
// The manifest of the build the module runs is read in the one place (A-484): its entry, else the composition this node runs of
|
||||
// it, else the trunk's manifest. Where it reads no manifest, the composition says whether the running build keeps data: with
|
||||
// none on either side no form can change and the move goes on; where either keeps data, the move waits (A-113, A-483), with
|
||||
// the words naming the three sources tried.
|
||||
// The entry of the running build is asked of the catalog half (once), and kept when answered, as every entry the composer reads.
|
||||
if e, state := c.entryOf(runningFp); state == meshcatalogclient.EntryAnswered && e.Module != "" {
|
||||
c.mu.Lock()
|
||||
if _, kept := c.keptEnt[runningFp]; !kept {
|
||||
c.keptEnt[runningFp] = keptEntry{entry: e, since: c.now()}
|
||||
}
|
||||
c.mu.Unlock()
|
||||
}
|
||||
ra := c.runningManifest(c.env.Node, module, runningFp)
|
||||
var running catalogue.Manifest
|
||||
if ra.Known {
|
||||
var err error
|
||||
if running, err = catalogue.Decode(ra.Raw); err != nil {
|
||||
return nil, fmt.Errorf("%s's running manifest: %w", module, err)
|
||||
}
|
||||
} else {
|
||||
wanted, werr := read(appliedFp)
|
||||
if werr != nil {
|
||||
return nil, fmt.Errorf("%s's wanted manifest: %w", module, werr)
|
||||
}
|
||||
if c.env.Running != nil && len(wanted.DataItems()) == 0 {
|
||||
for _, r := range c.env.Running() {
|
||||
if r.Module == module && r.FP != "" && !r.Data {
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
if ra.Source == SourceComposition && !ra.Data && len(wanted.DataItems()) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, fmt.Errorf("%s's running manifest: %w", module, err)
|
||||
return nil, fmt.Errorf("%s's running manifest: %s", module, ra.Why)
|
||||
}
|
||||
applied, err := read(appliedFp)
|
||||
if err != nil {
|
||||
@@ -873,27 +872,34 @@ func (c *Composer) syncShadowEntries(ctx context.Context) (pending bool) {
|
||||
// moduleVerb is the seat mesh-catalog's verb `module`: one module's trunk fingerprint and manifest by name.
|
||||
const moduleVerb = "seat:" + meshcatalog.Seat + "." + meshcatalog.VerbModule
|
||||
|
||||
// trunkFp is the fingerprint of a module's trunk build, by the seat's verb `module`; empty with why where the catalog half gives none.
|
||||
func (c *Composer) trunkFp(module string) (fp, why string) {
|
||||
// trunkOf is a module's trunk build, by the seat's verb `module`: its fingerprint, manifest and where it is built from; empty with
|
||||
// why where the catalog half gives none.
|
||||
func (c *Composer) trunkOf(module string) (t trunkBuild, why string) {
|
||||
if c.env.Entry == nil {
|
||||
return "", "this node reads no module of the catalog half"
|
||||
return t, "this node reads no module of the catalog half"
|
||||
}
|
||||
raw, err := c.env.Entry(moduleVerb, meshcatalog.ModuleInput{Module: module})
|
||||
if err != nil {
|
||||
return "", fmt.Sprintf("the catalog half's answer for %s: %v", module, err)
|
||||
return t, fmt.Sprintf("the catalog half's answer for %s: %v", module, err)
|
||||
}
|
||||
answer, said, ok := buscalls.Unwrap(raw)
|
||||
if !ok {
|
||||
return "", fmt.Sprintf("the catalog half holds no module %s: %s", module, said)
|
||||
return t, fmt.Sprintf("the catalog half holds no module %s: %s", module, said)
|
||||
}
|
||||
var a meshcatalog.ModuleAnswer
|
||||
if err := json.Unmarshal(answer, &a); err != nil {
|
||||
return "", fmt.Sprintf("the catalog half's answer for %s cannot be read: %v", module, err)
|
||||
return t, fmt.Sprintf("the catalog half's answer for %s cannot be read: %v", module, err)
|
||||
}
|
||||
if a.Module.Fp == "" {
|
||||
return "", fmt.Sprintf("the catalog half gives %s no fingerprint: %s", module, a.Module.None)
|
||||
return t, fmt.Sprintf("the catalog half gives %s no fingerprint: %s", module, a.Module.None)
|
||||
}
|
||||
return a.Module.Fp, ""
|
||||
return trunkBuild{fp: a.Module.Fp, manifest: a.Module.Manifest, repository: a.Module.Repository, commit: a.Module.Commit, path: a.Module.Path}, ""
|
||||
}
|
||||
|
||||
// trunkFp is the fingerprint of a module's trunk build (trunkOf); empty with why where the catalog half gives none.
|
||||
func (c *Composer) trunkFp(module string) (fp, why string) {
|
||||
t, why := c.trunkOf(module)
|
||||
return t.fp, why
|
||||
}
|
||||
|
||||
// addedModule is the trunk's build of a module an assignment candidate adds to this node when no want here names it yet: the
|
||||
|
||||
@@ -291,7 +291,7 @@ func runningModuleWithoutEntryStandsAsTheNewestBuild(t *testing.T) {
|
||||
{"heard no running event, its have says running (A-480a, A-482)", false, "", false, true, old, false, true, "running", ""},
|
||||
{"heard no running event, its have says held (A-482)", false, "", false, true, old, false, true, "held", ""},
|
||||
{"wanted here, heard no running event, no have (A-482)", false, "", false, false, old, false, true, "", ""},
|
||||
{"its running event names a manifest this node holds (A-480a)", true, "", false, false, old, false, true, "", "held"},
|
||||
{"its running event names a manifest this node holds: no source of the one place (A-484)", true, "", false, true, old, false, true, "", "held"},
|
||||
{"its running event names a manifest this node cannot read (A-480a)", true, "", false, true, old, false, true, "", "unread"},
|
||||
{"runs a composition at another build, no manifest read (A-480a)", true, "", false, true, old, false, true, "other", ""},
|
||||
{"heard stopped, trunk entry held (A-480a)", false, "", false, false, old, true, true, "running", ""},
|
||||
@@ -302,7 +302,9 @@ func runningModuleWithoutEntryStandsAsTheNewestBuild(t *testing.T) {
|
||||
trunkFp := meshcatalogclient.SourcePrefix2 + strings.Repeat("4", 64)
|
||||
env.Entry = EntryCall(func(_ context.Context, _, verb string, _ any) (json.RawMessage, error) {
|
||||
if verb == meshcatalog.VerbModule && tc.trunk {
|
||||
return json.Marshal(meshcatalog.ModuleAnswer{Module: meshcatalog.ModuleAnswerModule{Fp: trunkFp}})
|
||||
var man map[string]any
|
||||
_ = json.Unmarshal([]byte(body), &man)
|
||||
return json.Marshal(meshcatalog.ModuleAnswer{Module: meshcatalog.ModuleAnswerModule{Fp: trunkFp, Manifest: man}})
|
||||
}
|
||||
return nil, errors.New("not held")
|
||||
})
|
||||
@@ -426,6 +428,27 @@ func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// A-484: where neither the entry nor a composition answers, the trunk's manifest is the running build's: a form change is judged
|
||||
// against it, and its words name the three sources where the trunk answered none either.
|
||||
for _, trunk := range []bool{true, false} {
|
||||
env := newFakeBus().env()
|
||||
env.Node = "n1"
|
||||
c := New(env)
|
||||
c.holdEntry(t, "feh", next, `{"module":"feh","version":"2","data":{"own":[{"id":"state","kind":"state"}]}}`)
|
||||
if trunk {
|
||||
c.mu.Lock()
|
||||
c.trunkBuilds = map[string]trunkBuild{"feh": {running: old, fp: next, manifest: map[string]any{"module": "feh", "version": "1"}}}
|
||||
c.mu.Unlock()
|
||||
}
|
||||
changes, err := c.FormChanges(context.Background(), "feh", old, next)
|
||||
switch {
|
||||
case trunk && err != nil:
|
||||
t.Errorf("the trunk's manifest answers, FormChanges = %v, %v", changes, err)
|
||||
case !trunk && (err == nil || !strings.Contains(err.Error(), SourceEntry) || !strings.Contains(err.Error(), SourceComposition) || !strings.Contains(err.Error(), SourceTrunk)):
|
||||
t.Errorf("no source answers, FormChanges says %v, want the three named", err)
|
||||
}
|
||||
}
|
||||
|
||||
// A-461, A-461a, A-461b: another node's module whose running build has no entry is laid from the entry of the build the assignment
|
||||
// places for it on that node, or, where the placement names none, of its trunk build; with neither entry it stays as its name
|
||||
// alone, and this node's own module is never laid from a placement.
|
||||
@@ -453,7 +476,11 @@ func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) {
|
||||
env.Node = "n1"
|
||||
env.Entry = EntryCall(func(_ context.Context, _, verb string, _ any) (json.RawMessage, error) {
|
||||
if verb == meshcatalog.VerbModule {
|
||||
return json.Marshal(meshcatalog.ModuleAnswer{Module: meshcatalog.ModuleAnswerModule{Fp: tc.trunk}})
|
||||
var man map[string]any
|
||||
if tc.trunk != "" {
|
||||
man = map[string]any{"module": "distribution", "version": "2"}
|
||||
}
|
||||
return json.Marshal(meshcatalog.ModuleAnswer{Module: meshcatalog.ModuleAnswerModule{Fp: tc.trunk, Manifest: man}})
|
||||
}
|
||||
return nil, errors.New("not held")
|
||||
})
|
||||
@@ -481,7 +508,7 @@ func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) {
|
||||
if tc.node == "n2" && tc.build == "" && tc.trunk == "" && kept {
|
||||
t.Error("a trunk build that could not be had was kept, so it is asked once per process (A-461e)")
|
||||
}
|
||||
if _, asked := c.wantedBuilds()[placedFp]; asked != (tc.node == "n2" && (tc.build != "" || tc.trunk != "")) {
|
||||
if _, asked := c.wantedBuilds()[placedFp]; asked != (tc.node == "n2" && tc.build != "") {
|
||||
t.Errorf("the placed build asked = %v", asked)
|
||||
}
|
||||
c.layModules()
|
||||
|
||||
@@ -0,0 +1,227 @@
|
||||
package selfcompose
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
engcomp "github.com/novox/mesh-host/internal/compositions"
|
||||
)
|
||||
|
||||
// The one place that answers "the manifest of the build a module runs here" (design 47 G A-484, joining A-480, A-480a, A-483 and
|
||||
// A-461d). Every step that needs it reads it here and nowhere else: what the module provides (a held module keeps providing
|
||||
// what it runs, frombus.Scope.RunningManifest), what it keeps on the bus and whether that changes form (FormChanges), the
|
||||
// artifact store's holder (layModules, A-461d), and the picture of the catalog the composer resolves from. It answers in this
|
||||
// order: the entry of the running build; else the composition this node runs of that build; else the module's trunk manifest
|
||||
// through the seat mesh-catalog's verb `module`.
|
||||
|
||||
// The three sources of the one place, in the words it says them in.
|
||||
const (
|
||||
SourceEntry = "the entry of the running build"
|
||||
SourceComposition = "the composition this node runs of it"
|
||||
SourceTrunk = "the module's trunk manifest in the catalog"
|
||||
)
|
||||
|
||||
// runningAnswer is what the one place answers of one module.
|
||||
type runningAnswer struct {
|
||||
// Source is the source that answered; empty when none did, and Why then names the three.
|
||||
Source string
|
||||
// FP is the build the answer is of: the running build for an entry, the composition's build, or the trunk's.
|
||||
FP string
|
||||
// Known says the manifest itself was read (an entry or the trunk); a composition names its build and whether it keeps
|
||||
// data, which is all it holds of the manifest.
|
||||
Known bool
|
||||
Manifest catalogue.Manifest
|
||||
Raw []byte
|
||||
Digest string
|
||||
// Data is, from the composition, whether the running build keeps data on the bus.
|
||||
Data bool
|
||||
// Repository, Commit and Path are where the manifest's entry or the trunk's answer says it is built from.
|
||||
Repository, Commit, Path string
|
||||
// Why names what each of the three said, when none answered.
|
||||
Why string
|
||||
// RunFP is the running build the trunk manifest is asked for and kept against (A-461b).
|
||||
RunFP string
|
||||
// NeedTrunk says the trunk manifest is the one source left and is not held yet: the composer asks it beside the pass.
|
||||
NeedTrunk bool
|
||||
// Said is the line to say, once per module and source (principle 3); empty when it was said before.
|
||||
Said string
|
||||
}
|
||||
|
||||
// runningFpsLocked are the fingerprints of the build module runs on node, as the node's own record says (c.mu held), most direct
|
||||
// first: the build its running event names; on this node else the hint the caller knows and the build of the composition it runs;
|
||||
// on another node also the build its placement names, the mesh's truth of what runs there (A-461).
|
||||
func (c *Composer) runningFpsLocked(running []engcomp.Composed, node, module, hint string) (fps []string) {
|
||||
add := func(fp string) {
|
||||
if fp != "" && !slices.Contains(fps, fp) {
|
||||
fps = append(fps, fp)
|
||||
}
|
||||
}
|
||||
if r, ok := c.heard[node][module]; ok && !r.stopped {
|
||||
add(r.fingerprint)
|
||||
}
|
||||
if node != c.env.Node {
|
||||
add(c.placedBuild(node, module))
|
||||
return fps
|
||||
}
|
||||
add(hint)
|
||||
for _, r := range running {
|
||||
if r.Module == module {
|
||||
add(r.FP)
|
||||
}
|
||||
}
|
||||
return fps
|
||||
}
|
||||
|
||||
// runningLocked answers the manifest of the build module runs on node (c.mu held; running is what this node runs, read before
|
||||
// the lock), from the three sources in order, and says which answered once per module and source.
|
||||
func (c *Composer) runningLocked(running []engcomp.Composed, node, module, hint string) runningAnswer {
|
||||
fps := c.runningFpsLocked(running, node, module, hint)
|
||||
fp := ""
|
||||
if len(fps) > 0 {
|
||||
fp = fps[0]
|
||||
}
|
||||
var a runningAnswer
|
||||
entryWhy, compWhy, trunkWhy := "", "", ""
|
||||
// 1. The entry of the running build.
|
||||
for _, f := range fps {
|
||||
k, ok := c.keptEnt[f]
|
||||
if !ok || k.entry.Module == "" {
|
||||
continue
|
||||
}
|
||||
if digest, raw, err := entryManifest(k.entry); err == nil {
|
||||
if man, err := catalogue.Decode(raw); err == nil {
|
||||
a = runningAnswer{Source: SourceEntry, FP: f, Known: true, Manifest: man, Raw: raw, Digest: digest,
|
||||
Repository: k.entry.Repository, Commit: k.entry.Commit, Path: k.entry.Path}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if a.Source == "" {
|
||||
entryWhy = fmt.Sprintf("no entry of the build %s is held", orNone(fp))
|
||||
// 2. The composition this node runs of that build, whatever the want's build.
|
||||
if node == c.env.Node {
|
||||
for _, r := range running {
|
||||
if r.Module != module || r.FP == "" {
|
||||
continue
|
||||
}
|
||||
// The composition holds no manifest, only its build and whether that keeps data; its build's entry, if held, was
|
||||
// read as the running build's above.
|
||||
a = runningAnswer{Source: SourceComposition, FP: r.FP, Data: r.Data}
|
||||
break
|
||||
}
|
||||
if a.Source == "" {
|
||||
compWhy = "this node runs no composition of it"
|
||||
}
|
||||
} else {
|
||||
compWhy = "only the node itself runs compositions of its modules"
|
||||
}
|
||||
}
|
||||
// 3. The module's trunk manifest through the seat's verb `module`.
|
||||
if !a.Known {
|
||||
if t, ok := c.trunkBuilds[module]; ok && t.running == fp && len(t.manifest) > 0 {
|
||||
if raw, err := json.Marshal(t.manifest); err == nil {
|
||||
if man, err := catalogue.Decode(raw); err == nil {
|
||||
keep := a // the composition's words stay: it says whether the build keeps data
|
||||
a = runningAnswer{Source: SourceTrunk, FP: t.fp, Known: true, Manifest: man, Raw: raw, Digest: digestOf(raw),
|
||||
Repository: t.repository, Commit: t.commit, Path: t.path, Data: keep.Data}
|
||||
}
|
||||
}
|
||||
}
|
||||
if !a.Known {
|
||||
trunkWhy = c.trunkWhy[module]
|
||||
if trunkWhy == "" {
|
||||
trunkWhy = "the seat mesh-catalog's verb module has not answered"
|
||||
}
|
||||
a.NeedTrunk, a.RunFP = true, fp
|
||||
}
|
||||
}
|
||||
if a.Source == "" || (!a.Known && a.Source == SourceComposition) {
|
||||
a.Why = fmt.Sprintf("the manifest of the build %s runs here is read from none of: %s (%s); %s (%s); %s (%s)", module,
|
||||
SourceEntry, orWords(entryWhy, "its entry is held without a manifest"), SourceComposition,
|
||||
orWords(compWhy, "it names the build "+a.FP+" and no entry of that build is held"), SourceTrunk, trunkWhy)
|
||||
}
|
||||
if a.Source != "" {
|
||||
line := fmt.Sprintf("%s runs a build whose manifest is read from %s", module, a.Source)
|
||||
key := "running-manifest:" + node + "/" + module + "/" + a.Source
|
||||
if c.told == nil {
|
||||
c.told = map[string]bool{}
|
||||
}
|
||||
if !c.told[key] {
|
||||
c.told[key] = true
|
||||
a.Said = line
|
||||
}
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
// runningManifest is runningLocked with the lock taken here: what runs is read first, since the agent's record may wait.
|
||||
func (c *Composer) runningManifest(node, module, hint string) runningAnswer {
|
||||
var running []engcomp.Composed
|
||||
if c.env.Running != nil {
|
||||
running = c.env.Running()
|
||||
}
|
||||
c.mu.Lock()
|
||||
a := c.runningLocked(running, node, module, hint)
|
||||
c.mu.Unlock()
|
||||
if a.Said != "" {
|
||||
c.env.Say(a.Said)
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
// countsAsRunning says this node holds module on as it runs it (A-482, c.mu held): it is heard running here, in what the agent
|
||||
// runs, or its have names a build in the phase running or held. A module wanted here with none of these runs nothing here.
|
||||
func (c *Composer) countsAsRunning(module string) bool {
|
||||
if run := c.heard[c.env.Node][module]; run.stopped {
|
||||
return false
|
||||
}
|
||||
return c.runsHere(module) || c.haveRuns[module]
|
||||
}
|
||||
|
||||
// RunningManifest is what the one place says of module's running build here, in words, for the tool composition: the source that
|
||||
// answered with its build, or the words naming the three it tried.
|
||||
func (c *Composer) RunningManifest(module string) (source, fp, words string) {
|
||||
a := c.runningManifest(c.env.Node, module, "")
|
||||
if a.Source == "" || (!a.Known && a.Why != "") {
|
||||
return a.Source, a.FP, a.Why
|
||||
}
|
||||
return a.Source, a.FP, fmt.Sprintf("the manifest of the build %s runs here is read from %s", module, a.Source)
|
||||
}
|
||||
|
||||
// runningFor is the manifest of the build a module runs on node, for frombus.Scope.RunningManifest: only a module counted as
|
||||
// running here (A-482) answers, and only a manifest read, never a composition alone.
|
||||
func (c *Composer) runningFor(node string) func(module string) (catalogue.Manifest, bool) {
|
||||
return func(module string) (catalogue.Manifest, bool) {
|
||||
c.mu.Lock()
|
||||
counts := node != c.env.Node || c.countsAsRunning(module)
|
||||
c.mu.Unlock()
|
||||
if !counts {
|
||||
return catalogue.Manifest{}, false
|
||||
}
|
||||
a := c.runningManifest(node, module, "")
|
||||
return a.Manifest, a.Known
|
||||
}
|
||||
}
|
||||
|
||||
func digestOf(raw []byte) string {
|
||||
sum := sha256.Sum256(raw)
|
||||
return "sha256:" + hex.EncodeToString(sum[:])
|
||||
}
|
||||
|
||||
func orNone(s string) string {
|
||||
if s == "" {
|
||||
return "(none named)"
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func orWords(s, otherwise string) string {
|
||||
if s == "" {
|
||||
return otherwise
|
||||
}
|
||||
return s
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package selfcompose
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
"github.com/novox/mesh-host/internal/compositions"
|
||||
)
|
||||
|
||||
// A-484: the manifest of the build a module runs here is answered in one place, from the entry of the running build, else the
|
||||
// composition this node runs of it, else the module's trunk manifest; it says its source once per module and source, and where
|
||||
// none answers its words name the three.
|
||||
func TestTheManifestOfTheRunningBuildIsReadInOnePlace(t *testing.T) {
|
||||
running := meshcatalogclient.SourcePrefix2 + strings.Repeat("1", 64)
|
||||
other := meshcatalogclient.SourcePrefix2 + strings.Repeat("2", 64)
|
||||
body := `{"module":"xorg","version":"1","provides":[{"name":"x11-display"}]}`
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
entry string // the entry held, by fingerprint ("running", "other") or none
|
||||
composition string // the composition this node runs: its build ("running", "other") or none
|
||||
data bool
|
||||
trunk bool
|
||||
wantSource string
|
||||
wantKnown bool
|
||||
}{
|
||||
{"its entry answers first", "running", "running", false, true, SourceEntry, true},
|
||||
{"the entry of the composition's build is the running build's", "other", "other", true, true, SourceEntry, true},
|
||||
{"a composition with no manifest keeps the trunk's manifest and its data", "", "running", true, true, SourceTrunk, true},
|
||||
{"a composition and no trunk answer: its build and its data alone", "", "running", true, false, SourceComposition, false},
|
||||
{"the trunk alone", "", "", false, true, SourceTrunk, true},
|
||||
{"none answers", "", "", false, false, "", false},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
env := newFakeBus().env()
|
||||
env.Node = "n1"
|
||||
var said []string
|
||||
env.Say = func(s string) { said = append(said, s) }
|
||||
if tc.composition != "" {
|
||||
fp := map[string]string{"running": running, "other": other}[tc.composition]
|
||||
env.Running = func() []compositions.Composed {
|
||||
return []compositions.Composed{{Node: "n1", Module: "xorg", FP: fp, Data: tc.data}}
|
||||
}
|
||||
}
|
||||
c := New(env)
|
||||
c.mu.Lock()
|
||||
c.assignments["n1"] = meshmoduleassigner.Assignments{Node: "n1", Modules: []meshmoduleassigner.PlacedModule{{Module: "xorg"}}}
|
||||
c.heard = map[string]map[string]heardRun{"n1": {"xorg": {fingerprint: running}}}
|
||||
if tc.trunk {
|
||||
var man map[string]any
|
||||
_ = json.Unmarshal([]byte(body), &man)
|
||||
c.trunkBuilds = map[string]trunkBuild{"xorg": {running: running, fp: other, manifest: man}}
|
||||
}
|
||||
c.mu.Unlock()
|
||||
if tc.entry != "" {
|
||||
c.holdEntry(t, "xorg", map[string]string{"running": running, "other": other}[tc.entry], body)
|
||||
}
|
||||
a := c.runningManifest("n1", "xorg", "")
|
||||
again := c.runningManifest("n1", "xorg", "")
|
||||
if a.Source != tc.wantSource || a.Known != tc.wantKnown || (a.Known && len(a.Manifest.Provides) != 1) {
|
||||
t.Fatalf("answered %q (known %v, provides %d), want %q (known %v)", a.Source, a.Known, len(a.Manifest.Provides), tc.wantSource, tc.wantKnown)
|
||||
}
|
||||
if tc.wantSource != "" && (len(said) != 1 || again.Said != "" || !strings.Contains(said[0], tc.wantSource)) {
|
||||
t.Errorf("said %q (and %q again), want its source once", said, again.Said)
|
||||
}
|
||||
if tc.composition != "" && a.Data != tc.data && a.Source != SourceEntry {
|
||||
t.Errorf("the composition's data = %v, want %v", a.Data, tc.data)
|
||||
}
|
||||
if !tc.wantKnown && !strings.Contains(a.Why, SourceEntry) || !tc.wantKnown && !strings.Contains(a.Why, SourceComposition) || !tc.wantKnown && !strings.Contains(a.Why, SourceTrunk) {
|
||||
t.Errorf("the words of an answer that reads no manifest are %q, want the three sources named", a.Why)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -217,7 +217,9 @@ type Composer struct {
|
||||
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
|
||||
// trunkWhy is, by module, why the last ask of its trunk build gave none, for the words of the one place (A-484).
|
||||
trunkWhy map[string]string
|
||||
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).
|
||||
ends map[string]builds.BuildEnded
|
||||
@@ -1036,7 +1038,7 @@ func (c *Composer) compose(ctx context.Context) []agent.Update {
|
||||
var keptMu sync.Mutex
|
||||
var holds map[string]compose.Hold
|
||||
fromManifest := map[string]string{} // by module, why it is composed from the indexer's manifest and not a build
|
||||
scope := frombus.Scope{Node: c.env.Node, KeptAt: kept, InOwn: inOwn, Running: running, Heard: c.heardNow(), Engine: c.noteEngine, OwnFingerprint: os.Getenv(engcomp.FingerprintVar), Kept: func(module, words string) {
|
||||
scope := frombus.Scope{Node: c.env.Node, KeptAt: kept, InOwn: inOwn, Running: running, Heard: c.heardNow(), RunningManifest: c.runningFor(c.env.Node), Engine: c.noteEngine, OwnFingerprint: os.Getenv(engcomp.FingerprintVar), Kept: func(module, words string) {
|
||||
keptMu.Lock()
|
||||
defer keptMu.Unlock()
|
||||
if !slices.Contains(keptRuns[module], words) {
|
||||
@@ -1899,7 +1901,7 @@ func (c *Composer) ComposedToday(ctx context.Context, module, fp string) (string
|
||||
if c.env.Running != nil {
|
||||
running = c.env.Running()
|
||||
}
|
||||
scope := frombus.Scope{Node: c.env.Node, KeptAt: kept, InOwn: inOwn, Running: running, Heard: c.heardNow()}
|
||||
scope := frombus.Scope{Node: c.env.Node, KeptAt: kept, InOwn: inOwn, Running: running, Heard: c.heardNow(), RunningManifest: c.runningFor(c.env.Node)}
|
||||
comps, _, held, err := frombus.Compose(ctx, reader{c: c}, c.env.Mesh, scope, fps)
|
||||
if err != nil || held[module] != "" {
|
||||
return "", false
|
||||
@@ -2325,7 +2327,13 @@ func (c *Composer) WhyUnmade(module string) string {
|
||||
return c.last.Unmade[module]
|
||||
}
|
||||
|
||||
type trunkBuild struct{ running, fp string }
|
||||
// trunkBuild is a module's trunk build as the seat mesh-catalog's verb module answered it for the running build it was asked for
|
||||
// (A-461b, A-484): its fingerprint, its manifest and where it is built from.
|
||||
type trunkBuild struct {
|
||||
running, fp string
|
||||
manifest map[string]any
|
||||
repository, commit, path string
|
||||
}
|
||||
|
||||
// heardRun is one running event as the composer keeps it, with when it was said.
|
||||
type heardRun struct {
|
||||
|
||||
@@ -682,7 +682,7 @@ func (s *Shadow) answerProposal(ctx context.Context, proposal string) (nodeengin
|
||||
given[node] = &without
|
||||
}
|
||||
a := frombus.Answer(ctx, reader{c: c}, c.env.Mesh, frombus.Scope{Node: node, KeptAt: kept, Assignments: given, InOwn: inOwn,
|
||||
SameValue: c.sameValue, HeldToday: s.heldToday(heldAdded)}, fps, running, proposal, rev)
|
||||
SameValue: c.sameValue, HeldToday: s.heldToday(heldAdded), RunningManifest: c.runningFor(node)}, fps, running, proposal, rev)
|
||||
for _, module := range slices.Sorted(maps.Keys(heldAdded)) {
|
||||
a.Held = append(a.Held, nodeengine.CandidateRefusal{Module: module, Why: heldAdded[module]})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user