From 4bcc12d7b15296e3528d348ec6107b417505e9d8 Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 23 Nov 2026 22:35:43 +0100 Subject: [PATCH] T3 assigner: a run waits for its package's publish, bounded, then could not run naming it (issue 1984) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit T2 ended a composition or validate run at once when its entry named a package whose publisher's build in the step's revision was not published yet. Now the run waits: it reads mesh-builds' published first and again at each package-published heard (and at each bind of the consumer); the run's value names the package and the time its wait began in `waits`; its bound bound. is armed for what is left of the new setting package-wait-minutes (1 to 120, default 10). Past the bound the run ends could not run, "package has no published version within (package-wait-minutes)", never the builder's words. `waits` and the bound go when the run ask is put (an ask in the queue has no clock) or the run ends. Every step reading the run says the phase fetch while it holds `waits`, its journal naming the package, and run once none does. At the assigner's start a run holding `waits` and no program ends past its bound, or has its bound armed again for what is left and its whole start run again. A run with no publisher still ends at once (principle 3). The seat mesh-wants' CompositionRun gains `waits` {package, since}, its form raised to 3 as a field added (§780, H-A-352 (3)); the Go and TypeScript contracts regenerated by seatgen. The assigner consumes mesh-builds.package-published. Tests: TestTheCompositionStepRunsOneAskPerMachine (rows: the wait, its `waits` and bound, the phase fetch then run, the pin after the publish with `waits` and the bound gone at the put, past the bound) for 1984/AC9; TestACompositionRunIsOneKeyPerCandidateAndMachine/settings; TestManifest; TestTheCompositionStepComposesEachMachineThroughTheBuildSeat extended (the wait and the publish event, a restart during the wait, a run past its bound at the restart and one past it while running) for 1984/AC11. Builds: design 47 H2 H-A-628 (3), (4), (5) (hq 8aa70271); H-A-629 (1), (2), (3) (hq 8aa70271); D4 H-A-192; D9 H-A-326, H-A-328; G §719, §720; H2 §780 with H-A-352 (3) --- .../compositionbounds.go | 22 +++ .../mesh-delivery-assigner/compositionrun.go | 166 +++++++++++++++-- .../compositionrun_test.go | 140 ++++++++++++++- .../mesh-delivery-assigner/compositionruns.go | 89 +++++++++- .../compositionruns_test.go | 6 +- .../compositionstep_integration_test.go | 168 ++++++++++++++++-- .../cmd/mesh-delivery-assigner/main.go | 13 +- .../mesh-delivery-assigner/validatestep.go | 16 +- .../mesh-delivery-assigner/manifest_test.go | 11 +- modules/mesh-delivery-assigner/module.json | 20 ++- .../go/seats/meshwants/contract.go | 16 +- .../seats/mesh-wants/seat.json | 21 ++- .../ts/seats/meshwants/index.d.ts | 10 ++ 13 files changed, 649 insertions(+), 49 deletions(-) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionbounds.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionbounds.go index 1fb929de0..a8e2ce7ac 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionbounds.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionbounds.go @@ -193,6 +193,10 @@ func (r *compositionRuns) expired(boundKey string) { if err != nil || !ok || run.Ended != nil { return } + if setting == "composition-step-bound" && run.Waits != nil { // the bound a wait for a package's publish armed (H-A-628 (4)) + r.waitExpired(boundKey, key, run) + return + } // The marker of an expiry holds no value (A-470o): the run ends only while its bound is still absent when read again, and // the run is taken for bound., untaken for untaken., so an expiry heard after a bound was armed again, or of a run replaced // since, ends nothing. @@ -229,6 +233,24 @@ func (r *compositionRuns) expired(boundKey string) { } } +// waitExpired ends a run whose wait for a package's publish passed its bound, the expiry of the bound key bound. the +// wait armed (design 47 H2 H-A-628 (3), (4)): could not run naming the package, read from the run's value (H-A-629 (1)). Its run +// ask is not put yet, so none is dropped; a bound armed again since (the marker holds no value, A-470o) ends nothing. +func (r *compositionRuns) waitExpired(boundKey, key string, run meshwants.CompositionRun) { + _, _, armed, err := r.boundOf(boundKey) + if err != nil { + r.logf("the bound %s is not read again, so its expiry ends nothing: %v", boundKey, err) + return + } + if armed { + r.logf("the expiry of %s ends nothing: the bound is armed again (A-470o)", boundKey) + return + } + if _, err := r.endRun(key, run.Ask, meshwants.CompositionRunOutcomeCouldNotRun, r.pastWaitSaid(run.Machine, run.Waits.Package), nil); err != nil { + r.logf("the composition run %s past its wait for package %s is not ended: %v", key, run.Waits.Package, err) + } +} + // endRun ends a run (end) and clears its bounds: the untaken key's readers said superseded, both bound keys deleted. func (r *compositionRuns) endRun(key, ask, outcome, said string, verdict map[string]any) (bool, error) { return r.endRunOf(key, ask, outcome, said, verdict, r.untaken(key, ask)) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go index 0d9114d14..75debacea 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go @@ -142,11 +142,10 @@ func (r *compositionRun) run(ctx context.Context, id string, step meshwants.Step } // read waits for the end of each run of keys and judges the step of module from them, naming in its progress and its end the -// runs it reads and their asks (§723, §729). +// runs it reads and their asks (§723, §729); while a run it reads waits for a package's publish its phase is fetch (H-A-629 (2)). func (r *compositionRun) read(ctx context.Context, module string, keys []string, ends []machineEnd) stepOutcome { setShared(ctx, r.runs.sharedOf(keys, nil)) - setPhase(ctx, meshwants.StepProgressEventPhaseRun) - runs := r.runs.await(ctx, keys) + runs := r.runs.awaitEach(ctx, keys, r.sayingWaits(ctx, "the composition step of "+module)) setPhase(ctx, meshwants.StepProgressEventPhaseReport) for _, key := range keys { ends = append(ends, judgeRun(module, runs[key])) @@ -291,13 +290,11 @@ func (r *compositionRun) start(ctx context.Context, key string, run meshwants.Co end(node + ": " + err.Error()) return } - pins, waiting, err := r.filledPins(ctx, "the node-engine's entry "+engineFp, pins, prep.publishers) - if err != nil { - end(node + ": " + err.Error()) - return - } - if len(waiting) > 0 { - end(node + ": " + unpublishedSaid(waiting)) + pins, said, ok := r.awaitPins(ctx, key, ask, "the node-engine's entry "+engineFp, pins, prep.publishers) + if !ok { + if said != "" { // else the run ended or was replaced while it waited, or the step's wait ended + end(node + ": " + said) + } return } cs := composer.Case{Name: changeCase, Manifests: prep.manifests, None: prep.none} @@ -332,6 +329,7 @@ func (r *compositionRun) start(ctx context.Context, key string, run meshwants.Co } c.Program = &meshwants.CompositionRunProgram{Repository: program.Repository, Commit: program.Commit, Directory: program.Dir, Fingerprint: engineFp} c.Input = digest + c.Waits = nil // its wait ends as its run ask is put (H-A-629 (1)) return true }); err != nil { end(node + ": the run's program and input are not written: " + err.Error()) @@ -828,6 +826,154 @@ func (r *compositionRun) filledPins(ctx context.Context, what string, pins map[s return pins, waiting, nil } +// awaitPins fills the empty pins of the entry what names for the run of ask under key (filledPins) and, while a package's +// publisher's build is not published, waits for it (design 47 H2 H-A-628 (3), (4); H-A-629 (1), (3)): the run's value names the +// package in `waits`, the time its wait began kept across a start taken up again; the run's bound key bound. is armed +// for what is left of package-wait-minutes from that time, never in full again; published is read first and again at each +// package-published heard (H-A-326), and the run's end is heard through its own state, its bound's expiry among them. It answers +// the pins, every one filled, the bound key deleted again (an ask in the queue has no clock, §720), and true; else false and why the +// run could not run, or no words when the run ended or was replaced meanwhile, or ctx ended. +func (r *compositionRun) awaitPins(ctx context.Context, key, ask, what string, pins map[string]string, publishers map[string]packagePublisher) (map[string]string, string, bool) { + armed, said := false, "" + for { + published := r.runs.publishWake() // taken before the read, so a publish heard meanwhile wakes the next one + filled, waiting, err := r.filledPins(ctx, what, pins, publishers) + if err != nil { + return nil, err.Error(), false + } + if len(waiting) == 0 { + if armed { + if err := r.runs.clearBounds(key, ask, runBoundPrefix); err != nil { + r.logf("the bound of the composition run %s's wait is not deleted: %v", key, err) + } + r.logf("the composition run %s waits no more: every package %s names is published", key, what) + } + return filled, "", true + } + path := waiting[0].path + since, held, err := r.runs.waitFor(key, ask, path) + if err != nil { + return nil, "its wait for package " + path + " is not written: " + err.Error(), false + } + if !held { + return nil, "", false + } + left := since.Add(r.runs.set.packageWait).Sub(r.now()) + if left <= 0 { + return nil, r.runs.pastWaitSaid("", path), false + } + if !armed { + stands, err := r.runs.armBound(runBoundPrefix, key, ask, wholeSeconds(left)) + if err != nil { + return nil, "the bound of its wait for package " + path + " is not armed: " + err.Error(), false + } + if !stands { + return nil, "", false + } + armed = true + } + if path != said { + said = path + r.logf("the composition run %s waits for package %s, named with no version in %s: %s; %s ends its wait at %s", key, path, what, + unpublishedSaid(waiting), packageWaitSetting, since.Add(r.runs.set.packageWait).Format(time.RFC3339)) + } + for woke := false; !woke; { + changed := r.runs.wake() + run, _, ok, err := r.runs.read(key) + if err == nil && (!ok || run.Ended != nil || run.Ask != ask) { + return nil, "", false + } + select { + case <-ctx.Done(): + return nil, "", false + case <-published: + woke = true + case <-changed: + } + } + } +} + +// wholeSeconds is d rounded up to a whole second, the bus's least step of a key's time to live: what is left of a wait's bound +// is never refused as a time to live below a second. +func wholeSeconds(d time.Duration) time.Duration { + if w := d.Truncate(time.Second); w < d { + return w + time.Second + } + return d +} + +// sayingWaits is what a step reading runs says of them at each read (design 47 H2 H-A-629 (2)): the phase fetch while a run it +// reads holds `waits`, its journal naming the package, and run once none does. +func (r *compositionRun) sayingWaits(ctx context.Context, what string) func(map[string]meshwants.CompositionRun) { + said := "" + return func(runs map[string]meshwants.CompositionRun) { + waits, of := "", "" + for _, key := range slices.Sorted(maps.Keys(runs)) { + if run := runs[key]; run.Ended == nil && run.Waits != nil { + waits, of = run.Waits.Package, key + break + } + } + if waits == "" { + setPhase(ctx, meshwants.StepProgressEventPhaseRun) + } else { + setPhase(ctx, meshwants.StepProgressEventPhaseFetch) + } + if waits != said { + if waits != "" { + r.logf("%s says fetch: the composition run %s waits for package %s", what, of, waits) + } else { + r.logf("%s says run: no composition run it reads waits for a package", what) + } + said = waits + } + } +} + +// takeUpWaits takes up, at the assigner's start, each run still waiting for a package's publish, its value holding `waits` and +// no program (design 47 H2 H-A-629 (3)): past the time its wait began plus package-wait-minutes it ends could not run naming the +// package; before it, its bound key is armed again for what is left and its whole start runs again, a compose-candidate ask of the +// node and its kept request, which reads published first, as its first reader's step. +func (r *compositionRun) takeUpWaits(ctx context.Context) { + all, err := r.runs.keys() + if err != nil { + r.logf("composition-runs: the runs standing at the start are not read, so no run waiting for a package is taken up: %v", err) + return + } + for _, key := range all { + if !isRunKey(key) { + continue + } + run, _, ok, err := r.runs.read(key) + if err != nil || !ok || run.Ended != nil || run.Waits == nil || run.Program != nil { + continue + } + left := run.Waits.Since.Add(r.runs.set.packageWait).Sub(r.now()) + if left <= 0 { + if _, err := r.runs.endRun(key, run.Ask, meshwants.CompositionRunOutcomeCouldNotRun, r.runs.pastWaitSaid(run.Machine, run.Waits.Package), nil); err != nil { + r.logf("the composition run %s past its wait for package %s is not ended: %v", key, run.Waits.Package, err) + } + continue + } + if _, err := r.runs.armBound(runBoundPrefix, key, run.Ask, wholeSeconds(left)); err != nil { + r.logf("the bound of the composition run %s's wait is not armed again: %v", key, err) + } + if len(run.Readers) == 0 { + r.logf("the composition run %s waiting for package %s has no reader, so its start does not run again; its bound ends it", key, run.Waits.Package) + continue + } + first := run.Readers[0] + r.logf("the composition run %s, waiting for package %s since %s, is taken up again: its start runs again (H-A-629 (3))", key, run.Waits.Package, + run.Waits.Since.Format(time.RFC3339)) + if isValidateRun(run) { + go r.startValidate(ctx, key, run, stepRunOf(first)) + } else { + go r.start(ctx, key, run, &runPrep{r: r, step: stepRunOf(first)}, first.ID) + } + } +} + // publishedOf asks the seat mesh-builds' verb published whether by's build is published, answering the pin it is published at // (vMAJOR.MINOR.PATCH, spec S9) when it is. func (r *compositionRun) publishedOf(ctx context.Context, by packagePublisher) (string, bool, error) { 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 a21c45bc0..2a907854d 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 @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "errors" + "fmt" "git.novox.be/novox/mesh-sdk/go/process" "maps" "slices" @@ -57,6 +58,48 @@ type runStand struct { noPublisher bool } +// logLines is a journal a test awaits lines of: each write wakes the waiter, no sleep stands in for it. +type logLines struct { + mu sync.Mutex + text []string + grew chan struct{} +} + +func newLogLines() *logLines { return &logLines{grew: make(chan struct{})} } + +func (l *logLines) logf(format string, a ...any) { + l.mu.Lock() + defer l.mu.Unlock() + l.text = append(l.text, fmt.Sprintf(format, a...)) + close(l.grew) + l.grew = make(chan struct{}) +} + +// await returns once n lines hold words, and fails the test when they did not come within 10 s. +func (l *logLines) await(t *testing.T, words string, n int) { + t.Helper() + deadline := time.After(10 * time.Second) + for { + l.mu.Lock() + count, grew := 0, l.grew + for _, line := range l.text { + if strings.Contains(line, words) { + count++ + } + } + text := strings.Join(l.text, "\n") + l.mu.Unlock() + if count >= n { + return + } + select { + case <-grew: + case <-deadline: + t.Fatalf("no %d lines %q in the journal within 10 s:\n%s", n, words, text) + } + } +} + func newRunStand(t *testing.T, revisionEngine, trunkEngine, seatDigest string) *runStand { s := &runStand{asks: map[string]buildstep.StepAsk{}, requests: map[string]composer.Request{}, publishedAt: map[string]string{"src2:x1": "0.1.9"}} engine := func(fp, commit string) meshcatalog.CatalogEntry { @@ -218,14 +261,13 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) { if len(s.published) == 0 || s.published[0] != (builds.PublishedInput{Module: "x", Artifact: "x:go", Fingerprint: "src2:x1"}) { t.Errorf("published was asked %+v, want x's build of x:go at src2:x1 in the step's revision", s.published) } - // 1984/AC9: no run ask is put with a pin left out: x's build not published, or no build of the revision publishing x/go, - // ends the run could not run naming the package and the entry, never the builder (H-A-628 (5)). + // 1984/AC9: no run ask is put with a pin left out: no build of the revision publishing x/go ends the run could not run at once, + // naming the package and the entry, never the builder (H-A-628 (5)). for name, c := range map[string]struct { stand func(*runStand) said string }{ - "not published": {func(s *runStand) { s.publishedAt = nil }, "package git.novox.be/novox/x/go has no published version: the build of x at src2:x1 (x:go) is not published"}, - "no publisher": {func(s *runStand) { s.publishedAt = nil; s.noPublisher = true }, "package git.novox.be/novox/x/go has no version in the node-engine's entry src2:e1, and no build of the step's catalog revision publishes it"}, + "no publisher": {func(s *runStand) { s.publishedAt = nil; s.noPublisher = true }, "package git.novox.be/novox/x/go has no version in the node-engine's entry src2:e1, and no build of the step's catalog revision publishes it"}, } { u := newRunStand(t, "src2:e1", "src2:e1", "d1") c.stand(u) @@ -234,6 +276,96 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) { t.Errorf("%s: the step came to %+v with %d run asks put, want could not run saying %q and none put", name, out, len(u.asks), c.said) } } + // 1984/AC9; H-A-628 (3), (4); H-A-629 (1), (2): x's build not published yet: each run waits, its value naming x/go in `waits` + // with the time its wait began, its bound bound. armed for package-wait-minutes, the step saying fetch naming the + // package; at the publish heard each reads published again and puts its run ask with the pin, `waits` and the bound gone, the + // step saying run; past the bound each ends could not run naming the package and the bound, no run ask put. + for _, publish := range []bool{true, false} { + u := newRunStand(t, "src2:e1", "src2:e1", "d1") + u.publishedAt = nil + journal := newLogLines() + u.r.logf = journal.logf + atPut := map[string]string{} // by run key: what stood of its wait as its run ask was put + put := u.r.put + u.r.put = func(ctx context.Context, a buildstep.StepAsk) error { + key, run, _ := u.runs.keyOfAsk(a.ID) + bound, _, _ := u.runs.kv.get(runBoundPrefix + key) + u.mu.Lock() + atPut[key] = fmt.Sprintf("waits %v, bound %s", run.Waits, bound) + u.mu.Unlock() + return put(ctx, a) + } + phase := &stepPhase{} + done := make(chan stepOutcome, 1) + go func() { done <- u.r.run(context.WithValue(context.Background(), phaseKey{}, phase), "ask-step", step) }() + journal.await(t, "waits for package git.novox.be/novox/x/go, named with no version in the node-engine's entry src2:e", 2) + journal.await(t, "the composition step of m says fetch: the composition run", 1) + if got := phase.get(); got != meshwants.StepProgressEventPhaseFetch { + t.Errorf("waiting, the step says the phase %q, want fetch", got) + } + kv := u.runs.kv.(*runsMem) + var keys []string + all, _ := u.runs.keys() + for _, key := range all { + if isRunKey(key) { + keys = append(keys, key) + } + } + for _, key := range keys { + run, _, _, _ := u.runs.read(key) + kv.mu.Lock() + ttl := kv.ttl[runBoundPrefix+key] + kv.mu.Unlock() + if len(keys) != 2 || run.Waits == nil || run.Waits.Package != "git.novox.be/novox/x/go" || run.Waits.Since.IsZero() || ttl <= 9*time.Minute || ttl > 10*time.Minute { + t.Errorf("the waiting run %s of %v holds %+v, its bound %s; want x/go in waits and package-wait-minutes' bound", key, keys, run.Waits, ttl) + } + } + if !publish { + for _, key := range keys { + kv.expire(runBoundPrefix + key) + u.runs.expired(runBoundPrefix + key) + } + } else { + u.mu.Lock() + u.publishedAt = map[string]string{"src2:x1": "0.1.9"} + u.mu.Unlock() + u.runs.heardPublished() + } + var out stepOutcome + select { + case out = <-done: + case <-time.After(10 * time.Second): + t.Fatalf("publish %v: the waiting step said no end", publish) + } + journal.await(t, "the composition step of m says run", 1) + if !publish { + for _, key := range keys { + if run, _, _, _ := u.runs.read(key); run.Ended == nil || run.Waits != nil { + t.Errorf("past its bound the run %s holds ended %v, waits %+v; want it ended and its wait gone", key, run.Ended, run.Waits) + } + } + for _, node := range []string{"ace", "g14"} { + if want := node + ": package git.novox.be/novox/x/go has no published version within 10m0s (package-wait-minutes)"; out.Outcome != meshwants.StepEndedOutcomeCouldNotRun || + !strings.Contains(out.Said, want) || strings.Contains(out.Said, "the builder pins or waits") || len(u.asks) != 0 { + t.Errorf("past its bound the step came to %+v with %d run asks put, want could not run saying %q", out, len(u.asks), want) + } + } + continue + } + if out.Outcome != meshwants.StepEndedOutcomeFailed || !strings.Contains(out.Said, "g14 does not compose") || len(u.asks) != 2 { + t.Errorf("after the publish the step came to %+v with %d run asks", out, len(u.asks)) + } + for node, a := range u.asks { + if a.Packages["git.novox.be/novox/x/go"] != "v0.1.9" { + t.Errorf("after the publish %s's composer is built against %v, want x/go at v0.1.9", node, a.Packages) + } + } + for _, key := range keys { + if got := atPut[key]; got != "waits , bound " { + t.Errorf("as the run ask of %s was put its wait stood: %s; want waits and the bound gone (§720: an ask in the queue has no clock)", key, got) + } + } + } if req.Depth != composer.DepthCompose || req.BlameTries != 20 || len(req.Machines) != 1 || req.Machines[0] != "ace" || len(req.Cases) != 1 || req.Cases[0].Name != changeCase || string(req.Input) != `{"node":"ace"}` || len(req.Seats) != 1 || string(req.Seats[0]) != `{"seat":"s1"}` { t.Errorf("the request of ace %+v", req) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns.go index 22d713664..9aab4f502 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns.go @@ -60,16 +60,35 @@ type runSettings struct { kept, stepBound, untaken time.Duration // blameTries is blame-tries, carried in each run's request (§721). blameTries int + // packageWait is package-wait-minutes: how long a run waits for the publish of a package its entry names with no version + // before it ends could not run naming the package, counted from the time its wait began (design 47 H2 H-A-628 (3), H-A-629 (3)). + packageWait time.Duration } // defaultRunSettings are the settings' defaults, as the manifest gives them. -var defaultRunSettings = runSettings{capBytes: 16 << 20, kept: 24 * time.Hour, stepBound: 30 * time.Minute, untaken: 24 * time.Hour, blameTries: 20} +var defaultRunSettings = runSettings{capBytes: 16 << 20, kept: 24 * time.Hour, stepBound: 30 * time.Minute, untaken: 24 * time.Hour, blameTries: 20, + packageWait: 10 * time.Minute} + +// packageWaitUnit is the unit of the setting package-wait-minutes, a minute; the whole test sets a shorter one, so a run's wait +// passes its bound within the test (as tierBoundUnit). +var packageWaitUnit = time.Minute + +// packageWaitSetting names the setting package-wait-minutes in a run's words. +const packageWaitSetting = "package-wait-minutes" // runSettingsOf reads the settings composition-runs-cap-mib, composition-runs-kept, composition-step-bound, -// run-untaken-bound and blame-tries from the files the environment names (A-469x, as outsideSettings): a missing or empty -// file is its default; a content that is no positive whole number or Go duration is an error naming the file. +// run-untaken-bound, blame-tries and package-wait-minutes from the files the environment names (A-469x, as outsideSettings): a +// missing or empty file is its default; a content that is no positive whole number or Go duration is an error naming the file. func runSettingsOf(getenv func(string) string) (runSettings, error) { s := defaultRunSettings + s.packageWait = 10 * packageWaitUnit + minutes, err := settingFile(getenv("MESH_ASSIGNER_PACKAGE_WAIT_FILE")) + if err != nil { + return s, err + } + if minutes > 0 { + s.packageWait = time.Duration(minutes) * packageWaitUnit + } mib, err := settingFile(getenv("MESH_ASSIGNER_COMPOSITION_RUNS_CAP_MIB_FILE")) if err != nil { return s, err @@ -255,6 +274,9 @@ type compositionRuns struct { mu sync.Mutex // changed is closed and replaced at each change of the state heard (heard): a step waiting on a run reads its key again. changed chan struct{} + // published is closed and replaced at each package-published of the seat mesh-builds heard (heardPublished): a run waiting for + // a package's publish asks published again (design 47 H2 H-A-628 (3), H-A-326). + published chan struct{} // seen are the keys the state's watch handed and has not seen deleted: a listing of the bucket misses a key that is // being written at that moment, so every lookup takes these beside it (keys). seen map[string]bool @@ -268,7 +290,57 @@ type compositionRuns struct { } func newCompositionRuns(kv runsKV, set runSettings, now func() time.Time, logf func(string, ...any)) *compositionRuns { - return &compositionRuns{kv: kv, set: set, now: now, logf: logf, changed: make(chan struct{})} + return &compositionRuns{kv: kv, set: set, now: now, logf: logf, changed: make(chan struct{}), published: make(chan struct{})} +} + +// heardPublished wakes every run waiting for a package's publish, at the seat mesh-builds' package-published heard and at each +// bind of the assigner's consumer (an event said before it was made is not delivered): each reads published again, the event +// only its second path (design 47 H2 H-A-628 (3); H-A-326, H-A-328). +func (r *compositionRuns) heardPublished() { + r.mu.Lock() + close(r.published) + r.published = make(chan struct{}) + r.mu.Unlock() +} + +// publishWake is closed at the next package-published heard. +func (r *compositionRuns) publishWake() <-chan struct{} { + r.mu.Lock() + defer r.mu.Unlock() + return r.published +} + +// waitFor writes on the run of ask the package it waits for, `waits` (design 47 H2 H-A-629 (1)), by compare-and-set: the time +// its wait began is kept where the run holds one already (a start taken up again, H-A-629 (3)), else it is now. It answers that +// time, and false when the key holds another run, or the run ended or has its program. +func (r *compositionRuns) waitFor(key, ask, path string) (time.Time, bool, error) { + var since time.Time + held := false + _, _, err := r.change(key, func(c *meshwants.CompositionRun) bool { + if held = c.Ask == ask && c.Ended == nil && c.Program == nil; !held { + return false + } + since = r.now().UTC() + if c.Waits != nil { + since = c.Waits.Since + if c.Waits.Package == path { + return false + } + } + c.Waits = &meshwants.CompositionRunWaits{Package: path, Since: since} + return true + }) + return since, held, err +} + +// pastWaitSaid is the end of a run of machine whose wait for the publish of the package path passed package-wait-minutes (design +// 47 H2 H-A-628 (3)). +func (r *compositionRuns) pastWaitSaid(machine, path string) string { + said := fmt.Sprintf("package %s has no published version within %s (%s)", path, r.set.packageWait, packageWaitSetting) + if machine != "" { + said = machine + ": " + said + } + return said } // heard takes a change of the state from its watch (a module watches its own state, principle 1). @@ -642,6 +714,7 @@ func (r *compositionRuns) end(key, ask, outcome, said string, verdict map[string } at := r.now().UTC() c.Ended, c.Outcome, c.Said, c.Verdict = &at, outcome, said, verdict + c.Waits = nil // a run's wait ends with it (H-A-629 (1)) ended = true return true }) @@ -702,6 +775,11 @@ func (r *compositionRuns) heardEnd(e buildstep.StepEnded, read func(buildstep.St // await waits until each run of keys has ended, through the state's changes heard, or ctx ends: it answers each run as it // stands then; a key gone could not run. func (r *compositionRuns) await(ctx context.Context, keys []string) map[string]meshwants.CompositionRun { + return r.awaitEach(ctx, keys, nil) +} + +// awaitEach is await, handing each read of the runs, as they stand, to each before it waits again; nil hands none. +func (r *compositionRuns) awaitEach(ctx context.Context, keys []string, each func(map[string]meshwants.CompositionRun)) map[string]meshwants.CompositionRun { out := map[string]meshwants.CompositionRun{} for { wake := r.wake() @@ -722,6 +800,9 @@ func (r *compositionRuns) await(ctx context.Context, keys []string) map[string]m } out[key] = run } + if each != nil { + each(out) + } if !open { return out } diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns_test.go index 7a0ccf151..61dbef4fa 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns_test.go @@ -324,7 +324,8 @@ func TestACompositionRunIsOneKeyPerCandidateAndMachine(t *testing.T) { t.Run("settings", func(t *testing.T) { dir := t.TempDir() files := map[string]string{"MESH_ASSIGNER_COMPOSITION_RUNS_CAP_MIB_FILE": "8", "MESH_ASSIGNER_COMPOSITION_RUNS_KEPT_FILE": "2h", - "MESH_ASSIGNER_COMPOSITION_STEP_BOUND_FILE": "2s", "MESH_ASSIGNER_RUN_UNTAKEN_BOUND_FILE": "", "MESH_ASSIGNER_BLAME_TRIES_FILE": "5"} + "MESH_ASSIGNER_COMPOSITION_STEP_BOUND_FILE": "2s", "MESH_ASSIGNER_RUN_UNTAKEN_BOUND_FILE": "", "MESH_ASSIGNER_BLAME_TRIES_FILE": "5", + "MESH_ASSIGNER_PACKAGE_WAIT_FILE": "3"} // package-wait-minutes in minutes (design 47 H2 H-A-628 (3)) env := map[string]string{} for name, content := range files { p := filepath.Join(dir, name) @@ -334,7 +335,8 @@ func TestACompositionRunIsOneKeyPerCandidateAndMachine(t *testing.T) { env[name] = p } s, err := runSettingsOf(func(k string) string { return env[k] }) - if err != nil || s.capBytes != 8<<20 || s.kept != 2*time.Hour || s.stepBound != 2*time.Second || s.untaken != 24*time.Hour || s.blameTries != 5 { + if err != nil || s.capBytes != 8<<20 || s.kept != 2*time.Hour || s.stepBound != 2*time.Second || s.untaken != 24*time.Hour || s.blameTries != 5 || + s.packageWait != 3*time.Minute { t.Errorf("settings %+v %v", s, err) } _ = os.WriteFile(env["MESH_ASSIGNER_COMPOSITION_STEP_BOUND_FILE"], []byte("30"), 0o600) 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 51528de73..c89da0004 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 @@ -7,6 +7,7 @@ import ( "encoding/json" "fmt" "strings" + "sync/atomic" "testing" "time" @@ -16,6 +17,7 @@ import ( "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient/enginereads" "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshwatchdogs" + meshbuilds "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo" @@ -31,8 +33,25 @@ import ( // machine on the Go build seat's check queue under its name, its program the node-engine build each machine runs; the stand-in // build seat reads each request by the seat mesh-wants' verb input in chunks and says its step-ended with the composer's verdict; // the step's step-ended fails naming the machine that does not compose, warns of the machine away, and no input stays kept. +// 1984/AC11 (design 47 H2 H-A-628 (2) to (5), H-A-629): the node-engine's entry names the package x/go with no version, and x's +// build in the step's revision publishes it: each run waits while the seat mesh-builds' published answers not published, and +// puts its run ask with x/go at the version published once the package-published is heard; a restart during the wait takes the +// runs up, the one past package-wait-minutes ending could not run naming the package, the other's start run again composing +// after a publish heard while the assigner was down; a run whose wait passes its bound ends could not run naming the package +// and the bound, never "no pin … the builder pins or waits", with no run ask put. func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T) { b := startBed(t, "") + t.Cleanup(func() { + if t.Failed() { + b.journal.mu.Lock() + t.Log(b.journal.text.String()) + b.journal.mu.Unlock() + } + }) + packageWaitUnit = time.Second // package-wait-minutes in seconds at the test's unit + t.Cleanup(func() { packageWaitUnit = time.Minute }) + b.settings = map[string]string{"MESH_ASSIGNER_PACKAGE_WAIT_FILE": "30"} + const pkg = "git.novox.be/novox/x/go" nc, err := nats.Connect(b.srv.ClientURL()) if err != nil { t.Fatal(err) @@ -43,7 +62,7 @@ func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T) // machine-back, as the grants part derives them from its consumes; what each node runs it hears on its kept stream (the bed's). if _, err := b.js.CreateOrUpdateConsumer(b.ctx, "EVENTS", jetstream.ConsumerConfig{Durable: "n1_mesh-delivery-assigner", FilterSubjects: []string{enginereads.SubjectPrefix + "*", "mesh.mod." + buckets.IndexerModule + ".event.views.>", meshcatalog.SubjectCatalogRevisionAll, - nodebuildgo.SubjectStepEndedAll, meshwatchdogs.SubjectMachineAwayAll, meshwatchdogs.SubjectMachineBackAll}, AckPolicy: jetstream.AckExplicitPolicy}); err != nil { + nodebuildgo.SubjectStepEndedAll, meshwatchdogs.SubjectMachineAwayAll, meshwatchdogs.SubjectMachineBackAll, meshbuilds.SubjectPackagePublished}, AckPolicy: jetstream.AckExplicitPolicy}); err != nil { t.Fatal(err) } for _, node := range []string{"n1", "n2"} { @@ -59,10 +78,12 @@ func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T) } // The trunk's catalog half holds the module and the node-engine, the module claiming the seat node-engine. engine := meshcatalog.CatalogEntry{Module: "engine", Fp: "src2:e1", Repository: "novox/mesh-host", Commit: engineCommit, Path: ".", - Serves: []string{nodeengine.Seat + ".composition"}, Manifest: map[string]any{"module": "engine", "version": "0.1"}} + Serves: []string{nodeengine.Seat + ".composition"}, Manifest: map[string]any{"module": "engine", "version": "0.1"}, Packages: map[string]string{pkg: ""}} b.cat.mu.Lock() b.cat.entries[trunkBranch] = map[string]meshcatalog.CatalogEntry{"engine": engine, - "m": {Module: "m", Fp: "src2:m1", Repository: "novox/m", Commit: engineCommit, Path: ".", Manifest: map[string]any{"module": "m", "version": "0.1"}}} + "m": {Module: "m", Fp: "src2:m1", Repository: "novox/m", Commit: engineCommit, Path: ".", Manifest: map[string]any{"module": "m", "version": "0.1"}}, + "x": {Module: "x", Fp: "src2:x1", Repository: "novox/x", Commit: engineCommit, Path: ".", Manifest: map[string]any{"module": "x", "version": "0.1"}, + Artifacts: []meshcatalog.Artifact{{Ref: "x:go", Language: "go", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: pkg}}}}} b.cat.rev[trunkBranch] = 3 b.cat.mu.Unlock() for _, node := range []string{"n1", "n2", "n3"} { @@ -72,7 +93,10 @@ func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T) asked := make(chan string, 8) engines, err := nc.Subscribe("mesh.seat.node-engine.call.compose-candidate.*.*", func(m *nats.Msg) { node := strings.Split(m.Subject, ".")[5] - asked <- node + select { // the first step's asks are read; a later step's runs ask again + case asked <- node: + default: + } raw, _ := json.Marshal(map[string]any{"result": map[string]any{"candidate": "main.3", "node": node, "verdict": "composed", "input": map[string]any{"node": node}, "modules": []any{}, "own": map[string]any{}, "took": 1, "v": 1}, "node": node}) _ = m.Respond(raw) @@ -90,9 +114,23 @@ func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T) t.Fatal(err) } t.Cleanup(func() { _ = entries.Unsubscribe() }) + // The seat mesh-builds' published answers x's build published at 0.1.9 once pub is set (H-A-328). + var pub atomic.Bool + publishedAsks, err := nc.Subscribe("mesh.seat.mesh-builds.call.published.*", func(m *nats.Msg) { + a := meshbuilds.PublishedAnswer{} + if pub.Load() { + a = meshbuilds.PublishedAnswer{Published: true, Version: "0.1.9"} + } + raw, _ := json.Marshal(map[string]any{"result": a, "node": "n0"}) + _ = m.Respond(raw) + }) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = publishedAsks.Unsubscribe() }) subscribed(t, nc) // The runner hears the step's end. - ended := make(chan meshwants.StepEnded, 1) + ended := make(chan meshwants.StepEnded, 8) ends, err := nc.Subscribe("mesh.seat.mesh-wants.event.step-ended.n1", func(m *nats.Msg) { var e meshwants.StepEnded _ = json.Unmarshal(m.Data, &e) @@ -105,7 +143,7 @@ func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T) subscribed(t, nc) from := b.journal.mark() - b.start(t) + _, stop := b.startStoppable(t) b.journal.await(t, from, "the composition step is pulled from", "the composition step served", 30*time.Second) b.journal.await(t, from, "n3 is away (machine-away)", "the machine-away of n3 heard", 30*time.Second) @@ -116,6 +154,16 @@ func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T) } 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"}) + // 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) + } + b.journal.await(t, from, "the composition step of m says fetch", "the step says fetch", 30*time.Second) + pub.Store(true) + published, _ := json.Marshal(meshbuilds.PackagePublished{V: 1, Module: "x", Artifact: "x:go", Version: "0.1.9", Digest: "sha256:x", Branch: trunkBranch, Source: 3}) + if _, err := b.js.Publish(b.ctx, meshbuilds.SubjectPackagePublished, published); err != nil { + t.Fatal(err) + } // The stand-in Go build seat takes the run asks put under the assigner's name, reads each request by the verb input and says // its end with the composer's verdict: n1 composes, n2 does not. @@ -146,6 +194,9 @@ func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T) } node := req.Machines[0] programs[node] = a.Run.Program.Commit + if a.Packages[pkg] != "v0.1.9" { + t.Errorf("the composer of %s is built against %v, want x/go at v0.1.9 from published", node, a.Packages) + } m := composer.Machine{Composes: true} if node == "n2" { m = composer.Machine{Reason: "two modules own one path", Problems: []string{"/etc/x"}} @@ -170,10 +221,14 @@ func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T) if programs["n1"] != engineCommit || programs["n2"] != engineCommit { t.Errorf("the composers were built at %v, want the node-engine build each machine runs", programs) } - close(asked) - for node := range asked { - if node == "n3" { - t.Error("the machine away was asked for its input") + for drained := false; !drained; { + select { + case node := <-asked: + if node == "n3" { + t.Error("the machine away was asked for its input") + } + default: + drained = true } } // The run's end comes before the input's delete (A-470o, A-470p): the inputs go after the step's end, heard by their watch. @@ -196,6 +251,99 @@ func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T) } } queueEmpty(b.ctx, t, b.js) // the step's ask acknowledged at its end (design 47 H2 §777) + + // A restart during the wait (H-A-629 (3)): the runs of the next revision wait, the assigner stops, n2's wait is aged past + // package-wait-minutes as if the assigner were down that long, and x/go is published with no event heard. The start takes + // both up: n2's ends could not run naming the package; n1's start runs again, reads published first and composes. + revision := func(n int64) { + b.cat.mu.Lock() + b.cat.rev[trunkBranch] = n + b.cat.mu.Unlock() + } + stepEnd := func(id string) meshwants.StepEnded { + t.Helper() + for { + select { + case e := <-ended: + if e.ID == id { + return e + } + case <-time.After(30 * time.Second): + t.Fatalf("the step %s said no end within 30 s", id) + } + } + } + pub.Store(false) + revision(4) + from = b.journal.mark() + putStep(b.ctx, t, b.js, "step-ask-2", meshwants.StepRun{Pipeline: "main.4.m", Step: meshwants.StepRunStepComposition, Module: "m", Branch: trunkBranch, + Revision: 4, Commit: engineCommit, Fingerprint: "src2:m1"}) + for _, node := range []string{"n1", "n2"} { + b.journal.await(t, from, "the composition run main=2e4."+node+" waits for package "+pkg, "the run of "+node+" waits", 30*time.Second) + } + stop() + runs := b.buckets[buckets.CompositionRuns()] + e2, err := runs.Get(b.ctx, "main=2e4.n2") + if err != nil { + t.Fatal(err) + } + var waiting meshwants.CompositionRun + if err := json.Unmarshal(e2.Value(), &waiting); err != nil || waiting.Waits == nil || waiting.Waits.Package != pkg || waiting.Program != nil { + t.Fatalf("the waiting run of n2 holds %s (%v), want waits naming x/go and no program", e2.Value(), err) + } + waiting.Waits.Since = waiting.Waits.Since.Add(-time.Hour) + aged, _ := json.Marshal(waiting) + if _, err := runs.Update(b.ctx, "main=2e4.n2", aged, e2.Revision()); err != nil { + t.Fatal(err) + } + pub.Store(true) + from = b.journal.mark() + _, stop = b.startStoppable(t) + b.journal.await(t, from, "the composition run main=2e4.n1, waiting for package "+pkg, "the run of n1 taken up", 30*time.Second) + got, err := worker.Next(jetstream.FetchMaxWait(30 * time.Second)) + if err != nil { + t.Fatalf("no run ask is put after the restart: %v", err) + } + _ = got.Ack() + a, err := buildstep.DecodeStepAsk(got.Data()) + if err != nil || a.Run == nil || a.Packages[pkg] != "v0.1.9" { + t.Fatalf("the run ask after the restart %+v (%v), want x/go at v0.1.9", a, err) + } + if req, err := composer.Decode(readInput(t, nc, a.Run.Input)); err != nil || len(req.Machines) != 1 || req.Machines[0] != "n1" { + t.Fatalf("the run ask after the restart composes %+v (%v), want n1", req.Machines, err) + } + v, _ := json.Marshal(composer.Verdict{V: composer.Version, Cases: []composer.CaseVerdict{{Name: changeCase, Machines: map[string]composer.Machine{"n1": {Composes: true}}}}}) + end, _ := json.Marshal(buildstep.StepEnded{V: 1, ID: a.ID, Ask: a.ID, Asker: runAsker, Node: "b1", Outcome: buildstep.OutcomePassed, Output: string(v), At: time.Now().UTC()}) + if _, err := b.js.Publish(b.ctx, nodebuildgo.SubjectStepEnded("b1"), end); err != nil { + t.Fatal(err) + } + if e := stepEnd("step-ask-2"); e.Outcome != meshwants.StepEndedOutcomeCouldNotRun || strings.Contains(e.Said, "the builder pins or waits") || + !strings.Contains(e.Said, "n2: package "+pkg+" has no published version within 30s (package-wait-minutes)") || strings.Contains(e.Said, "n1") { + t.Fatalf("the step taken up ended %+v, want could not run naming n2's package past its bound alone", e) + } + + // Past the bound while running (H-A-628 (3), (4)): with package-wait-minutes at one, nothing is published, the bound's expiry + // ends each run could not run naming the package and the bound, and no run ask is put. + stop() + b.settings["MESH_ASSIGNER_PACKAGE_WAIT_FILE"] = "1" + pub.Store(false) + revision(5) + from = b.journal.mark() + _, stop = b.startStoppable(t) + b.journal.await(t, from, "the composition step is pulled from", "the composition step served again", 30*time.Second) + putStep(b.ctx, t, b.js, "step-ask-3", meshwants.StepRun{Pipeline: "main.5.m", Step: meshwants.StepRunStepComposition, Module: "m", Branch: trunkBranch, + Revision: 5, Commit: engineCommit, Fingerprint: "src2:m1"}) + e3 := stepEnd("step-ask-3") + for _, node := range []string{"n1", "n2"} { + if want := node + ": package " + pkg + " has no published version within 1s (package-wait-minutes)"; e3.Outcome != meshwants.StepEndedOutcomeCouldNotRun || + !strings.Contains(e3.Said, want) || strings.Contains(e3.Said, "the builder pins or waits") { + t.Fatalf("the step past its bound ended %+v, want could not run saying %q", e3, want) + } + } + if info, err := worker.Info(b.ctx); err != nil || info.NumPending != 0 || info.NumAckPending != 0 { + t.Errorf("run asks were put past the bound: %+v %v", info, err) + } + stop() } // readInput reads a run's input as a build seat does: the seat mesh-wants' verb input answers its digest and chunk count, then its diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go index 22e4783ac..d291c641e 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go @@ -10,6 +10,7 @@ import ( "context" "fmt" "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient" + meshbuilds "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" @@ -516,6 +517,15 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber, if err := hearRunBounds(hub, runs, logger.Printf); err != nil { logger.Printf("the build seats' ask-taken and step-progress are not heard, so a composition run is ended by no bound: %v", err) } + // The seat mesh-builds' package-published wakes a run waiting for a package's publish, which reads published again; so does + // each bind of the consumer, which hears no event said before it was made (design 47 H2 H-A-628 (3); H-A-326, H-A-328). + if err := hub.Handle(meshbuilds.SubjectPackagePublished, func(m jetstream.Msg) { + runs.heardPublished() + _ = m.Ack() + }); err != nil { + logger.Printf("the seat mesh-builds' package-published is not heard, so a composition run waiting for a package reads published only at its start: %v", err) + } + hub.OnBound(func(time.Time) { runs.heardPublished() }) } if inputs != nil { var runEnded func(buildstep.StepEnded) error @@ -699,7 +709,8 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber, runs.moved.Store(&move) // The state's watch wakes the steps waiting on a run and hears a bound's expiry; the runs standing at the start are taken up // once the values that stand are read (§719, §720). - if err := watchRuns(ctx, kvs[buckets.CompositionRuns()], runs, runs.expired, func() { steps.takeUp(ctx, runs) }); err != nil { + // A run still waiting for a package's publish has its start run again (H-A-629 (3)). + if err := watchRuns(ctx, kvs[buckets.CompositionRuns()], runs, runs.expired, func() { steps.takeUp(ctx, runs); run.takeUpWaits(ctx) }); err != nil { return fmt.Errorf("the state %s is not watched: %w", buckets.CompositionRunsState, err) } // The runs' read and drop, the seat mesh-wants' verbs compositions and compositions-drop (§728, A-469f), answered here 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 54a609a12..6ebc5eb41 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep.go @@ -92,8 +92,7 @@ func (r *compositionRun) resumeValidate(ctx context.Context, _ string, step mesh // readValidate waits for the end of the validate run of key and judges the step from it. func (r *compositionRun) readValidate(ctx context.Context, key string, step meshwants.StepRun) stepOutcome { setShared(ctx, r.runs.sharedOf([]string{key}, nil)) - setPhase(ctx, meshwants.StepProgressEventPhaseRun) - run := r.runs.await(ctx, []string{key})[key] + run := r.runs.awaitEach(ctx, []string{key}, r.sayingWaits(ctx, "the validate step of "+step.Module))[key] setPhase(ctx, meshwants.StepProgressEventPhaseReport) out := r.judgeValidate(ctx, step, run) out.Shared = r.runs.sharedOf([]string{key}, map[string]meshwants.CompositionRun{key: run}) @@ -288,13 +287,11 @@ func (r *compositionRun) startValidate(ctx context.Context, key string, run mesh return } program.Package = validatorPackage - pins, waiting, err := r.filledPins(ctx, "the manifest validator's entry "+entry.Fp, pinsOfEntry(entry), publishersOf(half.Entries)) - if err != nil { - couldNot(err.Error()) - return - } - if len(waiting) > 0 { - couldNot(unpublishedSaid(waiting)) + pins, said, ok := r.awaitPins(ctx, key, ask, "the manifest validator's entry "+entry.Fp, pinsOfEntry(entry), publishersOf(half.Entries)) + if !ok { + if said != "" { // else the run ended or was replaced while it waited, or the step's wait ended + couldNot(said) + } return } seats, list, err := r.validateSeats(ctx, ask, half.Revision.Definitions) @@ -336,6 +333,7 @@ func (r *compositionRun) startValidate(ctx context.Context, key string, run mesh } c.Program = &meshwants.CompositionRunProgram{Repository: program.Repository, Commit: program.Commit, Directory: program.Dir, Fingerprint: entry.Fp} c.Input = digest + c.Waits = nil // its wait ends as its run ask is put (H-A-629 (1)) return true }); err != nil { couldNot("the run's program and input are not written: " + err.Error()) diff --git a/modules/mesh-delivery-assigner/manifest_test.go b/modules/mesh-delivery-assigner/manifest_test.go index bf784b1f1..4d6b406f2 100644 --- a/modules/mesh-delivery-assigner/manifest_test.go +++ b/modules/mesh-delivery-assigner/manifest_test.go @@ -153,7 +153,7 @@ func TestManifest(t *testing.T) { // issue 1966 note 151: and the teller's ask-ended, its subject the one the assigner hears; §389: the watchman's machine-away // and machine-back, read whole at its start. A1/AC1 (design 47 H §750, §764): no version-delivered, delivery-waits, // delivered-again or assigner_delivered_again: a want waits on no dependency's delivery. - if !slices.Equal(m.Consumes, []string{"mesh-conditions.findings-asked", "mesh-conditions.condition-raised", "mesh-conditions.condition-changed", "mesh-conditions.condition-cleared", "mesh-catalog.catalog-revision", "mesh-catalog.registration-changed", "mesh-delivery.source-moved", "mesh-catalog.version-released", "mesh-watchdogs.machine-away", "mesh-watchdogs.machine-back", "mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed", builds.BuilderModule + "." + builds.BuildsStreamEvents, buckets.TellerModule + "." + tellerevents.AskEnded, buckets.TellerModule + ".views." + buckets.AnswersState, "mesh-pipeline-runner.pipeline-ended", "node-build-go.step-ended", "node-build-go.ask-taken", "node-build-go.step-progress", "node-engine.manifest-reads-changed", "node-engine.running"}) { + if !slices.Equal(m.Consumes, []string{"mesh-conditions.findings-asked", "mesh-conditions.condition-raised", "mesh-conditions.condition-changed", "mesh-conditions.condition-cleared", "mesh-catalog.catalog-revision", "mesh-catalog.registration-changed", "mesh-delivery.source-moved", "mesh-catalog.version-released", "mesh-watchdogs.machine-away", "mesh-watchdogs.machine-back", "mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed", builds.BuilderModule + "." + builds.BuildsStreamEvents, "mesh-builds.package-published", buckets.TellerModule + "." + tellerevents.AskEnded, buckets.TellerModule + ".views." + buckets.AnswersState, "mesh-pipeline-runner.pipeline-ended", "node-build-go.step-ended", "node-build-go.ask-taken", "node-build-go.step-progress", "node-engine.manifest-reads-changed", "node-engine.running"}) { t.Errorf("consumes = %v, want the catalog half's revisions (design 47 G §195), the teller's ask-ended, the engines' reads changed and what they run", m.Consumes) } if want := []string{"mesh-delivery-indexer.manifests", "mesh-delivery-indexer.modules", @@ -185,9 +185,11 @@ func TestManifest(t *testing.T) { } file, _ := os.ReadFile("module.json") if err := json.Unmarshal(file, &raw); err != nil || raw.Config["outside-wait-minutes"].Default != float64(30) || raw.Config["outside-settle-seconds"].Default != float64(90) || - raw.Config["ask-operator-for"].Default != "take-off,remove-node,stops" || len(raw.Config) != 15 || raw.Config["tier-bound"].Default != float64(30) || raw.Config["entry-asks"].Default != float64(5) || + raw.Config["ask-operator-for"].Default != "take-off,remove-node,stops" || len(raw.Config) != 16 || raw.Config["tier-bound"].Default != float64(30) || raw.Config["entry-asks"].Default != float64(5) || raw.Config["composition-runs-cap-mib"].Default != float64(16) || raw.Config["composition-runs-kept"].Default != "24h" || raw.Config["composition-step-bound"].Default != "30m" || raw.Config["run-untaken-bound"].Default != "24h" || raw.Config["blame-tries"].Default != float64(20) || + // design 47 H2 H-A-628 (3): the bound of a run's wait for a package's publish, the builder's default + raw.Config["package-wait-minutes"].Default != float64(10) || // design 47 H2 §775, H-A-381 (2): the taken key's bound and the kept-call pace, runtime settings raw.Config["ask-taken-bound"].Default != "10m" || raw.Config["kept-call-pace-first"].Default != "1s" || raw.Config["kept-call-pace-max"].Default != "30s" || raw.Config["compose-ask-bound"].Default != "10s" || raw.Config["keeping-retry"].Default != "30s" { t.Errorf("config = %+v (%v), want outside-wait-minutes of 30, outside-settle-seconds of 90 and ask-operator-for of take-off,remove-node,stops (A-425a)", raw.Config, err) @@ -202,8 +204,9 @@ func TestManifest(t *testing.T) { {"MESH_ASSIGNER_COMPOSITION_STEP_BOUND_FILE", "${dir:state}/composition-step-bound", "composition-step-bound"}, {"MESH_ASSIGNER_RUN_UNTAKEN_BOUND_FILE", "${dir:state}/run-untaken-bound", "run-untaken-bound"}, {"MESH_ASSIGNER_BLAME_TRIES_FILE", "${dir:state}/blame-tries", "blame-tries"}, - {"MESH_ASSIGNER_TIER_BOUND_FILE", "${dir:state}/tier-bound", "tier-bound"}, // design 47 H §751 - {"MESH_ASSIGNER_ENTRY_ASKS_FILE", "${dir:state}/entry-asks", "entry-asks"}, // design 47 H H-A-60 + {"MESH_ASSIGNER_PACKAGE_WAIT_FILE", "${dir:state}/package-wait-minutes", "package-wait-minutes"}, // design 47 H2 H-A-628 (3) + {"MESH_ASSIGNER_TIER_BOUND_FILE", "${dir:state}/tier-bound", "tier-bound"}, // design 47 H §751 + {"MESH_ASSIGNER_ENTRY_ASKS_FILE", "${dir:state}/entry-asks", "entry-asks"}, // design 47 H H-A-60 } { if !strings.Contains(string(file), `"`+f.env+`": "`+f.path+`"`) || !strings.Contains(string(file), `"path": "`+f.path+`"`) || !strings.Contains(string(file), `"content": "${config:`+f.key+`}"`) { diff --git a/modules/mesh-delivery-assigner/module.json b/modules/mesh-delivery-assigner/module.json index b5974c67e..d2266001d 100644 --- a/modules/mesh-delivery-assigner/module.json +++ b/modules/mesh-delivery-assigner/module.json @@ -56,6 +56,7 @@ "mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed", "mesh-delivery-builder.build.ended.**", + "mesh-builds.package-published", "mesh-delivery-teller.ask-ended", "mesh-delivery-teller.views.answers", "mesh-pipeline-runner.pipeline-ended", @@ -230,6 +231,14 @@ "trusted": false, "default": "24h" }, + "package-wait-minutes": { + "type": "number", + "description": "minutes a composition or validate run waits for the publish of a mesh package its entry names with no version, counted from the time its wait began, before it ends could not run naming the package (design 47 H2 H-A-628 (3), H-A-629 (3)); the builder's range and default.", + "minimum": 1, + "maximum": 120, + "trusted": false, + "default": 10 + }, "blame-tries": { "type": "number", "description": "the most compositions a machine's composer makes to find the modules it blames, carried in the run's request as blame_tries (design 47 G section 721, A-466r).", @@ -369,6 +378,14 @@ "mode": "0600", "content": "${config:run-untaken-bound}" }, + { + "id": "package-wait-minutes", + "type": "file", + "path": "${dir:state}/package-wait-minutes", + "owner": "mesh-delivery-assigner", + "mode": "0600", + "content": "${config:package-wait-minutes}" + }, { "id": "blame-tries", "type": "file", @@ -396,7 +413,8 @@ "MESH_ASSIGNER_COMPOSITION_RUNS_KEPT_FILE": "${dir:state}/composition-runs-kept", "MESH_ASSIGNER_COMPOSITION_STEP_BOUND_FILE": "${dir:state}/composition-step-bound", "MESH_ASSIGNER_RUN_UNTAKEN_BOUND_FILE": "${dir:state}/run-untaken-bound", - "MESH_ASSIGNER_BLAME_TRIES_FILE": "${dir:state}/blame-tries" + "MESH_ASSIGNER_BLAME_TRIES_FILE": "${dir:state}/blame-tries", + "MESH_ASSIGNER_PACKAGE_WAIT_FILE": "${dir:state}/package-wait-minutes" }, "user": "mesh-delivery-assigner", "health": { diff --git a/modules/mesh-delivery-contracts/go/seats/meshwants/contract.go b/modules/mesh-delivery-contracts/go/seats/meshwants/contract.go index 8f93ec1c9..5c93d9967 100644 --- a/modules/mesh-delivery-contracts/go/seats/meshwants/contract.go +++ b/modules/mesh-delivery-contracts/go/seats/meshwants/contract.go @@ -14,13 +14,13 @@ const Seat = "mesh-wants" // Form is the form of the seat's values, events and answers this contract was generated at (design 47 H2 §780): // a reader of a value of another form says "form N, this reader knows M". -const Form = 2 +const Form = 3 // The forms and the digest of the fields this contract was generated from: the generator's compare fails a definition // whose fields changed while its forms did not (design 47 H2 §780). const ( - generatedForms = "2" - generatedFieldsDigest = "Ask=6cb8b82e2fbe AskTakenEvent=6d5d3da7ac39 AsksByAssignmentsProposalValue=0bb5682c7b3b AsksByBackupNodeModuleFingerprintValue=0bb5682c7b3b AsksByHoldModuleFingerprintValue=0bb5682c7b3b AsksByOutsideNodeModuleFingerprintValue=0bb5682c7b3b AsksByRecordNodeModuleDigestValue=0bb5682c7b3b AsksByRestoreNodeModuleFingerprintValue=0bb5682c7b3b AsksByRevertNodeModuleFingerprintValue=0bb5682c7b3b AssignmentEntry=7d2549782eb2 AssignmentRevision=72c8701f7314 AssignmentRevisionCapabilitiesItem=0c89b0717762 AssignmentRevisionEvent=7faff968ce44 AssignmentRevisionsByCandidateGroupHeadsValue=8553b390118d AssignmentRevisionsByEntryDigestValue=4e5ee7a23e5b AssignmentRevisionsByTrunkRevisionValue=8553b390118d BusAnswer=7538f2f5e68e CatalogOf=7a4646fdbea7 Change=28d1f3c5cd32 ChangeAfterItem=30d718c21581 CompositionReader=5a943c1f8ef1 CompositionRun=a64bc503c99a CompositionRunProgram=5a1202df3497 CompositionsAnswer=f8bca93c7f9c CompositionsByGroupHeadsValue=9428965fab8f CompositionsDropAnswer=52803700282a Difference=4011cff516b1 DifferenceAnswer=629237aa39f0 DifferenceEvent=49066d0dff6d DifferenceRefusedItem=0e9caa83ace7 DifferencesByNodeModuleValue=a22487ffadfd DropAnswer=7538f2f5e68e Edge=a71709025a08 EntryAnswer=05adebad70d6 Fill=80f442916429 FillingEvent=5bd4df78ed84 FullEvent=5bd4df78ed84 Held=15abbd6a1a33 HeldCandidate=04872f6afbfa InputAnswer=cd41ee65565d KeepNowAnswer=9962ab9fc051 NodeEntryRef=3888ae847653 NotRunning=279b628db0ec PipelineWanted=e1e379c21e59 PipelineWantedEvent=59946b31ab7d PolicyChangedEvent=7538f2f5e68e RevisionAnswer=39002c770cbd RoomEvent=5bd4df78ed84 Shared=c981cf6aa860 SharedAskedBy=c9b30cc4d0d0 StepAccept=18efeefb6c34 StepEnded=edd08ab1a18b StepEndedEvent=207787118dac StepProgressEvent=8215e490ea8d StepRun=b975f402601a UpgradeAnswer=7538f2f5e68e Wait=951500be820c WaitEndedEvent=2bf6d38041c0 WaitHeldEvent=2bf6d38041c0 WantedEvent=58cf7a9f646b WantsByHeldModuleFingerprintValue=ff14aa998a5d WantsByWantNodeModuleValue=ab7c6799fd5d WantsByWantNodeNodeValue=a737a2108d53" + generatedForms = "3" + generatedFieldsDigest = "Ask=6cb8b82e2fbe AskTakenEvent=6d5d3da7ac39 AsksByAssignmentsProposalValue=0bb5682c7b3b AsksByBackupNodeModuleFingerprintValue=0bb5682c7b3b AsksByHoldModuleFingerprintValue=0bb5682c7b3b AsksByOutsideNodeModuleFingerprintValue=0bb5682c7b3b AsksByRecordNodeModuleDigestValue=0bb5682c7b3b AsksByRestoreNodeModuleFingerprintValue=0bb5682c7b3b AsksByRevertNodeModuleFingerprintValue=0bb5682c7b3b AssignmentEntry=7d2549782eb2 AssignmentRevision=72c8701f7314 AssignmentRevisionCapabilitiesItem=0c89b0717762 AssignmentRevisionEvent=7faff968ce44 AssignmentRevisionsByCandidateGroupHeadsValue=8553b390118d AssignmentRevisionsByEntryDigestValue=4e5ee7a23e5b AssignmentRevisionsByTrunkRevisionValue=8553b390118d BusAnswer=7538f2f5e68e CatalogOf=7a4646fdbea7 Change=28d1f3c5cd32 ChangeAfterItem=30d718c21581 CompositionReader=5a943c1f8ef1 CompositionRun=2a08fc65e2d0 CompositionRunProgram=5a1202df3497 CompositionRunWaits=92d1d2424265 CompositionsAnswer=f8bca93c7f9c CompositionsByGroupHeadsValue=9428965fab8f CompositionsDropAnswer=52803700282a Difference=4011cff516b1 DifferenceAnswer=629237aa39f0 DifferenceEvent=49066d0dff6d DifferenceRefusedItem=0e9caa83ace7 DifferencesByNodeModuleValue=a22487ffadfd DropAnswer=7538f2f5e68e Edge=a71709025a08 EntryAnswer=05adebad70d6 Fill=80f442916429 FillingEvent=5bd4df78ed84 FullEvent=5bd4df78ed84 Held=15abbd6a1a33 HeldCandidate=04872f6afbfa InputAnswer=cd41ee65565d KeepNowAnswer=9962ab9fc051 NodeEntryRef=3888ae847653 NotRunning=279b628db0ec PipelineWanted=e1e379c21e59 PipelineWantedEvent=59946b31ab7d PolicyChangedEvent=7538f2f5e68e RevisionAnswer=39002c770cbd RoomEvent=5bd4df78ed84 Shared=c981cf6aa860 SharedAskedBy=c9b30cc4d0d0 StepAccept=18efeefb6c34 StepEnded=edd08ab1a18b StepEndedEvent=207787118dac StepProgressEvent=8215e490ea8d StepRun=b975f402601a UpgradeAnswer=7538f2f5e68e Wait=951500be820c WaitEndedEvent=2bf6d38041c0 WaitHeldEvent=2bf6d38041c0 WantedEvent=58cf7a9f646b WantsByHeldModuleFingerprintValue=ff14aa998a5d WantsByWantNodeModuleValue=ab7c6799fd5d WantsByWantNodeNodeValue=a737a2108d53" ) const ( @@ -856,6 +856,14 @@ type CompositionRunProgram struct { Repository string `json:"repository,omitempty"` } +// CompositionRunWaits is the package the run waits for before its run ask is put, its publisher's build not yet published: written when the wait begins, deleted when the run ask is put or the run ends; absent while the run waits for nothing (design 47 H2 H-A-628 (3), H-A-629 (1)). +type CompositionRunWaits struct { + // the package's path + Package string `json:"package"` + // the time its wait began, which the bound package-wait-minutes counts from + Since time.Time `json:"since"` +} + // CompositionRun is one composition run of a candidate and a machine, a key of the assigner's state composition-runs (design 47 G §719, §728; A-469u). type CompositionRun struct { // the id of the build seat's run ask @@ -880,6 +888,8 @@ type CompositionRun struct { Unlisted []string `json:"unlisted,omitempty"` // that machine's composer verdict (design 47 G §721) Verdict map[string]any `json:"verdict,omitempty"` + // the package the run waits for before its run ask is put, its publisher's build not yet published: written when the wait begins, deleted when the run ask is put or the run ends; absent while the run waits for nothing (design 47 H2 H-A-628 (3), H-A-629 (1)) + Waits *CompositionRunWaits `json:"waits,omitempty"` } // The values of CompositionRun's outcome. diff --git a/modules/mesh-delivery-contracts/seats/mesh-wants/seat.json b/modules/mesh-delivery-contracts/seats/mesh-wants/seat.json index f9d926694..2ba3f893d 100644 --- a/modules/mesh-delivery-contracts/seats/mesh-wants/seat.json +++ b/modules/mesh-delivery-contracts/seats/mesh-wants/seat.json @@ -1807,6 +1807,25 @@ "type": "string" }, "description": "the module names of the assignments left out of the machine's composition, those no watched branch's newest revision lists, written when the run starts and read by every step's judgement and by the resume (design 47 H-A-152, H-A-153)" + }, + "waits": { + "type": "object", + "description": "the package the run waits for before its run ask is put, its publisher's build not yet published: written when the wait begins, deleted when the run ask is put or the run ends; absent while the run waits for nothing (design 47 H2 H-A-628 (3), H-A-629 (1))", + "properties": { + "package": { + "type": "string", + "description": "the package's path" + }, + "since": { + "type": "string", + "format": "date-time", + "description": "the time its wait began, which the bound package-wait-minutes counts from" + } + }, + "required": [ + "package", + "since" + ] } }, "required": [ @@ -1886,5 +1905,5 @@ "on": "every" } ], - "form": 2 + "form": 3 } diff --git a/modules/mesh-delivery-contracts/ts/seats/meshwants/index.d.ts b/modules/mesh-delivery-contracts/ts/seats/meshwants/index.d.ts index dd3efa85d..0990e6b10 100644 --- a/modules/mesh-delivery-contracts/ts/seats/meshwants/index.d.ts +++ b/modules/mesh-delivery-contracts/ts/seats/meshwants/index.d.ts @@ -312,6 +312,14 @@ export interface CompositionRunProgram { "repository"?: string; } +/** the package the run waits for before its run ask is put, its publisher's build not yet published: written when the wait begins, deleted when the run ask is put or the run ends; absent while the run waits for nothing (design 47 H2 H-A-628 (3), H-A-629 (1)) */ +export interface CompositionRunWaits { + /** the package's path */ + "package": string; + /** the time its wait began, which the bound package-wait-minutes counts from */ + "since": string; +} + /** one composition run of a candidate and a machine, a key of the assigner's state composition-runs (design 47 G §719, §728; A-469u) */ export interface CompositionRun { /** the id of the build seat's run ask */ @@ -336,6 +344,8 @@ export interface CompositionRun { "unlisted"?: string[]; /** that machine's composer verdict (design 47 G §721) */ "verdict"?: Record; + /** the package the run waits for before its run ask is put, its publisher's build not yet published: written when the wait begins, deleted when the run ask is put or the run ends; absent while the run waits for nothing (design 47 H2 H-A-628 (3), H-A-629 (1)) */ + "waits"?: CompositionRunWaits; } export interface DifferenceRefusedItem {