From 3fc9e194b9f07b3874341fcd0d38230256d7e51a Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 23 Nov 2026 17:37:51 +0100 Subject: [PATCH] Runner: a step's end only ends its step; the store lists no key (issue 1984) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The runner took the step ends one at a time at about 13 s each, because each handler aged up to twenty step-log entries and checked the stores' fill, and every read and write of a pipeline listed its mover keys through a new consumer (issue 1984, note 6). The ageing and the fill check now run as work of their own, nudged by the step ends: the ends heard while a pass runs merge into one pass after it, and never two run at once. The pipelines store reads each key by its name and keeps a running pipeline's mover keys from its last read or write while the record is still at that revision (every write of a mover key writes the record too), so a step's end reads the record and writes the record and its own mover key; a store after a restart, or a pipeline not running, reads the keys its record names, never a listing. Builds: issue 1984 note 6 (1984/AC1), ADR 0682 §11 --- .../cmd/mesh-delivery-pipeline/main.go | 2 + .../internal/pipeline/aged.go | 51 +++++- .../internal/pipeline/fill.go | 3 +- .../internal/pipeline/moverkeys.go | 165 ++++++++++++++---- .../internal/pipeline/moverkeys_test.go | 67 ++++++- .../internal/pipeline/stepend_test.go | 136 +++++++++++++++ .../internal/pipeline/steps.go | 14 +- 7 files changed, 388 insertions(+), 50 deletions(-) create mode 100644 modules/mesh-delivery-pipeline/internal/pipeline/stepend_test.go 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 c09058a4e..6e433bff2 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go @@ -414,6 +414,8 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro logger.Printf("the test runs taken up at the start: %d ended past their bound (%v)", n, err) } go whileTheLogIsFull(ctx, fills, hearer, time.Minute) + // The ageing and the stores' fill check run as work of their own, woken by the steps' ends (issue 1984). + go hearer.AgeOnStepEnds(ctx) // The seat list, read over the calls connection and heard on the hub (seatlist.Part), which the seat's write verbs check // their callers against (A-186): registered before the hub starts, read again once its events are live. seats := seatlist.NewPart("runner") diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/aged.go b/modules/mesh-delivery-pipeline/internal/pipeline/aged.go index 467ce3e5f..35cdcb07c 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/aged.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/aged.go @@ -1,8 +1,10 @@ package pipeline import ( + "context" "errors" "fmt" + "sync" "time" seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner" @@ -23,7 +25,7 @@ var ( Retention90 = Retention{"90d", 90 * 24 * time.Hour} ) -// AgedPerStep is the most entries one step's end ages at one retention (§330). +// AgedPerStep is the most entries one pass of the ageing, woken by the steps' ends, ages at one retention (§330). const AgedPerStep = 20 // LoggedEntry is one entry of the step log with its sequence. @@ -32,9 +34,10 @@ type LoggedEntry struct { Entry seat.LogEntry } -// Ager ages the runner's own kept data by its own deletes, in the step log's order (design 47 G §330): at each step's end it -// reads the step log onward from each retention's sequence, at most AgedPerStep entries, while the entry is past the -// retention, deletes what the retention says and moves the sequence; nothing is scanned whole, nothing waits on a timer. +// Ager ages the runner's own kept data by its own deletes, in the step log's order (design 47 G §330): at each pass the +// steps' ends wake (Hearer.AgeOnStepEnds) it reads the step log onward from each retention's sequence, at most AgedPerStep +// entries, while the entry is past the retention, deletes what the retention says and moves the sequence; nothing is +// scanned whole, nothing waits on a timer. type Ager struct { // Log reads the step log onward from a sequence, oldest first, at most limit entries. Log func(from uint64, limit int) ([]LoggedEntry, error) @@ -73,7 +76,7 @@ func (a *Ager) logf(format string, args ...any) { } } -// Age is the ageing of one step's end; an error of one retention is said and the others go on. +// Age is one pass of the ageing, woken by the steps' ends; an error of one retention is said and the others go on. func (a *Ager) Age() { if a == nil || a.Log == nil { return @@ -346,3 +349,41 @@ func (a *Ager) newest(p seat.Pipeline) (bool, error) { } return len(p.Movers) == 0, nil } + +// AgeOnStepEnds runs the ageing of the runner's own kept data (§330) and the check of its stores' fill (§366) as work of +// their own, woken by the steps' ends (ADR 0682 §11: a part wakes on its inputs alone; issue 1984): each step's end nudges +// it, the nudges heard while a pass runs merge into one pass after it, and never more than one pass runs, so a step end's +// handler only ends its step. It returns when ctx ends. +func (h *Hearer) AgeOnStepEnds(ctx context.Context) { + wake := h.ageNudge() + for { + select { + case <-ctx.Done(): + return + case <-wake: + h.Ager.Age() + h.Fills.Check() + } + } +} + +// ageWakeMade guards the first making of a hearer's ageWake, whichever of its step ends and AgeOnStepEnds comes first. +var ageWakeMade sync.Mutex + +// ageNudge is the nudge AgeOnStepEnds waits on, holding one nudge at most. +func (h *Hearer) ageNudge() chan struct{} { + ageWakeMade.Lock() + defer ageWakeMade.Unlock() + if h.ageWake == nil { + h.ageWake = make(chan struct{}, 1) + } + return h.ageWake +} + +// nudgeAgeing wakes AgeOnStepEnds for one pass, at once: a nudge already waiting takes this one in. +func (h *Hearer) nudgeAgeing() { + select { + case h.ageNudge() <- struct{}{}: + default: + } +} diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/fill.go b/modules/mesh-delivery-pipeline/internal/pipeline/fill.go index 4ad250092..bcfce44f9 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/fill.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/fill.go @@ -30,7 +30,8 @@ type Fills struct { full map[string]bool } -// Check reads each store's fill and says what changed since the last check; it is read at each step's end and at each start. +// Check reads each store's fill and says what changed since the last check; it is read at each pass the steps' ends wake +// (Hearer.AgeOnStepEnds) and at each start. func (f *Fills) Check() { if f == nil || f.Read == nil { return diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/moverkeys.go b/modules/mesh-delivery-pipeline/internal/pipeline/moverkeys.go index 8d6d32d30..a96d5ab51 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/moverkeys.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/moverkeys.go @@ -61,24 +61,67 @@ var ErrNoPipeline = errors.New("no such pipeline") // MoverStore is the state pipelines as the runner reads and writes it (§27, H-A-187): Get composes a pipeline from its // record and its mover keys, Update writes the record and each mover key that changed, each by compare-and-set on the -// revision read, and nothing when any of them was written since. One MoverStore serves a process: a write and a read of one -// pipeline take its lock, so the process never reads a record and mover keys of two writes. +// revision read, and nothing when any of them was written since. Get and Update read each key by its name and list none, so +// no call opens a consumer (issue 1984). One MoverStore serves a process: a write and a read of one pipeline take its lock, +// so the process never reads a record and mover keys of two writes. type MoverStore struct { Raw RawState Logf func(string, ...any) - // mu guards the three maps, which every pipeline's reads and writes share across goroutines (H §774): the lock table, - // the last reads and the records said inline. A pipeline's own lock is held across its read or write. + // mu guards the three maps and ended, which every pipeline's reads and writes share across goroutines (H §774): the + // lock table, the last reads and the records said inline. A pipeline's own lock is held across its read or write. mu sync.Mutex locks map[string]*sync.Mutex read map[string]readAt inline map[string]bool + // ended is the pipeline whose end this store wrote last: its mover keys' values are kept beside the running ones' (keep). + ended string } -// readAt is what the last read of a pipeline found: its record's revision and each mover key's revision. +// readAt is what the last read or write of a pipeline found: its record's revision and each mover key's revision, and for +// a running pipeline whose record carries no steps inline each mover key's value (issue 1984): every write of a mover key +// writes the record too, so while the record is still at rev a read takes the mover keys from here and reads the record +// alone, and a step's end reads and writes only its record and its own mover key. type readAt struct { rev uint64 movers map[string]uint64 + vals map[string][]byte +} + +// keep keeps r as the last read or write of pipeline key, whose record is p, under mu: the mover keys' values only of a +// running pipeline whose record carries no steps inline, and of the one pipeline whose end this store wrote last, so the +// writes that follow an end (its unlogged entries cleared) read no mover key either; what is kept is bounded by the +// pipelines running and one. +func (s *MoverStore) keep(key string, p seat.Pipeline, r readAt) { + s.mu.Lock() + defer s.mu.Unlock() + had := s.read[key].vals != nil + switch { + case len(p.Steps) > 0 || r.vals == nil: + r.vals = nil + case p.Outcome == seat.PipelineOutcomeRunning: + case had || s.ended == key: + if s.ended != key { + if e, ok := s.read[s.ended]; ok { + e.vals = nil + s.read[s.ended] = e + } + s.ended = key + } + default: + r.vals = nil + } + s.read[key] = r +} + +// held is the mover keys' values and revisions kept from the last read or write of pipeline key, while its record is still +// at rev. +func (s *MoverStore) held(key string, rev uint64) (map[string][]byte, map[string]uint64, bool) { + r, ok := s.seen(key) + if !ok || r.rev != rev || r.vals == nil { + return nil, nil, false + } + return r.vals, r.movers, true } func (s *MoverStore) lock(key string) func() { @@ -104,13 +147,6 @@ func (s *MoverStore) seen(key string) (readAt, bool) { return r, ok } -// setSeen keeps the last read of pipeline key, under mu. -func (s *MoverStore) setSeen(key string, r readAt) { - s.mu.Lock() - defer s.mu.Unlock() - s.read[key] = r -} - // markInline says whether pipeline key is said inline for the first time, marking it, under mu. func (s *MoverStore) markInline(key string) bool { s.mu.Lock() @@ -138,12 +174,40 @@ func (s *MoverStore) logf(f string, a ...any) { } } -// moverKeys are the mover keys of pipeline key with their values and revisions. +// moverKeys are the mover keys of pipeline key with their values and revisions, listed: a create's and a delete's, which +// find the keys an earlier pipeline of the key left. func (s *MoverStore) moverKeys(key string) (map[string][]byte, map[string]uint64, error) { ks, err := s.Raw.Keys(stepsPrefix(key) + "*") if err != nil { return nil, nil, fmt.Errorf("the mover keys of %s are not listed: %w", key, err) } + return s.readKeys(ks) +} + +// named are the mover keys pipeline key's record p names, each read by its name (issue 1984): its movers', its superseded +// movers' and, for a record carrying its steps inline, its steps' movers'. No key is listed, so no read opens a consumer. +func named(key string, p seat.Pipeline) []string { + var out []string + add := func(module string) { + if k := StepsKey(key, module); module != "" && !slices.Contains(out, k) { + out = append(out, k) + } + } + for _, m := range p.Movers { + add(m.Module) + } + for _, m := range p.Superseded { + add(m) + } + for _, st := range p.Steps { + add(st.Module) + } + return out +} + +// readKeys are the values and revisions of the mover keys ks, each read by its name; a key the state does not hold is left +// out. +func (s *MoverStore) readKeys(ks []string) (map[string][]byte, map[string]uint64, error) { vals, revs := map[string][]byte{}, map[string]uint64{} for _, k := range ks { v, rev, err := s.Raw.Get(k) @@ -268,11 +332,14 @@ func (s *MoverStore) Get(key string) (seat.Pipeline, uint64, error) { if err := json.Unmarshal(raw, &p); err != nil { return seat.Pipeline{}, 0, fmt.Errorf("the pipeline %s is no pipeline: %w", key, err) } - vals, revs, err := s.moverKeys(key) - if err != nil { - return seat.Pipeline{}, 0, err + vals, _, ok := s.held(key, rev) + if !ok { + var revs map[string]uint64 + if vals, revs, err = s.readKeys(named(key, p)); err != nil { + return seat.Pipeline{}, 0, err + } + s.keep(key, p, readAt{rev: rev, movers: revs, vals: vals}) } - s.setSeen(key, readAt{rev: rev, movers: revs}) if len(p.Steps) > 0 { if s.markInline(key) { s.logf("the pipeline %s carries its %d steps inline in its record: they are read whole and split into one key per mover at its next write (H-A-187)", key, len(p.Steps)) @@ -377,44 +444,69 @@ func (s *MoverStore) update(key string, p seat.Pipeline, revision uint64, kept m return 0, err } } - vals, revs, err := s.moverKeys(key) - if err != nil { - return 0, err - } - // A mover key written since the read is another write between: the read named its revision. - if seen, ok := s.seen(key); ok && seen.rev == revision { - for k, r := range revs { - if seen.movers[k] != r { - return 0, ErrChanged - } - } - for k := range seen.movers { - if _, ok := revs[k]; !ok { - return 0, ErrChanged - } - } - } var was seat.Pipeline inline := json.Unmarshal(raw, &was) == nil && len(was.Steps) > 0 + // The mover keys as the last read or write left them while the record is at the revision read: every write of a mover + // key writes the record too (issue 1984). Else each key the record and p name is read by its name, never listed. + vals, revs, ok := s.held(key, revision) + if !ok { + names := named(key, was) + for k := range want { + if !slices.Contains(names, k) { + names = append(names, k) + } + } + seen, read := s.seen(key) + read = read && seen.rev == revision + if read { + for k := range seen.movers { + if !slices.Contains(names, k) { + names = append(names, k) + } + } + } + if vals, revs, err = s.readKeys(names); err != nil { + return 0, err + } + // A mover key written since the read is another write between: the read named its revision. + if read { + for k, r := range revs { + if r != seen.movers[k] { + return 0, ErrChanged + } + } + for k := range seen.movers { + if _, ok := revs[k]; !ok { + return 0, ErrChanged + } + } + } + } var after map[string]uint64 if inline { if after, err = s.writeMovers(key, want, vals, revs); err != nil { + s.forget(key, true, false) return 0, err } } rev, err := s.Raw.Update(key, record, revision) if err != nil { + if inline { + s.forget(key, true, false) // the mover keys are written and the record is not: nothing kept is read again + } return 0, err } if !inline { if after, err = s.writeMovers(key, want, vals, revs); err != nil { + s.forget(key, true, false) return 0, err } } else { s.logf("the pipeline %s's steps are split into %d mover keys and its record no longer carries them (H-A-187)", key, len(want)) s.forget(key, false, true) } - s.setSeen(key, readAt{rev: rev, movers: after}) + p.Steps = nil // the record written carries no steps inline + s.keep(key, p, readAt{rev: rev, movers: after, vals: want}) return rev, nil } @@ -478,7 +570,8 @@ func (s *MoverStore) Create(key string, value []byte) error { if err != nil { return err } - s.setSeen(key, readAt{rev: rev, movers: after}) + p.Steps = nil // the record written carries no steps inline + s.keep(key, p, readAt{rev: rev, movers: after, vals: want}) return nil } diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/moverkeys_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/moverkeys_test.go index e0ca9f1ac..29a1c7619 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/moverkeys_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/moverkeys_test.go @@ -122,14 +122,75 @@ func TestMoverKeys(t *testing.T) { q, _, _ := s.Get(key) return fmt.Sprintf("beta kept %t: %s %v", m.revs["steps.main.7.beta"] == beta, steps(q), err) }, "beta kept true: beta build running; beta approval not asked; alpha build passed "}, - {"a mover key written since the read refuses the update, nothing written", func(t *testing.T) string { - m, s, _ := created(t) + {"a mover key written since the read of a pipeline not running refuses the update, nothing written", func(t *testing.T) string { + m := newMemRaw() + s := &MoverStore{Raw: m} + ended := two() + ended.Outcome = seat.PipelineOutcomeFailed + raw, _ := json.Marshal(ended) + if err := s.Create(key, raw); err != nil { + return err.Error() + } p, rev, _ := s.Get(key) m.put("steps.main.7.alpha", m.vals["steps.main.7.alpha"]) - p.Outcome = seat.PipelineOutcomePassed + p.Why = "read again" _, err := s.Update(key, p, rev) return fmt.Sprintf("%t, record at %t", errors.Is(err, ErrChanged), m.revs[key] == rev) }, "true, record at true"}, + // 1984/AC1: a running pipeline's mover keys are kept from the last read or write while its record is at the revision + // read; every write of a mover key writes the record too, so another store's write is never missed. + {"a mover key another store wrote since the read refuses the update, and the next read reads it (1984/AC1)", func(t *testing.T) string { + m, s, _ := created(t) + p, rev, _ := s.Get(key) + other := &MoverStore{Raw: m} + q, qrev, _ := other.Get(key) + q.Steps[2].Outcome = seat.StepResultOutcomePassed + if _, err := other.Update(key, q, qrev); err != nil { + return err.Error() + } + p.Outcome = seat.PipelineOutcomePassed + _, err := s.Update(key, p, rev) + again, _, _ := s.Get(key) + return fmt.Sprintf("%t: %s", errors.Is(err, ErrChanged), steps(again)) + }, "true: beta build running; beta approval not asked; alpha build passed"}, + {"each key is read by its name, none listed; while the record is at the revision kept a read reads the record alone (1984/AC1)", func(t *testing.T) string { + m, _, _ := created(t) + c := &countedRaw{memRaw: m} + fresh := &MoverStore{Raw: c} // a store after a restart keeps nothing yet + p, rev, _ := fresh.Get(key) + first := fmt.Sprintf("%d reads, %d listings", len(c.reads), c.listings) + c.reset() + _, _, _ = fresh.Get(key) + second := fmt.Sprintf("%v, %d listings", c.reads, c.listings) + c.reset() + p.Steps[0].Outcome = seat.StepResultOutcomePassed + if _, err := fresh.Update(key, p, rev); err != nil { + return err.Error() + } + return fmt.Sprintf("%s; %s; update read %v wrote %v, %d listings", first, second, c.reads, c.writes, c.listings) + }, "3 reads, 0 listings; [main.7], 0 listings; update read [main.7] wrote [main.7 steps.main.7.beta], 0 listings"}, + {"an ended pipeline's mover keys are kept only until another pipeline's end is written (1984/AC1)", func(t *testing.T) string { + m := newMemRaw() + c := &countedRaw{memRaw: m} + s := &MoverStore{Raw: c} + end := func(k string) { + p := two() + p.Pipeline = k + raw, _ := json.Marshal(p) + _ = s.Create(k, raw) + q, rev, _ := s.Get(k) + q.Outcome = seat.PipelineOutcomePassed + _, _ = s.Update(k, q, rev) + } + end("main.7") + c.reset() + _, _, _ = s.Get("main.7") + kept := len(c.reads) + end("main.8") + c.reset() + _, _, _ = s.Get("main.7") + return fmt.Sprintf("its end's read %d, after another's end %d", kept, len(c.reads)) + }, "its end's read 1, after another's end 3"}, {"a record written since the read refuses the update", func(t *testing.T) string { _, s, _ := created(t) p, rev, _ := s.Get(key) diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/stepend_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/stepend_test.go new file mode 100644 index 000000000..7f1081bf4 --- /dev/null +++ b/modules/mesh-delivery-pipeline/internal/pipeline/stepend_test.go @@ -0,0 +1,136 @@ +package pipeline + +import ( + "context" + "encoding/json" + "sync/atomic" + "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" +) + +// countedRaw is memRaw counting what each call reads and writes: the keys read, the keys written and the listings. +type countedRaw struct { + *memRaw + reads, writes []string + listings int +} + +func (c *countedRaw) Get(key string) ([]byte, uint64, error) { + c.reads = append(c.reads, key) + return c.memRaw.Get(key) +} + +func (c *countedRaw) Create(key string, value []byte) (uint64, error) { + c.writes = append(c.writes, key) + return c.memRaw.Create(key, value) +} + +func (c *countedRaw) Update(key string, value []byte, rev uint64) (uint64, error) { + c.writes = append(c.writes, key) + return c.memRaw.Update(key, value, rev) +} + +func (c *countedRaw) Keys(filter string) ([]string, error) { + c.listings++ + return c.memRaw.Keys(filter) +} + +func (c *countedRaw) reset() { c.reads, c.writes, c.listings = nil, nil, 0 } + +// 1984/AC1 (issue 1984 note 6; ADR 0682 §11): a step's end does the step's end alone. Its handler writes the record and its +// own mover key, lists no key and opens no consumer; the ageing and the stores' fill check run as work of their own, woken +// by the step ends: the ends heard before a pass merge into one pass, and never more than one pass runs. +func TestAStepEndDoesOnlyTheStepsEnd(t *testing.T) { + raw := &countedRaw{memRaw: newMemRaw()} + store := &MoverStore{Raw: raw} + p := seat.Pipeline{V: 1, Pipeline: pkey, Branch: "main", Source: 5, Outcome: seat.PipelineOutcomeRunning, + Movers: []seat.Mover{{Module: "app", Commit: "c1", Fingerprint: "src2:aa"}, {Module: "lib", Commit: "c2", Fingerprint: "src2:bb"}}, + Steps: []seat.StepResult{ + {Module: "app", Artifact: "program", Step: seat.StepResultStepLint, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeRunning, Ask: "a1", Seat: nodebuildgo.Seat}, + {Module: "app", Artifact: "program", Step: seat.StepResultStepUnit, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeRunning, Ask: "a2", Seat: nodebuildgo.Seat}, + {Module: "lib", Artifact: "lib", Step: seat.StepResultStepLint, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeRunning, Ask: "a3", Seat: nodebuildgo.Seat}}} + body, _ := json.Marshal(p) + if err := store.Create(pkey, body); err != nil { + t.Fatal(err) + } + var aged, inside, most atomic.Int32 + passed, entered, hold := make(chan struct{}, 16), make(chan struct{}, 1), make(chan struct{}) + held := atomic.Bool{} + h := &Hearer{Store: store, Name: "mesh-pipeline-runner", Say: func(string, any) error { return nil }, + Log: func(seat.LogEntry) error { return nil }, Now: func() time.Time { return time.Date(2026, 11, 23, 17, 0, 0, 0, time.UTC) }, + Ager: &Ager{Log: func(uint64, int) ([]LoggedEntry, error) { aged.Add(1); return nil, nil }, Aged: agedState{}}, + // One pass is one fill check, after the ageing; a pass held waits inside it. + Fills: &Fills{Read: func() ([]seat.Fill, error) { + if n := inside.Add(1); n > most.Load() { + most.Store(n) + } + defer inside.Add(-1) + if held.Load() { + entered <- struct{}{} + <-hold + } + passed <- struct{}{} + return nil, nil + }}} + end := func(ask, module, commit, fp, step string) { + t.Helper() + raw.reset() + ev := StepEnded{ID: ask, Ask: ask, Node: "n1", Pipeline: pkey, Module: module, Commit: commit, Fingerprint: fp, Step: step, Outcome: "passed"} + if _, err := h.OnStepEnded(goSeat, goSeat.Prefix+"n1", ev); err != nil { + t.Fatal(err) + } + mine := StepsKey(pkey, module) + for _, k := range raw.writes { + if k != pkey && k != mine { + t.Errorf("the end of %s wrote %s; want only the record and %s", ask, k, mine) + } + } + for _, k := range raw.reads { + if k != pkey && k != mine { + t.Errorf("the end of %s read %s; want only the record and %s", ask, k, mine) + } + } + if raw.listings != 0 { + t.Errorf("the end of %s listed the keys %d times, a consumer each; want none", ask, raw.listings) + } + } + end("a1", "app", "c1", "src2:aa", seat.StepResultStepLint) + if aged.Load() != 0 || len(passed) != 0 { + t.Fatalf("the handler of a step's end aged %d times; want none, the ageing is work of its own", aged.Load()) + } + end("a2", "app", "c1", "src2:aa", seat.StepResultStepUnit) + end("a3", "lib", "c2", "src2:bb", seat.StepResultStepLint) + if got, _, _ := store.Get(pkey); got.Outcome != seat.PipelineOutcomePassed { + t.Fatalf("the pipeline = %s (%s), want passed by its three ends", got.Outcome, got.Why) + } + + // The three ends' nudges are one pass; the nudges heard while a pass runs are one pass after it; never two at once. + ctx, cancel := context.WithCancel(context.Background()) + done := make(chan struct{}) + go func() { h.AgeOnStepEnds(ctx); close(done) }() + <-passed + if aged.Load() == 0 { + t.Error("the pass woken by the step ends aged nothing") + } + held.Store(true) + h.nudgeAgeing() + <-entered + for range 5 { + h.nudgeAgeing() + } + held.Store(false) + close(hold) + <-passed + <-passed + cancel() + <-done + if most.Load() != 1 { + t.Errorf("%d passes ran at once; want never more than one", most.Load()) + } + if n := len(passed); n != 0 { + t.Errorf("%d more passes ran; want the five nudges heard during one pass merged into one pass after it", n) + } +} diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/steps.go b/modules/mesh-delivery-pipeline/internal/pipeline/steps.go index a78936d96..a2a7103b5 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/steps.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/steps.go @@ -162,9 +162,10 @@ type Hearer struct { // RegistrationWaits judges, at every pipeline's end, the finding registration-missing of the modules no running pipeline // still waits on (Starter.JudgeRegistrationMissing, H-A-265 (4)); nil judges none. RegistrationWaits func() - // Ager ages the runner's own kept data at each step's end (§330); nil ages none. - Ager *Ager - // Fills says the stores' fill at each step's end (§366); nil says none. + // Ager ages the runner's own kept data, and Fills says the stores' fill, woken by the steps' ends as work of their own, + // never inside a step end's handler (§330, §366; ADR 0682 §11; issue 1984): AgeOnStepEnds runs them. Nil ages and says + // none. + Ager *Ager Fills *Fills // Widens makes, for one end, the reader of each mover's widens, kept in its value at the pipeline's end (§71, A-207; // H-A-51): made before the end's compare-and-set, its reads shared by every mover and every retry (H-A-289); nil keeps none. @@ -218,6 +219,9 @@ type Hearer struct { Aside func(do func()) // lateRuns counts the late events of ended runs' asks acknowledged at once (LateRunAsk, H-A-500 (a)). lateRuns int64 + // ageWake is the nudge of AgeOnStepEnds, made at its first use under ageWakeMade: one nudge waits at most, the rest merge + // into it (issue 1984). + ageWake chan struct{} } // EndReaders ends each of readers' steps of run with r's result (§725, §726): a step that read an ended run, or the steps @@ -516,8 +520,8 @@ func (h *Hearer) OnStepEndedRevised(bs StepSeat, subject string, ev StepEnded, s } // The step's end is written and said before its log entry is appended, so a log that refuses ends no step (§486, §606). h.appendUnlogged(ev.Pipeline) - h.Ager.Age() - h.Fills.Check() + // The ageing and the fill check are work of their own, nudged, never this handler's (ADR 0682 §11; issue 1984). + h.nudgeAgeing() if err := h.said(p, asked, ended); err != nil { return p, err }