diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionreads.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionreads.go index 08be1b15c..19cf7f6d4 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionreads.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionreads.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "slices" "strings" "sync" "time" @@ -280,20 +281,33 @@ func (r *compositionRun) waiting(id string, d int) { } } -// clearRead clears the finding of a read's seat verb when this process raised it; answered says the verb answered. +// clearRead clears the finding of a read's seat verb: at the verb's answer (answered), or once no read waits on it. The finding is +// read from the findings bucket's keys, never from what this process raised, so one written before a restart is cleared as well +// (design 47 H2 H-A-708 (4), H-A-722). func (r *compositionRun) clearRead(id string, answered bool) { r.readMu.Lock() - raised := r.raised[id] - if raised && (answered || r.inflight[id] <= 0) { + was := r.raised[id] + clear := answered || r.inflight[id] <= 0 + if clear { delete(r.raised, id) - } else { - raised = false } r.readMu.Unlock() - if !raised || r.findings.Delete == nil { + if !clear || r.findings.Delete == nil { return } - if err := r.findings.Delete(readFindingKey(id)); err != nil { - r.logf("the finding %s is not cleared: %v", readFindingKey(id), err) + key := readFindingKey(id) + if r.findings.Keys != nil { + ks, err := r.findings.Keys() + if err != nil { + r.logf("the finding %s is not cleared, the findings are not read: %v", key, err) + return + } + was = slices.Contains(ks, key) + } + if !was { + return + } + if err := r.findings.Delete(key); err != nil { + r.logf("the finding %s is not cleared: %v", key, err) } } diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go index 729aa48b4..a8fcf2674 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go @@ -787,25 +787,33 @@ func TestARunsReadsShareOneDeadline(t *testing.T) { // Design 47 H2 H-A-708 (4), H-A-731, AC-A7: a read that waited five minutes writes the finding call-unanswered, id `.`, // naming its holder and machine, the last fault and since when; the verb's answer clears it, and so does the end of the last read -// waiting on it past its bound. +// waiting on it past its bound; a finding written before a restart, which no process of this run raised, is cleared the same way +// (H-A-722: the clear reads the findings bucket's keys). func TestAReadUnansweredForFiveMinutesIsTheFindingCallUnanswered(t *testing.T) { step := meshwants.StepRun{Module: "m", Branch: "main", Revision: 7, Step: meshwants.StepRunStepComposition} - for _, answered := range []bool{true, false} { + for _, c := range []struct{ answered, restarted bool }{{true, false}, {false, false}, {true, true}, {false, true}} { + answered, restarted := c.answered, c.restarted s := newRunStand(t, "src2:e1", "src2:e1", "d1") inner := s.r.call findings := map[string]mcseat.Finding{} s.r.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 }} s.r.holder = func(string) (string, []string) { return "mesh-delivery-indexer", []string{"novox"} } since := time.Unix(500, 0) key := mccond.Key(mccond.ScopeCall, "mesh-catalog.revision", mccond.KindCallUnanswered) + if restarted { // written before a restart: this process raised nothing + findings[key] = mcseat.Finding{} + } s.r.call = func(ask process.KeptAsk, k string, body any) (json.RawMessage, error) { if k != mcc.RevisionVerb { return inner(ask, k, body) } - ask.Hook(busretry.Waited{Seat: "mesh-catalog", Verb: "revision", Since: since, Last: "away: the trunk's revision 512 not read yet"}) - if f, ok := findings[key]; !ok || !strings.Contains(f.Summary, "mesh-delivery-indexer on novox") || !strings.Contains(f.Summary, "the trunk's revision 512") || - !strings.Contains(f.Summary, since.UTC().Format(time.RFC3339)) { + if !restarted { + ask.Hook(busretry.Waited{Seat: "mesh-catalog", Verb: "revision", Since: since, Last: "away: the trunk's revision 512 not read yet"}) + } + if f, ok := findings[key]; !restarted && (!ok || !strings.Contains(f.Summary, "mesh-delivery-indexer on novox") || !strings.Contains(f.Summary, "the trunk's revision 512") || + !strings.Contains(f.Summary, since.UTC().Format(time.RFC3339))) { t.Errorf("at five minutes the findings are %+v", findings) } if answered { diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionstep_integration_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionstep_integration_test.go index 09a0cac1c..249429e97 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionstep_integration_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionstep_integration_test.go @@ -152,8 +152,19 @@ func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T) case <-time.After(30 * time.Second): t.Fatal("the assigner did not read the seat list within 30 s") } + // H2 H-A-708 (3), AC-A6b: the seat mesh-catalog's holder is stopped while the composition reads its entry: the read is a kept + // call, the journal says the seat does not answer, and the step goes on and passes once the holder answers again. + b.cat.stop() + outage := b.journal.mark() putStep(b.ctx, t, b.js, "step-ask-1", meshwants.StepRun{Pipeline: "main.3.m", Step: meshwants.StepRunStepComposition, Module: "m", Branch: trunkBranch, Revision: 3, Commit: engineCommit, Fingerprint: "src2:m1"}) + // The kept call's own journal line goes to the process's standard error, so the outage is a few seconds of the clock, over which + // the step must go no further. + time.Sleep(3 * time.Second) + if b.journal.has(outage, "the composition step of m says fetch") { + t.Fatal("the step went on while the seat mesh-catalog's holder was stopped") + } + b.cat.serve() // Each machine's run waits for x/go's publish, the step saying fetch; the publish heard, each puts its run ask (1984/AC11). for _, node := range []string{"n1", "n2"} { b.journal.await(t, from, "the composition run main=2e3."+node+" waits for package "+pkg, "the run of "+node+" waits", 30*time.Second) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/halves.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/halves.go index e7ed8cc32..3363b0b7f 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/halves.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/halves.go @@ -54,6 +54,13 @@ func (h *halves) follow() error { h.changed(branch, module, entry, deleted) } b.Adopted = h.adopted + // An entry read by fingerprint is kept until the next catalog revision taken in (design 47 H2 H-A-682 (2)): each revision + // held releases them, and a want at an older fingerprint asks its entry again. + b.Held = func(string, meshcatalog.CatalogRevision) { + for _, r := range b.Entries.Rows() { + b.Entries.Release(r.Fingerprint) + } + } // The one handler of registration-changed is the follower's (H-A-270 (3)): the pipeline ends are told each change from it, // never from a second handler on the hub. reconcile := b.Registrations.Follower.Changed diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/halvesnone_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/halvesnone_test.go index 35d7fedf4..02331e0c4 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/halvesnone_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/halvesnone_test.go @@ -105,3 +105,33 @@ func TestAModulesWatchedBranchesAreItsRegistrations(t *testing.T) { }) } } + +// H-A-682 (2): the entries read by fingerprint are kept until the next catalog revision the assigner takes in, and each revision +// held releases them. +func TestACatalogRevisionTakenInReleasesTheEntriesKept(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) + defer cancel() + call := func(key string, _ any) (json.RawMessage, error) { + if key == mcc.EntryVerb { + return json.Marshal(seat.EntryAnswer{Entry: seat.CatalogEntry{Module: "m", Needs: []string{"x"}}}) + } + return nil, errors.New("not answered here") + } + reader := &views.ProcessReader{Module: "mesh-delivery-assigner", Call: call, Logf: t.Logf} + h := &halves{w: newWorld(), call: call, reader: reader, wake: func() {}, logf: t.Logf, ctx: ctx} + if err := h.follow(); err != nil { + t.Fatal(err) + } + answered := make(chan struct{}, 1) + h.branches.Entries.Changed = func(mcc.EntryRow) { answered <- struct{}{} } + h.branches.Entries.Need(ctx, "src2:old") + select { + case <-answered: + case <-ctx.Done(): + t.Fatal("the entry is never answered") + } + h.branches.Held("main", seat.CatalogRevision{Branch: "main", Revision: 2}) + if rows := h.branches.Entries.Rows(); len(rows) != 0 { + t.Errorf("a catalog revision taken in leaves the entries kept: %+v", rows) + } +} diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/integration_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/integration_test.go index 0531f2932..b5ad3d75a 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/integration_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/integration_test.go @@ -98,6 +98,8 @@ type catalogBed struct { // at is, by branch and revision, a revision's entries a test keeps whole: the verb revision answers a revision asked by its // number from here, and the current one otherwise. at map[string]map[int64][]meshcatalog.CatalogEntry + // stop makes the seat's holder unheard, as a holder stopped is (no responders); serve makes it heard again (serveCatalog). + stop, serve func() } // journal is a program's journal as the bed hears it: a test awaits a line in it (await) where the line is the only sign @@ -124,6 +126,13 @@ func (j *journal) mark() int { return j.text.Len() } +// has says whether the journal holds, after from (mark), a line with words. +func (j *journal) has(from int, words string) bool { + j.mu.Lock() + defer j.mu.Unlock() + return strings.Contains(j.text.String()[from:], words) +} + // await returns once the journal holds, after from (mark), a line with words, and fails the test when none came within // bound. func (j *journal) await(t *testing.T, from int, words, what string, bound time.Duration) { @@ -1831,13 +1840,6 @@ func serveCatalog(t *testing.T, b *bed, nc *nats.Conn) { } t.Cleanup(func() { _ = sub.Unsubscribe() }) } - for _, subject := range []string{"mesh.seat.mesh-catalog.tool.revision", "mesh.seat.mesh-catalog.call.revision.*", "mesh.seat.mesh-catalog.tool.revision.*"} { - sub, err := nc.Subscribe(subject, answer) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { _ = sub.Unsubscribe() }) - } // The verb entry answers an entry by its fingerprint from every branch's half, and a fingerprint no half holds as not found, // as the seat's holder does: an entry the assigner asks for a form change is answered, never left asked (orderwaits.go). entry := func(m *nats.Msg) { @@ -1856,14 +1858,27 @@ func serveCatalog(t *testing.T, b *bed, nc *nats.Conn) { } _ = m.Respond([]byte(`{"error":"no catalog entry has the fingerprint ` + in.Fingerprint + `","node":"n0"}`)) } - for _, subject := range []string{"mesh.seat.mesh-catalog.tool.entry", "mesh.seat.mesh-catalog.call.entry.*"} { - sub, err := nc.Subscribe(subject, entry) - if err != nil { - t.Fatal(err) + var subs []*nats.Subscription + b.cat.serve = func() { + for subject, handler := range map[string]nats.MsgHandler{"mesh.seat.mesh-catalog.tool.revision": answer, "mesh.seat.mesh-catalog.call.revision.*": answer, + "mesh.seat.mesh-catalog.tool.revision.*": answer, "mesh.seat.mesh-catalog.tool.entry": entry, "mesh.seat.mesh-catalog.call.entry.*": entry} { + sub, err := nc.Subscribe(subject, handler) + if err != nil { + t.Fatal(err) + } + subs = append(subs, sub) } - t.Cleanup(func() { _ = sub.Unsubscribe() }) + subscribed(t, nc) } - subscribed(t, nc) + b.cat.stop = func() { + for _, sub := range subs { + _ = sub.Unsubscribe() + } + subs = nil + _ = nc.Flush() + } + b.cat.serve() + t.Cleanup(b.cat.stop) } // A-181: the assigner reads the builder's stream of build ends whole at its start (the last of each fingerprint, a failed one's error 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 978545b59..63b9ca8df 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 @@ -295,7 +295,9 @@ func TestTheSeatsVerbs(t *testing.T) { t.Fatalf("findings = %v", findings) } putAssignments(w, mma.Assignments{V: keys.Version, Node: "g14", Modules: []mma.PlacedModule{{Module: "web"}}}) - p.unplacedFindings() + // A process that starts again knows nothing of what the first said: it clears the finding from the bucket (H-A-722). + restarted := &passer{w: w, logf: func(string, ...any) {}, findings: p.findings} + restarted.unplacedFindings() if len(findings) != 0 { t.Errorf("placed again: findings %v", findings) } @@ -313,7 +315,9 @@ func TestTheSeatsVerbs(t *testing.T) { 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...) + if len(assigned) > 0 { // none: the node is gone, no assignments name it + placeOn(t, p.w, "g14", assigned...) + } raw, _ := mwc.EncodeWant(mwc.Want{Fp: fp, Version: version}) key, _ := mwc.WantKey("g14", "web") wantsKV.values[key] = raw @@ -338,6 +342,13 @@ func TestTheSeatsVerbs(t *testing.T) { if len(findings) != 0 { t.Errorf("the module is no longer assigned to the node: findings %v", findings) } + if pass("", "web").wants(context.Background()); len(findings) != 1 { + t.Fatalf("a want of no version again: findings %v", findings) + } + pass("").wants(context.Background()) // the node is gone: no assignments name it + if len(findings) != 0 { + t.Errorf("the node is gone: 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 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 18d32f708..d66bd317b 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tiers.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tiers.go @@ -219,18 +219,26 @@ func (p *passer) tiers(n assign.Nodes, placedOn func(module, branch string) []st if now.Before(t.Since) { t.PausedFrom = t.Since // never earlier than the progress's own start } - if p.writeTier(key, t, rev, "paused-from") { + err := p.writeTier(key, t, rev, "paused-from") + if err == nil { p.logf("pipeline %s: tier %d's count of tier-bound stands still: %s", pipeline, t.Tier, pauseNamed(standing, t, notRunning)) } - continue + if err == nil || errors.Is(err, errSwapped) { + continue // written, or a lost race: read the progress again + } + break // refused (said): reading it again would spin the pass } if !paused && !t.PausedFrom.IsZero() { held := now.Sub(t.PausedFrom) t.ClockFrom, t.PausedFrom = clock.Add(held), time.Time{} - if p.writeTier(key, t, rev, "clock-from") { + err := p.writeTier(key, t, rev, "clock-from") + if err == nil { p.logf("pipeline %s: tier %d's count of tier-bound stood still for %s and goes on; the tier is late at %s", pipeline, t.Tier, held.Round(time.Second), t.ClockFrom.Add(bound).Format(time.RFC3339)) } - continue + if err == nil || errors.Is(err, errSwapped) { + continue + } + break } if !t.PausedFrom.IsZero() { break // paused: no lateness, and no timer armed @@ -417,9 +425,9 @@ func tierBoundSetting(getenv func(string) string) (time.Duration, error) { // without a test waiting minutes. var tierBoundUnit = time.Minute -// writeTier swaps the tier progress at key by compare-and-set at rev; false when it was not written (the caller reads it again), -// the failure said but a lost race (what field the write was for names it). -func (p *passer) writeTier(key string, t tierProgress, rev uint64, field string) bool { +// writeTier swaps the tier progress at key by compare-and-set at rev; its error when it was not written: errSwapped for a lost race +// (the caller reads the progress again), any other said (what field the write was for names it) and the caller goes on. +func (p *passer) writeTier(key string, t tierProgress, rev uint64, field string) error { value, err := json.Marshal(t) if err == nil { err = p.ends.st.swap(key, value, rev) @@ -427,7 +435,7 @@ func (p *passer) writeTier(key string, t tierProgress, rev uint64, field string) if err != nil && !errors.Is(err, errSwapped) { p.logf("the tier progress %s is not written (%s): %v", key, field, err) } - return err == nil + return err } // pausingAsks are the keys of asks (the assigner's state asks, G §717) that pause the count of tier t of its pipeline: a key of 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 b1963be50..2bad78bdc 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,7 @@ package main import ( "context" "encoding/json" + "errors" "maps" "slices" "strings" @@ -36,8 +37,9 @@ func TestAPipelinesWantsAreWrittenTierByTier(t *testing.T) { runs bool pipeline string paused bool // H-A-627: the provider's record ask stands in asks from minute 5 to minute 45, and the count stands still - }{{true, trunkBranch + ".5", false}, {false, trunkBranch + ".5", false}, {true, trunkBranch + ".5.again.2", false}, {false, trunkBranch + ".5.again.2", false}, - {true, trunkBranch + ".5", true}, {false, trunkBranch + ".5", true}} { + held bool // H-A-682 (2), (4): the provider's entry needs a capability g14's node-engine does not state, so its want there is held + }{{true, trunkBranch + ".5", false, false}, {false, trunkBranch + ".5", false, false}, {true, trunkBranch + ".5.again.2", false, false}, {false, trunkBranch + ".5.again.2", false, false}, + {true, trunkBranch + ".5", true, false}, {false, trunkBranch + ".5", true, false}, {false, trunkBranch + ".5", false, true}} { runs, pipeline := c.runs, c.pipeline start := time.Date(2026, 11, 20, 4, 0, 0, 0, time.UTC) now := start @@ -63,13 +65,26 @@ func TestAPipelinesWantsAreWrittenTierByTier(t *testing.T) { } for i, m := range []struct{ name, fp string }{{"db", db}, {"web", web}} { digest := strings.Repeat(string(rune('e'+i)), 64) - mod, _ := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Fp2: m.fp, Manifest: digest, Repository: "novox/" + m.name, Commit: strings.Repeat("1", 40), Path: meshcatalogclient.RootPath}) + value := meshcatalog.ModulesByModuleValue{Fp2: m.fp, Manifest: digest, Repository: "novox/" + m.name, Commit: strings.Repeat("1", 40), Path: meshcatalogclient.RootPath} + if c.held && m.name == "db" { + value.Needs = []string{"directory-contents-owner"} + } + mod, _ := meshcatalogclient.EncodeModule(value) putModuleRaw(p.w, trunkBranch, m.name, mod) p.w.manifests[digest] = parsed{module: m.name, manifest: catalogue.Manifest{Module: m.name}} } placeOn(t, p.w, "g14", "db", "web") placeOn(t, p.w, "ace", "db", "web") p.w.heardPresence("ace", true, start) // away: not waited for + if c.held { // both engines state want:version; neither states the capability db needs + p.reads = &engineReadsKept{} + for _, node := range []string{"g14", "ace"} { + raw, _ := json.Marshal(engineWords{Words: []string{nodeengine.ManifestReadWordWantVersion}, At: start}) + if err := p.reads.take(node, raw, false); err != nil { + t.Fatal(err) + } + } + } p.w.mu.Lock() p.w.runningHeard = true p.w.mu.Unlock() @@ -94,6 +109,12 @@ func TestAPipelinesWantsAreWrittenTierByTier(t *testing.T) { 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) } + if c.held { + key, _ := mwc.WantKey("g14", "db") + if w, err := mwc.DecodeWant(wantsKV.values[key]); err != nil || !w.Hold || w.Words != mwc.HoldAwaitsReadsPrefix+"directory-contents-owner" { + t.Fatalf("%s: db's want on g14 is not held awaiting its reads: %+v (%v)", pipeline, w, err) + } + } runAt, lateBefore, lateAt := time.Minute, 29*time.Minute, 30*time.Minute if c.paused { runAt, lateBefore, lateAt = 50*time.Minute, 69*time.Minute, 70*time.Minute @@ -249,3 +270,43 @@ func TestALateMoverHoldsItsTier(t *testing.T) { }) } } + +// H-A-627 (2): a write of the tier progress that is refused (a full bucket), not lost to another writer, is said and not read +// again within the pass: the pass would spin on the same progress for ever. +func TestARefusedTierWriteDoesNotSpinThePass(t *testing.T) { + start := time.Date(2026, 11, 20, 4, 0, 0, 0, time.UTC) + for _, field := range []string{"paused-from", "clock-from"} { + st := &refusingEnds{memEnds: newMemEnds(), t: t} + p := newPasser(kvSet{buckets.Asks(): &memKV{values: map[string][]byte{}}}, start.Add(5*time.Minute)) + p.ends = newPipelineEnds(st, func() {}, func(string, ...any) {}) + prog := tierProgress{Tier: 1, Since: start, ClockFrom: start, Movers: []tierMover{{Module: "db", Fp: "fp", Tier: 1, NoVersion: true}}} + if field == "clock-from" { + prog.PausedFrom = start.Add(time.Minute) // the ask is gone: the pause ends + } else if akey, err := asks.RecordAskKey("g14", "db", "sha256:"+strings.Repeat("a", 64)); err != nil { + t.Fatal(err) + } else { + p.w.put(buckets.Asks(), akey, []byte(`{}`)) + } + raw, _ := json.Marshal(prog) + st.vals[tierKey(trunkBranch+".5")], st.revs[tierKey(trunkBranch+".5")] = raw, 1 + p.tiers(assign.Nodes{Online: map[string]bool{}}, func(string, string) []string { return []string{"g14"} }) + if st.swaps != 1 { + t.Errorf("%s: the refused write was made %d times in one pass", field, st.swaps) + } + } +} + +// refusingEnds is memEnds whose every swap is refused for a cause other than a lost race; it fails the test on the third. +type refusingEnds struct { + *memEnds + t *testing.T + swaps int +} + +func (r *refusingEnds) swap(string, []byte, uint64) error { + r.swaps++ + if r.swaps > 2 { + r.t.Fatal("the pass reads the refused progress again and writes it again") + } + return errors.New("the bucket is full") +} diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep.go index 280fdd5ee..4aef60129 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep.go @@ -128,10 +128,12 @@ func (r *compositionRun) judgeValidate(ctx context.Context, step meshwants.StepR if half.Revision.Base <= 0 { empty = emptyBeforeWords } - problems := causedProblems(v.Change, v.Before) - for _, p := range r.engineNeedProblems(half)[step.Module] { // H-A-682 (5): the node-engine's own build is refused, never held - problems = append(problems, step.Module+": "+p) + // H-A-682 (5): the node-engine's own build is refused, never held; the run adds the problem to its verdict, for the mover's + // manifest, so the run kept in composition-runs holds it and every step reads it as it reads the validator's. + if needs := r.engineNeedProblems(half)[step.Module]; len(needs) > 0 { + v = r.keepEngineNeeds(step, v, needs) } + problems := causedProblems(v.Change, v.Before) if len(problems) > 0 { said := reasonManifestRefused + ": " + strings.Join(problems, "; ") if empty != "" { @@ -142,6 +144,53 @@ func (r *compositionRun) judgeValidate(ctx context.Context, step meshwants.StepR return stepOutcome{Outcome: meshwants.StepEndedOutcomePassed, Said: empty} } +// keepEngineNeeds adds needs, the problems of step's module, to the verdict the validate run of its revision keeps, as the refusal of +// that module's manifest in the change case (none the verdict holds already), and answers the verdict as it is then; where the run +// cannot be written, the verdict it was read as with them added, said in the journal. +func (r *compositionRun) keepEngineNeeds(step meshwants.StepRun, read validateVerdict, needs []string) validateVerdict { + add := func(v *validateVerdict) bool { + m := v.Change.Manifests[step.Module] + held := strings.Split(m.Refused, "\n") + changed := false + for _, p := range needs { + if !slices.Contains(held, p) { + held, changed = append(held, p), true + } + } + if !changed { + return false + } + m.Accepted, m.Refused = false, strings.Join(slices.DeleteFunc(held, func(p string) bool { return p == "" }), "\n") + if v.Change.Manifests == nil { + v.Change.Manifests = map[string]composer.ManifestRead{} + } + v.Change.Manifests[step.Module] = m + return true + } + if !add(&read) { + return read + } + key, err := validateKeyOf(step) + if err == nil { + _, _, err = r.runs.change(key, func(c *meshwants.CompositionRun) bool { + var v validateVerdict + if raw, e := json.Marshal(c.Verdict); e != nil || json.Unmarshal(raw, &v) != nil || !add(&v) { + return false + } + verdict, e := v.asVerdict() + if e != nil { + return false + } + c.Verdict = verdict + return true + }) + } + if err != nil { + r.logf("the validate run's verdict is not written with the problems of %s: %v", step.Module, err) + } + return read +} + // engineNeedProblems are, by module, the problems of the revision's entries that claim the seat node-engine and need a reader capability // that no node's words in the state engine-reads hold: such an engine would be held on every machine and none could state it, so its // validate run refuses it (design 47 H2 H-A-682 (5)), counted as a new problem. None while no node's words are held. @@ -697,6 +746,9 @@ func validateAnswerOf(run meshwants.CompositionRun, module string, engine map[st continue } for _, p := range engine[name] { + if slices.ContainsFunc(out.Problems, func(q meshwants.ValidateAnswerProblemsItem) bool { return q.Module == name && q.Problem == p }) { + continue // the run's verdict holds it already + } out.Problems = append(out.Problems, meshwants.ValidateAnswerProblemsItem{Module: name, Problem: p}) counted = true } diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep_test.go index 6f761c2e4..cf620c1ba 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep_test.go @@ -315,6 +315,15 @@ func TestTheValidateStepRefusesAManifestProblemAndACycle(t *testing.T) { !strings.Contains(o.Said, "engine: needs directory-contents-owner, which no node-engine states") { t.Errorf("a node-engine needing what no node states ended %+v", o) } + // The run kept in composition-runs holds the problem in its verdict, for the mover's manifest (H-A-682 (5)). + if k, _ := validateKeyOf(engineStep(15)); true { + kept, _, _, _ := r.runs.read(k) + var v validateVerdict + raw, _ := json.Marshal(kept.Verdict) + if json.Unmarshal(raw, &v) != nil || v.Change.Manifests["engine"].Accepted || !strings.Contains(v.Change.Manifests["engine"].Refused, "needs directory-contents-owner, which no node-engine states") { + t.Errorf("the kept validate run's verdict is %+v, want the engine's manifest refused for its need", kept.Verdict) + } + } r.engineReads = &engineReadsKept{by: map[string]engineWords{"ace": {Words: []string{"want:version"}}, "g14": {Words: []string{"directory-contents-owner"}}}} if o := r.validate(ctx, "ask-engine-2", engineStep(16)); strings.Contains(o.Said, "which no node-engine states") { t.Errorf("a node-engine needing what g14 states ended %+v", o)