From ff2211b3a1c29427eece8e386dd6d8e8968a73a4 Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 20 Nov 2026 03:04:16 +0100 Subject: [PATCH] A2: the assigner holds no want for an acting part's new version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The acting waits go whole: actingwaits.go (the waits acting..., their wait-held and wait-ended, the acting-cycle finding), the acting half of internal/acting, the cycles among the acting waits and the node-engine read for them (assigngraph's Cycles, HeldCycles, Engines) and the wait's bound on an acting edge; the edge itself stays, kind acting, for the order it gives. assigner_waits and assigner_release keep the order waits (A3) and the outside waits. Builds: design 47 H §750, §764; H-A-70 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy --- .../cmd/mesh-delivery-assigner/actingwaits.go | 237 ----------------- .../actingwaits_test.go | 186 ------------- .../cmd/mesh-delivery-assigner/graphkept.go | 10 +- .../cmd/mesh-delivery-assigner/orderwaits.go | 31 ++- .../mesh-delivery-assigner/outside_tools.go | 16 +- .../cmd/mesh-delivery-assigner/pass.go | 6 +- .../cmd/mesh-delivery-assigner/pass_test.go | 19 ++ .../cmd/mesh-delivery-assigner/tools.go | 2 +- .../internal/acting/acting.go | 36 +-- .../internal/assign/findings.go | 15 -- .../internal/assigngraph/compute.go | 12 +- .../internal/assigngraph/cycle.go | 248 ------------------ .../internal/assigngraph/cycle_test.go | 60 ----- .../internal/assigngraph/graph_test.go | 2 +- .../internal/assigngraph/runner.go | 19 ++ 15 files changed, 89 insertions(+), 810 deletions(-) delete mode 100644 modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/actingwaits.go delete mode 100644 modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/actingwaits_test.go delete mode 100644 modules/mesh-delivery-assigner/internal/assigngraph/cycle.go delete mode 100644 modules/mesh-delivery-assigner/internal/assigngraph/cycle_test.go create mode 100644 modules/mesh-delivery-assigner/internal/assigngraph/runner.go diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/actingwaits.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/actingwaits.go deleted file mode 100644 index 5ff6f835..00000000 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/actingwaits.go +++ /dev/null @@ -1,237 +0,0 @@ -package main - -import ( - "context" - "maps" - "slices" - "strings" - - meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient" - seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" - - "mesh-delivery-assigner/internal/acting" - "mesh-delivery-assigner/internal/assign" - "mesh-delivery-assigner/internal/assigngraph" - "mesh-delivery-assigner/internal/assignment" - "mesh-delivery-assigner/internal/buckets" -) - -// The waits for an acting part's new version in the steps the assigner holds (design 47 G §266, §268, §276): an entry of the assignment -// graph whose acting edge names composing or placing waits, its want held, until the part's version runs on the edge's node. The wait is -// kept in the state `waits` under `acting...`, said as `wait-held` when it starts and `wait-ended` (ran, released, -// replaced) when it ends; `assigner_waits` reads it and `assigner_release` with how `now` lets the entry move with the part's running -// version. A node away starts no wait: its clock starts when the node is present (§268). - -// actingOf is the Module.Acting of module: the held acting edges of its entry on a node, those whose wait was not released left out. -func (p *passer) actingOf(module string, released map[string]bool) func(node string) []assign.ActingEdge { - return func(node string) []assign.ActingEdge { - var out []assign.ActingEdge - if p.engineOn(node) == module { - return nil // the node-engine's own want is held by no acting edge, so it is written first (§268, A-323, A-330) - } - 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, Seat: e.Seat}) - } - } - return out - } -} - -// engineOn is the module that holds the seat node-engine on node in the revision the pass computed, read from the acting edges' -// seat (A-330); "" when none is read. -func (p *passer) engineOn(node string) string { - if p.graph == nil { - return "" - } - return assigngraph.Engines(slices.Collect(maps.Values(p.graph.computed.Entries)))[node] -} - -// entryEdges are the acting edges of the entry of module on node in the revision the pass computed. -func (p *passer) entryEdges(node, module string) []seat.Edge { - g := p.graph - if g == nil { - return nil - } - for _, ref := range g.computed.Revision.Entries { - if ref.Node == node && ref.Module == module { - var out []seat.Edge - for _, e := range g.computed.Entries[ref.Digest].Edges { - if e.Kind == "acting" { - out = append(out, e) - } - } - return out - } - } - return nil -} - -// actingReleased is the waits released by hand and not yet run, by `@`. -func (p *passer) actingReleased() map[string]bool { - out := map[string]bool{} - for key, raw := range p.w.read(buckets.Waits()) { - if w, err := acting.Decode(raw); err == nil && w.Released && (acting.Is(key) || acting.IsOrder(key)) { - out[key+"@"+w.Fp] = true - } - } - return out -} - -// actingWaits keeps the acting waits after the pass's wants: it starts the wait of each entry held for a part's version, ends the -// wait of one that ran, was replaced or was released, and says each. -func (p *passer) actingWaits(ctx context.Context, n assign.Nodes, wanted map[string]map[string]meshwants.Want) { - g := p.graph - if g == nil || p.kvs[buckets.Waits()] == nil { - return - } - now := p.clock() - kept := p.w.read(buckets.Waits()) - standing := map[string]bool{} - engines := assigngraph.Engines(slices.Collect(maps.Values(g.computed.Entries))) - held := map[string]bool{} // `/` of each entry held for a part's version - for _, ref := range g.computed.Revision.Entries { - entry := g.computed.Entries[ref.Digest] - if w, ok := wanted[ref.Module][ref.Node]; ok && w.Fp == entry.Fp { - continue // the entry's version is wanted already: nothing moves, so nothing waits - } - if engines[ref.Node] == ref.Module { - continue // the node-engine's own want waits for no acting part (§268, A-323, A-330) - } - for _, e := range entry.Edges { - if e.Kind != "acting" || !acting.Held(e.Step) { - continue - } - key := acting.Key(ref.Node, ref.Module, e.Module) - 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 - held[ref.Node+"/"+ref.Module] = true - if raw := kept[key]; raw != nil { - if w, err := acting.Decode(raw); err == nil && w.Entry == entry.Fp && w.Fp == e.Fp { - p.actingReleaseSaid(ctx, key, w) - continue - } - } - if !n.Online[ref.Node] { - continue // a node away holds only itself, and its clock has not started (§268) - } - w := acting.Wait{Step: e.Step, Node: ref.Node, Module: ref.Module, Part: e.Module, PartNode: e.Node, Fp: e.Fp, Entry: entry.Fp, - Since: now, ClockFrom: now, Bound: acting.BoundOf(e).String()} - if err := p.wantsSay(seat.EventWaitHeld, acting.Body(w, assignment.Module()), key+"."+e.Fp+"."+entry.Fp); err != nil { - p.logf("the wait of %s on %s for %s is not said, and is said at the next pass: %v", ref.Module, ref.Node, e.Module, err) - continue - } - p.put(ctx, buckets.Waits(), key, func() ([]byte, error) { return acting.Encode(w) }) - p.logf("the want of %s on %s is held: its acting part %s (step %s) does not run the version %s on %s; the wait %s ends when it does, or by assigner_release", ref.Module, ref.Node, e.Module, e.Step, e.Fp, e.Node, key) - } - } - p.actingCycles(g.computed.Entries, engines, held, n) - for key, raw := range kept { - if !acting.Is(key) || standing[key] { - continue - } - w, err := acting.Decode(raw) - if err != nil { - continue - } - how := acting.HowRan - if w.Released { - how = acting.HowReleased - } else if e, ok := p.edgeOf(w); !ok { - how = acting.HowReplaced - } else if _, runs := n.ActingRuns(e); !runs { - how = acting.HowReplaced - } - if !w.EndSaid { - body := acting.Body(w, assignment.Module()) - body.How = how - if err := p.wantsSay(seat.EventWaitEnded, body, key+"."+w.Fp+"."+w.Entry+"."+how); err != nil { - p.logf("the end of the wait of %s on %s for %s is not said, and is said at the next pass: %v", w.Module, w.Node, w.Part, err) - continue - } - } - p.remove(ctx, buckets.Waits(), key) - } -} - -// actingReleaseSaid says wait-ended of a wait released by hand, once, and keeps its record so the entry is not held again. -func (p *passer) actingReleaseSaid(ctx context.Context, key string, w acting.Wait) { - if !w.Released || w.EndSaid { - return - } - body := acting.Body(w, assignment.Module()) - body.How = acting.HowReleased - body.By = w.By - if err := p.wantsSay(seat.EventWaitEnded, body, key+"."+w.Fp+"."+w.Entry+"."+acting.HowReleased); err != nil { - p.logf("the release of the wait of %s on %s for %s is not said, and is said at the next pass: %v", w.Module, w.Node, w.Part, err) - return - } - w.EndSaid = true - p.put(ctx, buckets.Waits(), key, func() ([]byte, error) { return acting.Encode(w) }) -} - -// edgeOf is the edge a kept wait stands on, as an acting edge. -func (p *passer) edgeOf(w acting.Wait) (assign.ActingEdge, bool) { - return assign.ActingEdge{Node: w.PartNode, Part: w.Part, Fp: w.Fp, Step: w.Step}, true -} - -// actingCycles writes the finding acting-cycle of each held want whose holding edges lie on a cycle no rule breaks, and clears it of -// every other want, a finding a pass before or another process wrote included (design 47 G A-323, A-330). An edge holds while its -// step is the assigner's, its part's version does not run and its wait was not released; the node-engine's own want is held by none. -func (p *passer) actingCycles(entries map[string]seat.AssignmentEntry, engines map[string]string, held map[string]bool, n assign.Nodes) { - if p.findings.Put == nil { - return - } - 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] && !actingRunsOf(n, edge) - }) - raised := map[string]bool{} - for _, at := range slices.Sorted(maps.Keys(cycles)) { - node, module, _ := strings.Cut(at, "/") - o := assign.ActingCycleFinding(node, module, cycles[at]) - key := mcseatKey(o) - raised[key] = true - if p.said[key+"="+o.Summary] { - continue // written already as it stands - } - if err := p.findings.Put(o.Finding(p.clock())); err != nil { - p.logf("the finding %s is not written: %v", key, err) - continue - } - p.said[key+"="+o.Summary] = true - } - if p.findings.Keys == nil || p.findings.Delete == nil { - return - } - keys, err := p.findings.Keys() - if err != nil { - p.logf("the findings %s are not read, so none is cleared this pass: %v", assign.KindActingCycle, err) - return - } - for _, key := range keys { - if strings.HasSuffix(key, "."+assign.KindActingCycle) && !raised[key] { - if err := p.findings.Delete(key); err != nil { - p.logf("the finding %s is not cleared: %v", key, err) - continue - } - for said := range p.said { - if strings.HasPrefix(said, key+"=") { - delete(p.said, said) - } - } - } - } -} - -// 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 deleted file mode 100644 index d622c908..00000000 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/actingwaits_test.go +++ /dev/null @@ -1,186 +0,0 @@ -package main - -import ( - "context" - "encoding/json" - "strings" - "testing" - "time" - - "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" - mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions" - mwc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient" - meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" - - "mesh-delivery-assigner/internal/acting" - "mesh-delivery-assigner/internal/assign" - "mesh-delivery-assigner/internal/buckets" -) - -// Design 47 G §266, §268, §276 (AS9): an entry with an acting edge in composing waits for the part's version to run on the edge's node; -// the wait is kept, said as wait-held with its bound and clock-from, read by assigner_waits, released by assigner_release with how -// `now` and ended when the version runs. -func TestAnEntryWaitsForItsActingPartAndTheWaitIsKeptSaidAndEnded(t *testing.T) { - now := time.Date(2026, 11, 12, 9, 0, 0, 0, time.UTC) - p := newPasser(kvSet{buckets.Waits(): &memKV{values: map[string][]byte{}}}, now) - var events []string - var bodies []meshwants.Wait - p.publishWants = func(event string, body any, id string) error { - events = append(events, event) - bodies = append(bodies, body.(meshwants.Wait)) - return nil - } - entry := meshwants.AssignmentEntry{Node: "ace", Module: "nats", Fp: fpTest, Edges: []meshwants.Edge{ - {Kind: "acting", Node: "ace", Module: "mesh-host", Fp: "src2:new", Seat: "node-engine", Step: "compose", Bound: "15m"}, - {Kind: "acting", Node: "ace", Module: "indexer", Fp: "src2:idx", Seat: "mesh-catalog", Step: "take-in"}}} - 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} - // 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() - - if got := p.actingOf("nats", nil)("ace"); len(got) != 1 || got[0].Part != "mesh-host" { - t.Fatalf("the assigner holds composing only: %+v", got) - } - p.actingWaits(ctx, n, wanted) - p.actingWaits(ctx, n, wanted) // said once - if len(events) != 1 || events[0] != meshwants.EventWaitHeld { - t.Fatalf("events %v", events) - } - b := bodies[0] - if b.Step != "compose" || b.Part != "mesh-host" || b.Fp != "src2:new" || b.Bound != "15m0s" || b.ClockFrom == nil || !b.ClockFrom.Equal(now) || b.Owner == "" { - t.Errorf("wait-held %+v", b) - } - key := acting.Key("ace", "nats", "mesh-host") - if _, err := acting.Decode(p.w.read(buckets.Waits())[key]); err != nil { - t.Fatalf("the wait is kept: %v", err) - } - // a release by hand lets the entry move, and ends the wait once - w, _ := acting.Decode(p.w.read(buckets.Waits())[key]) - w.Released = true - raw, _ := acting.Encode(w) - p.w.put(buckets.Waits(), key, raw) - if got := p.actingOf("nats", p.actingReleased())("ace"); len(got) != 0 { - t.Errorf("a released wait still holds: %+v", got) - } - p.actingWaits(ctx, n, wanted) - p.actingWaits(ctx, n, wanted) - if len(events) != 2 || events[1] != meshwants.EventWaitEnded || bodies[1].How != acting.HowReleased { - t.Fatalf("events %v bodies %+v", events, bodies) - } - // the version runs: the record goes, said nothing more - n.Running["ace"]["mesh-host"] = nodeengine.Running{Fingerprint: "src2:new"} - p.actingWaits(ctx, n, wanted) - if len(p.w.read(buckets.Waits())) != 0 || len(events) != 2 { - t.Errorf("kept %v events %v", p.w.read(buckets.Waits()), events) - } -} - -func TestAnActingWaitOfANodeAwayStartsNoClockAndAnEntryWantedAlreadyWaitsNot(t *testing.T) { - p := newPasser(kvSet{buckets.Waits(): &memKV{values: map[string][]byte{}}}, time.Now()) - p.publishWants = func(string, any, string) error { t.Fatal("said"); return nil } - 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": {Node: "ace", Module: "nats", Fp: "src2:a", Edges: []meshwants.Edge{ - {Kind: "acting", Node: "ace", Module: "mesh-host", Fp: "src2:new", Step: "compose"}}}} - n := assign.Nodes{Online: map[string]bool{}} - p.actingWaits(context.Background(), n, map[string]map[string]mwc.Want{}) - n.Online["ace"] = true - p.actingWaits(context.Background(), n, map[string]map[string]mwc.Want{"nats": {"ace": {Fp: "src2:a"}}}) - if len(p.w.read(buckets.Waits())) != 0 || strings.Contains(p.graph.computed.Entries["d1"].Fp, "x") { - t.Errorf("kept %v", p.w.read(buckets.Waits())) - } -} - -func TestTheToolsReadAndReleaseAnActingWait(t *testing.T) { - var acts []string - s := newPutTools(memStore{waitsState: &memKV{values: map[string][]byte{}}}, func(key string, body any) (json.RawMessage, error) { - acts = append(acts, key) - return json.RawMessage(`{"ok":true,"log":"logged"}`), nil - }) - w := acting.Wait{Step: "compose", Node: "ace", Module: "nats", Part: "mesh-host", PartNode: "ace", Fp: "src2:new", Entry: "src2:a", Since: time.Now(), ClockFrom: time.Now(), Bound: "30m0s"} - raw, _ := acting.Encode(w) - s.st.put(waitsState, acting.Key("ace", "nats", "mesh-host"), raw) - got, err := s.doWaits(map[string]any{"module": "nats"}) - if list := got.(map[string]any)["waits"].([]any); err != nil || len(list) != 1 || list[0].(actingSaid).BoundEnds == "" { - t.Fatalf("assigner_waits = %+v %v", got, err) - } - if _, err := s.doRelease(map[string]any{"node": "ace", "module": "nats", "how": "now"}, "x"); err == nil { - t.Error("a release with no why is taken") - } - if _, err := s.doRelease(map[string]any{"node": "ace", "module": "nats", "how": "now", "why": "the new engine is known good"}, "shanks.node-tools"); err != nil || len(acts) == 0 { - t.Fatalf("%v %v", err, acts) - } - raw, _, _, _ = s.st.get(waitsState, acting.Key("ace", "nats", "mesh-host")) - if r, _ := acting.Decode(raw); !r.Released || !strings.Contains(r.By, "known good") { - t.Errorf("wait = %+v", r) - } -} - -// Design 47 G §268, A-323, A-330: the assigner and the node-engine on a node are one step: the node-engine's own want waits for no -// acting part, so it moves first, and the node's other wants, the assigner's own included, wait for the new node-engine; a want held -// on a cycle no rule breaks is the finding acting-cycle (scope module, id .) naming each edge's step, cleared by the -// next pass that finds it on none. -func TestTheNodeEngineIsWantedFirstAndAWantHeldOnACycleIsAFinding(t *testing.T) { - p := newPasser(kvSet{buckets.Waits(): &memKV{values: map[string][]byte{}}}, time.Date(2026, 11, 13, 2, 0, 0, 0, time.UTC)) - p.publishWants = func(string, any, string) error { return nil } - findings := map[string]mcseat.Finding{} - p.findings = assign.Findings{ - Put: func(f mcseat.Finding) error { findings[f.Scope+"."+f.ID+"."+f.Kind] = f; return nil }, - Delete: func(key string) error { delete(findings, key); return nil }, - Keys: func() ([]string, error) { - var keys []string - for k := range findings { - keys = append(keys, k) - } - return keys, nil - }} - compose := meshwants.Edge{Kind: "acting", Node: "ace", Module: "mesh-host", Fp: "src2:engine", Seat: "node-engine", Step: "compose"} - place := meshwants.Edge{Kind: "acting", Node: "ace", Module: "assigner", Fp: "src2:assigner", Seat: "mesh-wants", Step: "place"} - entries := map[string]meshwants.AssignmentEntry{ - "d1": {Node: "ace", Module: "mesh-host", Fp: "src2:engine", Edges: []meshwants.Edge{place}}, - "d2": {Node: "ace", Module: "assigner", Fp: "src2:assigner", Edges: []meshwants.Edge{compose}}, - "d3": {Node: "ace", Module: "app", Fp: "src2:app", Edges: []meshwants.Edge{compose, place}}, - } - p.graph = &graphKeeper{} - for d, e := range entries { - p.graph.computed.Revision.Entries = append(p.graph.computed.Revision.Entries, meshwants.NodeEntryRef{Node: e.Node, Module: e.Module, Digest: d}) - } - 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"}}}, 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) - } - if got := p.actingOf("assigner", nil)("ace"); len(got) != 1 || got[0].Part != "mesh-host" { - t.Errorf("the assigner's own want is held by %+v, want by the new node-engine", got) - } - p.actingWaits(context.Background(), n, wanted) - kept := p.w.read(buckets.Waits()) - if kept[acting.Key("ace", "mesh-host", "assigner")] != nil || kept[acting.Key("ace", "assigner", "mesh-host")] == nil || kept[acting.Key("ace", "app", "mesh-host")] == nil { - t.Errorf("the waits kept: %v", kept) - } - if len(findings) != 0 { - t.Errorf("the cycle the node-engine's want breaks is a finding: %v", findings) - } - // Two parts holding each other across compose and place, neither the node-engine: no rule breaks it. - entries["d4"] = meshwants.AssignmentEntry{Node: "ace", Module: "x", Fp: "src2:x", Edges: []meshwants.Edge{{Kind: "acting", Node: "ace", Module: "y", Fp: "src2:y", Seat: "s-y", Step: "place"}}} - entries["d5"] = meshwants.AssignmentEntry{Node: "ace", Module: "y", Fp: "src2:y", Edges: []meshwants.Edge{{Kind: "acting", Node: "ace", Module: "x", Fp: "src2:x", Seat: "s-x", Step: "compose"}}} - p.graph.computed.Revision.Entries = append(p.graph.computed.Revision.Entries, meshwants.NodeEntryRef{Node: "ace", Module: "x", Digest: "d4"}, - meshwants.NodeEntryRef{Node: "ace", Module: "y", Digest: "d5"}) - p.actingWaits(context.Background(), n, wanted) - f, ok := findings["module.ace.x.acting-cycle"] - if len(findings) != 2 || !ok || !strings.Contains(f.Summary, "ace/x -[place]-> ace/y -[compose]-> ace/x") { - t.Fatalf("the findings of a cycle no rule breaks: %v", findings) - } - // x's new version runs: y no longer waits, so neither is held on a cycle, and both findings clear. - n.Running["ace"]["x"] = nodeengine.Running{Fingerprint: "src2:x"} - p.actingWaits(context.Background(), n, wanted) - if len(findings) != 0 { - t.Errorf("the findings after the cycle broke: %v", findings) - } -} diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphkept.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphkept.go index 4afa0d44..aaf3abba 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphkept.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphkept.go @@ -35,13 +35,11 @@ type graphKeeper struct { source int64 ok bool said string - // cycled is the cycles last said (assigngraph.Cycles). - cycled string // full says the next revision did not fit the store, so no want is written (graphfill.go); started says the first pass judged the fill. full, started bool // pins removes a revision that ceased to be current once nothing pins it (pins.go); nil keeps every revision. pins *pinKeeper - // computed is the revision computed by the last pass, with its entries: the edges the wants wait on (actingwaits.go). + // computed is the revision computed by the last pass, with its entries: its edges. computed assigngraph.Computed } @@ -62,12 +60,6 @@ func (p *passer) keepGraph(ctx context.Context) { p.logf("the assignment graph leaves out %s", u) } } - if cycles := strings.Join(c.Cycles, "; "); cycles != g.cycled { - g.cycled = cycles - if cycles != "" { - p.logf("the assignment graph holds a cycle among the acting waits, within one step or across steps: %s", cycles) - } - } if !g.started { g.started = true p.fillAtStart(ctx) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/orderwaits.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/orderwaits.go index dcdfdb3e..73647dc4 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/orderwaits.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/orderwaits.go @@ -199,6 +199,17 @@ func (p *passer) orderEdgesOf(ctx context.Context, m assign.Module, wanted map[s return unread } +// orderReleased is the order waits released by hand and not yet run, by `@`. +func (p *passer) orderReleased() map[string]bool { + out := map[string]bool{} + for key, raw := range p.w.read(buckets.Waits()) { + if w, err := acting.Decode(raw); err == nil && w.Released && acting.IsOrder(key) { + out[key+"@"+w.Fp] = true + } + } + return out +} + // orderActing is the order edges of module on node that still hold its want, as acting edges: those not met, and not released by hand. A // node whose catalog entry is not read yet holds its want too, on a stand-in edge no part runs. func (p *passer) orderActing(module string, released map[string]bool, unread map[string]bool, n func() assign.Nodes) func(node string) []assign.ActingEdge { @@ -217,7 +228,7 @@ func (p *passer) orderActing(module string, released map[string]bool, unread map } } -// orderWaits keeps the order waits after the pass's wants, as actingWaits keeps the acting waits: it starts the wait of each edge not met, +// orderWaits keeps the order waits after the pass's wants: it starts the wait of each edge not met, // ends the wait of one that ran, was replaced or was released, and says each. func (p *passer) orderWaits(ctx context.Context, n assign.Nodes, wanted map[string]map[string]mwc.Want) { if p.kvs[buckets.Waits()] == nil { @@ -248,7 +259,7 @@ func (p *passer) orderWaits(ctx context.Context, n assign.Nodes, wanted map[stri p.orderSaid[key] = true } } - p.actingReleaseSaid(ctx, key, w) + p.orderReleaseSaid(ctx, key, w) continue } } @@ -294,3 +305,19 @@ func (p *passer) orderWaits(ctx context.Context, n assign.Nodes, wanted map[stri delete(p.orderSaid, key) } } + +// orderReleaseSaid says wait-ended of an order wait released by hand, once, and keeps its record so the entry is not held again. +func (p *passer) orderReleaseSaid(ctx context.Context, key string, w acting.Wait) { + if !w.Released || w.EndSaid { + return + } + body := acting.Body(w, assignment.Module()) + body.How = acting.HowReleased + body.By = w.By + if err := p.wantsSay(seat.EventWaitEnded, body, key+"."+w.Fp+"."+w.Entry+"."+acting.HowReleased); err != nil { + p.logf("the release of the wait of %s on %s for %s is not said, and is said at the next pass: %v", w.Module, w.Node, w.Part, err) + return + } + w.EndSaid = true + p.put(ctx, buckets.Waits(), key, func() ([]byte, error) { return acting.Encode(w) }) +} diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/outside_tools.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/outside_tools.go index 461a9e01..a65b2a87 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/outside_tools.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/outside_tools.go @@ -34,7 +34,7 @@ type waitSaid struct { BoundEnds string `json:"bound-ends,omitempty"` } -// actingSaid is one wait for an acting part's new version as assigner_waits answers it (actingwaits.go). +// actingSaid is one order wait as assigner_waits answers it (orderwaits.go). type actingSaid struct { Key string `json:"key"` acting.Wait @@ -54,7 +54,7 @@ func (s *putTools) doWaits(args map[string]any) (any, error) { if err != nil || !found { continue } - if acting.Is(key) || acting.IsOrder(key) { + if acting.IsOrder(key) { if a, err := acting.Decode(raw); err == nil && (arg(args, "node") == "" || a.Node == arg(args, "node")) && (arg(args, "module") == "" || a.Module == arg(args, "module")) { said := actingSaid{Key: key, Wait: a} if d, err := time.ParseDuration(a.Bound); err == nil && !a.Released { @@ -131,7 +131,7 @@ func (s *putTools) doReleaseWait(args map[string]any, by string) (any, error) { return map[string]any{"released": key, "how": how, "by": by, "hand-act": taken.Log}, nil } -// doReleaseActing is assigner_release with how `now`: the entry of module on node moves with its acting parts' running versions. The +// doReleaseActing is assigner_release with how `now`: the entry of module on node moves with its order parts' running versions. The // hand act is recorded first; the release is written on each standing wait of the entry, and the process says wait-ended at its next pass. func (s *putTools) doReleaseActing(node, module, why, by string) (any, error) { if why == "" { @@ -146,9 +146,9 @@ func (s *putTools) doReleaseActing(node, module, why, by string) (any, error) { w acting.Wait } var held []one - prefix, orderPrefix := acting.Prefix+node+"."+module+".", acting.OrderPrefix+node+"."+module+"." + orderPrefix := acting.OrderPrefix + node + "." + module + "." for _, k := range keys { - if !strings.HasPrefix(k, prefix) && !strings.HasPrefix(k, orderPrefix) { + if !strings.HasPrefix(k, orderPrefix) { continue } raw, _, found, err := s.st.get(waitsState, k) @@ -160,11 +160,11 @@ func (s *putTools) doReleaseActing(node, module, why, by string) (any, error) { } } if len(held) == 0 { - return nil, fmt.Errorf("%s holds no wait of %s for an acting part: assigner_waits lists them", node, module) + return nil, fmt.Errorf("%s holds no order wait of %s: assigner_waits lists them", node, module) } rec := meshhandactsclient.Recorder{Ask: s.ask} taken, err := rec.Record(meshhandactsclient.Request{What: fmt.Sprintf("assigner_release %s %s %s", node, module, acting.HowNow), Why: why, - Cause: "acting-wait", Verb: "mesh-wants.assigner_release"}) + Cause: "order-wait", Verb: "mesh-wants.assigner_release"}) if err != nil { return nil, fmt.Errorf("the hand act could not be recorded, so nothing was released: %w", err) } @@ -185,7 +185,7 @@ func (s *putTools) doReleaseActing(node, module, why, by string) (any, error) { // waitsTool is assigner_waits as the runtime serves it. func (s *putTools) waitsTool() stdio.Tool { - return stdio.Tool{Name: toolWaits, Description: "Every wait of the delivery and where it stands: an entry waiting for an acting part's new version in composing or placing (§266, §268), with its part, version, step, clock-from and bound; and a moved module's failing health check on a " + + return stdio.Tool{Name: toolWaits, Description: "Every wait of the delivery and where it stands: an entry waiting in placing for the order of a delivery (§298), with its part, version, step, clock-from and bound; and a moved module's failing health check on a " + "machine whose open conditions name a cause outside the delivery (design 47 G §706), with its module, machine, fingerprint, the " + "condition's key, what it stands `on`, its clock-from, bound, its ask and its state; a settle shows as settling with its end. Narrowed by " + "machine or module. Read-only.", diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/pass.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/pass.go index 4f6813d2..c205946d 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/pass.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/pass.go @@ -314,9 +314,8 @@ func (p *passer) wants(ctx context.Context) { defer func() { p.sayNeither(neither, stale, left) }() // Where grants are read from, once for the pass: the grants part's (issue 774, ADR 0571 clause 9). grants := p.w.grantsBucket() - released := p.actingReleased() + released := p.orderReleased() p.orders, p.orderVisited = map[string]orderEdge{}, map[string]bool{} - defer func() { p.actingWaits(ctx, viewOf(p.w.trunkName()).nodes, wanted) }() defer func() { p.orderWaits(ctx, viewOf(p.w.trunkName()).nodes, wanted) }() for name := range names { groups := p.groups(name, nodesOf[name], assignedBranches[name]) @@ -412,8 +411,7 @@ func (p *passer) wants(ctx context.Context) { nodes = p.outsideReview(ctx, name, fp, m.Nodes, nodes, manifests[name].ClaimsSeat(mcseat.Seat), p.movedTo(wanted, nodes)) } unread := p.orderEdgesOf(ctx, m, wantedOf[name], trunk) - actingOf, orderOf := p.actingOf(name, released), p.orderActing(name, released, unread, func() assign.Nodes { return nodes }) - m.Acting = func(node string) []assign.ActingEdge { return append(actingOf(node), orderOf(node)...) } + m.Acting = p.orderActing(name, released, unread, func() assign.Nodes { return nodes }) out := assign.Wants(m, nodes, wantedOf[name], last) p.sayWhy(ctx, name, m.Nodes, wantWhy{Branch: g.branch, Fp: fp, Step: whyRules}, wantedOf[name], &out, &m) p.sayParts(name, m, nodes, out, wantedOf[name]) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/pass_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/pass_test.go index 76e97147..195df7f5 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/pass_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/pass_test.go @@ -23,6 +23,7 @@ import ( mdc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient" mwc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" + mwseat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-teller/tellerevents" "git.novox.be/novox/mesh-delivery/modules/mesh-grants/grantsstate" @@ -1613,3 +1614,21 @@ type readsMsg struct { func (m readsMsg) Ack() error { return nil } func (m readsMsg) Subject() string { return m.subject } func (m readsMsg) Data() []byte { return m.data } + +// A2/AC1 (design 47 H §750, §764; H-A-70): given an entry of the assignment graph whose acting part's new version does not run on +// its node, when the assigner passes, then it keeps no wait for the part and says no wait-held: no want is held for an acting part. +func TestAnActingPartsNewVersionHoldsNoWant(t *testing.T) { + waits := &memKV{values: map[string][]byte{}} + p := newPasser(kvSet{buckets.Wants(): &memKV{values: map[string][]byte{}}, buckets.Asks(): &memKV{values: map[string][]byte{}}, buckets.Waits(): waits}, time.Now()) + var said []string + p.publishWants = func(event string, _ any, _ string) error { said = append(said, event); return nil } + p.w.heardPresence("ace", false, time.Now()) + p.graph = &graphKeeper{} + p.graph.computed.Revision.Entries = []mwseat.NodeEntryRef{{Node: "ace", Module: "nats", Digest: "d1"}} + p.graph.computed.Entries = map[string]mwseat.AssignmentEntry{"d1": {Node: "ace", Module: "nats", Fp: fpTest, Edges: []mwseat.Edge{ + {Kind: "acting", Node: "ace", Module: "mesh-host", Fp: "src2:new", Seat: "node-engine", Step: "compose"}}}} + p.wants(context.Background()) + if len(waits.values) != 0 || len(said) != 0 { + t.Errorf("an acting part's version held the want: kept %v, said %v", waits.values, said) + } +} diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tools.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tools.go index 7113be74..892e88ad 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tools.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tools.go @@ -346,7 +346,7 @@ func (s *putTools) tools() []stdio.Tool { "rules write the machine's want again from their next pass. Nothing changes on the machine until they move it.", Input: schema(map[string]string{"node": "the machine", "module": "the module", "why": "why, kept with the put", "how": "with how, the wait of the delivery on an outside cause (assigner_waits) is released, not a put: go-on (the module counts healthy there), " + - "failed (the failing check is the delivery's), rejudge (judge it again now), or now (the entry waiting for an acting part's new version moves with the running one); written in the hand-act log first"}, + "failed (the failing check is the delivery's), rejudge (judge it again now), or now (the entry waiting in placing for an order part's version moves with the running one); written in the hand-act log first"}, []string{"module", "why"}), Run: func(a map[string]any) (any, error) { return s.doRelease(a, stdio.CallerOf(a)) }}, s.waitsTool(), diff --git a/modules/mesh-delivery-assigner/internal/acting/acting.go b/modules/mesh-delivery-assigner/internal/acting/acting.go index abc217c1..7906ef24 100644 --- a/modules/mesh-delivery-assigner/internal/acting/acting.go +++ b/modules/mesh-delivery-assigner/internal/acting/acting.go @@ -1,7 +1,5 @@ -// Package acting is the assigner's wait for an acting part's new version (design 47 G §266, §268, §276): an entry of the assignment -// graph whose edge of kind acting names a step the assigner holds (composing, placing) waits until the acting part's version runs -// on the node of the edge, with the bound of the rule that gave the edge, or the step's default. The package holds the rules and -// the kept record; the assigner's process reads what runs, says the events and keeps the records in its state `waits`. +// Package acting is the kept record of the assigner's order waits (design 47 G §298): a want held until a part's version runs on a +// node, with the placing step's default bound. No want is held for an acting part's new version (design 47 H §750, §764; H-A-70). package acting import ( @@ -14,7 +12,7 @@ import ( "git.novox.be/novox/mesh-sdk/go/seatdef" ) -// HowNow is the `how` of assigner_release for a wait for an acting part: the entry is wanted now, with the version running. +// HowNow is the `how` of assigner_release for an order wait: the entry is wanted now, with the version running. const HowNow = "now" // The ways a wait ends, as `wait-ended` says them. @@ -24,11 +22,8 @@ const ( HowReplaced = "replaced" ) -// Prefix opens the key of an acting wait in the state, apart from the outside waits' `..`. -const Prefix = "acting." - // OrderPrefix opens the key of an order wait (design 47 G §298, A-259): a want held for the order of a delivery that crosses a form change, -// kept beside the acting waits in the state `waits`, as `order...`. +// kept in the state `waits` apart from the outside waits' `..`, as `order...`. const OrderPrefix = "order." // The three order edges of §298, as a kept wait's Order names them. @@ -42,9 +37,6 @@ const ( OrderTakenIn = "taken-in-first" ) -// Held says whether the assigner holds the entries of step: composing and placing (§276's table). -func Held(step string) bool { return step == seatdef.StepCompose || step == seatdef.StepPlace } - // Wait is one wait as kept: Module's entry on Node waits for Part's version Fp to run on PartNode, in Step. type Wait struct { V int `json:"v"` @@ -67,9 +59,6 @@ type Wait struct { Why string `json:"why,omitempty"` } -// Key is the key of a wait in the state. -func Key(node, module, part string) string { return Prefix + node + "." + module + "." + part } - // OrderKey is the key of an order wait in the state. func OrderKey(node, module, part string) string { return OrderPrefix + node + "." + module + "." + part @@ -78,9 +67,6 @@ func OrderKey(node, module, part string) string { // IsOrder says a kept value is an order wait's record. func IsOrder(key string) bool { return strings.HasPrefix(key, OrderPrefix) } -// Is says a kept value is an acting wait's record. -func Is(key string) bool { return strings.HasPrefix(key, Prefix) } - // Encode is w as JSON. func Encode(w Wait) ([]byte, error) { w.V = 1; return json.Marshal(w) } @@ -91,7 +77,7 @@ func Decode(raw []byte) (Wait, error) { return w, err } if w.V != 1 || w.Step == "" || w.Node == "" || w.Module == "" || w.Part == "" { - return w, fmt.Errorf("acting: %q is not a kept acting wait", raw) + return w, fmt.Errorf("acting: %q is not a kept order wait", raw) } return w, nil } @@ -101,18 +87,6 @@ func BoundOf(e meshwants.Edge) time.Duration { return seatdef.ActingRule{Step: e.Step, Bound: e.Bound}.Wait() } -// Pending are the acting edges of the assigner's steps whose part's version does not run yet: runs says the edge's part runs -// its version on the edge's node. -func Pending(edges []meshwants.Edge, runs func(e meshwants.Edge) bool) []meshwants.Edge { - var out []meshwants.Edge - for _, e := range edges { - if e.Kind == "acting" && Held(e.Step) && !runs(e) { - out = append(out, e) - } - } - return out -} - // Body is the wait as the seat mesh-wants says it. func Body(w Wait, owner string) meshwants.Wait { since, from := w.Since.UTC(), w.ClockFrom.UTC() diff --git a/modules/mesh-delivery-assigner/internal/assign/findings.go b/modules/mesh-delivery-assigner/internal/assign/findings.go index c69387d9..260ba6ea 100644 --- a/modules/mesh-delivery-assigner/internal/assign/findings.go +++ b/modules/mesh-delivery-assigner/internal/assign/findings.go @@ -154,18 +154,3 @@ func (f Findings) Say(say func(oc.Condition) error) func(oc.Condition) error { return errors.Join(errs...) } } - -// KindActingCycle is the finding of a want held on a cycle of acting waits no rule breaks (design 47 G A-323, A-330): scope module, -// id `.` of the held want, naming the cycle with each edge's step; cleared by the next pass that finds it held on no -// cycle. -const KindActingCycle = "acting-cycle" - -// ActingCycleFinding is the finding acting-cycle of module's want on node, held on cycle. -func ActingCycleFinding(node, module, cycle string) Observed { - return Observed{Scope: mcc.ScopeModule, ID: node + "." + module, Kind: KindActingCycle, Machine: node, Severity: "warning", - Summary: fmt.Sprintf("the want of %s on %s is held on a cycle of acting waits: %s", module, node, cycle), - Headline: fmt.Sprintf("%s on %s waits on a cycle of acting parts", module, node), - Explanation: fmt.Sprintf("Each acting part on the cycle %s waits for another's new version to run, so none moves by itself. "+ - "assigner_release lets one move with the version running.", cycle), - Source: "assigner." + KindActingCycle} -} diff --git a/modules/mesh-delivery-assigner/internal/assigngraph/compute.go b/modules/mesh-delivery-assigner/internal/assigngraph/compute.go index b58a63ee..87bc9729 100644 --- a/modules/mesh-delivery-assigner/internal/assigngraph/compute.go +++ b/modules/mesh-delivery-assigner/internal/assigngraph/compute.go @@ -53,9 +53,6 @@ type Computed struct { // Uncomputed is each placed module whose entry could not be computed, as "/: why", sorted: it is said, // never left out in silence. Uncomputed []string - // Cycles are the cycles among the acting waits, within one step or across steps (Cycles, design 47 G §272, A-323): said, never - // left in silence. - Cycles []string } // placedAt is one placed module with what its entry is computed from. @@ -74,7 +71,7 @@ type placedAt struct { optional func(string) bool } -type actingRule struct{ seat, step, on, bound string } +type actingRule struct{ seat, step, on string } // Compute is the assignment graph revision of in: one entry per module placed on a node whose branch's catalog graph // holds it, its version the build the placement names or else the catalog entry's fingerprint (design 47 lines 909-914), @@ -128,7 +125,7 @@ func Compute(in Inputs) Computed { p.langs[lang] = true } for _, r := range ce.Acts { - p.acts = append(p.acts, actingRule{seat: r.Seat, step: r.Step, on: r.On, bound: r.Bound}) + p.acts = append(p.acts, actingRule{seat: r.Seat, step: r.Step, on: r.On}) } p.provides, p.contributes = ce.Provides, ce.Contributes p.delivering = map[string]seatdef.Definition{} @@ -199,7 +196,7 @@ func Compute(in Inputs) Computed { } for _, h := range from { t.entry.Edges = append(t.entry.Edges, meshwants.Edge{Kind: EdgeActing, Node: h.node, Module: part, Fp: h.entry.Fp, - Seat: rule.seat, Step: rule.step, Bound: rule.bound}) + Seat: rule.seat, Step: rule.step}) } } } @@ -217,7 +214,6 @@ func Compute(in Inputs) Computed { rev.Entries = append(rev.Entries, meshwants.NodeEntryRef{Node: p.node, Module: p.placed.Module, Digest: d}) } out.Revision = rev - out.Cycles = Cycles(slices.Collect(maps.Values(out.Entries))) slices.Sort(out.Uncomputed) return out } @@ -229,7 +225,7 @@ func sortEdges(edges []meshwants.Edge) { } func edgeKey(e meshwants.Edge) string { - return strings.Join([]string{e.Kind, e.Node, e.Module, e.Provision, e.Seat, e.Step, e.Fp, e.Bound}, "\x00") + return strings.Join([]string{e.Kind, e.Node, e.Module, e.Provision, e.Seat, e.Step, e.Fp}, "\x00") } // EntryDigest is the digest an entry is stored under: the same entry, the same digest. diff --git a/modules/mesh-delivery-assigner/internal/assigngraph/cycle.go b/modules/mesh-delivery-assigner/internal/assigngraph/cycle.go deleted file mode 100644 index d95014f9..00000000 --- a/modules/mesh-delivery-assigner/internal/assigngraph/cycle.go +++ /dev/null @@ -1,248 +0,0 @@ -package assigngraph - -import ( - "fmt" - "maps" - "slices" - "strings" - - "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" -) - -// Cycles are the cycles among the acting waits (design 47 G §272, ADR 0656, A-323): an entry waits for its acting parts in the step -// an edge names, so acting parts that wait for each other, in one step or across steps, wait for ever unless a rule breaks the -// cycle. A cycle within one step is `: a -> b -> a`; one across steps names each edge's step, `a -[compose]-> b -[place]-> a`; -// each by node and module, said once from its smallest member, sorted. A holder's own inputs are no edge here (the graph gives an -// acting edge only from a part to the entries it acts on, never to what the part is built from). -func Cycles(entries []meshwants.AssignmentEntry) []string { - type key struct{ step, at string } - next := map[key][]string{} - steps := map[string]bool{} - for _, e := range entries { - for _, edge := range e.Edges { - if edge.Kind != EdgeActing { - continue - } - k := key{edge.Step, e.Node + "/" + e.Module} - next[k] = append(next[k], edge.Node+"/"+edge.Module) - steps[edge.Step] = true - } - } - var out []string - for _, step := range slices.Sorted(maps.Keys(steps)) { - const ( - open = iota + 1 - done - ) - state := map[string]int{} - var path []string - var walk func(at string) - walk = func(at string) { - state[at] = open - path = append(path, at) - for _, to := range next[key{step, at}] { - switch state[to] { - case 0: - walk(to) - case open: - from := slices.Index(path, to) - cycle := slices.Clone(path[from:]) - // start at the smallest member so one cycle is said once, whichever member is met first - lowest := slices.Index(cycle, slices.Min(cycle)) - cycle = append(cycle[lowest:], cycle[:lowest]...) - out = append(out, fmt.Sprintf("%s: %s -> %s", step, strings.Join(cycle, " -> "), cycle[0])) - } - } - path = path[:len(path)-1] - state[at] = done - } - starts := map[string]bool{} - for k := range next { - if k.step == step { - starts[k.at] = true - } - } - for _, at := range slices.Sorted(maps.Keys(starts)) { - if state[at] == 0 { - walk(at) - } - } - } - // Across steps (A-323): the shortest cycle through each entry over every acting edge, said when its edges name two steps or more. - for _, hops := range cyclesThrough(entries, func(_ meshwants.AssignmentEntry, e meshwants.Edge) bool { return e.Kind == EdgeActing }) { - if crossesSteps(hops) { - out = append(out, hopWords(rotated(hops))) - } - } - slices.Sort(out) - return slices.Compact(out) -} - -// HeldCycles is, by `/`, the cycle each entry lies on among the edges holds says hold it (A-323, A-330): a want held -// on such a cycle is held for ever, since no rule breaks it. Each cycle starts at the entry and names each edge's step. -func HeldCycles(entries []meshwants.AssignmentEntry, holds func(e meshwants.AssignmentEntry, edge meshwants.Edge) bool) map[string]string { - out := map[string]string{} - for at, hops := range cyclesThrough(entries, holds) { - out[at] = hopWords(hops) - } - return out -} - -// Engines is, by node, the module that holds the seat node-engine there, read from the acting edges' seat (A-330). -func Engines(entries []meshwants.AssignmentEntry) map[string]string { - out := map[string]string{} - for _, e := range entries { - for _, edge := range e.Edges { - if edge.Kind == EdgeActing && edge.Seat == nodeengine.Seat { - out[edge.Node] = edge.Module - } - } - } - return out -} - -// Runner is the module that holds the seat mesh-pipeline-runner, read from the acting edges' seat as Engines reads the node-engine -// (A-334); "" when none is read. -func Runner(entries []meshwants.AssignmentEntry) string { - for _, e := range entries { - for _, edge := range e.Edges { - if edge.Kind == EdgeActing && edge.Seat == meshpipelinerunner.Seat { - return edge.Module - } - } - } - return "" -} - -// hop is one edge of a cycle: from the entry at, in step, to the next hop's entry. -type hop struct{ at, step string } - -// cyclesThrough is, by `/`, the shortest cycle through each entry over the edges keep takes, found within the -// entry's strongly connected part, each starting at the entry. -func cyclesThrough(entries []meshwants.AssignmentEntry, keep func(meshwants.AssignmentEntry, meshwants.Edge) bool) map[string][]hop { - type out struct{ to, step string } - next := map[string][]out{} - for _, e := range entries { - at := e.Node + "/" + e.Module - for _, edge := range e.Edges { - if keep(e, edge) { - next[at] = append(next[at], out{edge.Node + "/" + edge.Module, edge.Step}) - } - } - } - for at := range next { - slices.SortFunc(next[at], func(a, b out) int { return strings.Compare(a.to+"\x00"+a.step, b.to+"\x00"+b.step) }) - } - part := strongParts(slices.Sorted(maps.Keys(next)), func(at string) []string { - var to []string - for _, o := range next[at] { - to = append(to, o.to) - } - return to - }) - found := map[string][]hop{} - for _, start := range slices.Sorted(maps.Keys(next)) { - // breadth first from start back to it, within its part - prev := map[string]hop{} - queue := []string{start} - seen := map[string]bool{} - for len(queue) > 0 && found[start] == nil { - at := queue[0] - queue = queue[1:] - for _, o := range next[at] { - if part[o.to] != part[start] { - continue - } - if o.to == start { - hops := []hop{{at, o.step}} - for cur := at; cur != start; { - h := prev[cur] - hops = append(hops, h) - cur = h.at - } - slices.Reverse(hops) - found[start] = hops - break - } - if !seen[o.to] { - seen[o.to] = true - prev[o.to] = hop{at, o.step} - queue = append(queue, o.to) - } - } - } - } - return found -} - -// strongParts numbers each vertex by its strongly connected part (Tarjan). -func strongParts(vertices []string, succ func(string) []string) map[string]int { - index, low, part := map[string]int{}, map[string]int{}, map[string]int{} - on := map[string]bool{} - var stack []string - n, parts := 0, 0 - var visit func(v string) - visit = func(v string) { - index[v], low[v] = n, n - n++ - stack = append(stack, v) - on[v] = true - for _, w := range succ(v) { - if _, ok := index[w]; !ok { - visit(w) - low[v] = min(low[v], low[w]) - } else if on[w] { - low[v] = min(low[v], index[w]) - } - } - if low[v] == index[v] { - parts++ - for { - w := stack[len(stack)-1] - stack = stack[:len(stack)-1] - on[w] = false - part[w] = parts - if w == v { - break - } - } - } - } - for _, v := range vertices { - if _, ok := index[v]; !ok { - visit(v) - } - } - return part -} - -func crossesSteps(hops []hop) bool { - for _, h := range hops[1:] { - if h.step != hops[0].step { - return true - } - } - return false -} - -// rotated is the cycle started at its smallest member, so one cycle is said once. -func rotated(hops []hop) []hop { - lowest := 0 - for i, h := range hops { - if h.at < hops[lowest].at { - lowest = i - } - } - return append(slices.Clone(hops[lowest:]), hops[:lowest]...) -} - -// hopWords is a cycle with each edge's step: `a -[compose]-> b -[place]-> a`. -func hopWords(hops []hop) string { - var b strings.Builder - for _, h := range hops { - fmt.Fprintf(&b, "%s -[%s]-> ", h.at, h.step) - } - return b.String() + hops[0].at -} diff --git a/modules/mesh-delivery-assigner/internal/assigngraph/cycle_test.go b/modules/mesh-delivery-assigner/internal/assigngraph/cycle_test.go deleted file mode 100644 index 522dfec1..00000000 --- a/modules/mesh-delivery-assigner/internal/assigngraph/cycle_test.go +++ /dev/null @@ -1,60 +0,0 @@ -package assigngraph - -import ( - "slices" - "testing" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" -) - -// Design 47 G §272 (AS10), A-323: a cycle among the waits is found within one step and across steps, each edge's step named across -// steps; a chain and provisioning edges are none. -func TestACycleAmongTheWaitsWithinOrAcrossStepsIsFound(t *testing.T) { - act := func(node, module, step string) meshwants.Edge { - return meshwants.Edge{Kind: EdgeActing, Node: node, Module: module, Step: step} - } - entry := func(module string, edges ...meshwants.Edge) meshwants.AssignmentEntry { - return meshwants.AssignmentEntry{Node: "ace", Module: module, Edges: edges} - } - for _, c := range []struct { - name string - entries []meshwants.AssignmentEntry - want []string - }{ - {"two parts on each other in one step", []meshwants.AssignmentEntry{entry("a", act("ace", "b", "compose")), entry("b", act("ace", "a", "compose"))}, - []string{"compose: ace/a -> ace/b -> ace/a"}}, - {"three in a ring, said once", []meshwants.AssignmentEntry{entry("c", act("ace", "a", "build")), entry("a", act("ace", "b", "build")), entry("b", act("ace", "c", "build"))}, - []string{"build: ace/a -> ace/b -> ace/c -> ace/a"}}, - {"the indexer taking in the checker, the checker checking the indexer", []meshwants.AssignmentEntry{entry("checker", act("ace", "indexer", "take-in")), entry("indexer", act("ace", "checker", "check"))}, - []string{"ace/checker -[take-in]-> ace/indexer -[check]-> ace/checker"}}, - {"the assigner and the node-engine, across compose and place", []meshwants.AssignmentEntry{entry("assigner", act("ace", "engine", "compose")), - entry("engine", act("ace", "assigner", "place")), entry("app", act("ace", "engine", "compose"), act("ace", "assigner", "place"))}, - []string{"ace/assigner -[compose]-> ace/engine -[place]-> ace/assigner"}}, - {"a chain", []meshwants.AssignmentEntry{entry("a", act("ace", "b", "compose")), entry("b", act("ace", "c", "compose")), entry("c")}, nil}, - {"provisioning edges are no wait of a step", []meshwants.AssignmentEntry{entry("a", meshwants.Edge{Kind: EdgeProvisioning, Node: "ace", Module: "b"}), entry("b", meshwants.Edge{Kind: EdgeProvisioning, Node: "ace", Module: "a"})}, nil}, - } { - if got := Cycles(c.entries); !slices.Equal(got, c.want) { - t.Errorf("%s: cycles %v, want %v", c.name, got, c.want) - } - } -} - -// A-323, A-330: the node-engine on a node is read from the acting edges' seat, and the cycles that hold a want are those of the -// edges said to hold it, each from the entry, naming each edge's step. -func TestTheHeldCyclesAreThoseOfTheHoldingEdges(t *testing.T) { - entries := []meshwants.AssignmentEntry{ - {Node: "ace", Module: "assigner", Edges: []meshwants.Edge{{Kind: EdgeActing, Node: "ace", Module: "engine", Step: "compose", Seat: "node-engine"}}}, - {Node: "ace", Module: "engine", Edges: []meshwants.Edge{{Kind: EdgeActing, Node: "ace", Module: "assigner", Step: "place", Seat: "mesh-wants"}}}, - } - if got := Engines(entries); len(got) != 1 || got["ace"] != "engine" { - t.Errorf("the node-engines %v, want engine on ace", got) - } - all := func(meshwants.AssignmentEntry, meshwants.Edge) bool { return true } - if got := HeldCycles(entries, all); len(got) != 2 || got["ace/engine"] != "ace/engine -[place]-> ace/assigner -[compose]-> ace/engine" { - t.Errorf("held cycles %v", got) - } - // the node-engine's want held by no acting edge: no cycle holds anything - if got := HeldCycles(entries, func(e meshwants.AssignmentEntry, _ meshwants.Edge) bool { return e.Module != "engine" }); len(got) != 0 { - t.Errorf("held cycles with the node-engine's edges holding nothing: %v", got) - } -} diff --git a/modules/mesh-delivery-assigner/internal/assigngraph/graph_test.go b/modules/mesh-delivery-assigner/internal/assigngraph/graph_test.go index 5a207e22..88c41dfb 100644 --- a/modules/mesh-delivery-assigner/internal/assigngraph/graph_test.go +++ b/modules/mesh-delivery-assigner/internal/assigngraph/graph_test.go @@ -86,7 +86,7 @@ func TestTheAssignmentGraphIsComputedFromItsInputsAndKept(t *testing.T) { } want := []meshwants.Edge{ {Kind: EdgeActing, Node: "anchor", Module: "build-go", Fp: "src2:b1", Seat: "node-build-go", Step: "build"}, - {Kind: EdgeActing, Node: "anchor", Module: "node-engine", Fp: "src2:e1", Seat: "node-engine", Step: "compose", Bound: "30m"}, + {Kind: EdgeActing, Node: "anchor", Module: "node-engine", Fp: "src2:e1", Seat: "node-engine", Step: "compose"}, // the edge stays; the wait's bound goes (H-A-70) {Kind: EdgeProvisioning, Node: "anchor", Module: "postgres", Fp: "src2:p1", Provision: "database"}, } if fmt.Sprint(webA.Edges) != fmt.Sprint(want) { diff --git a/modules/mesh-delivery-assigner/internal/assigngraph/runner.go b/modules/mesh-delivery-assigner/internal/assigngraph/runner.go new file mode 100644 index 00000000..77089d23 --- /dev/null +++ b/modules/mesh-delivery-assigner/internal/assigngraph/runner.go @@ -0,0 +1,19 @@ +package assigngraph + +import ( + "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner" + "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" +) + +// Runner is the module that holds the seat mesh-pipeline-runner, read from the acting edges' seat +// (A-334); "" when none is read. +func Runner(entries []meshwants.AssignmentEntry) string { + for _, e := range entries { + for _, edge := range e.Edges { + if edge.Kind == EdgeActing && edge.Seat == meshpipelinerunner.Seat { + return edge.Module + } + } + } + return "" +}