diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/actingwaits.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/actingwaits.go index 58999f9e..5ff6f835 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/actingwaits.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/actingwaits.go @@ -31,7 +31,7 @@ func (p *passer) actingOf(module string, released map[string]bool) func(node str } for _, e := range p.entryEdges(node, module) { if acting.Held(e.Step) && !released[acting.Key(node, module, e.Module)+"@"+e.Fp] { - out = append(out, assign.ActingEdge{Node: e.Node, Part: e.Module, Fp: e.Fp, Step: e.Step}) + out = append(out, assign.ActingEdge{Node: e.Node, Part: e.Module, Fp: e.Fp, Step: e.Step, Seat: e.Seat}) } } return out @@ -103,7 +103,10 @@ func (p *passer) actingWaits(ctx context.Context, n assign.Nodes, wanted map[str continue } key := acting.Key(ref.Node, ref.Module, e.Module) - if n.Runs(assign.ActingEdge{Node: e.Node, Part: e.Module, Fp: e.Fp, Step: e.Step}) { + if took, runs := n.ActingRuns(assign.ActingEdge{Node: e.Node, Part: e.Module, Fp: e.Fp, Step: e.Step, Seat: e.Seat}); runs { + if took != e.Fp && kept[key] != nil { + p.logf("the wait of %s on %s for %s ends: %s runs %s, which serves the seat %s, though its newest is %s (design 47 G A-426)", ref.Module, ref.Node, e.Module, e.Node, took, e.Seat, e.Fp) + } continue } standing[key] = true @@ -139,7 +142,9 @@ func (p *passer) actingWaits(ctx context.Context, n assign.Nodes, wanted map[str how := acting.HowRan if w.Released { how = acting.HowReleased - } else if e, ok := p.edgeOf(w); !ok || !n.Runs(e) { + } else if e, ok := p.edgeOf(w); !ok { + how = acting.HowReplaced + } else if _, runs := n.ActingRuns(e); !runs { how = acting.HowReplaced } if !w.EndSaid { @@ -185,7 +190,7 @@ func (p *passer) actingCycles(entries map[string]seat.AssignmentEntry, engines m released := p.actingReleased() cycles := assigngraph.HeldCycles(slices.Collect(maps.Values(entries)), func(e seat.AssignmentEntry, edge seat.Edge) bool { return held[e.Node+"/"+e.Module] && engines[e.Node] != e.Module && edge.Kind == "acting" && acting.Held(edge.Step) && - !released[acting.Key(e.Node, e.Module, edge.Module)+"@"+edge.Fp] && !n.Runs(assign.ActingEdge{Node: edge.Node, Part: edge.Module, Fp: edge.Fp, Step: edge.Step}) + !released[acting.Key(e.Node, e.Module, edge.Module)+"@"+edge.Fp] && !actingRunsOf(n, edge) }) raised := map[string]bool{} for _, at := range slices.Sorted(maps.Keys(cycles)) { @@ -224,3 +229,9 @@ func (p *passer) actingCycles(entries map[string]seat.AssignmentEntry, engines m } } } + +// actingRunsOf says whether an assignment edge's acting part runs a build serving it (A-426). +func actingRunsOf(n assign.Nodes, edge seat.Edge) bool { + _, runs := n.ActingRuns(assign.ActingEdge{Node: edge.Node, Part: edge.Module, Fp: edge.Fp, Step: edge.Step, Seat: edge.Seat}) + return runs +} diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/actingwaits_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/actingwaits_test.go index 762332aa..8c746b80 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/actingwaits_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/actingwaits_test.go @@ -36,7 +36,9 @@ func TestAnEntryWaitsForItsActingPartAndTheWaitIsKeptSaidAndEnded(t *testing.T) p.graph = &graphKeeper{} p.graph.computed.Revision.Entries = []meshwants.NodeEntryRef{{Node: "ace", Module: "nats", Digest: "d1"}} p.graph.computed.Entries = map[string]meshwants.AssignmentEntry{"d1": entry} - n := assign.Nodes{Online: map[string]bool{"ace": true}, Running: map[string]map[string]nodeengine.Running{"ace": {"mesh-host": {Fingerprint: "src2:old"}}}} + // The old build of mesh-host serves no seat of the edge here, so the entry waits (A-426: one serving it ends the wait). + notServing := func(nodeengine.Running, string) (bool, bool) { return false, true } + n := assign.Nodes{Online: map[string]bool{"ace": true}, Running: map[string]map[string]nodeengine.Running{"ace": {"mesh-host": {Fingerprint: "src2:old"}}}, Serves: notServing} wanted := map[string]map[string]mwc.Want{"nats": {"ace": {Fp: "src2:older"}}} ctx := context.Background() @@ -149,7 +151,7 @@ func TestTheNodeEngineIsWantedFirstAndAWantHeldOnACycleIsAFinding(t *testing.T) } p.graph.computed.Entries = entries n := assign.Nodes{Online: map[string]bool{"ace": true}, Running: map[string]map[string]nodeengine.Running{"ace": { - "mesh-host": {Fingerprint: "src2:old"}, "assigner": {Fingerprint: "src2:old"}}}} + "mesh-host": {Fingerprint: "src2:old"}, "assigner": {Fingerprint: "src2:old"}}}, Serves: func(nodeengine.Running, string) (bool, bool) { return false, true }} wanted := map[string]map[string]mwc.Want{} if got := p.actingOf("mesh-host", nil)("ace"); len(got) != 0 { t.Errorf("the node-engine's want is held by %+v, want by no acting edge", got) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/world.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/world.go index c9927d9c..6738804f 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/world.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/world.go @@ -409,6 +409,17 @@ func (w *world) nodes(manifests map[string]catalogue.Manifest, assigned map[stri n := assign.Nodes{Online: map[string]bool{}, Running: w.runningNow(), Haves: map[string]map[string]nodeengine.HaveByNodeModuleValue{}, Providers: map[string]map[string][]string{}, Reads: map[string][]string{}} n.Online = w.online() + // The build a running statement names serves an acting edge's seat when its manifest claims it (design 47 G A-426). + n.Serves = func(r nodeengine.Running, seat string) (bool, bool) { + if r.Manifest == "" { + return false, false + } + got := w.manifest(r.Manifest) + if got.err != "" { + return false, false + } + return got.manifest.ClaimsSeat(seat), true + } for key, value := range w.read(buckets.Have) { node, module, isNode, err := nodeengineclient.ParseHaveKey(key) if err != nil { diff --git a/modules/mesh-delivery-assigner/internal/assign/wants.go b/modules/mesh-delivery-assigner/internal/assign/wants.go index 9434cc0b..08b29d8c 100644 --- a/modules/mesh-delivery-assigner/internal/assign/wants.go +++ b/modules/mesh-delivery-assigner/internal/assign/wants.go @@ -108,7 +108,7 @@ type Module struct { } // ActingEdge is one acting edge: Part's version Fp acts in Step on Node, before the entry moves. -type ActingEdge struct{ Node, Part, Fp, Step string } +type ActingEdge struct{ Node, Part, Fp, Step, Seat string } // Runs says the part's version of the edge runs on its node, as the node-engine seat's `running` says it. func (n Nodes) Runs(e ActingEdge) bool { @@ -126,7 +126,7 @@ func (m Module) actingWaiting(node string, n Nodes) (string, bool) { return "", false } for _, e := range m.Acting(node) { - if !n.Runs(e) { + if _, runs := n.ActingRuns(e); !runs { return fmt.Sprintf("%s on %s waits in %s for %s at %s to run on %s", m.Name, node, e.Step, e.Part, short(e.Fp), e.Node), true } } @@ -182,6 +182,30 @@ type Nodes struct { // Reads is, by node, the reader capabilities its node-engine states in its node record (nodeengine.NodeRecord.ManifestReads, // ADR 0614 §4). A node with none, or none read, is read as stating the baseline (catalogue.StatedManifestReads). Reads map[string][]string + // Serves says whether the build of a running statement serves an acting edge's seat, from that build's manifest: known false + // when its manifest cannot be read (design 47 G A-426). Nil: none is read. + Serves func(r nodeengine.Running, seat string) (serves, known bool) +} + +// ActingRuns says whether an acting edge's part runs a build serving the edge's seat on its node, and which build (design 47 G +// A-426): any running build of the part that serves the seat ends the wait, whatever version its newest is, so a wait on a version +// not yet built is never held for that alone. A build whose manifest cannot be read counts as serving it when it is the part's +// (the part holds the seat by its claim). Without the running statements the have is read as before: the edge's version only. +func (n Nodes) ActingRuns(e ActingEdge) (string, bool) { + if n.Running == nil { + return e.Fp, n.Runs(e) + } + r, ok := n.Running[e.Node][e.Part] + if !ok || r.Stopped || r.Fingerprint == "" { + return "", false + } + if r.Fingerprint == e.Fp || e.Seat == "" || n.Serves == nil { + return r.Fingerprint, true + } + if serves, known := n.Serves(r, e.Seat); known && !serves { + return "", false + } + return r.Fingerprint, true } // healthy says whether a have runs fp healthy. diff --git a/modules/mesh-delivery-assigner/internal/assign/wants_test.go b/modules/mesh-delivery-assigner/internal/assign/wants_test.go index 5854eddb..389265c5 100644 --- a/modules/mesh-delivery-assigner/internal/assign/wants_test.go +++ b/modules/mesh-delivery-assigner/internal/assign/wants_test.go @@ -1694,27 +1694,38 @@ func TestRuleOneSaysHowTheBuildStands(t *testing.T) { } } -// Design 47 G §266, §268 (AS9): an entry whose acting edge names a step the assigner holds waits, its want held, until the acting part's -// version runs on the edge's node, as the node-engine seat's `running` says it; then the want moves. +// Design 47 G §266, §268 (AS9), A-426: an entry whose acting edge names a step the assigner holds waits, its want held, only while +// the acting part runs nothing that serves the edge's seat on the edge's node: any build of it serving the seat (an older one, a +// hand start) ends the wait at once, a build not serving it or a stopped part holds it, and a released wait is no edge. func TestAWantWaitsForItsActingPartsNewVersion(t *testing.T) { - edge := ActingEdge{Node: "g14", Part: "mesh-host", Fp: fNew, Step: "compose"} - run := func(fp string, stopped bool) Nodes { + edge := ActingEdge{Node: "g14", Part: "mesh-host", Fp: fNew, Step: "compose", Seat: "node-engine"} + run := func(fp string, stopped bool, serves bool) Nodes { _, n := ready() - n.Running = map[string]map[string]nodeengine.Running{"g14": {"mesh-host": {Fingerprint: fp, Stopped: stopped}}} + n.Running = map[string]map[string]nodeengine.Running{"g14": {"mesh-host": {Fingerprint: fp, Stopped: stopped, Manifest: "m"}}} + n.Serves = func(nodeengine.Running, string) (bool, bool) { return serves, true } return n } m, _ := ready() m.Acting = func(string) []ActingEdge { return []ActingEdge{edge} } m.Nodes = []string{"g14"} - out := Wants(m, run(fOld, false), wantedOld(), nil) + out := Wants(m, run("", true, true), wantedOld(), nil) if out.Wants["g14"].Fp == fNew || out.Rules["g14"].Rule != mwc.RuleComposed || !strings.Contains(out.Rules["g14"].Words, "waits in compose for mesh-host") { - t.Fatalf("the old version runs: want %+v rule %+v", out.Wants["g14"], out.Rules["g14"]) + t.Fatalf("the part stopped: want %+v rule %+v", out.Wants["g14"], out.Rules["g14"]) } - if out := Wants(m, run(fNew, false), wantedOld(), nil); out.Wants["g14"].Fp != fNew { + if out := Wants(m, run(fOld, false, false), wantedOld(), nil); out.Wants["g14"].Fp == fNew { + t.Errorf("an old build not serving the seat runs: want %+v", out.Wants["g14"]) + } + if out := Wants(m, run(fOld, false, true), wantedOld(), nil); out.Wants["g14"].Fp != fNew { + t.Errorf("an old build serving the seat runs: want %+v, want the new version moved", out.Wants["g14"]) + } + if took, runs := run(fOld, false, true).ActingRuns(edge); !runs || took != fOld { + t.Errorf("ActingRuns took %q, %v: want the old build it runs", took, runs) + } + if out := Wants(m, run(fNew, false, true), wantedOld(), nil); out.Wants["g14"].Fp != fNew { t.Errorf("the new version runs: want %+v", out.Wants["g14"]) } m.Acting = func(string) []ActingEdge { return nil } // a released wait is no edge - if out := Wants(m, run(fOld, false), wantedOld(), nil); out.Wants["g14"].Fp != fNew { + if out := Wants(m, run("", true, true), wantedOld(), nil); out.Wants["g14"].Fp != fNew { t.Errorf("released: want %+v", out.Wants["g14"]) } }