Merge pull request 'Pipeline runner: a step's end ends only its step, read from the bus; a bound re-arms only while step ends still drain (issue 1984)' (#359) from fix/runner-step-ends into main
This commit was merged in pull request #359.
This commit is contained in:
@@ -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) {
|
||||
@@ -84,6 +86,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)) {
|
||||
|
||||
@@ -186,7 +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)
|
||||
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)
|
||||
@@ -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")
|
||||
|
||||
@@ -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"}}}
|
||||
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
//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. 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 {
|
||||
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"
|
||||
// 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)
|
||||
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")
|
||||
}
|
||||
}
|
||||
@@ -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))
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
@@ -23,7 +24,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 +33,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 +75,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 +348,38 @@ 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ageNudge is the nudge AgeOnStepEnds waits on, holding one nudge at most.
|
||||
func (h *Hearer) ageNudge() chan struct{} {
|
||||
h.ageWakeMade.Lock()
|
||||
defer h.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:
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,29 @@ func UnansweredWhy(ask string) string {
|
||||
return "its ask " + ask + " was not answered: its holder said nothing of it within ask-unanswered-bound"
|
||||
}
|
||||
|
||||
// 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).
|
||||
func UntakenWhy(onSeat string) string {
|
||||
return "its ask was not taken: " + onSeat + "'s holder takes none"
|
||||
@@ -58,6 +81,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 +166,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, unknown := "", ""
|
||||
if c.Waiting != nil && c.Rearm != nil {
|
||||
var again bool
|
||||
if read, again, unknown = v.endsWaiting(c, key, onSeat, s); again {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
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)
|
||||
}
|
||||
if err := h.endUnanswered(key, s.Ask, why); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -149,12 +191,100 @@ 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 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, 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)
|
||||
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, unreadWhat(onSeat)
|
||||
}
|
||||
now := h.now()
|
||||
mark.Unread = &now
|
||||
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)
|
||||
}
|
||||
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, ""
|
||||
}
|
||||
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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
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.
|
||||
type OpenAsk struct {
|
||||
Seat, Ask string
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
@@ -141,6 +142,121 @@ func TestAnAsksBoundCountsFromThePullAndEndsItsStep(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
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"}},
|
||||
// 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()
|
||||
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)
|
||||
}
|
||||
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))
|
||||
}
|
||||
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", "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)
|
||||
}
|
||||
}
|
||||
}
|
||||
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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -61,8 +61,9 @@ 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)
|
||||
@@ -138,12 +139,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,7 +297,7 @@ 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)
|
||||
vals, revs, err := s.readKeys(named(key, p))
|
||||
if err != nil {
|
||||
return seat.Pipeline{}, 0, err
|
||||
}
|
||||
@@ -377,12 +406,30 @@ func (s *MoverStore) update(key string, p seat.Pipeline, revision uint64, kept m
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
vals, revs, err := s.moverKeys(key)
|
||||
var was seat.Pipeline
|
||||
inline := json.Unmarshal(raw, &was) == nil && len(was.Steps) > 0
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
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 seen, ok := s.seen(key); ok && seen.rev == revision {
|
||||
if read {
|
||||
for k, r := range revs {
|
||||
if seen.movers[k] != r {
|
||||
return 0, ErrChanged
|
||||
@@ -394,8 +441,6 @@ 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
|
||||
var after map[string]uint64
|
||||
if inline {
|
||||
if after, err = s.writeMovers(key, want, vals, revs); err != nil {
|
||||
|
||||
@@ -130,6 +130,20 @@ func TestMoverKeys(t *testing.T) {
|
||||
_, 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"},
|
||||
{"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}
|
||||
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"},
|
||||
{"a record written since the read refuses the update", func(t *testing.T) string {
|
||||
_, s, _ := created(t)
|
||||
p, rev, _ := s.Get(key)
|
||||
|
||||
@@ -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"))
|
||||
}
|
||||
|
||||
@@ -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,18 @@ 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. 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"`
|
||||
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.
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
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 writes, and the listings.
|
||||
type countedRaw struct {
|
||||
*memRaw
|
||||
writes []string
|
||||
listings int
|
||||
}
|
||||
|
||||
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.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, 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()}
|
||||
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)
|
||||
}
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
|
||||
@@ -27,6 +28,9 @@ type StepSeat struct {
|
||||
Seat string
|
||||
// Prefix is the subject before <node>.
|
||||
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 +45,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,
|
||||
@@ -162,9 +167,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 +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, 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
|
||||
@@ -516,8 +526,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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user