From 43f2ebc4ba1c694ed9417081fee7eb3c92ece1a3 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 25 Nov 2026 17:27:43 +0100 Subject: [PATCH] A3 needs-hold: a want whose entry needs a capability its node's words lack is held awaiting its reads, one whose entry is not read awaiting its entry; assigner_why names the ask The test of the kept ask compares its fields (KeptAsk gains the hook). Builds: design 47 H2 H-A-682 (2) (3) (4), H-A-698 (1) (2), H-A-706 (DMC-14) --- .../compositioninputs_test.go | 2 +- .../cmd/mesh-delivery-assigner/pass.go | 28 +++++++ .../cmd/mesh-delivery-assigner/pass_test.go | 75 +++++++++++++++++++ .../cmd/mesh-delivery-assigner/why.go | 31 ++++++++ .../internal/assign/wants.go | 24 +++++- .../internal/assign/wants_test.go | 28 +++++++ 6 files changed, 186 insertions(+), 2 deletions(-) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositioninputs_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositioninputs_test.go index 596bcbab5..f53ea4907 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositioninputs_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositioninputs_test.go @@ -101,7 +101,7 @@ func TestAStepsInputsAreAskedOfEachMachine(t *testing.T) { t.Errorf("ace: %+v", got[0]) } // Design 47 H2 §775, H-A-405: each machine is asked as a kept call under the step's ask with the node, until compose-ask-bound. - if asks["ace"] != (process.KeptAsk{ID: "step-1.ace", Bound: time.Second}) || asks["g14"].ID != "step-1.g14" { + if asks["ace"].ID != "step-1.ace" || asks["ace"].Bound != time.Second || asks["g14"].ID != "step-1.g14" { t.Errorf("the kept asks %+v", asks) } if !strings.Contains(got[1].Why, "no responders") || !strings.Contains(got[2].Why, "unready") || got[1].Body != nil || got[2].Body != nil { 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 5d4daa346..1f6d6233a 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/pass.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/pass.go @@ -264,6 +264,10 @@ func (p *passer) wants(ctx context.Context) { ReadsVersion: func(node string) bool { return slices.Contains(nodes.Reads[node], nodeengine.ManifestReadWordWantVersion) }, + // H-A-682 (2), H-A-698: a want's needs are those of its entry, the node's missing ones the want held for. + MissingNeeds: func(node, fp string) ([]string, bool) { + return p.missingNeeds(ctx, bv.trunk[name], nodes.Reads[node], fp) + }, // H §750, H-A-5, H-A-99: a placement's build is read before the rule and names the want's version. Target: func(node string) (assign.Target, bool) { if build := builds[node][name]; build != "" { @@ -294,6 +298,30 @@ func (p *passer) wants(ctx context.Context) { p.unversionedFindings(unversioned, trunk) } +// missingNeeds reads what a want at fp lacks of its node's words (design 47 H2 H-A-682 (2), H-A-698): the needs of the entry at fp, +// those of the module's held entry when it names fp, else the seat `mesh-catalog`'s `entry` for it, asked once and kept; read is +// false while that ask stands out, is not found or is unanswered, and the answer wakes a pass. The pass never waits on it. +func (p *passer) missingNeeds(ctx context.Context, held meshcatalog.ModulesByModuleValue, words []string, fp string) (missing []string, read bool) { + needs := held.Needs + if held.Fp2 != fp { + if p.entries == nil { + return nil, true + } + e, state := p.entries.Need(ctx, fp) + if state != meshcatalogclient.EntryAnswered { + return nil, false + } + needs = e.Needs + } + for _, need := range needs { + if !slices.Contains(words, need) { + missing = append(missing, need) + } + } + slices.Sort(missing) + return slices.Compact(missing), true +} + // put writes one key of the assigner's own bucket; a write that fails is said and made again at the next pass. func (p *passer) put(ctx context.Context, bucket, key string, encode func() ([]byte, error)) { p.written(ctx, bucket, key, encode) 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 be395846b..6af9f772b 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 @@ -7,6 +7,7 @@ import ( "errors" "fmt" mpr "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner" + "git.novox.be/novox/mesh-sdk/go/busretry" "git.novox.be/novox/mesh-sdk/go/process" "mesh-delivery-assigner/internal/buckets" "mesh-delivery-assigner/internal/puts" @@ -1038,3 +1039,77 @@ func TestAnActingPartsNewVersionHoldsNoWant(t *testing.T) { t.Errorf("an acting part's version held the want: kept %v, said %v", waits.values, said) } } + +// H-A-682 (2), H-A-698 (1), (2): the needs of a want are those of the module's held entry when it names the fingerprint, else those +// the seat `mesh-catalog`'s `entry` answers; the pass never waits on that ask, the entry is not read while it is out, not found or +// unanswered, and the answer wakes a pass. +func TestAWantsNeedsAreReadFromItsEntryAndNeverWaitedFor(t *testing.T) { + const held, older, gone, lost = "src2:held", "src2:older", "src2:gone", "src2:lost" + words := []string{"want:version", "approval-mark/1"} + answered := make(chan struct{}, 8) + p := &passer{} + p.entries = meshcatalogclient.NewEntries(func(_ string, body any) (json.RawMessage, error) { + switch fp := body.(meshcatalog.EntryInput).Fingerprint; fp { + case gone: + return nil, &busretry.Answered{Words: "no entry"} + case lost: + return nil, errors.New("no responders") + default: + return json.Marshal(meshcatalog.EntryAnswer{Entry: meshcatalog.CatalogEntry{Module: "m", Fp: fp, Needs: []string{"directory-contents-owner", "approval-mark/1"}}}) + } + }) + p.entries.Changed = func(meshcatalogclient.EntryRow) { answered <- struct{}{} } + value := meshcatalog.ModulesByModuleValue{Fp2: held, Needs: []string{"want:version", "zeta", "approval-mark/1"}} + ctx := context.Background() + for _, c := range []struct { + fp string + missing []string + read bool + asked bool + }{ + {held, []string{"zeta"}, true, false}, + {older, nil, false, true}, // asked: not read yet + {older, []string{"directory-contents-owner"}, true, false}, // answered, and kept + {gone, nil, false, true}, + {lost, nil, false, false}, // out and failed in transport: asked again at the next revision, its answer awaited by no pass + } { + missing, read := p.missingNeeds(ctx, value, words, c.fp) + if !slices.Equal(missing, c.missing) || read != c.read { + t.Errorf("%s: missing %v read %v, want %v %v", c.fp, missing, read, c.missing, c.read) + } + if c.asked { + select { + case <-answered: + case <-time.After(10 * time.Second): // a bound on a failure only + t.Fatalf("%s: the ask is never answered", c.fp) + } + } + } + if _, read := p.missingNeeds(ctx, value, words, gone); read { + t.Error("an entry not found is read") + } +} + +// H-A-698 (2): the why of a want held awaiting its entry names the ask: its state, how often it was asked again and its last failure. +func TestTheWhyOfAWantAwaitingItsEntryNamesTheAsk(t *testing.T) { + const fp = "src2:lost" + kv := &memKV{values: map[string][]byte{}} + p := &passer{kvs: map[string]jetstream.KeyValue{writtenBucket(): kv}} + p.entries = meshcatalogclient.NewEntries(func(string, any) (json.RawMessage, error) { return nil, errors.New("no responders") }) + p.entries.Need(context.Background(), fp) + deadline := time.Now().Add(10 * time.Second) // a bound on a failure only + for len(p.entries.Rows()) == 0 || p.entries.Rows()[0].Detail == "" { + if time.Now().After(deadline) { + t.Fatal("the ask never failed") + } + time.Sleep(time.Millisecond) // the ask runs on its own goroutine + } + held := mwc.Want{Fp: fp, Hold: true, Words: mwc.HoldAwaitsEntryPrefix + fp} + p.sayWhy(context.Background(), "m", []string{"ace"}, wantWhy{Branch: "main", Fp: fp, Step: whyPassed}, nil, &assign.Outcome{Wants: map[string]mwc.Want{"ace": held}}) + raw, ok := kv.values[whyKey("ace", "m")] + var got wantWhy + if !ok || json.Unmarshal(raw, &got) != nil || got.Entry == nil || got.Entry.Fingerprint != fp || got.Entry.State != meshcatalogclient.EntryAsked || + !strings.Contains(got.Entry.Detail, "no responders") { + t.Errorf("the why = %s, want the ask of %s named with its state and last failure", raw, fp) + } +} diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/why.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/why.go index 94d73776d..dcf8a44e7 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/why.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/why.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "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" stdio "git.novox.be/novox/mesh-sdk/go" @@ -50,6 +51,28 @@ type wantWhy struct { // Before is the want that stood before the pass, After the one the pass wrote (none: it kept Before). Before *mwc.Want `json:"before,omitempty"` After *mwc.Want `json:"after,omitempty"` + // Entry is the ask of the catalog entry a want held awaiting its entry waits on: its state, how often it was asked again and its + // last failure (design 47 H2 H-A-698 (2)). + Entry *entryAsk `json:"entry,omitempty"` +} + +// entryAsk is where the ask of one catalog entry stands. +type entryAsk struct { + Fingerprint string `json:"fingerprint"` + State meshcatalogclient.EntryState `json:"state"` + Asks int `json:"asks"` + Detail string `json:"detail,omitempty"` +} + +// heldWant is the want a why says stands after the pass: the one written, else the one before. +func heldWant(w wantWhy) mwc.Want { + switch { + case w.After != nil: + return *w.After + case w.Before != nil: + return *w.Before + } + return mwc.Want{} } func whyKey(node, module string) string { return whyPrefix + node + "." + module } @@ -74,6 +97,14 @@ func (p *passer) sayWhy(ctx context.Context, module string, nodes []string, w wa one.After = &a } } + if held := heldWant(one); p.entries != nil && strings.HasPrefix(held.Words, mwc.HoldAwaitsEntryPrefix) { + fp := strings.TrimPrefix(held.Words, mwc.HoldAwaitsEntryPrefix) + for _, row := range p.entries.Rows() { + if row.Fingerprint == fp { + one.Entry = &entryAsk{Fingerprint: fp, State: row.State, Asks: row.Asks, Detail: row.Detail} + } + } + } same := one same.At = time.Time{} cmp, _ := json.Marshal(same) diff --git a/modules/mesh-delivery-assigner/internal/assign/wants.go b/modules/mesh-delivery-assigner/internal/assign/wants.go index e7eeef0ae..e9f57f7e2 100644 --- a/modules/mesh-delivery-assigner/internal/assign/wants.go +++ b/modules/mesh-delivery-assigner/internal/assign/wants.go @@ -17,7 +17,7 @@ import ( // A want names the newest released version whose pipeline passed (design 47 H §750): for every node whose assignment places // a module on a watched branch, the want names the version, the pipeline and the mover's rank in it, written tier by tier -// (§751). It is held for nothing else: the rules of ADR 0429 §6 (the build done, not held, the canary and step, every +// (§751). It is held for nothing else than a reader capability its node-engine does not state (ADR 0614 §4, §772 being its first case, H-A-682); the rules of ADR 0429 §6 (the build done, not held, the canary and step, every // provider healthy, the grant, the composition and the reader capabilities, the provisions, the served verbs and the bus // state), the network hold and A-428's exceptions end (H-A-55). A put owns its node's want as before (ADR 0546), and the // operator's yes on a module of policy record is the node-engine's have and the asker's (the pass's yeses). @@ -58,6 +58,10 @@ type Module struct { // node-engine, design 47 H §772, H-A-45); a node whose engine does not is written its want held, awaiting its hand placement // (H-A-73). Nil: every node does. ReadsVersion func(node string) bool + // MissingNeeds says what the want of node at fp lacks of its node-engine's words: the reader capabilities the entry at fp + // needs that the node's words in `engine-reads` do not hold, sorted; read false while the entry's needs are not read yet + // (design 47 H2 H-A-682 (2), H-A-698 (2)). Nil: no want needs more than want:version. + MissingNeeds func(node, fp string) (missing []string, read bool) } func (m Module) selfOn(node string) bool { return m.Self != nil && m.Self(node) } @@ -143,6 +147,19 @@ func Wants(m Module, wants map[string]mwc.Want) Outcome { if m.ReadsVersion != nil && !m.ReadsVersion(node) { // A node-engine that cannot read a want by version is placed by hand when its machine is back (design 47 H §772). next.Hold, next.Words, next.Backup, next.Revert = true, mwc.HoldAwaitsHandPlacement, "", "" + } else if m.MissingNeeds != nil { + // A node-engine whose words lack a reader capability the entry needs reads the want no better (ADR 0614 §4): the want is + // held, saying which, or saying the entry is not read yet (design 47 H2 H-A-682 (2), H-A-698 (2)). + missing, read := m.MissingNeeds(node, t.Fp) + switch { + case !read: + next.Hold, next.Words, next.Backup, next.Revert = true, mwc.HoldAwaitsEntryPrefix+t.Fp, "", "" + case len(missing) > 0: + next.Hold, next.Words, next.Backup, next.Revert = true, mwc.HoldAwaitsReadsPrefix+strings.Join(missing, ","), "", "" + } + } + if !next.Hold && holdWords(next.Words) { + next.Words = "" // the hold ended: its words with it } if !had || !mwc.SameWant(normal(before), normal(next)) { out.Wants[node] = next @@ -156,6 +173,11 @@ func Wants(m Module, wants map[string]mwc.Want) Outcome { return out } +// holdWords says whether words are those of a want the assigner holds for what its node-engine does not read. +func holdWords(words string) bool { + return words == mwc.HoldAwaitsHandPlacement || strings.HasPrefix(words, mwc.HoldAwaitsReadsPrefix) || strings.HasPrefix(words, mwc.HoldAwaitsEntryPrefix) +} + // failed says whether a have's health check failed once the node is done moving: phase running or failed (never removed, held, or // moving). func failed(h nodeengine.HaveByNodeModuleValue) bool { diff --git a/modules/mesh-delivery-assigner/internal/assign/wants_test.go b/modules/mesh-delivery-assigner/internal/assign/wants_test.go index 1d77b9027..c8f2542f9 100644 --- a/modules/mesh-delivery-assigner/internal/assign/wants_test.go +++ b/modules/mesh-delivery-assigner/internal/assign/wants_test.go @@ -69,6 +69,34 @@ func TestAWantNamesTheNewestPassedVersion(t *testing.T) { m.ReadsVersion = func(node string) bool { return node == "ace" } return m }, nil, map[string]mwc.Want{"ace": want, "g14": {Fp: fNew, Version: "1.2.3", Pipeline: "main.12", Rank: 2, Hold: true, Words: mwc.HoldAwaitsHandPlacement}}}, + {"A3a (H-A-682 (2)): a node whose words lack a need of the entry is held, awaiting its reads; one whose words hold it is not", func() Module { + m := released() + m.MissingNeeds = func(node, fp string) ([]string, bool) { + if node == "ace" { + return []string{"directory-contents-owner", "approval-mark/1"}, true + } + return nil, true + } + return m + }, nil, map[string]mwc.Want{"ace": {Fp: fNew, Version: "1.2.3", Pipeline: "main.12", Rank: 2, Hold: true, Words: mwc.HoldAwaitsReadsPrefix + "directory-contents-owner,approval-mark/1"}, "g14": want}}, + {"A3a: a node without want:version keeps awaiting its hand placement, whatever its needs", func() Module { + m := released() + m.ReadsVersion = func(node string) bool { return node == "g14" } + m.MissingNeeds = func(string, string) ([]string, bool) { return []string{"directory-contents-owner"}, true } + return m + }, nil, map[string]mwc.Want{"ace": {Fp: fNew, Version: "1.2.3", Pipeline: "main.12", Rank: 2, Hold: true, Words: mwc.HoldAwaitsHandPlacement}, + "g14": {Fp: fNew, Version: "1.2.3", Pipeline: "main.12", Rank: 2, Hold: true, Words: mwc.HoldAwaitsReadsPrefix + "directory-contents-owner"}}}, + {"A3a: the node's next manifest-reads-changed naming the need writes the want with no hold", func() Module { + m := released() + m.MissingNeeds = func(string, string) ([]string, bool) { return nil, true } + return m + }, map[string]mwc.Want{"ace": {Fp: fNew, Version: "1.2.3", Pipeline: "main.12", Rank: 2, Hold: true, Words: mwc.HoldAwaitsReadsPrefix + "directory-contents-owner"}, "g14": want}, + map[string]mwc.Want{"ace": want}}, + {"A3b (H-A-698 (2)): a want whose entry is not read yet is held awaiting its entry", func() Module { + m := released() + m.MissingNeeds = func(node, fp string) ([]string, bool) { return nil, node != "ace" } + return m + }, wantedOld(), map[string]mwc.Want{"ace": {Fp: fNew, Version: "1.2.3", Pipeline: "main.12", Rank: 2, Hold: true, Words: mwc.HoldAwaitsEntryPrefix + fNew}, "g14": want}}, {"a node no longer assigned is removed", func() Module { m := released() m.Nodes = []string{"ace"}