From 9afc8a160d76906b51722de29bf8ed0af9684a40 Mon Sep 17 00:00:00 2001 From: jochen Date: Sun, 22 Nov 2026 23:57:08 +0100 Subject: [PATCH] H-A-506 runner: every ask put has an ask key; its events read that key, never the pipelines An ask-taken or step-progress of an ask with no test-run key listed and read every pipeline (about 3,850), 1 to 2 s per event on the runner's one consumer. Now every ask the runner puts gets its ask key at the put, naming its pipeline, mover, step and run: the test run's ask key of H-A-500 and the key of every other ask are merged into this one form, `ask.` in test-runs (a key written before holds its run alone and still reads). Taken, RunTaken and RunProgress read that key and the one pipeline it names; an event whose ask has no key is acknowledged at once, counted in H-A-500's one journal line per hundred. The key goes with the pipeline's end or its run's end, so a late ask-taken after the end clears no finding (H-A-506 second addendum). The drops of an ended pipeline's asks are asked beside the end (the Hearer's Aside): a seat with no holder answers a kept call only at its bound, which held the cancel verb's answer past its caller's wait in the queue integration test. Builds: design 47 H2 H-A-506, H-A-506 addendum, H-A-506 second addendum --- .../cmd/mesh-delivery-pipeline/main.go | 7 +- .../cmd/mesh-delivery-pipeline/testruns.go | 27 ++-- .../internal/pipeline/asks_test.go | 8 +- .../internal/pipeline/declined.go | 1 - .../internal/pipeline/drops.go | 38 +++-- .../internal/pipeline/place.go | 11 ++ .../internal/pipeline/runends.go | 133 ++++++++++++------ .../internal/pipeline/start.go | 4 +- .../internal/pipeline/steps.go | 7 + .../internal/pipeline/supersede.go | 65 +++++---- .../internal/pipeline/supersede_test.go | 33 +++++ .../internal/pipeline/testruns.go | 2 - .../internal/pipeline/testruns_test.go | 46 ++++-- .../internal/pipeline/verbs.go | 4 +- .../internal/pipeline/verbs_test.go | 22 ++- 15 files changed, 276 insertions(+), 132 deletions(-) diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go index 14820be9f..94bdb3d73 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go @@ -188,9 +188,10 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro clock := askClock(ctx, bounds, askBound, rv.Findings, cred.Module, time.Now) starter.Asks, hearer.Asks = clock, clock starter.Supersede = func(newer seat.Pipeline) { hearer.SupersedeRunning(newer) } - starter.Drop = hearer.DropOpen // a placing's end drops the asks still open (H-A-506) - starter.Left = hearer.LeftInPlace // a same-source re-pin's superseded steps leave their runs (H-A-284) - starter.Revision = widener.Revision // a kept mover is placed from its kept revision (H-A-286) + starter.Drop = hearer.DropOpen // a placing's end drops the asks still open (H-A-506) + hearer.Aside = func(do func()) { go do() } // each drop of an ended pipeline's asks beside its end (H-A-506) + starter.Left = hearer.LeftInPlace // a same-source re-pin's superseded steps leave their runs (H-A-284) + starter.Revision = widener.Revision // a kept mover is placed from its kept revision (H-A-286) // A mover's wait on a package is read first: a package published before the wait places it at once (H-A-326, H-A-328). // It is a kept call within ask-unanswered-bound (design 47 H2 §775). starter.AskPublished = publishedOf(func(key string, body any) (json.RawMessage, error) { diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns.go index afe5b284d..02f416a70 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns.go @@ -166,14 +166,9 @@ func (t testRunsKV) Has(key string) (bool, error) { return err == nil, err } -// askValue is an ask key's value: the key of the run the ask is of (H-A-500 addendum (1)). -type askValue struct { - Run string `json:"run"` -} - -// MarkAsk creates the ask key of ask holding run; one written already is kept. -func (t testRunsKV) MarkAsk(ask, run string) error { - raw, err := json.Marshal(askValue{Run: run}) +// MarkAsk creates the ask key of ask holding mark (H-A-506 addendum); one written already is kept. +func (t testRunsKV) MarkAsk(ask string, mark pipeline.AskMark) error { + raw, err := json.Marshal(mark) if err != nil { return err } @@ -183,20 +178,20 @@ func (t testRunsKV) MarkAsk(ask, run string) error { return nil } -// RunOfAsk reads the ask key of ask: the run it holds. -func (t testRunsKV) RunOfAsk(ask string) (string, bool, error) { +// AskOf reads the ask key of ask: the mark it holds, a key written before the H-A-506 addendum naming its run alone. +func (t testRunsKV) AskOf(ask string) (pipeline.AskMark, bool, error) { e, err := t.kv.Get(t.ctx, pipeline.AskKey(ask)) if errors.Is(err, jetstream.ErrKeyNotFound) { - return "", false, nil + return pipeline.AskMark{}, false, nil } if err != nil { - return "", false, err + return pipeline.AskMark{}, false, err } - var v askValue - if err := json.Unmarshal(e.Value(), &v); err != nil || v.Run == "" { - return "", false, fmt.Errorf("the ask key of ask %s holds no run: %v", ask, err) + var m pipeline.AskMark + if err := json.Unmarshal(e.Value(), &m); err != nil || (m.Run == "" && m.Pipeline == "") { + return pipeline.AskMark{}, false, fmt.Errorf("the ask key of ask %s names no pipeline and no run: %v", ask, err) } - return v.Run, true, nil + return m, true, nil } func (t testRunsKV) Keys() ([]string, error) { diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/asks_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/asks_test.go index bf8faf926..e7a745d2e 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/asks_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/asks_test.go @@ -110,15 +110,17 @@ func TestAnAsksBoundCountsFromThePullAndEndsItsStep(t *testing.T) { if !slices.Equal(raised, []string{nodebuildgo.Seat + " " + ask}) || !slices.Contains(*said, "pipeline-ended.main.5") { t.Errorf("raised %v, said %v", raised, *said) } - // A bound whose step ended asks nothing; the step's end deletes the bound; a late ask-taken clears the finding. + // A bound whose step ended asks nothing; the step's end deletes the bound; a late ask-taken after the pipeline's + // end clears nothing: the end deleted the ask's key, so the finding stands as what happened (H-A-506 second + // addendum; H-A-238 (2) holds while the pipeline runs). if err := v.AskUnanswered(nodebuildgo.Seat, ask); err != nil || len(asks.ids) != 1 || len(dropped) != 1 { t.Errorf("a bound of an ended step asked %v, dropped %v (%v)", asks.ids, dropped, err) } if err := c.Ended(nodebuildgo.Seat, ask); err != nil || !slices.Equal(unbound, []string{key}) { t.Errorf("the step's end deleted %v (%v)", unbound, err) } - if _, err := v.Hearer.Taken(ask, "n2", now); err != nil || !slices.Equal(cleared, []string{nodebuildgo.Seat + " " + ask}) { - t.Errorf("a late ask-taken cleared %v (%v)", cleared, err) + if _, err := v.Hearer.Taken(ask, "n2", now); err != nil || len(cleared) != 0 { + t.Errorf("a late ask-taken after the pipeline's end cleared %v (%v), want nothing", cleared, err) } }) } diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/declined.go b/modules/mesh-delivery-pipeline/internal/pipeline/declined.go index 1cdd6b43e..ea3fbd385 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/declined.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/declined.go @@ -96,7 +96,6 @@ func (h *Hearer) putDeclined(key, old string, s seat.StepResult, a Asked, ev Ste } else if err != nil { return fmt.Errorf("the test run %s is not written: %w", a.Run, err) } - markAsk(h.Clock, a.ID, a.Run, h.logf) // H-A-500 addendum (1) break } } diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/drops.go b/modules/mesh-delivery-pipeline/internal/pipeline/drops.go index 709e03f4c..fc2818924 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/drops.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/drops.go @@ -37,9 +37,12 @@ func openAtEnd(steps []seat.StepResult) []seat.StepResult { // H-A-506): a step reading a test run leaves it (leaveRun, whose last reader's leave drops the run's ask), and every own // ask still open, a shared test run's and a mesh-wants step's alike, is dropped through its seat's drop, so its holder // refuses it unrun and no build capacity goes to an ended pipeline. Each drop and each refusal is said in one journal line -// per ask; a drop that is not answered fails nothing. +// per ask; a drop that is not answered fails nothing. The leaves are written before it answers; the drops are asked beside +// the path that ended the pipeline (Aside), since a seat with no holder answers a kept call only at its bound, so a cancel +// is answered at once whatever its seats. func (h *Hearer) DropOpen(key string, steps []seat.StepResult, why string) { done := map[string]bool{} + var drops []seat.StepResult for _, st := range steps { if sharedRun(st) != "" && st.Seat != wants.Seat { if dropped := h.leaveRun(key, st, why); dropped != "" { @@ -55,12 +58,26 @@ func (h *Hearer) DropOpen(key string, steps []seat.StepResult, why string) { h.logf("%s: the ask %s of %s's %s on %s is not dropped: the runner has no drop (H-A-506)", key, st.Ask, st.Module, st.Step, st.Seat) continue } - if err := h.DropRun(st.Seat, st.Node, st.Ask, why); err != nil { - h.logf("%s: the drop of the ask %s of %s's %s is refused or not answered by %s: %v (H-A-506)", key, st.Ask, st.Module, st.Step, st.Seat, err) - continue - } - h.logf("%s: the ask %s of %s's %s on %s is dropped (H-A-506)", key, st.Ask, st.Module, st.Step, st.Seat) + drops = append(drops, st) } + for _, st := range drops { + h.aside(func() { + if err := h.DropRun(st.Seat, st.Node, st.Ask, why); err != nil { + h.logf("%s: the drop of the ask %s of %s's %s is refused or not answered by %s: %v (H-A-506)", key, st.Ask, st.Module, st.Step, st.Seat, err) + return + } + h.logf("%s: the ask %s of %s's %s on %s is dropped (H-A-506)", key, st.Ask, st.Module, st.Step, st.Seat) + }) + } +} + +// aside runs do through Aside, in place when there is none. +func (h *Hearer) aside(do func()) { + if h.Aside == nil { + do() + return + } + h.Aside(do) } // endedOpen are the steps of prior, a pipeline's steps read before a placing that ended it, which the end took while asked @@ -83,10 +100,15 @@ func endedOpen(prior, steps []seat.StepResult, unput []Asked) []seat.StepResult // dropEnded drops, through Drop, the asks the placing end of pipeline p took while open (H-A-506); a pipeline not ended // drops nothing. func (s *Starter) dropEnded(p seat.Pipeline, prior []seat.StepResult, unput []Asked) { - if s.Drop == nil || p.Ended == nil { + if p.Ended == nil { return } - if steps := endedOpen(prior, p.Steps, unput); len(steps) > 0 { + steps := endedOpen(prior, p.Steps, unput) + if s.Drop != nil && len(steps) > 0 { s.Drop(p.Pipeline, steps, "the pipeline "+p.Pipeline+" ended "+p.Outcome+": "+p.Why) } + // The end cleared these steps' asks, so their ask keys go here, not with the end's own (H-A-506 addendum). + for _, st := range steps { + unmarkAsk(s.Clock, st.Ask, s.logf) + } } diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/place.go b/modules/mesh-delivery-pipeline/internal/pipeline/place.go index e74f96a53..d093ffa2f 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/place.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/place.go @@ -508,6 +508,17 @@ func askAll(asker StepAsker, key string, asks []Asked, recovery func(commit stri return first } +// armAsk is what askAll does before each ask of pipeline key is put: its ask key is written, naming the pipeline, the step +// and the run (H-A-506 addendum), then its bound armed (§778); an ask whose key or bound is not written is not put. +func (s *Starter) armAsk(key string) func(Asked) error { + return func(a Asked) error { + if err := markAsk(s.Clock, key, a); err != nil { + return err + } + return s.Asks.arm(a) + } +} + // askedStep is the mover and the step an ask names, read from its body; "-" where it names none (the validate ask names no // mover, H-A-51). func askedStep(a Asked) (mover, step string) { diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/runends.go b/modules/mesh-delivery-pipeline/internal/pipeline/runends.go index c2d3f8399..4b9a280c9 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/runends.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/runends.go @@ -55,15 +55,17 @@ type RunClock interface { Has(key string) (bool, error) // Keys are test-runs' keys. Keys() ([]string, error) - // MarkAsk writes the ask key of ask (AskKey) holding run, create-only: one written already is kept (H-A-500 addendum (1)). - MarkAsk(ask, run string) error - // RunOfAsk reads the ask key of ask: the key of the run it holds; ok false when it is not written. - RunOfAsk(ask string) (run string, ok bool, err error) + // MarkAsk writes the ask key of ask (AskKey) holding mark, create-only: one written already is kept (H-A-500 addendum + // (1), H-A-506 addendum). + MarkAsk(ask string, mark AskMark) error + // AskOf reads the ask key of ask: the mark it holds; ok false when it is not written. + AskOf(ask string) (mark AskMark, ok bool, err error) } -// AskPrefix begins the ask key of a test run's ask in test-runs, `ask.`, holding the run's key: written with each ask -// a run is given and deleted with the run, so an ask-taken or step-progress finds its run in one read and never lists the -// pipelines (design 47 H2 H-A-500 addendum (1)). +// AskPrefix begins the ask key of an ask the runner put, `ask.` in test-runs, holding its AskMark: written at the put +// of every ask, a test run's and every other's, and deleted with its pipeline's end or its run's, so an ask-taken or a +// step-progress finds its pipeline, step and run in one read and never lists the pipelines (design 47 H2 H-A-500 addendum +// (1), H-A-506 addendum: one key per ask, the test run's ask key of H-A-500 and the ask key of every other ask in one form). const AskPrefix = "ask." // AskKey is the ask key of ask. @@ -72,13 +74,42 @@ func AskKey(ask string) string { return AskPrefix + ask } // IsRunAsk says whether a key of test-runs is an ask key rather than a run. func IsRunAsk(key string) bool { return strings.HasPrefix(key, AskPrefix) } -// markAsk writes the ask key of a run's ask; one not written is said, and the ask's events are then found by the pipelines. -func markAsk(clock RunClock, ask, run string, logf func(string, ...any)) { - if clock == nil || ask == "" || run == "" { +// AskMark is what an ask key holds (H-A-506 addendum): the pipeline that put the ask, the mover and the step it asks, and +// the test run it asks, empty for an ask of no test run. An ask key written before the addendum holds its run alone. +type AskMark struct { + Pipeline string `json:"pipeline,omitempty"` + Module string `json:"module,omitempty"` + Step string `json:"step,omitempty"` + Run string `json:"run,omitempty"` +} + +// markOf is the mark of ask a, put by the pipeline key. +func markOf(key string, a Asked) AskMark { + mover, step := askedStep(a) + if mover == "-" { + mover = "" + } + return AskMark{Pipeline: key, Module: mover, Step: step, Run: a.Run} +} + +// markAsk writes the ask key of ask a of pipeline key before it is put (H-A-506 addendum); a nil clock writes none. +func markAsk(clock RunClock, key string, a Asked) error { + if clock == nil || a.ID == "" { + return nil + } + if err := clock.MarkAsk(a.ID, markOf(key, a)); err != nil { + return fmt.Errorf("the ask key of ask %s of %s is not written: %w", a.ID, key, err) + } + return nil +} + +// unmarkAsk deletes the ask key of ask, at its pipeline's end or its run's (H-A-506 addendum); one not deleted is said. +func unmarkAsk(clock RunClock, ask string, logf func(string, ...any)) { + if clock == nil || ask == "" { return } - if err := clock.MarkAsk(ask, run); err != nil && logf != nil { - logf("the ask key of ask %s of the test run %s is not written, so its events are found by the pipelines: %v", ask, run, err) + if err := clock.Unbound(AskKey(ask)); err != nil { + logf("the ask key of ask %s is not deleted: %v", ask, err) } } @@ -98,7 +129,7 @@ func unmarkAsks(clock RunClock, run string, logf func(string, ...any)) { if !IsRunAsk(k) { continue } - if held, ok, err := clock.RunOfAsk(strings.TrimPrefix(k, AskPrefix)); err != nil || !ok || held != run { + if held, ok, err := clock.AskOf(strings.TrimPrefix(k, AskPrefix)); err != nil || !ok || held.Run != run { continue } if err := clock.Unbound(k); err != nil { @@ -110,24 +141,35 @@ func unmarkAsks(clock RunClock, run string, logf func(string, ...any)) { // LateEveryLine is how many late events of ended runs' asks one journal line says (H-A-500 (a)). const LateEveryLine = 100 -// LateRunAsk says whether ask is the ask of a test run that has ended, or whose run was asked again under another ask -// since, read from its ask key and its run, never from the pipelines (design 47 H2 H-A-500 (a) and its addenda): such an -// event is acknowledged at once and moves nothing, which replaces H-A-311 (2)'s placing and H-A-238 (2)'s clearing for -// it. One journal line says every LateEveryLine of them. An ask with no ask key, or whose run is gone, is not judged here. +// LateRunAsk says whether an event of ask is acknowledged at once, moving nothing (design 47 H2 H-A-500 (a) and its addenda, +// H-A-506 addendum): an ask with no ask key, put before the ask keys or of a pipeline or a run already ended, reads nothing +// else; an ask of a test run that has ended, or whose run was asked again under another ask since, is read from its ask +// key and its run. Both are said in one journal line every LateEveryLine of them. This replaces +// H-A-311 (2)'s placing and H-A-238 (2)'s clearing for it. With no clock nothing is judged here. func (h *Hearer) LateRunAsk(event, ask string) bool { - if h.TestRuns == nil || h.Clock == nil || ask == "" { + if h.Clock == nil || ask == "" { return false } - run, ok, err := h.Clock.RunOfAsk(ask) - if err != nil || !ok { + m, ok, err := h.Clock.AskOf(ask) + if err != nil { + h.logf("the %s of ask %s is acknowledged, moving nothing: its ask key is not read: %v (H-A-506)", event, ask, err) + return true + } + if !ok { + if n := atomic.AddInt64(&h.lateRuns, 1); n%LateEveryLine == 0 { + h.logf("%d late events acknowledged at once, moving nothing; the last the %s of ask %s, which has no ask key (H-A-500, H-A-506)", n, event, ask) + } + return true + } + if m.Run == "" || h.TestRuns == nil { return false } - r, _, err := h.TestRuns.Get(run) + r, _, err := h.TestRuns.Get(m.Run) if err != nil || (r.Ended == nil && r.Ask == ask) { return false } if n := atomic.AddInt64(&h.lateRuns, 1); n%LateEveryLine == 0 { - h.logf("%d late events of ended test runs' asks acknowledged at once, moving nothing; the last the %s of ask %s of the test run %s (H-A-500)", n, event, ask, run) + h.logf("%d late events of ended test runs' asks acknowledged at once, moving nothing; the last the %s of ask %s of the test run %s (H-A-500)", n, event, ask, m.Run) } return true } @@ -149,39 +191,38 @@ func IsRunBound(key string) bool { return ok } -// runOfAsk is the test run asked under ask: the run its asking step names in Shared, read from the state pipelines. +// markOfAsk is the mark of ask, read from its ask key alone, never from the pipelines (H-A-506 addendum); ok false when the +// ask has no key, or no clock is held. +func (h *Hearer) markOfAsk(ask string) (AskMark, bool) { + if h.Clock == nil || ask == "" { + return AskMark{}, false + } + m, ok, err := h.Clock.AskOf(ask) + if err != nil { + h.logf("the ask key of ask %s is not read, so its event moves nothing: %v", ask, err) + return AskMark{}, false + } + return m, ok +} + +// runOfAsk is the test run asked under ask, read from its ask key (H-A-500 addendum (1)). func (h *Hearer) runOfAsk(ask string) (string, bool) { run, _, ok := h.runAndPipelineOfAsk(ask) return run, ok } -// runAndPipelineOfAsk is runOfAsk with the key of the pipeline whose step asked it. +// runAndPipelineOfAsk is runOfAsk with the key of the pipeline that put the ask, both read from its ask key alone (H-A-506 +// addendum); an ask key written before the addendum names no pipeline, the run's readers then naming every pipeline that +// reads it, the asking one among them. func (h *Hearer) runAndPipelineOfAsk(ask string) (string, string, bool) { - if h.TestRuns == nil || ask == "" { + if h.TestRuns == nil { return "", "", false } - // The ask key names the run in one read (H-A-500 addendum (1)); the pipeline is then left unnamed, the run's readers - // naming every pipeline that reads it, the asking one among them. - if h.Clock != nil { - if run, ok, err := h.Clock.RunOfAsk(ask); err == nil && ok { - return run, "", true - } - } - pkeys, err := allKeys(h.Store) - if err != nil { + m, ok := h.markOfAsk(ask) + if !ok || m.Run == "" { return "", "", false } - for _, key := range pkeys { - p, _, err := h.Store.Get(key) - if err != nil { - continue - } - if i := stepOfAsk(p, ask); i >= 0 { - run := sharedRun(p.Steps[i]) - return run, key, run != "" - } - } - return "", "", false + return m.Run, m.Pipeline, true } // releaseLate places what the end of a step heard late unlocks (H-A-311 (2)): a step-progress or step-end that arrives @@ -420,6 +461,7 @@ func (h *Hearer) EndRun(run string, end seat.TestRun, skip *seat.TestRunReader) h.logf("the bound %s of the ended test run is not deleted: %v", k, err) } } + unmarkAsk(h.Clock, r.Ask, h.logf) // the ask key goes with its run's end (H-A-506 addendum) } var first error for _, reader := range r.Readers { @@ -546,6 +588,7 @@ func (h *Hearer) leaveRun(key string, s seat.StepResult, why string) string { h.logf("the bound %s of the ended test run is not deleted: %v", k, err) } } + unmarkAsk(h.Clock, r.Ask, h.logf) // the ask key goes with its run's end (H-A-506 addendum) } if h.DropRun != nil { if err := h.DropRun(r.Seat, r.Node, r.Ask, why); err != nil { diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/start.go b/modules/mesh-delivery-pipeline/internal/pipeline/start.go index c8a05b6a2..1082dbc0d 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/start.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/start.go @@ -389,7 +389,7 @@ func (s *Starter) askSteps(key string, asks []Asked) error { var err error if len(asks) > 0 { s.carry(key, asks) - err = askAll(s.Steps, key, asks, func(commit string) bool { return s.recovered(key, commit) }, s.Asks.arm, s.logf) + err = askAll(s.Steps, key, asks, func(commit string) bool { return s.recovered(key, commit) }, s.armAsk(key), s.logf) } s.sayStarted(key, placed) return err @@ -681,7 +681,7 @@ func (s *Starter) PutAgain(key string, a Asked) error { return errors.New("the runner puts no ask") } s.carry(key, []Asked{a}) - return askAll(s.Steps, key, []Asked{a}, func(commit string) bool { return s.recovered(key, commit) }, s.Asks.arm, s.logf) + return askAll(s.Steps, key, []Asked{a}, func(commit string) bool { return s.recovered(key, commit) }, s.armAsk(key), s.logf) } // validateStep is the index of p's first validate step that names its ask, -1 when it has none. diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/steps.go b/modules/mesh-delivery-pipeline/internal/pipeline/steps.go index 23d4ecb90..c32279218 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/steps.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/steps.go @@ -195,6 +195,9 @@ type Hearer struct { AskDeclined func(p seat.Pipeline, s seat.StepResult, now time.Time) (*Asked, error) PutAgain func(key string, a Asked) error + // Aside runs do beside the caller's path: the drops of an ended pipeline's open asks, each asked side by side, so an end is + // never held by a seat that answers a kept call only at its bound (H-A-506); nil runs it in place. + Aside func(do func()) // lateRuns counts the late events of ended runs' asks acknowledged at once (LateRunAsk, H-A-500 (a)). lateRuns int64 } @@ -517,6 +520,10 @@ func (h *Hearer) said(p seat.Pipeline, asked []int, ended bool) error { } h.Failures.Ended(p) h.Unfinished.Ended(p) + // Every ask key of its steps goes with the pipeline's end (H-A-506 addendum). + for _, st := range p.Steps { + unmarkAsk(h.Clock, st.Ask, h.logf) + } if h.RegistrationWaits != nil { h.RegistrationWaits() } diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/supersede.go b/modules/mesh-delivery-pipeline/internal/pipeline/supersede.go index 420ce2ec9..03c4de5d3 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/supersede.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/supersede.go @@ -25,43 +25,42 @@ func (h *Hearer) Taken(ask, node string, at time.Time) (*time.Time, error) { if ask == "" || node == "" { return nil, nil } - pkeys, err := allKeys(h.Store) - if err != nil { - return nil, fmt.Errorf("the pipelines are not listed: %w", err) + // The ask key names the ask's pipeline: that one record is read, never the pipelines list (H-A-506 addendum). + m, ok := h.markOfAsk(ask) + if !ok || m.Pipeline == "" { + return nil, nil } - for _, key := range pkeys { - for { - p, rev, err := h.Store.Get(key) - if err != nil { - break - } - i := stepOfAsk(p, ask) - if i >= 0 && !open(p.Steps[i]) { - h.Asks.answeredLate(p.Steps[i], h.logf) - } - if i < 0 || !open(p.Steps[i]) { - break - } - s := &p.Steps[i] - if s.Node == node && s.TakenAt != nil { - return s.TakenAt, nil - } - s.Node = node - if s.TakenAt == nil { - if at.IsZero() { - at = h.now() - } - s.TakenAt = ptrTime(at.UTC()) - } - if _, err := h.Store.Update(key, p, rev); errors.Is(err, ErrChanged) { - continue - } else if err != nil { - return nil, fmt.Errorf("pipeline %s cannot be written: %w", key, err) - } + key := m.Pipeline + for { + p, rev, err := h.Store.Get(key) + if err != nil { + return nil, nil + } + i := stepOfAsk(p, ask) + if i >= 0 && !open(p.Steps[i]) { + h.Asks.answeredLate(p.Steps[i], h.logf) + } + if i < 0 || !open(p.Steps[i]) { + return nil, nil + } + s := &p.Steps[i] + if s.Node == node && s.TakenAt != nil { return s.TakenAt, nil } + s.Node = node + if s.TakenAt == nil { + if at.IsZero() { + at = h.now() + } + s.TakenAt = ptrTime(at.UTC()) + } + if _, err := h.Store.Update(key, p, rev); errors.Is(err, ErrChanged) { + continue + } else if err != nil { + return nil, fmt.Errorf("pipeline %s cannot be written: %w", key, err) + } + return s.TakenAt, nil } - return nil, nil } func ptrTime(t time.Time) *time.Time { return &t } diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/supersede_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/supersede_test.go index d604054e3..50c93f174 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/supersede_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/supersede_test.go @@ -3,6 +3,9 @@ package pipeline import ( "errors" "testing" + "time" + + seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner" nodebuildgo "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo" ) @@ -11,16 +14,46 @@ import ( // supersedes it no more (design 47 H §748). func TestATakenAskNamesItsNode(t *testing.T) { h, store, _, _, _ := fixture() + clock := &clockMem{runs: testRunsMem{}, bound: map[string]time.Duration{}} + h.Clock = clock + _ = clock.MarkAsk("a1", AskMark{Pipeline: pkey, Module: "app", Step: "lint"}) + // The ask key names the pipeline: the ask-taken reads that one record and never lists the pipelines; an ask with no + // key reads none (H-A-506 addendum). + counted := &countedStore{memStore: store} + h.Store = counted if _, err := h.Taken("a1", "n7", h.now()); err != nil { t.Fatal(err) } if p, _, _ := store.Get(pkey); p.Steps[0].Node != "n7" || p.Steps[1].Node != "" { t.Fatalf("after ask-taken of a1 on n7 the steps name %q and %q", p.Steps[0].Node, p.Steps[1].Node) } + if counted.gets != 1 || counted.lists != 0 { + t.Errorf("the ask-taken of a1 read %d pipelines and listed %d times, want one read and no list", counted.gets, counted.lists) + } + counted.gets = 0 + if at, err := h.Taken("a2", "n7", h.now()); err != nil || at != nil || counted.gets != 0 || counted.lists != 0 { + t.Errorf("the ask-taken of a2, which has no ask key, = %v, %v, read %d and listed %d; want nothing read", at, err, counted.gets, counted.lists) + } } // A-222, A-77: a drop is bounded by a key of its own armed before it is asked and deleted when it is answered; one never // answered leaves its key to expire. +// countedStore is a memStore that counts its reads and its lists. +type countedStore struct { + memStore + gets, lists int +} + +func (c *countedStore) Get(key string) (seat.Pipeline, uint64, error) { + c.gets++ + return c.memStore.Get(key) +} + +func (c *countedStore) Keys(filter string) ([]string, error) { + c.lists++ + return c.memStore.Keys(filter) +} + func TestBoundDrop(t *testing.T) { var armed, answered []string arm := func(key string) error { armed = append(armed, key); return nil } diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/testruns.go b/modules/mesh-delivery-pipeline/internal/pipeline/testruns.go index 422badffb..a46e85e85 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/testruns.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/testruns.go @@ -250,8 +250,6 @@ func (s *Starter) started(a Asked, write func() error) error { if err := write(); err != nil { return err } - // The run's ask gets its ask key, so its events find the run in one read (H-A-500 addendum (1)). - markAsk(s.Clock, a.ID, a.Run, s.logf) if s.Clock != nil { untaken := s.Runs.Untaken if untaken <= 0 { diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go index fdd0d8cc9..44de0eac6 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go @@ -4,6 +4,7 @@ import ( "fmt" "slices" "strings" + "sync" "testing" "time" @@ -20,8 +21,8 @@ type clockMem struct { asks map[string]string revs map[string]uint64 rev uint64 - // askRuns are the ask keys, each holding its run (H-A-500 addendum (1)). - askRuns map[string]string + // askRuns are the ask keys, each holding its mark (H-A-500 addendum (1), H-A-506 addendum). + askRuns map[string]AskMark // before is called once at the next Bound, a write that comes between its caller's read and its write. before func() } @@ -54,19 +55,25 @@ func (c *clockMem) UnboundAt(key string, rev uint64) error { return nil } func (c *clockMem) Has(key string) (bool, error) { _, ok := c.bound[key]; return ok, nil } -func (c *clockMem) MarkAsk(ask, run string) error { +func (c *clockMem) MarkAsk(ask string, m AskMark) error { if _, ok := c.askRuns[AskKey(ask)]; ok { return nil } if c.askRuns == nil { - c.askRuns = map[string]string{} + c.askRuns = map[string]AskMark{} } - c.askRuns[AskKey(ask)] = run + c.askRuns[AskKey(ask)] = m return nil } +func (c *clockMem) AskOf(ask string) (AskMark, bool, error) { + m, ok := c.askRuns[AskKey(ask)] + return m, ok, nil +} + +// RunOfAsk is the run the ask key of ask names. func (c *clockMem) RunOfAsk(ask string) (string, bool, error) { - run, ok := c.askRuns[AskKey(ask)] - return run, ok, nil + m, ok := c.askRuns[AskKey(ask)] + return m.Run, ok, nil } func (c *clockMem) Keys() ([]string, error) { var out []string @@ -107,6 +114,8 @@ type runFixture struct { fill int64 s *Starter h *Hearer + // mu guards drops and logged, written also by the drops DropOpen asks side by side (H-A-506). + mu sync.Mutex } func newRunFixture() *runFixture { @@ -120,8 +129,14 @@ func newRunFixture() *runFixture { return nil } f.h = &Hearer{Store: f.store, Say: say, TestRuns: f.runs, Clock: f.clock, RunOutputs: f.objects, - Logf: func(format string, a ...any) { f.logged = append(f.logged, fmt.Sprintf(format, a...)) }, + Logf: func(format string, a ...any) { + f.mu.Lock() + defer f.mu.Unlock() + f.logged = append(f.logged, fmt.Sprintf(format, a...)) + }, DropRun: func(seatName, node, ask, why string) error { + f.mu.Lock() + defer f.mu.Unlock() f.drops = append(f.drops, seatName+" "+node+" "+ask) return nil }} @@ -280,9 +295,11 @@ func TestATestRunHasOneClockACapAndAnAge(t *testing.T) { if _, _, err := f.runs.Get(run); err != nil { t.Fatal("a run is aged before test-runs-kept passed") } - if held, ok, _ := f.clock.RunOfAsk(unit.Ask); !ok || held != run { - t.Fatalf("the ask key of %s holds %q before the run is aged, want %s", unit.Ask, held, run) + // The ask key goes with the run's end, not its aging (H-A-506 addendum). + if held, ok, _ := f.clock.RunOfAsk(unit.Ask); ok { + t.Fatalf("the ask key of %s holds %q after its run ended, want it deleted with the end", unit.Ask, held) } + _ = f.clock.MarkAsk(unit.Ask, AskMark{Run: run}) // a key written before the addendum, holding its run alone now = now.Add(2 * 24 * time.Hour) a.Age() if _, _, err := f.runs.Get(run); err != ErrNoRun || len(f.objects) != 0 { @@ -676,8 +693,9 @@ func TestNoWriteOfATestRunActsOnAReadBeforeItsLatestChange(t *testing.T) { p := f.start(t, 4, 9) unit := stepNamed(p, "app:program", "unit") run := unit.Shared[0].Run - if got, ok, _ := f.clock.RunOfAsk(unit.Ask); !ok || got != run { - t.Fatalf("the ask key of %s holds %q, %v; want the run %s", unit.Ask, got, ok, run) + // The ask key of the run's ask names its pipeline, its step and its run (H-A-506 addendum). + if got, ok, _ := f.clock.AskOf(unit.Ask); !ok || got != (AskMark{Pipeline: p.Pipeline, Module: "app", Step: "unit", Run: run}) { + t.Fatalf("the ask key of %s holds %+v, %v; want %s's unit step of the run %s", unit.Ask, got, ok, p.Pipeline, run) } if f.h.LateRunAsk("step-progress", unit.Ask) { t.Fatal("the ask of a running run is judged late") @@ -692,8 +710,8 @@ func TestNoWriteOfATestRunActsOnAReadBeforeItsLatestChange(t *testing.T) { t.Fatalf("event %d of the ended run's ask is not judged late", i) } } - if f.h.LateRunAsk("ask-taken", "anaskofnorun") { - t.Error("an ask with no ask key is judged late") + if !f.h.LateRunAsk("ask-taken", "anaskofnorun") { + t.Error("an ask with no ask key is not acknowledged at once (H-A-506 addendum)") } if len(f.logged) != 2 || !strings.Contains(f.logged[1], "200 late events") { t.Errorf("journal %q; want one line per hundred late events", f.logged) diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go b/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go index 47608faa7..a82b751af 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go @@ -416,7 +416,7 @@ func (v Verbs) rerun(caller string, in seat.RerunInput, reopens bool) (seat.Reru v.sayReopened(p, reopens) if ask != nil { v.Starter.carry(in.Pipeline, []Asked{*ask}) - if err := askAll(v.Starter.Steps, in.Pipeline, []Asked{*ask}, func(commit string) bool { return v.Starter.recovered(in.Pipeline, commit) }, v.Starter.Asks.arm, v.Starter.logf); err != nil { + if err := askAll(v.Starter.Steps, in.Pipeline, []Asked{*ask}, func(commit string) bool { return v.Starter.recovered(in.Pipeline, commit) }, v.Starter.armAsk(in.Pipeline), v.Starter.logf); err != nil { return seat.RerunAnswer{}, fmt.Errorf("the step is written running but not asked, it is asked again at the next start: %w", err) } } @@ -564,7 +564,7 @@ func (v Verbs) rerunTest(caller string, in seat.RerunInput, st seat.StepResult, break } v.Starter.carry(in.Pipeline, []Asked{*ask}) - if err := askAll(v.Starter.Steps, in.Pipeline, []Asked{*ask}, func(commit string) bool { return v.Starter.recovered(in.Pipeline, commit) }, v.Starter.Asks.arm, v.Starter.logf); err != nil { + if err := askAll(v.Starter.Steps, in.Pipeline, []Asked{*ask}, func(commit string) bool { return v.Starter.recovered(in.Pipeline, commit) }, v.Starter.armAsk(in.Pipeline), v.Starter.logf); err != nil { return seat.RerunAnswer{}, fmt.Errorf("the step is written running but not asked, it is asked again at the next start: %w", err) } } diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/verbs_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/verbs_test.go index 6aeb4b8aa..2fb55c882 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/verbs_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/verbs_test.go @@ -4,7 +4,9 @@ import ( "encoding/json" "errors" "fmt" + "slices" "strings" + "sync" "testing" "time" @@ -36,10 +38,22 @@ func verbsFixture() (Verbs, memStore, *[]string, *stepAsks, *actLog, *[]string) rev uint64 }{p, 1} asks, acts, dropped := &stepAsks{}, &actLog{}, &[]string{} + clock := &clockMem{runs: testRunsMem{}, bound: map[string]time.Duration{}} + h.Clock = clock s := &Starter{Steps: asks, Name: "the-runner", Registration: func(string) (catalog.Registration, bool) { return reg, true }, - Now: h.Now} - h.DropRun = func(onSeat, _, ask, _ string) error { *dropped = append(*dropped, onSeat+" "+ask); return nil } - h.Logf = func(format string, args ...any) { *dropped = append(*dropped, "log: "+fmt.Sprintf(format, args...)) } + Now: h.Now, Clock: clock} + var mu sync.Mutex // the drops DropOpen asks side by side write here too (H-A-506) + h.DropRun = func(onSeat, _, ask, _ string) error { + mu.Lock() + defer mu.Unlock() + *dropped = append(*dropped, onSeat+" "+ask) + return nil + } + h.Logf = func(format string, args ...any) { + mu.Lock() + defer mu.Unlock() + *dropped = append(*dropped, "log: "+fmt.Sprintf(format, args...)) + } return Verbs{Hearer: h, Starter: s, View: func(string) (Half, bool) { return Half{Entries: entries}, true }, Acts: acts}, store, said, asks, acts, dropped } @@ -164,6 +178,8 @@ func TestAcceptRerunAndCancelWriteByCompareAndSetAndRecordTheirHandAct(t *testin drops = append(drops, d) } } + slices.Sort(drops) + slices.Sort(open) if len(open) < 4 || !seats["mesh-builds"] || !seats["mesh-wants"] || !seats["node-build-go"] || fmt.Sprint(drops) != fmt.Sprint(open) { t.Fatalf("cancel dropped %v, want every open ask %v, on mesh-builds, node-build-go and mesh-wants", drops, open) }