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 d32129583..5d4daa346 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/pass.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/pass.go @@ -31,6 +31,7 @@ import ( "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/graph" "git.novox.be/novox/mesh-sdk/go/catalogue" + mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient" mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions" "mesh-delivery-assigner/internal/assign" @@ -60,8 +61,6 @@ type passer struct { whys map[string]string // findings is the assigner's findings bucket (its said conditions, ADR 0564 §2). findings assign.Findings - // unplaced are the nodes whose unplaced finding this process wrote. - unplaced map[string]bool // listed says whether a module's watched branches list it (catalogViews.listed), for the clear of assignment-unlisted. listed func(module string) bool // answeredAt is, by the id of a backup ask, how many values the have had when its answer was written into the want. @@ -252,6 +251,7 @@ func (p *passer) wants(ctx context.Context) { for name := range wanted { names[name] = true } + unversioned := map[string]unversionedWant{} for name := range names { groups := p.groups(name, nodesOf[name], assignedBranches[name]) for gi, g := range groups { @@ -279,6 +279,9 @@ func (p *passer) wants(ctx context.Context) { p.outsideReview(ctx, name, target.Fp, m.Nodes, bv.nodes, bv.manifests[name].ClaimsSeat(mcseat.Seat), p.movedTo(wanted, bv.nodes)) } out := assign.Wants(m, wantedOf) + for node, fp := range out.Unversioned { + unversioned[assign.UnversionedKey(name, node)] = unversionedWant{module: name, node: node, fp: fp} + } p.sayWhy(ctx, name, m.Nodes, wantWhy{Branch: g.branch, Fp: target.Fp, Version: target.Version, Pipeline: target.Pipeline, Step: whyStep(ok)}, wantedOf, &out) if ok { p.yeses(ctx, name, m, wantedOf, &out) @@ -288,6 +291,7 @@ func (p *passer) wants(ctx context.Context) { } } } + p.unversionedFindings(unversioned, trunk) } // put writes one key of the assigner's own bucket; a write that fails is said and made again at the next pass. @@ -767,17 +771,37 @@ func chosenOf(chosen map[string]catalogue.PersonPolicy, module string) *catalogu return nil } +// findingKeys is the keys the assigner's findings bucket holds now; false when it cannot be read (no bucket, or a read that +// failed, said), so that nothing is written or cleared from what was not read (H-A-722: a finding is cleared from what the bucket +// holds, never from what a process remembers). +func (p *passer) findingKeys(what string) (map[string]bool, bool) { + if p.findings.Keys == nil || p.findings.Put == nil || p.findings.Delete == nil { + return nil, false + } + ks, err := p.findings.Keys() + if err != nil { + p.logf("the findings are not read, so %s is not written or cleared in this pass: %v", what, err) + return nil, false + } + have := make(map[string]bool, len(ks)) + for _, k := range ks { + have[k] = true + } + return have, true +} + // unplacedFindings writes, from the lease write, the finding `machine..unplaced` for each node that runs but no -// assignments names, which gets no want (ADR 0571 §6), and deletes it once the node is placed. +// assignments names, which gets no want (ADR 0571 §6), and deletes it at the pass that finds the node placed or gone: the +// findings' keys are read from the bucket at each pass (H-A-722). func (p *passer) unplacedFindings() { - if p.findings.Put == nil { + have, ok := p.findingKeys("the finding unplaced") + if !ok { return } - now := []string(p.w.unplacedNodes()) is := map[string]bool{} - for _, node := range now { + for _, node := range p.w.unplacedNodes() { is[node] = true - if p.unplaced[node] { + if have[assign.UnplacedKey(node)] { continue } f, err := assign.UnplacedFinding(node, p.clock()) @@ -786,23 +810,71 @@ func (p *passer) unplacedFindings() { } if err != nil { p.logf("the unplaced node %s is not said: %v", node, err) - continue } - if p.unplaced == nil { - p.unplaced = map[string]bool{} - } - p.unplaced[node] = true } - for node := range p.unplaced { - if is[node] { + for key := range have { + node, found := unplacedOfKey(key) + if !found || is[node] { continue } - if err := p.findings.Delete(assign.UnplacedKey(node)); err == nil { - delete(p.unplaced, node) + if err := p.findings.Delete(key); err != nil { + p.logf("the finding %s is not cleared: %v", key, err) } } } +// unplacedOfKey is the node of an unplaced finding's key `machine..unplaced`, or false for another finding's. +func unplacedOfKey(key string) (string, bool) { + rest, ok := strings.CutPrefix(key, mcc.ScopeMachine+".") + if !ok { + return "", false + } + node, ok := strings.CutSuffix(rest, "."+assign.KindUnplaced) + return node, ok && node != "" && assign.UnplacedKey(node) == key +} + +// unversionedWant is a want of no version for which no target is held, as a pass finds it (design 47 H2 H-A-673, H-A-706). +type unversionedWant struct{ module, node, fp string } + +// unversionedFindings writes the finding want-unversioned (id `.`) of each want a pass found with no version and no +// target, naming its fingerprint and why no target is held, and clears, at the pass that finds its cause gone, each one the +// bucket holds that the pass did not find: the want names a version, the module is no longer assigned to the node, or the node +// is gone (H-A-722). Nothing is cleared while the trunk is unread. +func (p *passer) unversionedFindings(found map[string]unversionedWant, trunk map[string]meshcatalog.ModulesByModuleValue) { + have, ok := p.findingKeys("the finding want-unversioned") + if !ok { + return + } + for key, u := range found { + if have[key] { + continue + } + f, err := assign.UnversionedFinding(u.module, u.node, u.fp, "no version of it released on its branch has a passed pipeline whose tier is written, and no placement names a build", p.clock()) + if err == nil { + err = p.findings.Put(f) + } + if err != nil { + p.logf("the finding want-unversioned of %s on %s is not written: %v", u.module, u.node, err) + } + } + if len(trunk) == 0 { + return + } + for key := range have { + if _, _, is := assign.UnversionedOfKey(key); !is { + continue + } + if _, still := found[key]; still { + continue + } + if err := p.findings.Delete(key); err != nil { + p.logf("the finding %s is not cleared: %v", key, err) + continue + } + p.logf("the finding %s is cleared: its want names a version, or its module or its node is gone", key) + } +} + // clearUnlisted clears, in the pass over the assignments, each finding assignment-unlisted whose assignment is gone or whose module // one of its watched branches lists again, so the clear never waits for the next composition step on that machine (H-A-149). func (p *passer) clearUnlisted() { diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/seat_tools_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/seat_tools_test.go index 8b18c9f0d..978545b59 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/seat_tools_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/seat_tools_test.go @@ -17,6 +17,7 @@ import ( "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient" "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" + 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" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/catalogkey" "git.novox.be/novox/mesh-sdk/go/keys" @@ -287,6 +288,7 @@ func TestTheSeatsVerbs(t *testing.T) { findings := map[string][]byte{} p := &passer{w: w, logf: func(string, ...any) {}, findings: assign.Findings{ Put: putInto(findings), + Keys: func() ([]string, error) { return slices.Collect(maps.Keys(findings)), nil }, Delete: func(k string) error { delete(findings, k); return nil }}} p.unplacedFindings() if _, ok := findings[assign.UnplacedKey("g14")]; !ok || len(findings) != 1 { @@ -298,6 +300,45 @@ func TestTheSeatsVerbs(t *testing.T) { t.Errorf("placed again: findings %v", findings) } }) + t.Run("H-A-673, H-A-706, H-A-722: want-unversioned is written, and cleared from the bucket by a pass after a restart", func(t *testing.T) { + fp := meshcatalogclient.SourcePrefix2 + strings.Repeat("3", 64) + wantsKV := &memKV{values: map[string][]byte{}} + findings := map[string][]byte{} + pass := func(version string, assigned ...string) *passer { + p := newPasser(kvSet{buckets.Wants(): wantsKV, buckets.Asks(): &memKV{values: map[string][]byte{}}}, time.Now()) + p.publishWants = func(string, any, string) error { return nil } + p.findings = assign.Findings{Put: putInto(findings), Keys: func() ([]string, error) { return slices.Collect(maps.Keys(findings)), nil }, + Delete: func(k string) error { delete(findings, k); return nil }} + digest := strings.Repeat("4", 64) + mod, _ := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Fp2: fp, Manifest: digest, Repository: "novox/web", Commit: strings.Repeat("1", 40), Path: meshcatalogclient.RootPath}) + putModuleRaw(p.w, trunkBranch, "web", mod) + p.w.manifests[digest] = parsed{module: "web", manifest: catalogue.Manifest{Module: "web"}} + placeOn(t, p.w, "g14", assigned...) + raw, _ := mwc.EncodeWant(mwc.Want{Fp: fp, Version: version}) + key, _ := mwc.WantKey("g14", "web") + wantsKV.values[key] = raw + p.w.putEntry(buckets.Wants(), key, raw, 1, time.Now()) + return p + } + key := assign.UnversionedKey("web", "g14") + pass("", "web").wants(context.Background()) + if _, ok := findings[key]; !ok || len(findings) != 1 { + t.Fatalf("a want of no version and no target: findings %v", findings) + } + pass("", "web").wants(context.Background()) // a process that starts again: written once, and it stands + if _, ok := findings[key]; !ok || len(findings) != 1 { + t.Fatalf("a restarted pass changed the finding: %v", findings) + } + pass("1.0.0", "web").wants(context.Background()) // the want names a version now + if len(findings) != 0 { + t.Errorf("the want names a version: findings %v", findings) + } + pass("", "web").wants(context.Background()) + pass("", "other").wants(context.Background()) // the module is no longer assigned to the node + if len(findings) != 0 { + t.Errorf("the module is no longer assigned to the node: findings %v", findings) + } + }) t.Run("1955/L7 (ADR 0571 §4): seat-holders is written from assignments, only the keys a change moves, and answered by assignments seats", func(t *testing.T) { writes := 0 kv := &countingKV{memKV: memKV{values: map[string][]byte{}}, writes: &writes} diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tiers.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tiers.go index 685614f10..18d32f708 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tiers.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tiers.go @@ -187,6 +187,13 @@ func (p *passer) tiers(n assign.Nodes, placedOn func(module, branch string) []st bound := p.tierBoundOf() var next time.Time standing := p.w.read(buckets.Asks()) + followed := map[string]bool{} + for _, key := range ks { + if isTierKey(key) { + followed[assign.KeyID(strings.TrimPrefix(key, tierPrefix))] = true + } + } + defer p.clearTierLate(followed) for _, key := range ks { if !isTierKey(key) { continue @@ -465,3 +472,29 @@ func pauseNamed(standing map[string][]byte, t tierProgress, notRunning []meshwan } return strings.Join(named, "; ") } + +// clearTierLate clears, at the pass that finds its pipeline no longer followed (no tier progress stands for it), each finding +// tier-late the findings bucket holds, read from the bucket, never from what a process said (H-A-722). followed are the +// pipelines' ids as a finding's key holds them. +func (p *passer) clearTierLate(followed map[string]bool) { + have, ok := p.findingKeys("the finding tier-late") + if !ok { + return + } + for key := range have { + rest, is := strings.CutPrefix(key, mcc.ScopeDelivery+".") + if !is { + continue + } + id, is := strings.CutSuffix(rest, "."+kindTierLate) + if !is || followed[id] { + continue + } + if err := p.findings.Delete(key); err != nil { + p.logf("the finding %s is not cleared: %v", key, err) + continue + } + delete(p.said, key+".raised") + p.logf("the finding %s is cleared: its pipeline is no longer followed", key) + } +} diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tiers_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tiers_test.go index c570ceb8f..b1963be50 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tiers_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tiers_test.go @@ -3,6 +3,8 @@ package main import ( "context" "encoding/json" + "maps" + "slices" "strings" "testing" "time" @@ -45,7 +47,10 @@ func TestAPipelinesWantsAreWrittenTierByTier(t *testing.T) { p.say = func(oc.Condition) error { return nil } findings := map[string]mcseat.Finding{} p.findings = assign.Findings{Put: func(f mcseat.Finding) error { findings[views.FindingKey(f.Scope, f.ID, f.Kind)] = f; return nil }, + Keys: func() ([]string, error) { return slices.Collect(maps.Keys(findings)), nil }, Delete: func(key string) error { delete(findings, key); return nil }} + // H-A-722: a tier-late of a pipeline no longer followed, written before a restart, is cleared at the first pass. + findings["delivery.main.3.tier-late"] = mcseat.Finding{Scope: "delivery", ID: "main.3", Kind: kindTierLate} var said []meshwants.PipelineWanted p.publishWants = func(event string, body any, _ string) error { if b, ok := body.(meshwants.PipelineWantedEvent); ok { @@ -83,6 +88,9 @@ func TestAPipelinesWantsAreWrittenTierByTier(t *testing.T) { return ok } p.wants(context.Background()) + if _, old := findings["delivery.main.3.tier-late"]; old { + t.Errorf("%s: a tier-late of a pipeline no longer followed stands after a pass: %v", pipeline, findings) + } if !wanted("g14", "db") || !wanted("ace", "db") || wanted("g14", "web") || wanted("ace", "web") { t.Fatalf("%s runs %v: tier 1 alone is not what is wanted first: %v", pipeline, runs, wantsKV.values) } diff --git a/modules/mesh-delivery-assigner/internal/assign/unlisted.go b/modules/mesh-delivery-assigner/internal/assign/unlisted.go index 11b4f0b84..eebf7b5a3 100644 --- a/modules/mesh-delivery-assigner/internal/assign/unlisted.go +++ b/modules/mesh-delivery-assigner/internal/assign/unlisted.go @@ -44,3 +44,35 @@ func UnlistedFinding(node, module string, at time.Time) (mcseat.Finding, error) "Take it off, or register the module on a watched branch.", Source: "assigner." + KindAssignmentUnlisted}, at) } + +// KindWantUnversioned is a want that names no version, for a module whose target no release gives (design 47 H2 H-A-673, +// H-A-706 on DQ-40): scope delivery, id `.`, severity warning. +const KindWantUnversioned = "want-unversioned" + +// UnversionedKey is its finding's key, `delivery...want-unversioned`. +func UnversionedKey(module, node string) string { + return views.FindingKey(ScopeAssignmentUnlisted, KeyID(module+"."+node), KindWantUnversioned) +} + +// UnversionedOfKey is the module and node of a want-unversioned finding's key, or false for another finding's. +func UnversionedOfKey(key string) (module, node string, ok bool) { + rest, ok := strings.CutPrefix(key, ScopeAssignmentUnlisted+".") + if !ok { + return "", "", false + } + if rest, ok = strings.CutSuffix(rest, "."+KindWantUnversioned); !ok { + return "", "", false + } + module, node, ok = strings.Cut(rest, ".") + return module, node, ok && module != "" && node != "" && !strings.Contains(node, ".") +} + +// UnversionedFinding is the finding of the want of module on node that names fingerprint fp and no version, while no target is +// held (why). +func UnversionedFinding(module, node, fp, why string, at time.Time) (mcseat.Finding, error) { + summary := fmt.Sprintf("the want of %s on %s names %s and no version, and no target is held for it: %s", module, node, short(fp), why) + return encode(Observed{Scope: ScopeAssignmentUnlisted, ID: module + "." + node, Kind: KindWantUnversioned, Machine: node, + Severity: mcseat.FindingSeverityWarning, Summary: summary, Headline: clipHeadline(module + " on " + node + " is wanted with no version"), + Explanation: summary + ". The want stands as written, so the node composes nothing new for it; it clears once the want names a version.", + Source: "assigner." + KindWantUnversioned}, at) +} diff --git a/modules/mesh-delivery-assigner/internal/assign/wants.go b/modules/mesh-delivery-assigner/internal/assign/wants.go index 99fa6f5b7..e7eeef0ae 100644 --- a/modules/mesh-delivery-assigner/internal/assign/wants.go +++ b/modules/mesh-delivery-assigner/internal/assign/wants.go @@ -96,13 +96,16 @@ func (n Nodes) RunsHealthy(node, module, fp string) bool { // Outcome is what one module's pass decides: each node's want to write (only those that change). type Outcome struct { Wants map[string]mwc.Want + // Unversioned is, by node, the fingerprint of a want that names no version and for which Target answers none: the want + // stands as written, and the pass says it with the finding want-unversioned (design 47 H2 H-A-673, H-A-706 on DQ-40). + Unversioned map[string]string } // Wants is the pass of one module m: for each of its nodes, the want naming its Target, starting from the want written before // (wants, by node). A put that owns a node's want writes the put's; a node with no target keeps the want written. A node that // wants m but is no longer among its nodes gets its want written removed, never deleted (ADR 0408 §4). func Wants(m Module, wants map[string]mwc.Want) Outcome { - out := Outcome{Wants: map[string]mwc.Want{}} + out := Outcome{Wants: map[string]mwc.Want{}, Unversioned: map[string]string{}} for _, node := range m.Nodes { before, had := wants[node] p, put := m.Puts[node] @@ -124,6 +127,9 @@ func Wants(m Module, wants map[string]mwc.Want) Outcome { t, ok = m.Target(node) } if !ok || t.Fp == "" { + if had && !before.Removed && !before.Put && before.Version == "" && before.Fp != "" { + out.Unversioned[node] = before.Fp + } continue } next := mwc.Want{Fp: t.Fp, Version: t.Version, Pipeline: t.Pipeline, Rank: t.Rank, Self: m.selfOn(node)} diff --git a/modules/mesh-delivery-assigner/internal/assign/wants_test.go b/modules/mesh-delivery-assigner/internal/assign/wants_test.go index 74c117e72..1d77b9027 100644 --- a/modules/mesh-delivery-assigner/internal/assign/wants_test.go +++ b/modules/mesh-delivery-assigner/internal/assign/wants_test.go @@ -86,6 +86,28 @@ func TestAWantNamesTheNewestPassedVersion(t *testing.T) { } } } + // H-A-673, H-A-706 (DQ-40): a node whose want names no version and for which Target answers none is named in the outcome + // beside the wants, with the fingerprint; one whose want names a version, one with a target (rewritten) and one removed are not. + none := func() Module { + m := released() + m.Target = func(string) (Target, bool) { return Target{}, false } + return m + } + for _, c := range []struct { + name string + module func() Module + before map[string]mwc.Want + named map[string]string + }{ + {"no version and no target", none, map[string]mwc.Want{"ace": {Fp: fOld}, "g14": {Fp: fOld, Version: "1.2.2"}}, map[string]string{"ace": fOld}}, + {"a target rewrites the want", released, map[string]mwc.Want{"ace": {Fp: fOld}}, map[string]string{}}, + {"a removed want", none, map[string]mwc.Want{"ace": {Removed: true}}, map[string]string{}}, + } { + got := Wants(c.module(), c.before).Unversioned + if len(got) != len(c.named) || (len(got) > 0 && got["ace"] != c.named["ace"]) { + t.Errorf("%s: unversioned = %v, want %v", c.name, got, c.named) + } + } } // ADR 0546: a put owns the node's want from its asking until it ends; while it waits the rule writes nothing there, once wanted its