From 3fc9e194b9f07b3874341fcd0d38230256d7e51a Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 23 Nov 2026 17:37:51 +0100 Subject: [PATCH 1/3] 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 } From 1a8b7c85918016b2895867c8fc6ee6e2144ea2e4 Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 23 Nov 2026 17:43:07 +0100 Subject: [PATCH 2/3] Runner: a bound passing while step ends wait arms it again (issue 1984) An ask's bound ended its step "not answered: its holder said nothing" while the holder's end waited, untaken, in the runner's own step-ended durable: the runner's queue was counted against the holder (issue 1984, note 6). As a bound passes the runner now reads that durable once, its consumer's not-yet-delivered and unacknowledged step ends: while any wait, the step is not ended, its bound is armed again whole and the journal says how many wait; with none waiting the step ends with the why it had, the journal naming the count read. A read that fails arms the bound once more, kept as `unread` on the ask's own mark in test-runs, cleared by a read that succeeds; a second failed read in a row ends the step saying the runner could not read its durable, and raises no call-unanswered, whose words say the holder said nothing. Builds: issue 1984 note 6 (1984/AC2), note 7 (a), (b), (c) --- .../cmd/mesh-delivery-pipeline/askbounds.go | 26 +++++ .../cmd/mesh-delivery-pipeline/main.go | 2 + .../run_integration_test.go | 1 + .../stependswaiting_integration_test.go | 80 ++++++++++++++ .../cmd/mesh-delivery-pipeline/testruns.go | 10 ++ .../internal/pipeline/asks.go | 95 +++++++++++++++- .../internal/pipeline/asks_test.go | 104 ++++++++++++++++++ .../internal/pipeline/runends.go | 16 ++- .../internal/pipeline/steps.go | 16 ++- .../internal/pipeline/testruns_test.go | 7 ++ 10 files changed, 343 insertions(+), 14 deletions(-) create mode 100644 modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/stependswaiting_integration_test.go diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/askbounds.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/askbounds.go index 6020618e3..01ebd2af8 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/askbounds.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/askbounds.go @@ -84,6 +84,32 @@ func askClock(ctx context.Context, bounds jetstream.KeyValue, bound time.Duratio }} } +// stepEndsWaiting reads, once, the runner's own durable named durable on onSeat's step-ended stream (issue 1984 notes 6, 7): +// its consumer's info, the step ends not yet delivered and those delivered and not yet acknowledged. A seat whose step-ended +// stream the runner does not know, and a stream or durable the bus does not hold, hold none. +func stepEndsWaiting(ctx context.Context, js jetstream.JetStream, durable string) func(onSeat string) (uint64, uint64, error) { + return func(onSeat string) (uint64, uint64, error) { + stream := "" + for _, bs := range pipeline.StepSeats { + if bs.Seat == onSeat { + stream = bs.Stream + } + } + if stream == "" { + return 0, 0, nil + } + c, err := js.Consumer(ctx, stream, durable) + if errors.Is(err, jetstream.ErrConsumerNotFound) || errors.Is(err, jetstream.ErrStreamNotFound) { + return 0, 0, nil + } + if err != nil { + return 0, 0, fmt.Errorf("the consumer %s on %s is not read: %w", durable, stream, err) + } + info := c.CachedInfo() // read by the one call that bound c + return info.NumPending, uint64(info.NumAckPending), nil + } +} + // progressed arms the bound of the ask on onSeat again from now, at a step-progress its holder says for it (H-A-395), // said when it fails: the bound then ends the step at its time. func progressed(c *pipeline.AskClock, onSeat, ask string, logf func(string, ...any)) { 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 6e433bff2..40d98124d 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go @@ -187,6 +187,8 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro hearer.RegistrationWaits = func() { starter.JudgeRegistrationMissing(store) } // at every end (H-A-265 (4)) logger.Printf("asks: an ask's bound %s, counted from its put until its holder's ask-taken, then from the take and each step-progress; past it the step ends could not run and its ask is dropped", askBound) clock := askClock(ctx, bounds, askBound, rv.Findings, cred.Module, time.Now) + // A bound passing reads the runner's own step-ended durable first: an end waiting there is not the holder's silence (issue 1984). + clock.Waiting = stepEndsWaiting(ctx, js, cred.EventConsumerName()) 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) diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/run_integration_test.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/run_integration_test.go index 58272cbd4..7f1215003 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/run_integration_test.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/run_integration_test.go @@ -56,6 +56,7 @@ func TestTheRunnerPlacesAPipelineAsksItsBuildTakesItsEndAndAnswersAReview(t *tes t.Run("a take-in said before the bind is still worked", testATakeInSaidBeforeTheBindIsStillWorked) t.Run("a takeins bind that failed is bound again on registration-changed", testATakeInsBindThatFailedIsBoundAgainOnRegistrationChanged) t.Run("step log read does not wait for a batch it cannot fill", testStepLogReadDoesNotWaitForABatchItCannotFill) + t.Run("a bound passing reads the runner's own step-ended durable", testABoundPassingReadsTheRunnersOwnStepEndedDurable) ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() reg := catalog.Registration{Module: "app", Branches: []string{"main"}, Origin: "o/app", Policy: catalog.Policy{Steps: catalog.StepStatuses{Review: "optional", Validate: "bypass", Composition: "required", Approval: "bypass"}}} diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/stependswaiting_integration_test.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/stependswaiting_integration_test.go new file mode 100644 index 000000000..bd5a18a01 --- /dev/null +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/stependswaiting_integration_test.go @@ -0,0 +1,80 @@ +//go:build integration + +package main + +import ( + "context" + "testing" + "time" + + "github.com/nats-io/nats.go" + "github.com/nats-io/nats.go/jetstream" + + wants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" + nodebuildgo "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo" + "git.novox.be/novox/mesh-sdk/go/testbus" +) + +// testABoundPassingReadsTheRunnersOwnStepEndedDurable is a row of TestTheRunnerPlacesAPipelineAsksItsBuildTakesItsEndAndAnswersAReview +// (design 47 H2 §819: the module's tests are folded under its budget). 1984/AC2: as an ask's bound passes the runner reads its own +// durable on the seat's step-ended stream once, against the bus: the ends not yet delivered and those delivered and not +// acknowledged; a durable or stream the bus does not hold holds none; a read the bus does not answer is an error. +func testABoundPassingReadsTheRunnersOwnStepEndedDurable(t *testing.T) { + nc, err := nats.Connect(testbus.URL(t)) + if err != nil { + t.Fatal(err) + } + defer nc.Close() + js, _ := jetstream.New(nc) + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + const durable = "n1_mesh-delivery-pipeline" + waiting := stepEndsWaiting(ctx, js, durable) + read := func(onSeat string) (uint64, uint64) { + t.Helper() + p, u, err := waiting(onSeat) + if err != nil { + t.Fatalf("the durable of %s: %v", onSeat, err) + } + return p, u + } + if _, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: nodebuildgo.StreamStepEnded, Subjects: []string{nodebuildgo.SubjectStepEndedAll}}); err != nil { + t.Fatal(err) + } + if p, u := read(nodebuildgo.Seat); p+u != 0 { + t.Errorf("a stream with no durable of the runner holds %d and %d; want none", p, u) + } + if p, u := read(wants.Seat); p+u != 0 { + t.Errorf("a stream the bus does not hold holds %d and %d; want none", p, u) + } + if p, u := read("no-such-seat"); p+u != 0 { + t.Errorf("a seat with no step-ended stream holds %d and %d; want none", p, u) + } + c, err := js.CreateOrUpdateConsumer(ctx, nodebuildgo.StreamStepEnded, jetstream.ConsumerConfig{Durable: durable, + AckPolicy: jetstream.AckExplicitPolicy, FilterSubjects: []string{nodebuildgo.SubjectStepEndedAll}}) + if err != nil { + t.Fatal(err) + } + for range 3 { + if _, err := js.Publish(ctx, "mesh.seat.node-build-go.event.step-ended.n1", []byte(`{}`)); err != nil { + t.Fatal(err) + } + } + if p, u := read(nodebuildgo.Seat); p != 3 || u != 0 { + t.Errorf("three ends said and none taken: %d not yet delivered, %d unacknowledged; want 3 and 0", p, u) + } + b, err := c.Fetch(1) + if err != nil { + t.Fatal(err) + } + for range b.Messages() { + } + if p, u := read(nodebuildgo.Seat); p != 2 || u != 1 { + t.Errorf("one end taken and not acknowledged: %d not yet delivered, %d unacknowledged; want 2 and 1", p, u) + } + gone, stop := context.WithCancel(ctx) + stop() + if _, _, err := stepEndsWaiting(gone, js, durable)(nodebuildgo.Seat); err == nil { + t.Error("a read the bus does not answer says no error; want one, so the bound is armed once more") + } +} 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 364512a1c..4e2eae26c 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns.go @@ -177,6 +177,16 @@ func (t testRunsKV) MarkAsk(ask string, mark pipeline.AskMark) error { return nil } +// MarkAskAgain writes the ask key of ask holding mark over the one written (issue 1984 note 7 (c)). +func (t testRunsKV) MarkAskAgain(ask string, mark pipeline.AskMark) error { + raw, err := json.Marshal(mark) + if err != nil { + return err + } + _, err = t.kv.Put(t.ctx, pipeline.AskKey(ask), raw) + return err +} + // 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)) diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/asks.go b/modules/mesh-delivery-pipeline/internal/pipeline/asks.go index 60ad7e29c..0727ef8a4 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/asks.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/asks.go @@ -41,6 +41,13 @@ func UnansweredWhy(ask string) string { return "its ask " + ask + " was not answered: its holder said nothing of it within ask-unanswered-bound" } +// unreadWhy is the why of a step whose bound passed twice in a row while the runner could not read its own step-ended +// durable of onSeat (issue 1984 note 7 (b)): whether its end waits there is not known, so its holder is not said silent. +func unreadWhy(onSeat, ask string) string { + return "its ask " + ask + " is not known to be answered: the runner could not read its own step-ended durable of " + onSeat + + " at two bounds in a row" +} + // UntakenWhy is the why of a step whose ask no holder of onSeat took within the bound after it was asked (§778). func UntakenWhy(onSeat string) string { return "its ask was not taken: " + onSeat + "'s holder takes none" @@ -58,6 +65,10 @@ type AskClock struct { Unbound func(key string) error Raise func(onSeat, ask string, bound time.Duration) error Clear func(onSeat, ask string) error + // Waiting reads, once, the runner's own durable on onSeat's step-ended stream (issue 1984 notes 6, 7): the step ends it + // holds not yet delivered and those delivered and not yet acknowledged, none for a durable or stream the bus does not + // hold; nil reads none, and a bound then ends its step as it passes. + Waiting func(onSeat string) (pending, unacknowledged uint64, err error) } // arm arms the bound of a, before it is put (§778); a test run's ask, and a nil clock, arm none. @@ -139,8 +150,23 @@ func (v Verbs) AskUnanswered(onSeat, ask string) error { if s.TakenAt == nil { why, said = UntakenWhy(onSeat), "was taken by no holder" } - h.logf("the ask %s of the %s step of %s on %s %s within %s: the step ends could not run and its ask is dropped (§778)", - s.Ask, s.Step, key, onSeat, said, c.bound()) + // Its end may wait in the runner's own step-ended durable, not yet taken: the runner's queue is never counted against + // the holder (issue 1984 notes 6, 7). + read, unread := "", false + if c.Waiting != nil && c.Rearm != nil { + var again bool + if read, again, unread = v.endsWaiting(c, key, onSeat, s); again { + return nil + } + } + if unread { + why = unreadWhy(onSeat, s.Ask) + h.logf("the ask %s of the %s step of %s on %s is not known to be answered within %s: the runner could not read its own step-ended durable of %s at this bound and the one before; the step ends could not run and its ask is dropped (§778)", + s.Ask, s.Step, key, onSeat, c.bound(), onSeat) + } else { + h.logf("the ask %s of the %s step of %s on %s %s within %s%s: the step ends could not run and its ask is dropped (§778)", + s.Ask, s.Step, key, onSeat, said, c.bound(), read) + } if err := h.endUnanswered(key, s.Ask, why); err != nil { return err } @@ -149,12 +175,75 @@ func (v Verbs) AskUnanswered(onSeat, ask string) error { h.logf("the ask %s on %s, ended by its bound, is not dropped: %v", s.Ask, onSeat, err) } } - if c.Raise != nil { + // The finding call-unanswered says its holder said nothing, which is not known of an ask whose ends were not read: its + // step's why and the pipeline's failure say it. + if c.Raise != nil && !unread { return c.Raise(onSeat, s.Ask, c.bound()) } return nil } +// endsWaiting reads the runner's own step-ended durable of onSeat once, as the bound of step s's ask passes (issue 1984 +// notes 6, 7): while step ends wait there, or at the first read that fails, the bound is armed again whole and said, again +// true; a read that fails at the bound after one that failed answers unread true; else it answers what the journal adds to +// the step's end, the count read, and the ask's mark loses its unread. +func (v Verbs) endsWaiting(c *AskClock, key, onSeat string, s seat.StepResult) (read string, again, unread bool) { + h := v.Hearer + boundKey := AskBoundKey(onSeat, s.Ask) + pending, unacked, err := c.Waiting(onSeat) + var mark AskMark + marked := false + if h.Clock != nil { + var merr error + if mark, marked, merr = h.Clock.AskOf(s.Ask); merr != nil { + h.logf("the mark of ask %s is not read, so the bound passing reads it as unmarked: %v", s.Ask, merr) + } + } + if !marked { + mark = AskMark{Pipeline: key, Module: s.Module, Step: s.Step} + } + if err != nil { + if mark.Unread != nil { + h.logf("the bound of ask %s of the %s step of %s on %s passed and the runner's own step-ended durable of %s is not read again (%v), as at the bound before (%s)", + s.Ask, s.Step, key, onSeat, onSeat, err, mark.Unread.Format(time.RFC3339)) + return "", false, true + } + if h.Clock == nil { + h.logf("the bound of ask %s of the %s step of %s on %s passed and the runner's own step-ended durable of %s is not read (%v); the runner keeps no ask marks to arm it once more", + s.Ask, s.Step, key, onSeat, onSeat, err) + return "", false, true + } + now := h.now() + mark.Unread = &now + if werr := h.Clock.MarkAskAgain(s.Ask, mark); werr != nil { + h.logf("the bound of ask %s of the %s step of %s on %s passed and the runner's own step-ended durable of %s is not read (%v), and the ask's mark keeping that is not written (%v)", + s.Ask, s.Step, key, onSeat, onSeat, err, werr) + return "", false, true + } + if rerr := c.Rearm(boundKey, c.bound()); rerr != nil { + h.logf("the bound of ask %s on %s is not armed again after its durable was not read: %v", s.Ask, onSeat, rerr) + } + h.logf("the bound of ask %s of the %s step of %s on %s passed and the runner's own step-ended durable of %s is not read (%v): the step is not ended and its bound is armed again with %s; a second failed read at that bound ends it", + s.Ask, s.Step, key, onSeat, onSeat, err, c.bound()) + return "", true, false + } + if mark.Unread != nil && h.Clock != nil { + mark.Unread = nil + if werr := h.Clock.MarkAskAgain(s.Ask, mark); werr != nil { + h.logf("the mark of ask %s keeps its unread, its durable read now: %v", s.Ask, werr) + } + } + if n := pending + unacked; n > 0 { + if rerr := c.Rearm(boundKey, c.bound()); rerr != nil { + h.logf("the bound of ask %s on %s is not armed again while step ends wait: %v", s.Ask, onSeat, rerr) + } + h.logf("the bound of ask %s of the %s step of %s on %s passed while %d step ends wait in the runner's own step-ended durable of %s (%d not yet delivered, %d delivered and not acknowledged): the step is not ended and its bound is armed again with %s", + s.Ask, s.Step, key, onSeat, n, onSeat, pending, unacked, c.bound()) + return "", true, false + } + return fmt.Sprintf(", and no step end waits in the runner's own step-ended durable of %s (0 not yet delivered, 0 unacknowledged)", onSeat), false, false +} + // OpenAsk is an ask a running step waits on, and when its holder last spoke of it: its taken-at, else its asked-at. type OpenAsk struct { Seat, Ask string diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/asks_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/asks_test.go index c855dadf7..874d03ac1 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/asks_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/asks_test.go @@ -1,6 +1,7 @@ package pipeline import ( + "errors" "fmt" "slices" "strings" @@ -141,6 +142,109 @@ func TestAnAsksBoundCountsFromThePullAndEndsItsStep(t *testing.T) { } } +// 1984/AC2 (issue 1984 notes 6 and 7): before a bound ends its step, the runner reads its own step-ended durable of the +// ask's seat once. While step ends wait there the step is not ended: its bound is armed again and the journal says how many +// wait. With none waiting the step ends as before, its why true, the journal naming the count read. A read that fails arms +// the bound once more, kept on the ask's mark; a second failed read at that bound ends the step saying the durable was not +// read, never that its holder said nothing, and raises no call-unanswered. A read that succeeds between clears the mark. +func TestABoundPassingWhileStepEndsWaitArmsItAgain(t *testing.T) { + type read struct { + pending, unacked uint64 + err error + } + for _, c := range []struct { + name string + reads []read + // what each bound's passing leaves: "armed" (the step still running, its bound armed again) or the why it ended with + want []string + }{ + {"step ends wait: armed again, then ended once none waits", []read{{3, 1, nil}, {0, 0, nil}}, []string{"armed", "unanswered"}}, + {"a failed read arms once more; a second ends saying the durable was not read", []read{{0, 0, errors.New("timeout")}, {0, 0, errors.New("timeout")}}, []string{"armed", "unread"}}, + {"a read between two failed ones clears the first", []read{{0, 0, errors.New("timeout")}, {2, 0, nil}, {0, 0, errors.New("timeout")}, {0, 0, errors.New("timeout")}}, []string{"armed", "armed", "armed", "unread"}}, + } { + t.Run(c.name, func(t *testing.T) { + v, store, _, _, _, journal := verbsFixture() + now := time.Date(2026, 11, 23, 17, 0, 0, 0, time.UTC) + v.Hearer.Now = func() time.Time { return now } + var rearmed, raised, dropped []string + n := 0 + clock := &AskClock{Bound: 10 * time.Minute, + Arm: func(string, time.Duration) error { return nil }, + Rearm: func(key string, ttl time.Duration) error { rearmed = append(rearmed, key+" "+ttl.String()); return nil }, + Unbound: func(string) error { return nil }, + Raise: func(s, ask string, _ time.Duration) error { raised = append(raised, s+" "+ask); return nil }, + Waiting: func(onSeat string) (uint64, uint64, error) { + if onSeat != nodebuildgo.Seat { + t.Errorf("the durable of %s was read; want the ask's seat's", onSeat) + } + r := c.reads[n] + n++ + return r.pending, r.unacked, r.err + }} + v.Starter.Asks, v.Hearer.Asks = clock, clock + v.Hearer.DropRun = func(onSeat, _, ask, why string) error { dropped = append(dropped, ask+" "+why); return nil } + p, rev, _ := store.Get(pkey) + for i := range p.Steps { + if open(p.Steps[i]) { + p.Steps[i].Outcome = seat.StepResultOutcomePassed + } + } + p.Steps[stepIndex(p, "lint", "app:program")].Outcome = seat.StepResultOutcomeFailed + store.Update(pkey, p, rev) + r, err := v.Rerun("operator", seat.RerunInput{Pipeline: pkey, Step: "lint", Artifact: "app:program", Why: "retry"}) + if err != nil { + t.Fatal(err) + } + ask := r.Result.Ask + if _, err := v.Hearer.Taken(ask, "n1", now.Add(-10*time.Minute)); err != nil { + t.Fatal(err) + } + for i, want := range c.want { + *journal = nil + if err := v.AskUnanswered(nodebuildgo.Seat, ask); err != nil { + t.Fatal(err) + } + got, _, _ := store.Get(pkey) + s := got.Steps[stepIndex(got, "lint", "app:program")] + switch want { + case "armed": + if !open(s) || len(rearmed) != i+1 || rearmed[i] != AskBoundKey(nodebuildgo.Seat, ask)+" 10m0s" || len(dropped)+len(raised) != 0 { + t.Fatalf("bound %d: the step is %s (%s), armed again %v, dropped %v, raised %v; want it running and its bound armed again whole", + i+1, s.Outcome, s.Why, rearmed, dropped, raised) + } + if c.reads[i].err != nil && countLines(*journal, "is not read") != 1 { + t.Errorf("bound %d: the journal %q does not say the durable was not read", i+1, *journal) + } + if c.reads[i].err == nil && countLines(*journal, fmt.Sprintf("%d step ends wait", c.reads[i].pending+c.reads[i].unacked)) != 1 { + t.Errorf("bound %d: the journal %q does not say how many step ends wait", i+1, *journal) + } + m, _, _ := v.Hearer.Clock.AskOf(ask) + if (m.Unread != nil) != (c.reads[i].err != nil) { + t.Errorf("bound %d: the ask's mark keeps unread %v after a read that failed %v", i+1, m.Unread, c.reads[i].err != nil) + } + case "unanswered": + if s.Outcome != seat.StepResultOutcomeCouldNotRun || s.Why != UnansweredWhy(ask) || len(raised) != 1 { + t.Fatalf("bound %d: the step is %s (%s), raised %v; want could not run: %s, and its finding", i+1, s.Outcome, s.Why, raised, UnansweredWhy(ask)) + } + if countLines(*journal, "0 not yet delivered, 0 unacknowledged") != 1 { + t.Errorf("bound %d: the journal %q does not name the count read", i+1, *journal) + } + case "unread": + if s.Outcome != seat.StepResultOutcomeCouldNotRun || s.Why != unreadWhy(nodebuildgo.Seat, ask) || strings.Contains(s.Why, "said nothing") { + t.Fatalf("bound %d: the step is %s (%s); want could not run: %s", i+1, s.Outcome, s.Why, unreadWhy(nodebuildgo.Seat, ask)) + } + if len(raised) != 0 || len(dropped) != 1 { + t.Errorf("bound %d: raised %v, dropped %v; want no call-unanswered, which says its holder said nothing, and the ask dropped", i+1, raised, dropped) + } + } + } + if n != len(c.reads) { + t.Errorf("the durable was read %d times; want once at each bound, %d", n, len(c.reads)) + } + }) + } +} + // H-A-252: the pipeline's one validate ask names no mover (H-A-51), and its holder's end names the mover whose body it took: // it is matched by its ask alone and ends the validate step of every mover under it, whichever mover it names. func TestAValidateEndNamingOneMoverEndsEveryMoversValidate(t *testing.T) { diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/runends.go b/modules/mesh-delivery-pipeline/internal/pipeline/runends.go index 3b3a869cc..ebadac686 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/runends.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/runends.go @@ -57,6 +57,9 @@ type RunClock interface { // 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 + // MarkAskAgain writes the ask key of ask holding mark over the one written, or writes it when none is: its unread set or + // cleared as a bound passes (issue 1984 note 7 (c)). + MarkAskAgain(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) } @@ -74,12 +77,15 @@ func AskKey(ask string) string { return AskPrefix + ask } func IsRunAsk(key string) bool { return strings.HasPrefix(key, AskPrefix) } // 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. +// the test run it asks, empty for an ask of no test run. An ask key written before the addendum holds its run alone. Unread +// is when the runner last could not read its own step-ended durable of the ask's seat as the ask's bound passed, cleared +// by a read that succeeds (issue 1984 note 7 (c)): a second failed read at the bound after ends the step. type AskMark struct { - Pipeline string `json:"pipeline,omitempty"` - Module string `json:"module,omitempty"` - Step string `json:"step,omitempty"` - Run string `json:"run,omitempty"` + Pipeline string `json:"pipeline,omitempty"` + Module string `json:"module,omitempty"` + Step string `json:"step,omitempty"` + Run string `json:"run,omitempty"` + Unread *time.Time `json:"unread,omitempty"` } // markOf is the mark of ask a, put by the pipeline key. diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/steps.go b/modules/mesh-delivery-pipeline/internal/pipeline/steps.go index a2a7103b5..6b253e20b 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/steps.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/steps.go @@ -27,6 +27,9 @@ type StepSeat struct { Seat string // Prefix is the subject before . Prefix string + // Stream is the stream the seat's step-ended is kept in, from its contract: the runner's own durable there holds the + // ends it has not taken yet, read as an ask's bound passes (issue 1984). + Stream string // Decode reads the seat's step-ended body; nil is the build seats' one form. Decode func([]byte) (StepEnded, error) // Shared reads the runs a step-ended names in `shared`, carried into the step's result as they came (A-468d); nil for @@ -41,14 +44,15 @@ type StepSeat struct { // StepSeats are the three build seats, from their contracts. var StepSeats = []StepSeat{ - {Seat: nodebuildgo.Seat, Prefix: strings.TrimSuffix(nodebuildgo.SubjectStepEndedAll, "*")}, - {Seat: nodebuildnode.Seat, Prefix: strings.TrimSuffix(nodebuildnode.SubjectStepEndedAll, "*")}, - {Seat: nodebuildimage.Seat, Prefix: strings.TrimSuffix(nodebuildimage.SubjectStepEndedAll, "*")}, + {Seat: nodebuildgo.Seat, Prefix: strings.TrimSuffix(nodebuildgo.SubjectStepEndedAll, "*"), Stream: nodebuildgo.StreamStepEnded}, + {Seat: nodebuildnode.Seat, Prefix: strings.TrimSuffix(nodebuildnode.SubjectStepEndedAll, "*"), Stream: nodebuildnode.StreamStepEnded}, + {Seat: nodebuildimage.Seat, Prefix: strings.TrimSuffix(nodebuildimage.SubjectStepEndedAll, "*"), Stream: nodebuildimage.StreamStepEnded}, // The seat mesh-builds answers the build step of a candidate, one entry named by its fingerprint (A-97, A-99). - {Seat: builds.Seat, Prefix: strings.TrimSuffix(builds.SubjectStepEndedAll, "*"), Decode: decodeBuildEnded, Pins: buildPins, - Superseding: buildSuperseding}, + {Seat: builds.Seat, Prefix: strings.TrimSuffix(builds.SubjectStepEndedAll, "*"), Stream: builds.StreamStepEnded, Decode: decodeBuildEnded, + Pins: buildPins, Superseding: buildSuperseding}, // The seat mesh-wants answers the composition step (§22, §24). - {Seat: wants.Seat, Prefix: strings.TrimSuffix(wants.SubjectStepEndedAll, "*"), Decode: decodeWantsEnded, Shared: wantsShared}, + {Seat: wants.Seat, Prefix: strings.TrimSuffix(wants.SubjectStepEndedAll, "*"), Stream: wants.StreamStepEnded, Decode: decodeWantsEnded, + Shared: wantsShared}, } // wantsShared is the composition runs a mesh-wants step-ended names, one per machine (design 47 G §723, §729; A-468d, diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go index 5446491fa..c35cc487d 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go @@ -65,6 +65,13 @@ func (c *clockMem) MarkAsk(ask string, m AskMark) error { c.askRuns[AskKey(ask)] = m return nil } +func (c *clockMem) MarkAskAgain(ask string, m AskMark) error { + if c.askRuns == nil { + c.askRuns = map[string]AskMark{} + } + 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 From e9673046cb84391a18ed95b481f9e759a0024600 Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 23 Nov 2026 18:07:56 +0100 Subject: [PATCH 3/3] Runner: read the bus, not a copy; arm a bound only while its count shrinks (issue 1984) Review round 1. The store kept a running pipeline's mover-key values in memory while its record stayed at the revision read, but the module's own runner_unlogged_append writes through a store of its own: a read between that store's record write and its mover-key writes kept old values at the new revision, and the runner served `running` while the bus held `passed`. The copy goes; each key is still read by its name, none listed, with the trunk's check of the revisions read. A bound passing while step ends wait now arms the bound again only while their count (not yet delivered plus unacknowledged) shrank since the bound before, kept as `waited` on the ask's mark beside `unread`: an end the handler naks forever, which no delivery limit stops, ends the step saying the count did not shrink. Every such why says only what is true ("its ask X is not known to be answered: ..."), and none raises call-unanswered. The ask clock the start makes now reads the durable itself, so the integration row fails when the start wires none; the nudge's mutex is the hearer's own. Builds: issue 1984 note 6 (1984/AC1, 1984/AC2), notes 7 (b), (c), 9 (d), 10 (e) --- .../cmd/mesh-delivery-pipeline/askbounds.go | 8 +- .../cmd/mesh-delivery-pipeline/main.go | 4 +- .../stependswaiting_integration_test.go | 9 +- .../internal/pipeline/aged.go | 8 +- .../internal/pipeline/asks.go | 145 +++++++++++------- .../internal/pipeline/asks_test.go | 28 +++- .../internal/pipeline/moverkeys.go | 128 +++++----------- .../internal/pipeline/moverkeys_test.go | 55 +------ .../internal/pipeline/order_test.go | 7 +- .../internal/pipeline/runends.go | 5 +- .../internal/pipeline/stepend_test.go | 20 +-- .../internal/pipeline/steps.go | 8 +- 12 files changed, 190 insertions(+), 235 deletions(-) diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/askbounds.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/askbounds.go index 01ebd2af8..96c7bae84 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/askbounds.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/askbounds.go @@ -42,9 +42,11 @@ func durationSetting(getenv func(string) string, env string, def time.Duration) // askClock is the bound of every ask but a test run's over the state bounds (design 47 H2 §778, H-A-395): a key armed with // its own time to live before the ask is put, armed again at the holder's ask-taken and at each step-progress of the ask, // its expiry heard by watchBounds; the finding call-unanswered, scope call, id the ask, raised when the bound ends the -// step and cleared when the ask is answered after all (H-A-238 (2)). -func askClock(ctx context.Context, bounds jetstream.KeyValue, bound time.Duration, w callFindings, module string, now func() time.Time) *pipeline.AskClock { - return &pipeline.AskClock{Bound: bound, +// step and cleared when the ask is answered after all (H-A-238 (2)). Before a bound ends its step, the runner's own durable +// named durable on the seat's step-ended stream is read (issue 1984): an end waiting there is not the holder's silence. +func askClock(ctx context.Context, bounds jetstream.KeyValue, bound time.Duration, w callFindings, module string, now func() time.Time, + js jetstream.JetStream, durable string) *pipeline.AskClock { + return &pipeline.AskClock{Bound: bound, Waiting: stepEndsWaiting(ctx, js, durable), Arm: func(key string, ttl time.Duration) error { _, err := bounds.Create(ctx, key, []byte(`{"ask":"`+key+`"}`), jetstream.KeyTTL(ttl)) if errors.Is(err, jetstream.ErrKeyExists) { 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 40d98124d..e8418b4e8 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go @@ -186,9 +186,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro hearer.AskSteps = starter.AskSteps hearer.RegistrationWaits = func() { starter.JudgeRegistrationMissing(store) } // at every end (H-A-265 (4)) logger.Printf("asks: an ask's bound %s, counted from its put until its holder's ask-taken, then from the take and each step-progress; past it the step ends could not run and its ask is dropped", askBound) - clock := askClock(ctx, bounds, askBound, rv.Findings, cred.Module, time.Now) - // A bound passing reads the runner's own step-ended durable first: an end waiting there is not the holder's silence (issue 1984). - clock.Waiting = stepEndsWaiting(ctx, js, cred.EventConsumerName()) + clock := askClock(ctx, bounds, askBound, rv.Findings, cred.Module, time.Now, js, cred.EventConsumerName()) 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) diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/stependswaiting_integration_test.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/stependswaiting_integration_test.go index bd5a18a01..0d5c622a4 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/stependswaiting_integration_test.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/stependswaiting_integration_test.go @@ -18,7 +18,8 @@ import ( // testABoundPassingReadsTheRunnersOwnStepEndedDurable is a row of TestTheRunnerPlacesAPipelineAsksItsBuildTakesItsEndAndAnswersAReview // (design 47 H2 §819: the module's tests are folded under its budget). 1984/AC2: as an ask's bound passes the runner reads its own // durable on the seat's step-ended stream once, against the bus: the ends not yet delivered and those delivered and not -// acknowledged; a durable or stream the bus does not hold holds none; a read the bus does not answer is an error. +// acknowledged; a durable or stream the bus does not hold holds none; a read the bus does not answer is an error. The clock +// is made as the runner's start makes it (askClock), so a start that reads no durable fails here. func testABoundPassingReadsTheRunnersOwnStepEndedDurable(t *testing.T) { nc, err := nats.Connect(testbus.URL(t)) if err != nil { @@ -29,7 +30,11 @@ func testABoundPassingReadsTheRunnersOwnStepEndedDurable(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() const durable = "n1_mesh-delivery-pipeline" - waiting := stepEndsWaiting(ctx, js, durable) + // The ask clock the runner's start makes reads the durable it is given: without it a bound ends its step unread. + waiting := askClock(ctx, nil, time.Minute, nil, "mesh-delivery-pipeline", time.Now, js, durable).Waiting + if waiting == nil { + t.Fatal("the runner's ask clock reads no step-ended durable as a bound passes") + } read := func(onSeat string) (uint64, uint64) { t.Helper() p, u, err := waiting(onSeat) diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/aged.go b/modules/mesh-delivery-pipeline/internal/pipeline/aged.go index 35cdcb07c..fe49a2185 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/aged.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/aged.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "sync" "time" seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner" @@ -367,13 +366,10 @@ func (h *Hearer) AgeOnStepEnds(ctx context.Context) { } } -// 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() + h.ageWakeMade.Lock() + defer h.ageWakeMade.Unlock() if h.ageWake == nil { h.ageWake = make(chan struct{}, 1) } diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/asks.go b/modules/mesh-delivery-pipeline/internal/pipeline/asks.go index 0727ef8a4..d86c568d1 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/asks.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/asks.go @@ -41,11 +41,27 @@ func UnansweredWhy(ask string) string { return "its ask " + ask + " was not answered: its holder said nothing of it within ask-unanswered-bound" } -// unreadWhy is the why of a step whose bound passed twice in a row while the runner could not read its own step-ended -// durable of onSeat (issue 1984 note 7 (b)): whether its end waits there is not known, so its holder is not said silent. -func unreadWhy(onSeat, ask string) string { - return "its ask " + ask + " is not known to be answered: the runner could not read its own step-ended durable of " + onSeat + - " at two bounds in a row" +// notKnownWhy is the why of a step its bound ended while whether its end waits in the runner's own step-ended durable is not +// known, what saying why (issue 1984 notes 7 (b), 10 (e)): its holder is never said silent. +func notKnownWhy(ask, what string) string { + return "its ask " + ask + " is not known to be answered: " + what +} + +// unreadWhat is why a step's end is not known when the runner could not read its own step-ended durable of onSeat. +func unreadWhat(onSeat string) string { + return "the runner could not read its own step-ended durable of " + onSeat +} + +// stuckWhat is why a step's end is not known when n step ends of onSeat wait in the runner's own step-ended durable, no +// fewer than the before at the bound before (issue 1984 notes 9 (d), 10 (e)). +func stuckWhat(onSeat string, n, before uint64) string { + return fmt.Sprintf("%d step ends of %s wait in the runner's own step-ended durable and did not shrink since the bound before (%d then)", n, onSeat, before) +} + +// unkeptWhat is why a step's end is not known when n step ends of onSeat wait in the runner's own step-ended durable and +// the runner cannot keep their count to judge the bound after, so it arms no bound it could not end. +func unkeptWhat(onSeat string, n uint64) string { + return fmt.Sprintf("%d step ends of %s wait in the runner's own step-ended durable, and the runner could not keep their count to judge the bound after", n, onSeat) } // UntakenWhy is the why of a step whose ask no holder of onSeat took within the bound after it was asked (§778). @@ -152,17 +168,17 @@ func (v Verbs) AskUnanswered(onSeat, ask string) error { } // Its end may wait in the runner's own step-ended durable, not yet taken: the runner's queue is never counted against // the holder (issue 1984 notes 6, 7). - read, unread := "", false + read, unknown := "", "" if c.Waiting != nil && c.Rearm != nil { var again bool - if read, again, unread = v.endsWaiting(c, key, onSeat, s); again { + if read, again, unknown = v.endsWaiting(c, key, onSeat, s); again { return nil } } - if unread { - why = unreadWhy(onSeat, s.Ask) - h.logf("the ask %s of the %s step of %s on %s is not known to be answered within %s: the runner could not read its own step-ended durable of %s at this bound and the one before; the step ends could not run and its ask is dropped (§778)", - s.Ask, s.Step, key, onSeat, c.bound(), onSeat) + if unknown != "" { + why = notKnownWhy(s.Ask, unknown) + h.logf("the ask %s of the %s step of %s on %s is not known to be answered within %s: %s; the step ends could not run and its ask is dropped (§778)", + s.Ask, s.Step, key, onSeat, c.bound(), unknown) } else { h.logf("the ask %s of the %s step of %s on %s %s within %s%s: the step ends could not run and its ask is dropped (§778)", s.Ask, s.Step, key, onSeat, said, c.bound(), read) @@ -175,73 +191,98 @@ func (v Verbs) AskUnanswered(onSeat, ask string) error { h.logf("the ask %s on %s, ended by its bound, is not dropped: %v", s.Ask, onSeat, err) } } - // The finding call-unanswered says its holder said nothing, which is not known of an ask whose ends were not read: its - // step's why and the pipeline's failure say it. - if c.Raise != nil && !unread { + // The finding call-unanswered says its holder said nothing, which is not known of an ask whose end may wait in the + // runner's own durable: its step's why and the pipeline's failure say it (issue 1984 note 10 (e)). + if c.Raise != nil && unknown == "" { return c.Raise(onSeat, s.Ask, c.bound()) } return nil } // endsWaiting reads the runner's own step-ended durable of onSeat once, as the bound of step s's ask passes (issue 1984 -// notes 6, 7): while step ends wait there, or at the first read that fails, the bound is armed again whole and said, again -// true; a read that fails at the bound after one that failed answers unread true; else it answers what the journal adds to -// the step's end, the count read, and the ask's mark loses its unread. -func (v Verbs) endsWaiting(c *AskClock, key, onSeat string, s seat.StepResult) (read string, again, unread bool) { +// notes 6, 7, 9, 10): the step ends waiting there, not yet delivered and unacknowledged. While some wait, and fewer than at +// the bound before, or at the first read that fails, the bound is armed again whole and said: again true. A read that +// fails after one that failed, or a count no smaller than the one before, answers in unknown what is true of the ask, and +// the step ends saying it. With none waiting it answers what the journal adds to the step's end, the count read. What a +// bound read is kept on the ask's mark, unread and waited, for the bound after (notes 7 (c), 10 (e)); a mark not kept +// ends the step, so no bound is armed again endlessly. +func (v Verbs) endsWaiting(c *AskClock, key, onSeat string, s seat.StepResult) (read string, again bool, unknown string) { h := v.Hearer boundKey := AskBoundKey(onSeat, s.Ask) pending, unacked, err := c.Waiting(onSeat) - var mark AskMark - marked := false - if h.Clock != nil { - var merr error - if mark, marked, merr = h.Clock.AskOf(s.Ask); merr != nil { - h.logf("the mark of ask %s is not read, so the bound passing reads it as unmarked: %v", s.Ask, merr) + if h.Clock == nil { + if err != nil { + h.logf("the bound of ask %s of the %s step of %s on %s passed and the runner's own step-ended durable of %s is not read (%v); the runner keeps no ask marks to arm it once more", + s.Ask, s.Step, key, onSeat, onSeat, err) + return "", false, unreadWhat(onSeat) } + if n := pending + unacked; n > 0 { + h.logf("the bound of ask %s of the %s step of %s on %s passed while %d step ends wait in the runner's own step-ended durable of %s; the runner keeps no ask marks to judge the next bound", + s.Ask, s.Step, key, onSeat, n, onSeat) + return "", false, unkeptWhat(onSeat, n) + } + return fmt.Sprintf(", and no step end waits in the runner's own step-ended durable of %s (0 not yet delivered, 0 unacknowledged)", onSeat), false, "" + } + mark, marked, merr := h.Clock.AskOf(s.Ask) + if merr != nil { + h.logf("the mark of ask %s is not read, so the bound passing reads it as unmarked: %v", s.Ask, merr) } if !marked { mark = AskMark{Pipeline: key, Module: s.Module, Step: s.Step} } + keep := func(what string) bool { + if werr := h.Clock.MarkAskAgain(s.Ask, mark); werr != nil { + h.logf("the bound of ask %s of the %s step of %s on %s passed and %s, and the ask's mark keeping it is not written: %v", + s.Ask, s.Step, key, onSeat, what, werr) + return false + } + return true + } + arm := func(what string) { + if rerr := c.Rearm(boundKey, c.bound()); rerr != nil { + h.logf("the bound of ask %s on %s is not armed again after %s: %v", s.Ask, onSeat, what, rerr) + } + } if err != nil { if mark.Unread != nil { h.logf("the bound of ask %s of the %s step of %s on %s passed and the runner's own step-ended durable of %s is not read again (%v), as at the bound before (%s)", s.Ask, s.Step, key, onSeat, onSeat, err, mark.Unread.Format(time.RFC3339)) - return "", false, true - } - if h.Clock == nil { - h.logf("the bound of ask %s of the %s step of %s on %s passed and the runner's own step-ended durable of %s is not read (%v); the runner keeps no ask marks to arm it once more", - s.Ask, s.Step, key, onSeat, onSeat, err) - return "", false, true + return "", false, unreadWhat(onSeat) } now := h.now() mark.Unread = &now - if werr := h.Clock.MarkAskAgain(s.Ask, mark); werr != nil { - h.logf("the bound of ask %s of the %s step of %s on %s passed and the runner's own step-ended durable of %s is not read (%v), and the ask's mark keeping that is not written (%v)", - s.Ask, s.Step, key, onSeat, onSeat, err, werr) - return "", false, true + what := fmt.Sprintf("the runner's own step-ended durable of %s is not read (%v)", onSeat, err) + if !keep(what) { + return "", false, unreadWhat(onSeat) } - if rerr := c.Rearm(boundKey, c.bound()); rerr != nil { - h.logf("the bound of ask %s on %s is not armed again after its durable was not read: %v", s.Ask, onSeat, rerr) - } - h.logf("the bound of ask %s of the %s step of %s on %s passed and the runner's own step-ended durable of %s is not read (%v): the step is not ended and its bound is armed again with %s; a second failed read at that bound ends it", - s.Ask, s.Step, key, onSeat, onSeat, err, c.bound()) - return "", true, false + arm("its durable was not read") + h.logf("the bound of ask %s of the %s step of %s on %s passed and %s: the step is not ended and its bound is armed again with %s; a second failed read at that bound ends it", + s.Ask, s.Step, key, onSeat, what, c.bound()) + return "", true, "" } - if mark.Unread != nil && h.Clock != nil { - mark.Unread = nil - if werr := h.Clock.MarkAskAgain(s.Ask, mark); werr != nil { - h.logf("the mark of ask %s keeps its unread, its durable read now: %v", s.Ask, werr) + n, before, wasUnread := pending+unacked, mark.Waited, mark.Unread != nil + mark.Unread = nil + switch { + case n == 0: + if wasUnread || before != nil { + mark.Waited = nil + keep("no step end waits") } + return fmt.Sprintf(", and no step end waits in the runner's own step-ended durable of %s (0 not yet delivered, 0 unacknowledged)", onSeat), false, "" + case before != nil && n >= *before: + h.logf("the bound of ask %s of the %s step of %s on %s passed while %d step ends wait in the runner's own step-ended durable of %s (%d not yet delivered, %d delivered and not acknowledged), no fewer than the %d at the bound before: the runner takes none of them", + s.Ask, s.Step, key, onSeat, n, onSeat, pending, unacked, *before) + return "", false, stuckWhat(onSeat, n, *before) } - if n := pending + unacked; n > 0 { - if rerr := c.Rearm(boundKey, c.bound()); rerr != nil { - h.logf("the bound of ask %s on %s is not armed again while step ends wait: %v", s.Ask, onSeat, rerr) - } - h.logf("the bound of ask %s of the %s step of %s on %s passed while %d step ends wait in the runner's own step-ended durable of %s (%d not yet delivered, %d delivered and not acknowledged): the step is not ended and its bound is armed again with %s", - s.Ask, s.Step, key, onSeat, n, onSeat, pending, unacked, c.bound()) - return "", true, false + mark.Waited = &n + what := fmt.Sprintf("%d step ends wait in the runner's own step-ended durable of %s", n, onSeat) + if !keep(what) { + return "", false, unkeptWhat(onSeat, n) } - return fmt.Sprintf(", and no step end waits in the runner's own step-ended durable of %s (0 not yet delivered, 0 unacknowledged)", onSeat), false, false + arm("step ends wait") + h.logf("the bound of ask %s of the %s step of %s on %s passed while %s (%d not yet delivered, %d delivered and not acknowledged), fewer than at any bound before: the step is not ended and its bound is armed again with %s", + s.Ask, s.Step, key, onSeat, what, pending, unacked, c.bound()) + return "", true, "" } // OpenAsk is an ask a running step waits on, and when its holder last spoke of it: its taken-at, else its asked-at. diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/asks_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/asks_test.go index 874d03ac1..a9f8dd57c 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/asks_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/asks_test.go @@ -142,11 +142,12 @@ func TestAnAsksBoundCountsFromThePullAndEndsItsStep(t *testing.T) { } } -// 1984/AC2 (issue 1984 notes 6 and 7): before a bound ends its step, the runner reads its own step-ended durable of the -// ask's seat once. While step ends wait there the step is not ended: its bound is armed again and the journal says how many -// wait. With none waiting the step ends as before, its why true, the journal naming the count read. A read that fails arms -// the bound once more, kept on the ask's mark; a second failed read at that bound ends the step saying the durable was not -// read, never that its holder said nothing, and raises no call-unanswered. A read that succeeds between clears the mark. +// 1984/AC2 (issue 1984 notes 6, 7, 9 and 10): before a bound ends its step, the runner reads its own step-ended durable of the +// ask's seat once. While step ends wait there, fewer than at the bound before, the step is not ended: its bound is armed +// again and the journal says how many wait; a count no smaller ends the step naming it. With none waiting the step ends as +// before, its why true, the journal naming the count read. A read that fails arms the bound once more, kept on the ask's +// mark; a second failed read at that bound ends the step saying the durable was not read. Neither says its holder said +// nothing, and neither raises call-unanswered. A read that succeeds between clears the mark. func TestABoundPassingWhileStepEndsWaitArmsItAgain(t *testing.T) { type read struct { pending, unacked uint64 @@ -161,6 +162,10 @@ func TestABoundPassingWhileStepEndsWaitArmsItAgain(t *testing.T) { {"step ends wait: armed again, then ended once none waits", []read{{3, 1, nil}, {0, 0, nil}}, []string{"armed", "unanswered"}}, {"a failed read arms once more; a second ends saying the durable was not read", []read{{0, 0, errors.New("timeout")}, {0, 0, errors.New("timeout")}}, []string{"armed", "unread"}}, {"a read between two failed ones clears the first", []read{{0, 0, errors.New("timeout")}, {2, 0, nil}, {0, 0, errors.New("timeout")}, {0, 0, errors.New("timeout")}}, []string{"armed", "armed", "armed", "unread"}}, + // 1984/AC2, notes 9 (d) and 10 (e): an end the runner takes again and again (the durables keep no delivery limit) + // never shrinks the count, so the bound is armed again only while the count shrinks, and a count no smaller ends the + // step saying it. + {"armed again only while the count shrinks; a count no smaller ends the step naming it", []read{{5, 0, nil}, {3, 1, nil}, {4, 0, nil}}, []string{"armed", "armed", "stuck"}}, } { t.Run(c.name, func(t *testing.T) { v, store, _, _, _, journal := verbsFixture() @@ -222,6 +227,9 @@ func TestABoundPassingWhileStepEndsWaitArmsItAgain(t *testing.T) { if (m.Unread != nil) != (c.reads[i].err != nil) { t.Errorf("bound %d: the ask's mark keeps unread %v after a read that failed %v", i+1, m.Unread, c.reads[i].err != nil) } + if n := c.reads[i].pending + c.reads[i].unacked; c.reads[i].err == nil && (m.Waited == nil || *m.Waited != n) { + t.Errorf("bound %d: the ask's mark keeps waited %v; want %d, the count read", i+1, m.Waited, n) + } case "unanswered": if s.Outcome != seat.StepResultOutcomeCouldNotRun || s.Why != UnansweredWhy(ask) || len(raised) != 1 { t.Fatalf("bound %d: the step is %s (%s), raised %v; want could not run: %s, and its finding", i+1, s.Outcome, s.Why, raised, UnansweredWhy(ask)) @@ -229,9 +237,13 @@ func TestABoundPassingWhileStepEndsWaitArmsItAgain(t *testing.T) { if countLines(*journal, "0 not yet delivered, 0 unacknowledged") != 1 { t.Errorf("bound %d: the journal %q does not name the count read", i+1, *journal) } - case "unread": - if s.Outcome != seat.StepResultOutcomeCouldNotRun || s.Why != unreadWhy(nodebuildgo.Seat, ask) || strings.Contains(s.Why, "said nothing") { - t.Fatalf("bound %d: the step is %s (%s); want could not run: %s", i+1, s.Outcome, s.Why, unreadWhy(nodebuildgo.Seat, ask)) + case "unread", "stuck": + what := unreadWhat(nodebuildgo.Seat) + if want == "stuck" { + what = stuckWhat(nodebuildgo.Seat, 4, 4) + } + if s.Outcome != seat.StepResultOutcomeCouldNotRun || s.Why != notKnownWhy(ask, what) || strings.Contains(s.Why, "said nothing") { + t.Fatalf("bound %d: the step is %s (%s); want could not run: %s", i+1, s.Outcome, s.Why, notKnownWhy(ask, what)) } if len(raised) != 0 || len(dropped) != 1 { t.Errorf("bound %d: raised %v, dropped %v; want no call-unanswered, which says its holder said nothing, and the ask dropped", i+1, raised, dropped) diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/moverkeys.go b/modules/mesh-delivery-pipeline/internal/pipeline/moverkeys.go index a96d5ab51..b6598bd08 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/moverkeys.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/moverkeys.go @@ -68,60 +68,18 @@ type MoverStore struct { Raw RawState Logf func(string, ...any) - // 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 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 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 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. +// readAt is what the last read of a pipeline found: its record's revision and each mover key's revision. 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() { @@ -147,6 +105,13 @@ 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() @@ -332,14 +297,11 @@ 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, _, 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}) + vals, revs, err := s.readKeys(named(key, p)) + if err != nil { + return seat.Pipeline{}, 0, err } + 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)) @@ -446,67 +408,58 @@ func (s *MoverStore) update(key string, p seat.Pipeline, revision uint64, kept m } 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 { + // Each mover key the record and p name, and each the read found, is read by its name, never listed (issue 1984). + seen, read := s.seen(key) + read = read && seen.rev == revision + names := named(key, was) + for k := range want { + if !slices.Contains(names, k) { + names = append(names, k) + } + } + if read { + for k := range seen.movers { 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) - } + } + vals, revs, err := s.readKeys(names) + if 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 seen.movers[k] != r { + return 0, ErrChanged } } - 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 - } + 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) } - p.Steps = nil // the record written carries no steps inline - s.keep(key, p, readAt{rev: rev, movers: after, vals: want}) + s.setSeen(key, readAt{rev: rev, movers: after}) return rev, nil } @@ -570,8 +523,7 @@ func (s *MoverStore) Create(key string, value []byte) error { if err != nil { return err } - p.Steps = nil // the record written carries no steps inline - s.keep(key, p, readAt{rev: rev, movers: after, vals: want}) + s.setSeen(key, readAt{rev: rev, movers: after}) 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 29a1c7619..434ff3ec8 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/moverkeys_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/moverkeys_test.go @@ -122,24 +122,15 @@ 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 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() - } + {"a mover key written since the read refuses the update, nothing written", func(t *testing.T) string { + m, s, _ := created(t) p, rev, _ := s.Get(key) m.put("steps.main.7.alpha", m.vals["steps.main.7.alpha"]) - p.Why = "read again" + p.Outcome = seat.PipelineOutcomePassed _, 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 { + {"a mover key another store wrote since the read refuses the update, and the next read reads it", func(t *testing.T) string { m, s, _ := created(t) p, rev, _ := s.Get(key) other := &MoverStore{Raw: m} @@ -153,44 +144,6 @@ func TestMoverKeys(t *testing.T) { 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/order_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/order_test.go index ea457f0ec..91399bfc6 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/order_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/order_test.go @@ -97,11 +97,12 @@ func TestAMoversBuildWaitsForItsDependenciesInThePipeline(t *testing.T) { before := mem["main.7"] // H-A-311 (2): the build's end written while its placing was cut (heard by a hearer that places nothing): the same end // heard again, late, moves nothing of the build and still places tool, which that end unlocked. - cut := *h - cut.Release = nil - if _, err := cut.OnStepEnded(bs, bs.Prefix+"n1", end("passed")); err != nil { + release := h.Release + h.Release = nil + if _, err := h.OnStepEnded(bs, bs.Prefix+"n1", end("passed")); err != nil { t.Fatal(err) } + h.Release = release if p, _, _ = mem.Get("main.7"); placed(p, "tool") { t.Fatalf("the cut placing placed tool: %+v", stepsOf(p, "tool")) } diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/runends.go b/modules/mesh-delivery-pipeline/internal/pipeline/runends.go index ebadac686..f5745d664 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/runends.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/runends.go @@ -79,13 +79,16 @@ func IsRunAsk(key string) bool { return strings.HasPrefix(key, AskPrefix) } // 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. Unread // is when the runner last could not read its own step-ended durable of the ask's seat as the ask's bound passed, cleared -// by a read that succeeds (issue 1984 note 7 (c)): a second failed read at the bound after ends the step. +// by a read that succeeds (issue 1984 note 7 (c)): a second failed read at the bound after ends the step. Waited is how +// many step ends waited in that durable at the last bound that armed the bound again (notes 9 (d), 10 (e)): a count no +// smaller at the bound after ends the step. type AskMark struct { Pipeline string `json:"pipeline,omitempty"` Module string `json:"module,omitempty"` Step string `json:"step,omitempty"` Run string `json:"run,omitempty"` Unread *time.Time `json:"unread,omitempty"` + Waited *uint64 `json:"waited,omitempty"` } // markOf is the mark of ask a, put by the pipeline key. diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/stepend_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/stepend_test.go index 7f1081bf4..b3eae80eb 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/stepend_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/stepend_test.go @@ -11,16 +11,11 @@ import ( 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. +// countedRaw is memRaw counting what each call writes, 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) + writes []string + listings int } func (c *countedRaw) Create(key string, value []byte) (uint64, error) { @@ -38,10 +33,10 @@ func (c *countedRaw) Keys(filter string) ([]string, error) { return c.memRaw.Keys(filter) } -func (c *countedRaw) reset() { c.reads, c.writes, c.listings = nil, nil, 0 } +func (c *countedRaw) reset() { c.writes, c.listings = 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 +// own mover key, reads each key by its name, lists none and so 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()} @@ -88,11 +83,6 @@ func TestAStepEndDoesOnlyTheStepsEnd(t *testing.T) { 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) } diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/steps.go b/modules/mesh-delivery-pipeline/internal/pipeline/steps.go index 6b253e20b..ec3d1201d 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/steps.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/steps.go @@ -7,6 +7,7 @@ import ( "slices" "sort" "strings" + "sync" "time" oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel" @@ -223,9 +224,10 @@ 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{} + // ageWake is the nudge of AgeOnStepEnds, made at its first use under ageWakeMade, whichever of a step's end and + // AgeOnStepEnds comes first: one nudge waits at most, the rest merge into it (issue 1984). + ageWakeMade sync.Mutex + 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