assigner: a package-published wakes only the runs waiting for its artifact's package (issue 1984, review round 1)
Every package-published heard woke every run waiting for any package, each asking mesh-builds' published again. Now the wake is kept per the artifact of a package's publisher: the assigner's consumer reads the heard event's artifact (hearPublished) and wakes only the runs whose `waits` names the package that artifact publishes, as the runner's hearPublished matches by artifact; a publish of another package wakes none and asks no published. An event that does not read is journaled and wakes none. Each bind of the consumer still wakes every waiting run (heardBind). Test: TestTheCompositionStepRunsOneAskPerMachine, the wait's row: a package-published of y:go, handed to the consumer's handler while the runs wait for x/go, leaves their wake standing and asks no published; x:go's own then wakes them (failed first with the wake ignoring the artifact). Builds: design 47 H2 H-A-630 (1) (hq 1cdfa6ff); H-A-628 (3) (hq cea6404c); H-A-326
This commit is contained in:
@@ -836,7 +836,14 @@ func (r *compositionRun) filledPins(ctx context.Context, what string, pins map[s
|
|||||||
func (r *compositionRun) awaitPins(ctx context.Context, key, ask, what string, pins map[string]string, publishers map[string]packagePublisher) (map[string]string, string, bool) {
|
func (r *compositionRun) awaitPins(ctx context.Context, key, ask, what string, pins map[string]string, publishers map[string]packagePublisher) (map[string]string, string, bool) {
|
||||||
armed, said := false, ""
|
armed, said := false, ""
|
||||||
for {
|
for {
|
||||||
published := r.runs.publishWake() // taken before the read, so a publish heard meanwhile wakes the next one
|
// The wake of each empty pin's publisher, taken before the read, so a publish heard meanwhile wakes the next one; the run
|
||||||
|
// waits on the one of the package its `waits` names alone (H-A-630 (1)).
|
||||||
|
wakes := map[string]<-chan struct{}{}
|
||||||
|
for path, v := range pins {
|
||||||
|
if by, ok := publishers[path]; ok && v == "" {
|
||||||
|
wakes[path] = r.runs.publishWake(by.artifact)
|
||||||
|
}
|
||||||
|
}
|
||||||
filled, waiting, err := r.filledPins(ctx, what, pins, publishers)
|
filled, waiting, err := r.filledPins(ctx, what, pins, publishers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err.Error(), false
|
return nil, err.Error(), false
|
||||||
@@ -851,6 +858,7 @@ func (r *compositionRun) awaitPins(ctx context.Context, key, ask, what string, p
|
|||||||
return filled, "", true
|
return filled, "", true
|
||||||
}
|
}
|
||||||
path := waiting[0].path
|
path := waiting[0].path
|
||||||
|
published := wakes[path]
|
||||||
since, held, err := r.runs.waitFor(key, ask, path)
|
since, held, err := r.runs.waitFor(key, ask, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "its wait for package " + path + " is not written: " + err.Error(), false
|
return nil, "its wait for package " + path + " is not written: " + err.Error(), false
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.novox.be/novox/mesh-sdk/go/process"
|
"git.novox.be/novox/mesh-sdk/go/process"
|
||||||
|
"github.com/nats-io/nats.go/jetstream"
|
||||||
"maps"
|
"maps"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -100,6 +101,29 @@ func (l *logLines) await(t *testing.T, words string, n int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eventsOf is the assigner's hub as a test hands it events: each handler by its subject, each bind's hearer.
|
||||||
|
type eventsOf struct {
|
||||||
|
handle map[string]func(jetstream.Msg)
|
||||||
|
bound []func(time.Time)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *eventsOf) Handle(subject string, f func(jetstream.Msg)) error {
|
||||||
|
h.handle[subject] = f
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (h *eventsOf) OnBound(f func(time.Time)) { h.bound = append(h.bound, f) }
|
||||||
|
|
||||||
|
// say hands the handler of subject the event ev, and fails the test when it is not acknowledged.
|
||||||
|
func (h *eventsOf) say(t *testing.T, subject string, ev any) {
|
||||||
|
t.Helper()
|
||||||
|
raw, _ := json.Marshal(ev)
|
||||||
|
m := &heardMsg{data: raw, subject: subject}
|
||||||
|
h.handle[subject](m)
|
||||||
|
if !m.acked {
|
||||||
|
t.Errorf("the event %s on %s is not acknowledged", raw, subject)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func newRunStand(t *testing.T, revisionEngine, trunkEngine, seatDigest string) *runStand {
|
func newRunStand(t *testing.T, revisionEngine, trunkEngine, seatDigest string) *runStand {
|
||||||
s := &runStand{asks: map[string]buildstep.StepAsk{}, requests: map[string]composer.Request{}, publishedAt: map[string]string{"src2:x1": "0.1.9"}}
|
s := &runStand{asks: map[string]buildstep.StepAsk{}, requests: map[string]composer.Request{}, publishedAt: map[string]string{"src2:x1": "0.1.9"}}
|
||||||
engine := func(fp, commit string) meshcatalog.CatalogEntry {
|
engine := func(fp, commit string) meshcatalog.CatalogEntry {
|
||||||
@@ -326,10 +350,27 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) {
|
|||||||
u.runs.expired(runBoundPrefix + key)
|
u.runs.expired(runBoundPrefix + key)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// H-A-630 (1): a package-published of another package wakes no run waiting for x/go, so it asks no published; x's own
|
||||||
|
// wakes each.
|
||||||
|
hub := &eventsOf{handle: map[string]func(jetstream.Msg){}}
|
||||||
|
if err := hearPublished(hub, u.runs, t.Logf); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
u.mu.Lock()
|
u.mu.Lock()
|
||||||
|
asked := len(u.published)
|
||||||
|
u.mu.Unlock()
|
||||||
|
hub.say(t, builds.SubjectPackagePublished, builds.PackagePublished{Module: "y", Artifact: "y:go", Branch: "main", Source: 7, Version: "0.2.0", V: 1})
|
||||||
|
u.runs.mu.Lock()
|
||||||
|
_, open := u.runs.published["x:go"]
|
||||||
|
u.runs.mu.Unlock()
|
||||||
|
u.mu.Lock()
|
||||||
|
after := len(u.published)
|
||||||
u.publishedAt = map[string]string{"src2:x1": "0.1.9"}
|
u.publishedAt = map[string]string{"src2:x1": "0.1.9"}
|
||||||
u.mu.Unlock()
|
u.mu.Unlock()
|
||||||
u.runs.heardPublished()
|
if !open || after != asked {
|
||||||
|
t.Errorf("a publish of y:go woke the runs waiting for x/go (their wake standing %v) or asked published %d times more", open, after-asked)
|
||||||
|
}
|
||||||
|
hub.say(t, builds.SubjectPackagePublished, builds.PackagePublished{Module: "x", Artifact: "x:go", Branch: "main", Source: 7, Version: "0.1.9", V: 1})
|
||||||
}
|
}
|
||||||
var out stepOutcome
|
var out stepOutcome
|
||||||
select {
|
select {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
|
|
||||||
"github.com/nats-io/nats.go/jetstream"
|
"github.com/nats-io/nats.go/jetstream"
|
||||||
|
|
||||||
|
meshbuilds "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
||||||
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||||
@@ -274,9 +275,10 @@ type compositionRuns struct {
|
|||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
// changed is closed and replaced at each change of the state heard (heard): a step waiting on a run reads its key again.
|
// changed is closed and replaced at each change of the state heard (heard): a step waiting on a run reads its key again.
|
||||||
changed chan struct{}
|
changed chan struct{}
|
||||||
// published is closed and replaced at each package-published of the seat mesh-builds heard (heardPublished): a run waiting for
|
// published holds, by the artifact of a package's publisher (<module>:<artifact>), what is closed and deleted at the seat
|
||||||
// a package's publish asks published again (design 47 H2 H-A-628 (3), H-A-326).
|
// mesh-builds' package-published of that artifact heard (heardPublished), and at each bind of the consumer: a run waiting for
|
||||||
published chan struct{}
|
// the package that artifact publishes asks published again (design 47 H2 H-A-628 (3), H-A-630 (1); H-A-326).
|
||||||
|
published map[string]chan struct{}
|
||||||
// seen are the keys the state's watch handed and has not seen deleted: a listing of the bucket misses a key that is
|
// seen are the keys the state's watch handed and has not seen deleted: a listing of the bucket misses a key that is
|
||||||
// being written at that moment, so every lookup takes these beside it (keys).
|
// being written at that moment, so every lookup takes these beside it (keys).
|
||||||
seen map[string]bool
|
seen map[string]bool
|
||||||
@@ -290,24 +292,60 @@ type compositionRuns struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newCompositionRuns(kv runsKV, set runSettings, now func() time.Time, logf func(string, ...any)) *compositionRuns {
|
func newCompositionRuns(kv runsKV, set runSettings, now func() time.Time, logf func(string, ...any)) *compositionRuns {
|
||||||
return &compositionRuns{kv: kv, set: set, now: now, logf: logf, changed: make(chan struct{}), published: make(chan struct{})}
|
return &compositionRuns{kv: kv, set: set, now: now, logf: logf, changed: make(chan struct{}), published: map[string]chan struct{}{}}
|
||||||
}
|
}
|
||||||
|
|
||||||
// heardPublished wakes every run waiting for a package's publish, at the seat mesh-builds' package-published heard and at each
|
// heardPublished wakes the runs waiting for the package artifact publishes, at the seat mesh-builds' package-published of that
|
||||||
// bind of the assigner's consumer (an event said before it was made is not delivered): each reads published again, the event
|
// artifact heard: each reads published again, the event only its second path; a publish of another package wakes none, so it asks
|
||||||
// only its second path (design 47 H2 H-A-628 (3); H-A-326, H-A-328).
|
// no published (design 47 H2 H-A-628 (3), H-A-630 (1); H-A-326, H-A-328).
|
||||||
func (r *compositionRuns) heardPublished() {
|
func (r *compositionRuns) heardPublished(artifact string) {
|
||||||
r.mu.Lock()
|
|
||||||
close(r.published)
|
|
||||||
r.published = make(chan struct{})
|
|
||||||
r.mu.Unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
// publishWake is closed at the next package-published heard.
|
|
||||||
func (r *compositionRuns) publishWake() <-chan struct{} {
|
|
||||||
r.mu.Lock()
|
r.mu.Lock()
|
||||||
defer r.mu.Unlock()
|
defer r.mu.Unlock()
|
||||||
return r.published
|
if w, ok := r.published[artifact]; ok {
|
||||||
|
close(w)
|
||||||
|
delete(r.published, artifact)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// heardBind wakes every run waiting for a package's publish, at each bind of the assigner's consumer of package-published, which
|
||||||
|
// hears no event said before it was made: each reads published again.
|
||||||
|
func (r *compositionRuns) heardBind() {
|
||||||
|
r.mu.Lock()
|
||||||
|
defer r.mu.Unlock()
|
||||||
|
for artifact, w := range r.published {
|
||||||
|
close(w)
|
||||||
|
delete(r.published, artifact)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// publishWake is closed at the next package-published of artifact heard, or the consumer's next bind.
|
||||||
|
func (r *compositionRuns) publishWake(artifact string) <-chan struct{} {
|
||||||
|
r.mu.Lock()
|
||||||
|
defer r.mu.Unlock()
|
||||||
|
w, ok := r.published[artifact]
|
||||||
|
if !ok {
|
||||||
|
w = make(chan struct{})
|
||||||
|
r.published[artifact] = w
|
||||||
|
}
|
||||||
|
return w
|
||||||
|
}
|
||||||
|
|
||||||
|
// hearPublished hears the seat mesh-builds' package-published on the assigner's durable consumer: the runs waiting for the
|
||||||
|
// package its artifact publishes are woken (heardPublished, design 47 H2 H-A-630 (1)); one that does not read wakes none and is
|
||||||
|
// journaled.
|
||||||
|
func hearPublished(hub interface {
|
||||||
|
Handle(string, func(jetstream.Msg)) error
|
||||||
|
}, r *compositionRuns, logf func(string, ...any)) error {
|
||||||
|
return hub.Handle(meshbuilds.SubjectPackagePublished, func(m jetstream.Msg) {
|
||||||
|
ev, _, err := meshbuilds.DecodePackagePublishedEvent(m.Data())
|
||||||
|
if err != nil || ev.Artifact == "" {
|
||||||
|
logf("%s holds what is no package-published naming its artifact, so it wakes no composition run: %v", m.Subject(), err)
|
||||||
|
_ = m.Ack()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r.heardPublished(ev.Artifact)
|
||||||
|
_ = m.Ack()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// waitFor writes on the run of ask the package it waits for, `waits` (design 47 H2 H-A-629 (1)), by compare-and-set: the time
|
// waitFor writes on the run of ask the package it waits for, `waits` (design 47 H2 H-A-629 (1)), by compare-and-set: the time
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||||
meshbuilds "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
|
||||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
|
||||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||||
@@ -517,15 +516,13 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
|||||||
if err := hearRunBounds(hub, runs, logger.Printf); err != nil {
|
if err := hearRunBounds(hub, runs, logger.Printf); err != nil {
|
||||||
logger.Printf("the build seats' ask-taken and step-progress are not heard, so a composition run is ended by no bound: %v", err)
|
logger.Printf("the build seats' ask-taken and step-progress are not heard, so a composition run is ended by no bound: %v", err)
|
||||||
}
|
}
|
||||||
// The seat mesh-builds' package-published wakes a run waiting for a package's publish, which reads published again; so does
|
// The seat mesh-builds' package-published wakes the runs waiting for the package its artifact publishes, which read published
|
||||||
// each bind of the consumer, which hears no event said before it was made (design 47 H2 H-A-628 (3); H-A-326, H-A-328).
|
// again; each bind of the consumer, which hears no event said before it was made, wakes every waiting run (design 47 H2
|
||||||
if err := hub.Handle(meshbuilds.SubjectPackagePublished, func(m jetstream.Msg) {
|
// H-A-628 (3), H-A-630 (1); H-A-326, H-A-328).
|
||||||
runs.heardPublished()
|
if err := hearPublished(hub, runs, logger.Printf); err != nil {
|
||||||
_ = m.Ack()
|
|
||||||
}); err != nil {
|
|
||||||
logger.Printf("the seat mesh-builds' package-published is not heard, so a composition run waiting for a package reads published only at its start: %v", err)
|
logger.Printf("the seat mesh-builds' package-published is not heard, so a composition run waiting for a package reads published only at its start: %v", err)
|
||||||
}
|
}
|
||||||
hub.OnBound(func(time.Time) { runs.heardPublished() })
|
hub.OnBound(func(time.Time) { runs.heardBind() })
|
||||||
}
|
}
|
||||||
if inputs != nil {
|
if inputs != nil {
|
||||||
var runEnded func(buildstep.StepEnded) error
|
var runEnded func(buildstep.StepEnded) error
|
||||||
|
|||||||
Reference in New Issue
Block a user