Node-engine: holds carry their wait; upstream images are no part; the store's address from another node's placed or trunk build (A-453, A-454, A-454a, A-461, A-461a, A-461b) #233

Merged
mesh-tools merged 9 commits from fix/47-G-hold-carries-its-wait into main 2026-11-17 00:23:01 +00:00
9 changed files with 325 additions and 48 deletions
+18 -4
View File
@@ -660,16 +660,25 @@ func (a *Agent) NotComposedEach(ctx context.Context, why string, held map[string
a.notComposed[module] = mark
a.mu.Unlock()
phase, detail := string(nodeengineclient.PhaseFailed), NotComposedDetail+why
var wait *nodeengine.Wait
if heldForEntry(why) {
// The entry its want names is not held: the phase held, its detail opening entry-asked: or entry-missing: and
// naming the fingerprint (design 47 G section 421).
phase, detail = string(nodeengineclient.PhaseHeld), why
// The hold says what it waits on, as every hold but a failed backup does (design 47 G A-453, section 541).
wait = a.composeWait(strings.TrimSuffix(heldReason(why), ":"), why)
}
a.writeHave(ctx, Have{Module: module, FP: mark.prior.FP, Composed: mark.prior.Composed, Sealed: mark.prior.Sealed,
Phase: phase, Detail: detail})
Phase: phase, Detail: detail, Wait: wait})
}
}
// composeWait is the wait a hold of the composition carries in its have: step compose, with its reason and its words (design 47 G
// A-453, section 541). Only a hold for a failed backup carries none.
func (a *Agent) composeWait(reason, words string) *nodeengine.Wait {
return &nodeengine.Wait{Owner: nodeengine.Seat, Step: nodeengine.WaitStepCompose, Reason: reason, Since: a.now(), Words: words}
}
// writeHave writes a module's have (the node's own key for NodeModule); on a node composing its own, with the sealed
// values of the composition it names when the caller gave none (Have.Sealed): those of the composition the agent applied or holds at that digest, else
// those the module's last have said at that digest.
@@ -1634,7 +1643,7 @@ func (a *Agent) apply(ctx context.Context, module string, w wantNow, comp compNo
}
a.env.Say(fmt.Sprintf("%s is held: %s", module, words))
a.writeHave(ctx, Have{Module: module, FP: prev.Fp, Composed: prev.Composed, Phase: string(nodeengineclient.PhaseHeld),
Detail: words})
Detail: words, Wait: a.composeWait("parts-differ", words)})
return
}
@@ -1671,9 +1680,14 @@ func (a *Agent) apply(ctx context.Context, module string, w wantNow, comp compNo
a.mu.Lock()
a.attempt[module] = attempt{FP: fp, Composed: dig, WantRev: w.Rev, CompRev: comp.Rev, Held: true, AnsweredRev: w.Rev}
a.mu.Unlock()
// It keeps running what it has: the have says what it holds and why it waits.
// It keeps running what it has: the have says what it holds and why it waits. A backup interrupted is no failure of it, so
// its hold waits as kept.go's do, with the words as the reason; only a failed backup carries no wait (A-453).
var wait *nodeengine.Wait
if words == BackupInterrupted {
wait = a.composeWait(words, words)
}
a.writeHave(ctx, Have{Module: module, FP: prev.Fp, Composed: prev.Composed, Phase: string(nodeengineclient.PhaseHeld),
Detail: words})
Detail: words, Wait: wait})
return
}
}
+38 -9
View File
@@ -357,15 +357,37 @@ func TestAWantAndItsCompositionApplyTheModuleAndTheHaveNamesBoth(t *testing.T) {
if got := len(b.appliedList()) - before; (got == 1) != row.applies {
t.Fatalf("parts %q: applied %d times, want applies=%v", row.name, got, row.applies)
}
if h := b.haves.last("web"); !row.applies && (h.Phase != string(nodeengineclient.PhaseHeld) || h.Detail != row.detail) {
t.Fatalf("parts %q: the have is %s %q, want held %q", row.name, h.Phase, h.Detail, row.detail)
if h := b.haves.last("web"); !row.applies && (h.Phase != string(nodeengineclient.PhaseHeld) || h.Detail != row.detail ||
h.Wait == nil || h.Wait.Step != nodeengine.WaitStepCompose || h.Wait.Reason != "parts-differ" || h.Wait.Words != row.detail) {
t.Fatalf("parts %q: the have is %s %q wait %+v, want held %q waiting on parts-differ (A-453)", row.name, h.Phase, h.Detail, h.Wait, row.detail)
}
}
// A container's digest is the one after its image's @.
container := json.RawMessage(`{"id":"web.c","type":"container","name":"web-c","image":"store/web@` + d3 + `","module":"web"}`)
container := json.RawMessage(`{"id":"web.c","type":"container","name":"web-c","image":"store/web@` + d3 + `","image-seat":"mesh-artifact-store","image-holder":"n1","module":"web"}`)
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container}); got != "" {
t.Fatalf("a container whose digest is in the parts differs: %q", got)
}
// A-454: an image the manifest pins from outside, by its digest, is no part of the want's parts, and a mesh-built one still is.
upstream := json.RawMessage(`{"id":"web.u","type":"container","name":"web-u","image":"registry@` + d2 + `","module":"web"}`)
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container, upstream}); got != "" {
t.Fatalf("an upstream image pinned by its digest is a part: %q", got)
}
// And neither is the registry seat's copy of an upstream image, though it is routed through the seat.
mirrored := json.RawMessage(`{"id":"web.m","type":"container","name":"web-m","image":"store:5000/upstream/docker.io/library/registry@` + d1 + `","image-seat":"container-image-registry","image-holder":"n1","module":"web"}`)
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container, mirrored}); got != "" {
t.Fatalf("an upstream copy served through the registry seat is a part: %q", got)
}
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{upstream}); !strings.Contains(got, "in the want's parts and not fetched: "+d3) || strings.Contains(got, d2) {
t.Fatalf("with only an upstream image the mesh-built one is not missing, or the upstream one is named: %q", got)
}
// A-454a: a mesh-built image whose seat holder is not on record carries no image-seat; its digest is in the parts, so it is fetched.
noSeat := json.RawMessage(`{"id":"web.n","type":"container","name":"web-n","image":"store/web@` + d3 + `","module":"web"}`)
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{noSeat}); got != "" {
t.Fatalf("a mesh-built image with no image-seat, named by the parts, is not fetched: %q", got)
}
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{noSeat, upstream}); got != "" {
t.Fatalf("an upstream image beside it is a part: %q", got)
}
// A-432: a runtime of its own runs the tool runner's program, which the module's parts do not name.
ownRuntime := json.RawMessage(`{"id":"web.own-runtime","type":"process","name":"web-runtime","source":"store/node-tools","digest":"` + d1 + `","run":["./node-tools"],"module":"web"}`)
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container, ownRuntime}); got != "" {
@@ -754,7 +776,8 @@ func TestADataModuleIsBackedUpFirstAndHeldWhenItFails(t *testing.T) {
})
eventually(t, "the have does not say held", func() bool {
h := b.haves.last("db")
return h.Phase == string(nodeengineclient.PhaseHeld) && strings.Contains(h.Detail, "repository is locked") && h.FP == fp1
// A hold for a failed backup carries no wait: the operator is asked about it (A-453).
return h.Phase == string(nodeengineclient.PhaseHeld) && strings.Contains(h.Detail, "repository is locked") && h.FP == fp1 && h.Wait == nil
})
if got := b.appliedList(); len(got) != 0 {
t.Fatalf("something was applied behind a failed backup: %v", got)
@@ -813,8 +836,9 @@ func TestADataModuleIsBackedUpFirstAndHeldWhenItFails(t *testing.T) {
stopI := ib.run()
<-began
stopI()
if h := ib.haves.last("db"); h.Phase != string(nodeengineclient.PhaseHeld) || h.FP != fp1 || h.Composed != dig1 || h.Detail != BackupInterrupted {
t.Errorf("held after an interrupted backup: %+v", h)
if h := ib.haves.last("db"); h.Phase != string(nodeengineclient.PhaseHeld) || h.FP != fp1 || h.Composed != dig1 || h.Detail != BackupInterrupted ||
h.Wait == nil || h.Wait.Step != nodeengine.WaitStepCompose || h.Wait.Reason != BackupInterrupted {
t.Errorf("held after an interrupted backup, with its wait (A-453): %+v", h)
}
// At a start: a backup the node agent's own stop interrupted (postgres on novox, 2026-10-31) is no failure, so it is
@@ -1784,9 +1808,14 @@ func TestTheNodesOwnCompositionIsAppliedWhenItDiffersAndARecordMoveWaitsForAYes(
}
// Design 47 G §421: a module whose want's entry the catalog half holds none of is the phase held, its detail opening
// entry-missing: and naming the fingerprint; composed again, its have is what it runs.
b.ag.NotComposedEach(context.Background(), "", map[string]string{"idle": EntryMissing + " the catalog half holds no entry of the build src2:x"})
if h := b.haves.last("idle"); h.Phase != string(nodeengineclient.PhaseHeld) || h.Composed != idleDig || h.Detail != EntryMissing+" the catalog half holds no entry of the build src2:x" {
t.Errorf("idle's have while its entry is missing: %+v", h)
// A-453: the hold carries its wait, step compose with the reason, as every hold but a failed backup does.
for _, row := range []struct{ opening, reason string }{{EntryMissing, "entry-missing"}, {EntryAsked, "entry-asked"}} {
words := row.opening + " the catalog half holds no entry of the build src2:x"
b.ag.NotComposedEach(context.Background(), "", map[string]string{"idle": words})
if h := b.haves.last("idle"); h.Phase != string(nodeengineclient.PhaseHeld) || h.Composed != idleDig || h.Detail != words ||
h.Wait == nil || h.Wait.Step != nodeengine.WaitStepCompose || h.Wait.Reason != row.reason || h.Wait.Words != words || h.Wait.Since.IsZero() {
t.Errorf("idle's have while its entry is %s: %+v", row.reason, h)
}
}
b.ag.NotComposedEach(context.Background(), "", nil)
if h := b.haves.last("idle"); h.Phase != string(nodeengineclient.PhaseRunning) || h.Composed != idleDig {
+38 -3
View File
@@ -6,6 +6,7 @@ import (
"sort"
"strings"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/containerimageregistryclient/reference"
"git.novox.be/novox/mesh-sdk/go/catalogue"
"git.novox.be/novox/mesh-sdk/go/declaration"
)
@@ -30,11 +31,30 @@ func judgedAgain(why string) bool {
return strings.HasPrefix(why, PartsDiffer) || heldForEntry(why)
}
// heldReason is the opening of a detail held for an entry: EntryAsked or EntryMissing.
func heldReason(why string) string {
if strings.HasPrefix(why, EntryAsked) {
return EntryAsked
}
return EntryMissing
}
// heldForEntry says whether why is a hold for the entry a want names.
func heldForEntry(why string) bool {
return strings.HasPrefix(why, EntryAsked) || strings.HasPrefix(why, EntryMissing)
}
// upstreamCopy is whether a routed image is the registry seat's copy of an upstream image, `<address>/upstream/<host>/<image>@<digest>`:
// the mesh mirrors it, but it built nothing, so it is no part of a want (design 47 G A-454).
func upstreamCopy(image string) bool {
_, path, ok := strings.Cut(image, "/")
if !ok {
return false
}
_, _, upstream := reference.InUpstream(path)
return upstream
}
// partsDifference checks a want's `parts` against the digests of the archive, process and container resources of the
// composition, which are the digests the apply fetches and checks (design 47 G section 524). A want with no `parts` (an
// assigner of before G, or a node whose record does not state `want-parts`) is applied as today: it returns "". With
@@ -44,6 +64,10 @@ func partsDifference(parts map[string]string, resources []json.RawMessage) strin
if len(parts) == 0 {
return ""
}
inParts := map[string]bool{}
for _, d := range parts {
inParts[d] = true
}
fetched := map[string]bool{}
for _, raw := range resources {
r, err := declaration.ParseResource(raw)
@@ -61,11 +85,22 @@ func partsDifference(parts map[string]string, resources []json.RawMessage) strin
fetched[res.Digest] = true
}
case *declaration.Container:
// A digest the want's parts name always counts as fetched, whatever marks the resource carries; one they do not
// name counts only when it is the mesh's own: an image the manifest pins from outside, or the registry seat's
// copy of an upstream image, is no part (design 47 G A-454, A-454a).
digest := ""
if strings.HasPrefix(res.Image, "sha256:") {
fetched[res.Image] = true
} else if _, digest, ok := strings.Cut(res.Image, "@"); ok {
fetched[digest] = true
digest = res.Image
} else if _, d, ok := strings.Cut(res.Image, "@"); ok {
digest = d
}
if digest == "" {
continue
}
if !inParts[digest] && (res.ImageSeat == "" || upstreamCopy(res.Image)) {
continue
}
fetched[digest] = true
}
}
named := map[string]bool{}
+10
View File
@@ -125,6 +125,16 @@ func (c *composer) render(nodeName string, mode Mode) (Rendered, error) {
}
}
// A module that fetches from an artifact store with no known address waits for it; the machine composes the rest (A-461).
for module, why := range placed.storeHeld {
if r.NotPlaced == nil {
r.NotPlaced = map[string]string{}
}
if _, said := r.NotPlaced[module]; !said {
r.NotPlaced[module] = why
}
}
// And a certificate for this machine's name inside the mesh, when anything on it asks.
for _, m := range plan.Modules {
if m.Certificate == nil {
+43 -4
View File
@@ -10,6 +10,7 @@ import (
"git.novox.be/novox/mesh-networking/modules/mesh-wireguard/go/overlay"
"git.novox.be/novox/mesh-sdk/go/catalogue"
"github.com/novox/mesh-host/internal/compose/resolution"
"github.com/novox/mesh-host/internal/registryforms"
)
// The contracts of the node-engine's statement that gate what a machine is sent, as the controller's link package names them
@@ -41,6 +42,8 @@ type Placed struct {
// manifest's own number as the Reading mode composes them, and never invented. The controller's adapter allocates and
// composes again.
ForeseenPorts []string
// storeHeld are the modules left out of the declaration because the artifact store has no known address, and why (A-461).
storeHeld map[string]string
}
// Places composes the place half of the rendering for a node (the controller's renderingFor in the Reading and Foreseeing modes,
@@ -92,7 +95,15 @@ func (c *composer) places(nodeName string, resolved Resolved) (Placed, error) {
r.MeshRange = c.overlayRange()
// The artifact store as this node reaches it now, with what the mesh has built.
// Where no address is known (the holder opens no listen to the mesh, or two), only the modules that fetch from the store
// wait, with the words of an unanswered requirement; the node composes the rest (design 47 G A-461, A-452).
store, err := c.artifactStoreAddress(nodeName)
var noAddress *storeListenError
if errors.As(err, &noAddress) {
// Only the store holder's listen refusal holds its fetchers; any other error still refuses the node (A-461b).
out.storeHeld = modulesNeedingTheStore(plan.Modules, err)
store, err = "", nil
}
if err != nil {
return out, err
}
@@ -327,6 +338,29 @@ func (c *composer) namesInTheMesh() map[string]string {
return out
}
// modulesNeedingTheStore are the modules with a resource whose image or source is a kept reference into the artifact store, each
// with why it waits: nothing provides the store's address (A-461).
func modulesNeedingTheStore(modules []catalogue.Manifest, why error) map[string]string {
out := map[string]string{}
for _, m := range modules {
for _, res := range m.Resources {
needs := false
for _, key := range []string{"image", "source"} {
if written, ok := res[key].(string); ok {
if _, kept := registryforms.Forms.InArtifactStore(written); kept {
needs = true
}
}
}
if needs {
out[m.Module] = fmt.Sprintf("nothing provides %q, wanted by %s: %v", "the artifact store's address", m.Module, why)
break
}
}
}
return out
}
// StoreSeat is the seat whose holder is the artifact store (novox/hq ADR 0632 §1): the store's address is that holder's
// listen open to the mesh, on the machine assignment puts it on. The provision artifact-store it was found by before is
// retired; no module serves it.
@@ -363,6 +397,11 @@ func (c *composer) storeHolders() map[string]catalogue.Manifest {
return out
}
// storeListenError is the refusal of a holder that opens no listen to the mesh, or two: the store has no address (A-461).
type storeListenError struct{ said string }
func (e *storeListenError) Error() string { return e.said }
// storeListen is the store holder's listen every machine pulls from: its one listen open to the mesh. A holder opening
// none, or more than one, says no address, by name: which of two ports is the store is no guess the composer makes.
func storeListen(m catalogue.Manifest) (catalogue.Listening, error) {
@@ -376,15 +415,15 @@ func storeListen(m catalogue.Manifest) (catalogue.Listening, error) {
case 1:
return open[0], nil
case 0:
return catalogue.Listening{}, fmt.Errorf("%s holds %s and opens no tcp listen to the mesh: the artifact store has no "+
"address (novox/hq ADR 0632 §1)", m.Module, StoreSeat)
return catalogue.Listening{}, &storeListenError{fmt.Sprintf("%s holds %s and opens no tcp listen to the mesh: the artifact store has no "+
"address (novox/hq ADR 0632 §1)", m.Module, StoreSeat)}
}
var said []string
for _, l := range open {
said = append(said, fmt.Sprintf("%s (%d)", l.Name, l.Port))
}
return catalogue.Listening{}, fmt.Errorf("%s holds %s and opens %s to the mesh: the artifact store's address is its one "+
"listen open to the mesh (novox/hq ADR 0632 §1)", m.Module, StoreSeat, strings.Join(said, ", "))
return catalogue.Listening{}, &storeListenError{fmt.Sprintf("%s holds %s and opens %s to the mesh: the artifact store's address is its one "+
"listen open to the mesh (novox/hq ADR 0632 §1)", m.Module, StoreSeat, strings.Join(said, ", "))}
}
// artifactStoreOnNetwork is the machine on this network that holds the store's seat, and the port that machine put the
+24 -2
View File
@@ -351,8 +351,30 @@ func TestTheStoreIsFoundByTheImageSeatsHolderAndItsListen(t *testing.T) {
m := in.Catalogue["registry"]
m.Listens = append(m.Listens, catalogue.Listening{Name: "other", Port: 5300, From: catalogue.FromMesh})
in.Catalogue["registry"] = m
if _, err := Places(in, "laptop"); err == nil || !strings.Contains(err.Error(), "opens registry (5000), other (5300) to the mesh") {
t.Errorf("a holder opening two listens to the mesh: %v", err)
// A-461: a store with no known address (two listens open to the mesh, so none is a guess) costs the modules that fetch from
// it, not the node: those wait with the words of an unanswered requirement, and the node composes the rest.
in.Catalogue["app"] = catalogue.Manifest{Module: "app", Version: "1",
Resources: []map[string]any{{"id": "c", "type": "container", "name": "app", "image": "artifact-store://app/c@sha256:" + strings.Repeat("a", 64)}}}
in.Catalogue["plain"] = catalogue.Manifest{Module: "plain", Version: "1"}
laptop := nodeOf(t, &in, "laptop")
laptop.Assigned = append(laptop.Assigned, "app", "plain")
got, err := Render(in, "laptop", Reading)
if err != nil {
t.Fatalf("a holder opening two listens to the mesh refuses the whole node: %v", err)
}
if why := got.Rendering.NotPlaced["app"]; !strings.Contains(why, "nothing provides") || !strings.Contains(why, "opens registry (5000), other (5300) to the mesh") {
t.Errorf("the module that fetches from the store waits with %q", why)
}
if why, held := got.Rendering.NotPlaced["plain"]; held {
t.Errorf("a module that fetches nothing from the store waits: %q", why)
}
// A-461b: only the listen refusal holds the store's fetchers; any other fault of finding the store (here the holder's machine is
// on the network as first read but unknown when its assignment is read) still refuses the node.
broken := newComposer(in)
broken.onTheNetwork()
broken.in.Nodes = []Node{*nodeOf(t, &in, "laptop")}
if _, err := broken.places("laptop", Resolved{}); err == nil || !strings.Contains(err.Error(), "reading what anchor is assigned") {
t.Errorf("a fault of finding the store other than its listen refusal did not refuse the node: %v", err)
}
}
+100 -24
View File
@@ -274,13 +274,19 @@ func (c *Composer) wantedBuilds() map[string]bool {
}
}
}
for _, mods := range c.heard {
for _, run := range mods {
for node, mods := range c.heard {
for module, 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) {
if _, named := out[built]; !named {
out[built] = 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
@@ -299,6 +305,7 @@ func (c *Composer) wantedBuilds() map[string]bool {
// composes from, and lays the picture frombus reads (c.modules, c.manifests) from the entries it holds. It runs at the start of
// each pass.
func (c *Composer) syncEntries(ctx context.Context) {
c.askTrunkBuilds()
need := c.wantedBuilds()
for fp := range need {
c.entryOf(fp)
@@ -372,15 +379,15 @@ func (c *Composer) layModules() {
c.mu.Lock()
defer c.mu.Unlock()
modules := map[string]meshcatalog.ModulesByModuleValue{}
lay := func(module, fp string) {
lay := func(module, fp string) bool {
k, ok := c.keptEnt[fp]
if !ok || k.entry.Module == "" {
return
return false
}
e := k.entry
digest, raw, err := entryManifest(e)
if err != nil {
return
return false
}
m := meshcatalog.ModulesByModuleValue{Fp2: fp, Manifest: digest, Repository: e.Repository, Commit: e.Commit, Path: e.Path,
Needs: e.Needs, Packages: e.Packages, Verdict: e.Verdict}
@@ -389,6 +396,7 @@ func (c *Composer) layModules() {
}
modules[module] = m
c.manifests[digest] = raw
return true
}
nodes := make([]string, 0, len(c.heard))
for node := range c.heard {
@@ -398,7 +406,13 @@ func (c *Composer) layModules() {
for _, node := range nodes {
for module, run := range c.heard[node] {
if !run.stopped && run.fingerprint != "" {
lay(module, run.fingerprint)
// 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)
}
}
}
}
}
@@ -443,6 +457,60 @@ 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.
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 ""
}
// 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 == "" {
return false
}
k, ok := c.keptEnt[run.fingerprint]
return !ok || k.entry.Module == ""
}
// 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() {
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) {
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})
}
}
}
}
c.mu.Unlock()
for _, a := range asks {
fp, _ := c.trunkFp(a.module)
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()
}
}
// 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
// none, the digest of the manifest's bytes.
func entryManifest(e meshcatalog.CatalogEntry) (digest string, raw []byte, err error) {
@@ -651,30 +719,38 @@ 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) {
if c.env.Entry == nil {
return "", "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)
}
answer, said, ok := buscalls.Unwrap(raw)
if !ok {
return "", 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)
}
if a.Module.Fp == "" {
return "", fmt.Sprintf("the catalog half gives %s no fingerprint: %s", module, a.Module.None)
}
return a.Module.Fp, ""
}
// addedModule is the trunk's build of a module an assignment candidate adds to this node when no want here names it yet: the
// fingerprint the seat's verb `module` answers, then its entry by the verb `entry` as for a wanted module (design 47 G §421, A-312).
// A call, not a watch: nothing of the catalog is kept. It answers the entry when held; otherwise why not: a module with no
// fingerprint says the verb's reason, an entry asked says so (its answer wakes the shadow, which composes again).
func (c *Composer) addedModule(ctx context.Context, module string) (fp string, entry meshcatalog.CatalogEntry, held, pending bool, why string) {
if c.env.Entry == nil {
return "", entry, false, false, "this node reads no module of the catalog half"
fp, why = c.trunkFp(module)
if fp == "" {
return "", entry, false, false, why
}
raw, err := c.env.Entry(moduleVerb, meshcatalog.ModuleInput{Module: module})
if err != nil {
return "", entry, false, false, fmt.Sprintf("the catalog half's answer for %s: %v", module, err)
}
answer, said, ok := buscalls.Unwrap(raw)
if !ok {
return "", entry, false, false, 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 "", entry, false, false, fmt.Sprintf("the catalog half's answer for %s cannot be read: %v", module, err)
}
if a.Module.Fp == "" {
return "", entry, false, false, fmt.Sprintf("the catalog half gives %s no fingerprint: %s", module, a.Module.None)
}
fp = a.Module.Fp
c.mu.Lock()
if c.addedFps == nil {
c.addedFps = map[string]bool{}
+48
View File
@@ -341,4 +341,52 @@ func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) {
if still {
t.Error("an entry of the running build was answered, and the composition was not handed again")
}
// 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.
placedFp := meshcatalogclient.SourcePrefix2 + strings.Repeat("3", 64)
for _, tc := range []struct {
name string
node string
build, trunk string
holds, laid bool
}{
{"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},
} {
t.Run(tc.name, func(t *testing.T) {
env := newFakeBus().env()
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}})
}
return nil, errors.New("not held")
})
c := New(env)
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}}}
c.mu.Unlock()
if tc.holds {
c.holdEntry(t, "distribution", placedFp, `{"module":"distribution","version":"2"}`)
}
c.askTrunkBuilds()
if _, asked := c.wantedBuilds()[placedFp]; asked != (tc.node == "n2" && (tc.build != "" || tc.trunk != "")) {
t.Errorf("the placed build asked = %v", asked)
}
c.layModules()
c.mu.Lock()
m, ok := c.modules["distribution"]
raw := c.manifests[m.Manifest]
c.mu.Unlock()
if got := ok && strings.Contains(string(raw), `"version":"2"`); got != tc.laid {
t.Errorf("laid from the placed build = %v, want %v (%+v %s)", got, tc.laid, m, raw)
}
})
}
}
+6 -2
View File
@@ -209,8 +209,10 @@ type Composer struct {
addedFps map[string]bool
// heard is, by node and module, what each node's event running last said it runs, kept from the seat's stream by this
// node's own consumer (NoteRunning), under mu; heardRead is whether the first read of the stream ended (RunningRead).
heard map[string]map[string]heardRun
heardRead bool
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
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
@@ -2311,6 +2313,8 @@ func (c *Composer) WhyUnmade(module string) string {
return c.last.Unmade[module]
}
type trunkBuild struct{ running, fp string }
// heardRun is one running event as the composer keeps it, with when it was said.
type heardRun struct {
at time.Time