Compare commits
68
Commits
main
...
feat/47-H2b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0102fc95c5 | ||
|
|
3ad4e78c11 | ||
|
|
56296ccc43 | ||
|
|
8101731ebc | ||
|
|
f04f4d4128 | ||
|
|
c98e92afae | ||
|
|
50945e9b9a | ||
|
|
ec21db3158 | ||
|
|
74f280b843 | ||
|
|
abd2e6e50f | ||
|
|
465a6d4cd9 | ||
|
|
f3d678d88d | ||
|
|
da551f530a | ||
|
|
5e25feee3a | ||
|
|
b77cdf1513 | ||
|
|
39f78836d2 | ||
|
|
781108b07e | ||
|
|
c9599c8b82 | ||
|
|
b371f980d5 | ||
|
|
3ab7943882 | ||
|
|
e296f57489 | ||
|
|
bd655b28c5 | ||
|
|
e061c319f1 | ||
|
|
e06c204af3 | ||
|
|
896b0e1f75 | ||
|
|
613e89c8e3 | ||
|
|
e8f398be64 | ||
|
|
f4a9ea5e3f | ||
|
|
30817f1f39 | ||
|
|
dc3986313f | ||
|
|
3fe271acf3 | ||
|
|
f9232d5e60 | ||
|
|
bfefd71b4c | ||
|
|
3089814382 | ||
|
|
16dc5a0bd0 | ||
|
|
6e75c4198a | ||
|
|
ae12fa5988 | ||
|
|
016e2e94d7 | ||
|
|
b2f3b2e2d3 | ||
|
|
a16654e248 | ||
|
|
9141bd514a | ||
|
|
0c3c930979 | ||
|
|
0941bd6d09 | ||
|
|
388626ac82 | ||
|
|
3c9be07489 | ||
|
|
5162465293 | ||
|
|
83cbf2e464 | ||
|
|
b44a9ee1dc | ||
|
|
499bb15eae | ||
|
|
aea1e6129c | ||
|
|
4eae3d6847 | ||
|
|
ca4735f35f | ||
|
|
aef199cb83 | ||
|
|
f05fb8ab55 | ||
|
|
79c0bf8e90 | ||
|
|
45c9d20baf | ||
|
|
8371945725 | ||
|
|
b5e3b94489 | ||
|
|
891256f413 | ||
|
|
a90572e297 | ||
|
|
cecf4142e6 | ||
|
|
d36511022f | ||
|
|
6f21579887 | ||
|
|
21370394d7 | ||
|
|
bcd6ac4e60 | ||
|
|
ff22c20d66 | ||
|
|
a807a4511e | ||
|
|
e706f2577e |
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"maps"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -60,6 +61,20 @@ func (b *builtEnds) endOf(module, fp string) (builds.BuildEnded, bool) {
|
||||
return e, ok
|
||||
}
|
||||
|
||||
// doneStarting is the done builds of module the assigner hears whose fingerprint starts with prefix, in fingerprint order.
|
||||
func (b *builtEnds) doneStarting(module, prefix string) []builds.BuildEnded {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
var out []builds.BuildEnded
|
||||
for _, e := range b.ends {
|
||||
if e.Module == module && e.Outcome == builds.BuildDone && strings.HasPrefix(e.Fingerprint, prefix) {
|
||||
out = append(out, e)
|
||||
}
|
||||
}
|
||||
sort.Slice(out, func(i, j int) bool { return out[i].Fingerprint < out[j].Fingerprint })
|
||||
return out
|
||||
}
|
||||
|
||||
// partsOf is the parts of module's build at fp as its end names them (each artifact's digest by `<module>:<artifact>`), with the
|
||||
// node that keeps it, for a kept build or a build of another watched branch; false for a build of the trunk not kept, whose
|
||||
// parts the version's release says (releasedVersions).
|
||||
|
||||
@@ -79,7 +79,7 @@ func (r *compositionRuns) sayWaitsAtPut(run meshwants.CompositionRun) {
|
||||
|
||||
// sayWaitsOf is sayWaits, each held id with after added.
|
||||
func (r *compositionRuns) sayWaitsOf(run meshwants.CompositionRun, readers []meshwants.CompositionReader, how, after string) {
|
||||
if r.say == nil {
|
||||
if r.owe == nil {
|
||||
return
|
||||
}
|
||||
for _, c := range readers {
|
||||
@@ -92,9 +92,40 @@ func (r *compositionRuns) sayWaitsOf(run meshwants.CompositionRun, readers []mes
|
||||
if how != "" {
|
||||
w.How, event, id = how, meshwants.EventWaitEnded, strings.TrimSuffix(id, ".held")+".ended"
|
||||
}
|
||||
if err := r.say(event, w, id); err != nil {
|
||||
r.logf("the %s of %s on the composition run of %s is not said: %v", event, c.Pipeline, run.Machine, err)
|
||||
// Owed in the order of its `<node>.<module>`, said again until the bus takes it (design 47 H2b §832 1., H-A-873).
|
||||
r.owe(compositionWaitOrder(run.Machine, c.Module), event, w, id)
|
||||
}
|
||||
}
|
||||
|
||||
// compositionWaitOrder is the order the events of a composition run's reader wait are said in: its `<node>.<module>` (H-A-873).
|
||||
func compositionWaitOrder(node, module string) string {
|
||||
return "composition-wait." + node + "." + module
|
||||
}
|
||||
|
||||
// sayWaitsAgain says again, at the assigner's start, the wait-held of each reader of a run with no `ended` that still waits (its
|
||||
// ask untaken, or its wait for a package's publish standing), under the id first said, from the kept runs alone (design 47 H2b
|
||||
// §832 4., H-A-873).
|
||||
func (r *compositionRuns) sayWaitsAgain() {
|
||||
all, err := r.keys()
|
||||
if err != nil {
|
||||
r.logf("composition-runs: the runs standing at the start are not read, so their waits are not said again: %v", err)
|
||||
return
|
||||
}
|
||||
for _, key := range all {
|
||||
if !isRunKey(key) {
|
||||
continue
|
||||
}
|
||||
run, _, ok, err := r.read(key)
|
||||
if err != nil || !ok || run.Ended != nil || (run.Waits == nil && !r.untaken(key, run.Ask)) {
|
||||
continue
|
||||
}
|
||||
var waiting []meshwants.CompositionReader
|
||||
for _, c := range run.Readers {
|
||||
if c.Ended == nil {
|
||||
waiting = append(waiting, c)
|
||||
}
|
||||
}
|
||||
r.sayWaits(run, waiting, "")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -426,4 +457,6 @@ func (c *compositionSteps) takeUp(ctx context.Context, r *compositionRuns) {
|
||||
}
|
||||
go c.say1(ctx, reader.ID, stepRunOf(reader.CompositionReader), how, again)
|
||||
}
|
||||
// the waits of the open runs are said again once the readers are taken up: the runs' ends race the take-up, and a say must not delay it
|
||||
r.sayWaitsAgain()
|
||||
}
|
||||
|
||||
@@ -327,7 +327,7 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) {
|
||||
return put(ctx, a)
|
||||
}
|
||||
lastHeld := map[string]string{} // by machine: what its newest wait-held waits on, and its id
|
||||
u.runs.say = func(event string, body any, id string) error {
|
||||
u.runs.owe = func(_, event string, body any, id string) {
|
||||
w := body.(meshwants.Wait)
|
||||
journal.logf("said %s on %s: %s (%s)", event, w.On, w.Words, id)
|
||||
if event == meshwants.EventWaitHeld {
|
||||
@@ -335,7 +335,6 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) {
|
||||
lastHeld[w.Node] = w.On + " (" + id + ")"
|
||||
u.mu.Unlock()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
phase := &stepPhase{}
|
||||
done := make(chan stepOutcome, 1)
|
||||
|
||||
@@ -282,9 +282,9 @@ type compositionRuns 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
|
||||
// being written at that moment, so every lookup takes these beside it (keys).
|
||||
seen map[string]bool
|
||||
// say says an event of the seat mesh-wants (a reader's wait, A-469y); drop asks the build seat's drop of a run ask (§119);
|
||||
// nil says or drops nothing.
|
||||
say publisher
|
||||
// owe owes an event of the seat mesh-wants (a reader's wait, A-469y) in the order given, as the passer owes every event it says
|
||||
// (design 47 H2b §832 1., H-A-873); drop asks the build seat's drop of a run ask (§119); nil owes or drops nothing.
|
||||
owe func(order, event string, body any, id string)
|
||||
drop func(ask, why string) error
|
||||
// moved is told each run that ended, for the readers a rerun carried to say their end again (compositionSteps.move).
|
||||
// Set once the steps are served, after the hub starts.
|
||||
|
||||
@@ -374,13 +374,12 @@ func TestACompositionRunsBoundTimesOwedProgress(t *testing.T) {
|
||||
journal = append(journal, fmt.Sprintf(f, a...))
|
||||
mu.Unlock()
|
||||
})
|
||||
r.say = func(event string, body any, _ string) error {
|
||||
r.owe = func(_, event string, body any, _ string) {
|
||||
w := body.(meshwants.Wait)
|
||||
if w.On != waitOnBuildNode || w.Step != "pipeline" || w.Owner != meshwants.Seat || w.Node == "" {
|
||||
t.Errorf("the wait said %+v", w)
|
||||
}
|
||||
saids = append(saids, said{event, w.How, w.Module})
|
||||
return nil
|
||||
}
|
||||
r.drop = func(ask, why string) error { drops = append(drops, ask+": "+why); return nil }
|
||||
return kv, r, &saids, &drops, &journal
|
||||
@@ -451,6 +450,56 @@ func TestACompositionRunsBoundTimesOwedProgress(t *testing.T) {
|
||||
t.Errorf("an ended run is dropped again: %v", *drops)
|
||||
}
|
||||
})
|
||||
// Design 47 H2b §832 1., 2., 4. (H-A-873, review r1 finding 4): a reader's wait-held and wait-ended are owed as every event is, in the order
|
||||
// of their `<node>.<module>`, said again under their ids once the bus takes them, and a start says the waits of an open run again.
|
||||
t.Run("a refused wait event is owed in order and said again; a start says the waits of an open run again", func(t *testing.T) {
|
||||
kv := newRunsMem()
|
||||
r := newCompositionRuns(kv, defaultRunSettings, func() time.Time { return now }, t.Logf)
|
||||
p := newPasser(kvSet{}, now)
|
||||
var said []string
|
||||
refuse := true
|
||||
p.publishWants = func(event string, _ any, id string) error {
|
||||
if refuse {
|
||||
return context.DeadlineExceeded
|
||||
}
|
||||
said = append(said, event+" "+id)
|
||||
return nil
|
||||
}
|
||||
r.owe = func(order, event string, body any, id string) { p.wantsOwe(order, event, body, id, nil) }
|
||||
if _, err := r.join(reader("a"), "main.3", "n1", "run-1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
held := p.owedAll()
|
||||
if len(held) != 1 || !strings.HasSuffix(held[0].ID, ".a.held") {
|
||||
t.Fatalf("the refused wait-held is not owed: %+v", held)
|
||||
}
|
||||
// A restart: a new passer and runs over the kept state say the open run's waits again under the same id.
|
||||
p = newPasser(kvSet{}, now)
|
||||
p.publishWants = func(event string, _ any, id string) error { said = append(said, event+" "+id); return nil }
|
||||
r = newCompositionRuns(kv, defaultRunSettings, func() time.Time { return now }, t.Logf)
|
||||
r.owe = func(order, event string, body any, id string) { p.wantsOwe(order, event, body, id, nil) }
|
||||
r.sayWaitsAgain()
|
||||
if len(said) != 1 || said[0] != meshwants.EventWaitHeld+" "+held[0].ID {
|
||||
t.Fatalf("the start said %v, want the wait-held under %s", said, held[0].ID)
|
||||
}
|
||||
// The end made while the held is owed is said after it.
|
||||
refuse, said = true, nil
|
||||
p.publishWants = func(event string, _ any, id string) error {
|
||||
if refuse {
|
||||
return context.DeadlineExceeded
|
||||
}
|
||||
said = append(said, event+" "+id)
|
||||
return nil
|
||||
}
|
||||
kv.expire(runUntakenPrefix + key)
|
||||
r.expired(runUntakenPrefix + key)
|
||||
refuse = false
|
||||
p.owed.list[0].next = p.clock()
|
||||
p.sayOwed()
|
||||
if len(said) != 1 || !strings.HasPrefix(said[0], meshwants.EventWaitEnded+" ") || len(p.owedAll()) != 0 {
|
||||
t.Errorf("the owed wait-ended said %v, still owed %v", said, p.owedAll())
|
||||
}
|
||||
})
|
||||
// A-470n, A-470o: a bound holds its run's ask, armed for it alone; a late signal of a run replaced moves nothing and is
|
||||
// journaled; an expiry ends the run only while its bound is still absent and the run taken (bound.) or untaken (untaken.).
|
||||
rerun := func(kv *runsMem, r *compositionRuns) func() { // a rerun replaces run-1 by run-2, its bounds gone, run-2's untaken armed
|
||||
|
||||
@@ -365,8 +365,10 @@ func (p *passer) capabilityDigests() []meshwants.AssignmentRevisionCapabilitiesI
|
||||
}
|
||||
|
||||
// sayWanted says `wanted` for a want written or removed now, from the revision the pass keeps (A-61, A-67); with none kept, it is
|
||||
// said in the log that it was not said. fp is the want's, and for a removal the fingerprint last wanted there.
|
||||
func (p *passer) sayWanted(node, module, fp, pipeline string, removed bool) {
|
||||
// said in the log that it was not said. fp is the want's, and for a removal the fingerprint last wanted there. at is the want key's
|
||||
// write time when the event is said again after a restart (design 47 H2b H-A-859), zero for a say made with the write; taken runs
|
||||
// once the bus has taken it (a removal's mark goes then, §832 4.).
|
||||
func (p *passer) sayWanted(node, module, fp, pipeline string, removed bool, wantRevision uint64, at time.Time, taken func()) {
|
||||
if p.publishWants == nil {
|
||||
return
|
||||
}
|
||||
@@ -381,13 +383,14 @@ func (p *passer) sayWanted(node, module, fp, pipeline string, removed bool) {
|
||||
p.logf("the want of %s on %s is written, but no assignment graph revision is kept, so wanted is not said", module, node)
|
||||
return
|
||||
}
|
||||
at := p.clock().UTC()
|
||||
body := meshwants.WantedEvent{V: keys.Version, Node: node, Module: module, Fp: fp, Pipeline: pipeline, Removed: removed, Revision: kept.Revision, Source: source, At: &at}
|
||||
event := strings.TrimPrefix(meshwants.SubjectWanted(keys.EscapeName(node), keys.EscapeName(module)), "mesh.seat."+meshwants.Seat+".event.")
|
||||
id := fmt.Sprintf("wanted.%s.%s.%s.%t.%d.%s", keys.EscapeName(node), keys.EscapeName(module), fp, removed, kept.Revision, at.Format(time.RFC3339Nano))
|
||||
if err := p.wantsSay(event, body, id); err != nil {
|
||||
p.logf("wanted of %s on %s is not said: %v", module, node, err)
|
||||
if at.IsZero() {
|
||||
at = p.clock()
|
||||
}
|
||||
at = at.UTC()
|
||||
body := meshwants.WantedEvent{V: keys.Version, Node: node, Module: module, Fp: fp, Pipeline: pipeline, Removed: removed, Revision: kept.Revision, Source: source, At: &at, WantRevision: int64(wantRevision)}
|
||||
event := strings.TrimPrefix(meshwants.SubjectWanted(keys.EscapeName(node), keys.EscapeName(module)), "mesh.seat."+meshwants.Seat+".event.")
|
||||
id := fmt.Sprintf("wanted.%s.%s.%s.%t.%d", keys.EscapeName(node), keys.EscapeName(module), fp, removed, wantRevision)
|
||||
p.wantsOwe("want."+keys.EscapeName(node)+"."+keys.EscapeName(module), event, body, id, taken)
|
||||
}
|
||||
|
||||
// namedBuild answers what a want of module at fp names of its build (design 47 G §379, §526, A-96): a kept build's or another watched
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -102,6 +103,159 @@ func TestTheWantsAreSaidWantedFromTheKeptAssignmentGraphRevision(t *testing.T) {
|
||||
// pipeline's sequence the want rule set, as information; a want of no pipeline the newest source held. The order is the bus's:
|
||||
// a want is written by compare-and-set on the key's revision the pass read, whatever its run, and one that differs only by its
|
||||
// run stands; a pass whose read the key has moved past writes nothing, says so once, and the next pass writes it.
|
||||
// Design 47 H §832 3. (H-A-830, H-A-832): the id of `wanted` names the want's key revision, never the say's time or the graph
|
||||
// revision, so puts of F1, F0 and F1 say three under three ids, and a removal is the id of the write it removes.
|
||||
t.Run("a want's ids name its key revision", func(t *testing.T) {
|
||||
fp0 := fpTest[:len(fpTest)-1] + "0"
|
||||
events = nil
|
||||
for _, f := range []string{fpTest, fp0, fpTest} {
|
||||
p.putWant(ctx, "ace", "owed", mwc.Want{Fp: f, Self: true})
|
||||
}
|
||||
p.putWant(ctx, "ace", "owed", mwc.Want{Removed: true})
|
||||
ids := map[string]bool{}
|
||||
for _, e := range events {
|
||||
ids[e.id] = true
|
||||
}
|
||||
var last meshwants.WantedEvent
|
||||
_ = json.Unmarshal(events[len(events)-1].body, &last)
|
||||
if len(events) != 4 || len(ids) != 4 || !strings.Contains(events[0].id, "wanted.ace.owed."+fpTest+".false.") || strings.Contains(events[0].id, "T") {
|
||||
t.Errorf("ids %v", events)
|
||||
}
|
||||
if !last.Removed || last.WantRevision == 0 || !strings.HasSuffix(events[3].id, ".true."+strconv.FormatInt(last.WantRevision, 10)) {
|
||||
t.Errorf("the removal said %+v under %s", last, events[3].id)
|
||||
}
|
||||
})
|
||||
// Design 47 H2b §832 3. (H-A-832, 1984/AC-832q): a `wanted` the bus refused and said again carries the body first said, its `at`
|
||||
// included, under the id first made.
|
||||
t.Run("a wanted owed and said again carries the body first said, at included (AC-832q)", func(t *testing.T) {
|
||||
first := time.Date(2026, 11, 27, 6, 0, 0, 0, time.UTC)
|
||||
clock, refuse := first, true
|
||||
p.now = func() time.Time { return clock }
|
||||
defer func() { p.now = func() time.Time { return at } }()
|
||||
p.publishWants = func(event string, body any, id string) error {
|
||||
if refuse {
|
||||
return errors.New("the bus refuses")
|
||||
}
|
||||
raw, _ := json.Marshal(body)
|
||||
events = append(events, said{event, id, raw})
|
||||
return nil
|
||||
}
|
||||
events = nil
|
||||
p.putWant(ctx, "ace", "late", mwc.Want{Fp: fpTest, Self: true})
|
||||
owed := p.owedAll()
|
||||
if len(owed) != 1 || len(events) != 0 {
|
||||
t.Fatalf("the refused wanted is owed %+v, said %d", owed, len(events))
|
||||
}
|
||||
clock, refuse = first.Add(10*time.Minute), false
|
||||
p.owed.list[0].next = clock
|
||||
if !p.sayOwed() || len(events) != 1 {
|
||||
t.Fatalf("the owed wanted is not said again: %d events", len(events))
|
||||
}
|
||||
var b meshwants.WantedEvent
|
||||
_ = json.Unmarshal(events[0].body, &b)
|
||||
if events[0].id != owed[0].ID || b.At == nil || !b.At.Equal(first) {
|
||||
t.Errorf("said again under %s with at %v, want %s and the first said's %v", events[0].id, b.At, owed[0].ID, first)
|
||||
}
|
||||
})
|
||||
// Design 47 H2b §832 4. (H-A-843, H-A-859; 1984/AC-832e, AC-832f, AC-832r, AC-832w): a start says again what the kept state implies
|
||||
// under the same ids; a removal is marked before it is written and said, and the mark is said from at a start; a `wanted` said
|
||||
// again carries the want key's write time as its `at`.
|
||||
t.Run("a start says again the wants written and the removals marked, under the same ids", func(t *testing.T) {
|
||||
first := time.Date(2026, 11, 27, 5, 0, 0, 0, time.UTC)
|
||||
build := func(kv *memKV, ends *memEnds, now time.Time) (*passer, *[]said) {
|
||||
q := newPasser(kvSet{buckets.Wants(): kv}, now)
|
||||
q.now = func() time.Time { return now }
|
||||
q.logf = t.Logf
|
||||
var out []said
|
||||
q.publishWants = func(event string, body any, id string) error {
|
||||
raw, _ := json.Marshal(body)
|
||||
out = append(out, said{event, id, raw})
|
||||
return nil
|
||||
}
|
||||
q.graph = &graphKeeper{objects: memObjects{}, halves: func() map[string]mcc.Half { return map[string]mcc.Half{trunkBranch: half} }}
|
||||
q.ends = newPipelineEnds(ends, func() {}, t.Logf)
|
||||
q.keepGraph(ctx)
|
||||
out = nil
|
||||
return q, &out
|
||||
}
|
||||
// the process before the restart: the want written, said, then a removal the bus refuses
|
||||
kv, ends := &memKV{values: map[string][]byte{}}, newMemEnds()
|
||||
q, out := build(kv, ends, first)
|
||||
q.putWant(ctx, "ace", "web", mwc.Want{Fp: fpTest, Self: true})
|
||||
q.putWant(ctx, "ace", "keep", mwc.Want{Fp: fpTest, Self: true})
|
||||
keepID := (*out)[1].id
|
||||
q.publishWants = func(string, any, string) error { return errors.New("the bus refuses") }
|
||||
q.putWant(ctx, "ace", "web", mwc.Want{Removed: true})
|
||||
if raw, _, _ := ends.get(removalKey("ace", "web")); raw == nil {
|
||||
t.Fatal("AC-832f: the removal has no mark")
|
||||
}
|
||||
// AC-832r: assigner_written answers the mark
|
||||
written := writtenTools(memStore{writtenState: &memKV{values: map[string][]byte{removalKey("ace", "web"): ends.vals[removalKey("ace", "web")]}}})
|
||||
if got, err := written[0].Run(map[string]any{}); err != nil || got.(map[string]any)[removalKey("ace", "web")] == nil {
|
||||
t.Errorf("AC-832r: assigner_written answered %v (%v)", got, err)
|
||||
}
|
||||
// the restart: the kept state is the want keys and the mark
|
||||
restart := func(now time.Time) (*passer, *[]said) {
|
||||
r, out := build(kv, ends, now)
|
||||
for k, v := range kv.values {
|
||||
r.w.putEntry(buckets.Wants(), k, v, kv.revision(k), first)
|
||||
}
|
||||
return r, out
|
||||
}
|
||||
r, out2 := restart(first.Add(time.Hour))
|
||||
r.startSays(ctx)
|
||||
var removal, again *said
|
||||
for i, e := range *out2 {
|
||||
var b meshwants.WantedEvent
|
||||
_ = json.Unmarshal(e.body, &b)
|
||||
switch {
|
||||
case b.Module == "web" && b.Removed:
|
||||
removal = &(*out2)[i]
|
||||
case b.Module == "keep":
|
||||
again = &(*out2)[i]
|
||||
}
|
||||
}
|
||||
if removal == nil || (*out2)[len(*out2)-1].event == "" || again == nil {
|
||||
t.Fatalf("AC-832e: the start said %v", *out2)
|
||||
}
|
||||
var b meshwants.WantedEvent
|
||||
_ = json.Unmarshal(again.body, &b)
|
||||
if again.id != keepID || b.At == nil || !b.At.Equal(first) || b.WantRevision == 0 {
|
||||
t.Errorf("AC-832w: the want said again is %s %+v, want the key's write time %v as its at", again.id, b, first)
|
||||
}
|
||||
if raw, _, _ := ends.get(removalKey("ace", "web")); raw != nil {
|
||||
t.Errorf("AC-832f: the mark stands once the removal was taken")
|
||||
}
|
||||
webKey, _ := mwc.WantKey("ace", "web")
|
||||
if w, _ := mwc.DecodeWant(kv.values[webKey]); !w.Removed {
|
||||
t.Errorf("AC-832f: the want's key holds %+v, want the removing want", w)
|
||||
}
|
||||
// the same ids again at the next start; the removal's mark is gone, so only the want written is said
|
||||
r2, out3 := restart(first.Add(2 * time.Hour))
|
||||
r2.startSays(ctx)
|
||||
ids := map[string]bool{}
|
||||
for _, e := range *out3 {
|
||||
ids[e.id] = true
|
||||
}
|
||||
if !ids[again.id] || len(*out3) != 1 {
|
||||
t.Errorf("AC-832e: the second start said %v, want the want written under %s", *out3, again.id)
|
||||
}
|
||||
// a crash between the mark and the removing want: the key still holds the revision the mark names, so the start writes it first
|
||||
kv2, ends2 := &memKV{values: map[string][]byte{}}, newMemEnds()
|
||||
c, _ := build(kv2, ends2, first)
|
||||
c.putWant(ctx, "ace", "web", mwc.Want{Fp: fpTest, Self: true})
|
||||
cKey, _ := mwc.WantKey("ace", "web")
|
||||
mark, _ := json.Marshal(removalMark{Node: "ace", Module: "web", Fp: fpTest, WantRevision: kv2.revision(cKey)})
|
||||
ends2.vals[removalKey("ace", "web")], ends2.revs[removalKey("ace", "web")] = mark, 1
|
||||
d, out4 := build(kv2, ends2, first.Add(time.Hour))
|
||||
for k, v := range kv2.values {
|
||||
d.w.putEntry(buckets.Wants(), k, v, kv2.revision(k), first)
|
||||
}
|
||||
d.startSays(ctx)
|
||||
if w, _ := mwc.DecodeWant(kv2.values[cKey]); !w.Removed || len(*out4) != 1 || !strings.HasSuffix((*out4)[0].id, ".true."+strconv.FormatUint(kv2.revision(cKey)-1, 10)) {
|
||||
t.Errorf("AC-832f: a mark whose want still stands left %+v and said %v", w, *out4)
|
||||
}
|
||||
})
|
||||
t.Run("a want's run", func(t *testing.T) {
|
||||
wkey, _ := mwc.WantKey("g14", "db")
|
||||
stored := func() mwc.Want { w, _ := mwc.DecodeWant(kv.values[wkey]); return w }
|
||||
|
||||
@@ -897,7 +897,7 @@ func TestWantsAreWrittenAndNoDifferenceIs(t *testing.T) {
|
||||
t.Error("the state engine-reads holds a key of shanks, whose engine said nothing")
|
||||
}
|
||||
// H-A-270 (3): registration-changed has one handler, the catalog half's follower, so the start's hub refuses no overlap.
|
||||
b.journal.await(t, 0, "the kept seat events heard", "the hub started", time.Second)
|
||||
b.journal.await(t, 0, "the hub started: the events and the kept seat events", "the hub started", time.Second)
|
||||
b.journal.mu.Lock()
|
||||
overlap := strings.Contains(b.journal.text.String(), "a message has one taker")
|
||||
b.journal.mu.Unlock()
|
||||
|
||||
@@ -8,7 +8,10 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient/heard"
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||
"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"
|
||||
@@ -324,6 +327,17 @@ func findingsOf(ctx context.Context, account process.Account, conn *nats.Conn, j
|
||||
return w.Clear(ctx, scope, rest[:i], rest[i+1:], "the assigner no longer observes it")
|
||||
}
|
||||
f.Keys = state.Keys
|
||||
f.Get = func(key string) (mcseat.Finding, bool, error) {
|
||||
entry, err := state.Get(key)
|
||||
if err != nil || entry == nil {
|
||||
return mcseat.Finding{}, false, err
|
||||
}
|
||||
var found mcseat.Finding
|
||||
if err := json.Unmarshal(entry.Value, &found); err != nil {
|
||||
return mcseat.Finding{}, false, fmt.Errorf("the finding %s does not read: %w", key, err)
|
||||
}
|
||||
return found, true, nil
|
||||
}
|
||||
return f, w
|
||||
}
|
||||
|
||||
@@ -506,9 +520,6 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
||||
return err
|
||||
}
|
||||
runs = newCompositionRuns(busRuns{ctx, js, kv}, set, time.Now, logger.Printf)
|
||||
if js != nil {
|
||||
runs.say = wantsPublisher(ctx, js, thisNode)
|
||||
}
|
||||
if bus != nil {
|
||||
runs.drop = dropOver(bus.CallKept)
|
||||
}
|
||||
@@ -598,7 +609,13 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.tierBound, p.tierWake = tierBound, wake
|
||||
p.tierBound, p.wake = tierBound, wake
|
||||
if p.owed.first, p.owed.last, err = owedSetting(getenv); err != nil {
|
||||
return err
|
||||
}
|
||||
if p.owed.unsaid, err = durationFile(getenv("MESH_ASSIGNER_EVENT_UNSAID_AFTER_FILE")); err != nil { // design 47 H2b §832 6.
|
||||
return err
|
||||
}
|
||||
// The setting pass-stall-seconds: a pass still running after it says which phase it is in (design 47 H2 H-A-635).
|
||||
if p.passStall, err = passStallSetting(getenv); err != nil {
|
||||
return err
|
||||
@@ -703,6 +720,7 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
||||
}
|
||||
var ackWait atomic.Int64 // the worker's ack wait, read when it is bound
|
||||
ackWait.Store(int64(buscompose.SeatQueueDefaultAckWait))
|
||||
runs.owe = func(order, event string, body any, id string) { p.wantsOwe(order, event, body, id, nil) } // owed as every event is (H-A-873)
|
||||
steps := &compositionSteps{node: thisNode, say: p.publishWants, run: run.run, resume: run.resume,
|
||||
validate: run.validate, resumeValidate: run.resumeValidate, ended: runs.stepEnded, now: time.Now, logf: logger.Printf,
|
||||
takenBound: takenBound, inProgress: inProgressOf(seatlist.Definition(gate.Reader, meshwants.Seat), func() time.Duration { return time.Duration(ackWait.Load()) })}
|
||||
@@ -725,7 +743,8 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
||||
return err
|
||||
}
|
||||
verbs := compositionVerbs(runs, steps, record, run)
|
||||
maps.Copy(verbs, dropVerb(steps)) // the seat's act drop (§778, H-A-404)
|
||||
maps.Copy(verbs, dropVerb(steps)) // the seat's act drop (§778, H-A-404)
|
||||
maps.Copy(verbs, owedVerbs(p, record)) // the owed events' read, say and drop (§832 6., H-A-847)
|
||||
if p.graph != nil {
|
||||
maps.Copy(verbs, keepNowVerb(ctx, p)) // the keeping by hand (§813 (2), H-A-417)
|
||||
}
|
||||
@@ -845,6 +864,10 @@ func hearReadsChanged(ctx context.Context, js jetstream.JetStream, hub *process.
|
||||
account := process.Account{Node: thisNode, Module: assignment.Module()}
|
||||
w := notHeardWriter(findings, logf)
|
||||
handle := readsChangedHandler(reads, logf)
|
||||
// Start answers nil while a durable is not yet bound (mesh-sdk S1): what waits on live events is done where the hub says it
|
||||
// hears every pattern, and a pattern it does not hear is said through its unheard hook (design 47 H2b §836 1., 4.).
|
||||
hub.OnAllHeard(readsLive(live, logf))
|
||||
hub.OnUnheard(readsUnheard(w, logf))
|
||||
err := hub.Handle(enginereads.SubjectPrefix+"*", handle)
|
||||
if err == nil {
|
||||
err = hub.Start(ctx, js, account)
|
||||
@@ -853,19 +876,37 @@ func hearReadsChanged(ctx context.Context, js jetstream.JetStream, hub *process.
|
||||
w.NotHeard(process.EventsStream, enginereads.Event+" is not heard until the assigner starts again, so no node's new words are kept", err)
|
||||
return
|
||||
}
|
||||
w.Heard(process.EventsStream)
|
||||
// The build seats' step-ended is a kept seat event, on its own stream and never on EVENTS: bound here, or no composition
|
||||
// run's end is heard and every composition step waits for ever (design 47 G §354, A-240; mesh-sdk EventHub.StartKept).
|
||||
logf("the kept seat events heard: %d streams bound", hub.StartKept(ctx, js, account))
|
||||
if live != nil {
|
||||
live() // the seat list, unread while the seat was silent, is read now (seatlist.Part.EventsLive)
|
||||
}
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
hub.Stop()
|
||||
}()
|
||||
}
|
||||
|
||||
// readsLive is what the hub's OnAllHeard does: the seat list, unread while the seat was silent, is read now
|
||||
// (seatlist.Part.EventsLive), once every registered pattern is heard (design 47 H2b §836 1.).
|
||||
func readsLive(live func(), logf func(string, ...any)) func() {
|
||||
return func() {
|
||||
logf("the hub started: the events and the kept seat events are bound by Start")
|
||||
if live != nil {
|
||||
live()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// readsUnheard is what the hub's OnUnheard does: the finding of the reads' family is written while the hub does not hear the
|
||||
// node-engine seat's manifest-reads-changed, and deleted once it does (design 47 H2b §836 4.).
|
||||
func readsUnheard(w heard.Writer, logf func(string, ...any)) func([]process.Unheard) {
|
||||
return func(unheard []process.Unheard) {
|
||||
for _, u := range unheard {
|
||||
if u.Pattern == enginereads.SubjectPrefix+"*" {
|
||||
w.NotHeard(process.EventsStream, enginereads.Event+" is not heard until the hub binds it, so no node's new words are kept", errors.New(u.Why))
|
||||
return
|
||||
}
|
||||
}
|
||||
w.Heard(process.EventsStream)
|
||||
}
|
||||
}
|
||||
|
||||
// holderOf names the module holding a seat, asked of the seat that places modules (seatlist.HolderOf), and the machines whose
|
||||
// assignments place it, for the words of a read that met a fault (design 47 H2 H-A-708 (3)).
|
||||
func holderOf(bus caller, w *world) func(seat string) (string, []string) {
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -21,6 +23,7 @@ import (
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-assigner/asks"
|
||||
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/catalogkey"
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatdef"
|
||||
"git.novox.be/novox/mesh-sdk/go/views"
|
||||
|
||||
@@ -69,17 +72,80 @@ type outsideActs struct {
|
||||
// bound and settle are the settings outside-wait-minutes and outside-settle-seconds.
|
||||
bound, settle time.Duration
|
||||
// reading is a read in flight by machine, answered the answers it brought, not yet judged by.
|
||||
reading map[string]bool
|
||||
answered map[string][]outside.Cond
|
||||
// dirty is a machine whose waits are judged again, cleared a wait's key whose cause's clearing was heard.
|
||||
dirty map[string]bool
|
||||
cleared map[string]bool
|
||||
reading map[string]bool
|
||||
// answered is, by machine, the newest answer of the conditions and when it was received, kept for the pass that first takes it
|
||||
// and replaced by each new one (design 47 H2b §829 1.); condAt is the time of the last condition event naming the machine.
|
||||
answered map[string]*machineAnswer
|
||||
condAt map[string]time.Time
|
||||
// dirty is a machine whose waits are judged again, cleared a wait's key whose cause's clearing was heard; each is read by every
|
||||
// judging of one pass alike (marks).
|
||||
dirty marks
|
||||
cleared marks
|
||||
// pass is the number of the pass judging now; clock is the passer's, nil for the wall clock.
|
||||
pass int64
|
||||
clock func() time.Time
|
||||
// sigs is each check's last signature, by node.module.
|
||||
sigs map[string]string
|
||||
// causes is, by condition key, the nodes whose waits stand on it, as the last pass kept them.
|
||||
causes map[string][]string
|
||||
// started says the first pass judged every wait again.
|
||||
started bool
|
||||
// started says a pass began before this one, so the first pass judges every wait again.
|
||||
started, first bool
|
||||
}
|
||||
|
||||
// machineAnswer is one answer of the keeper's `conditions` for a machine, the pass that first took it (zero: none yet).
|
||||
type machineAnswer struct {
|
||||
conds []outside.Cond
|
||||
at time.Time
|
||||
takenIn int64
|
||||
}
|
||||
|
||||
// marks are the machines (or keys) whose waits are judged again, read alike by every judging of one pass: a mark is cleared at the
|
||||
// next pass's start only when the pass saw it, so an event heard after a judging is judged by the next (§829 2.).
|
||||
type marks struct {
|
||||
n uint64
|
||||
at, done, seen map[string]uint64
|
||||
}
|
||||
|
||||
func (m *marks) set(k string) {
|
||||
if m.at == nil {
|
||||
m.at, m.done, m.seen = map[string]uint64{}, map[string]uint64{}, map[string]uint64{}
|
||||
}
|
||||
m.n++
|
||||
m.at[k] = m.n
|
||||
}
|
||||
|
||||
func (m *marks) is(k string) bool {
|
||||
v := m.at[k]
|
||||
if v <= m.done[k] {
|
||||
return false
|
||||
}
|
||||
m.seen[k] = max(m.seen[k], v)
|
||||
return true
|
||||
}
|
||||
|
||||
func (m *marks) next() {
|
||||
for k, v := range m.seen {
|
||||
m.done[k] = v
|
||||
delete(m.seen, k)
|
||||
}
|
||||
}
|
||||
|
||||
// beginPass starts a pass of the judgings: what the last pass judged by is spent, and the first pass judges every wait again.
|
||||
func (o *outsideActs) beginPass(now func() time.Time) {
|
||||
o.mu.Lock()
|
||||
defer o.mu.Unlock()
|
||||
o.clock = now
|
||||
o.pass++
|
||||
o.dirty.next()
|
||||
o.cleared.next()
|
||||
o.first, o.started = !o.started, true
|
||||
}
|
||||
|
||||
func (o *outsideActs) now() time.Time {
|
||||
if o.clock != nil {
|
||||
return o.clock()
|
||||
}
|
||||
return time.Now()
|
||||
}
|
||||
|
||||
func newOutsideActs(call func(string, any) (json.RawMessage, error), wake func(), logf func(string, ...any), bound, settle time.Duration) *outsideActs {
|
||||
@@ -89,8 +155,7 @@ func newOutsideActs(call func(string, any) (json.RawMessage, error), wake func()
|
||||
if settle <= 0 {
|
||||
settle = outside.DefaultSettle
|
||||
}
|
||||
return &outsideActs{call: call, wake: wake, logf: logf, bound: bound, settle: settle, reading: map[string]bool{}, answered: map[string][]outside.Cond{},
|
||||
dirty: map[string]bool{}, cleared: map[string]bool{}, sigs: map[string]string{}, causes: map[string][]string{}}
|
||||
return &outsideActs{call: call, wake: wake, logf: logf, bound: bound, settle: settle, reading: map[string]bool{}, answered: map[string]*machineAnswer{}, condAt: map[string]time.Time{}, sigs: map[string]string{}, causes: map[string][]string{}}
|
||||
}
|
||||
|
||||
// outsideSettings are the bounds of the wait, the settings outside-wait-minutes and outside-settle-seconds (design 47 G §633, §706),
|
||||
@@ -142,29 +207,44 @@ func (o *outsideActs) Heard(subject string, body []byte) {
|
||||
}
|
||||
cleared := strings.HasSuffix(subject, "."+mcseat.EventConditionCleared)
|
||||
o.mu.Lock()
|
||||
at := o.now()
|
||||
if cleared {
|
||||
for _, node := range o.causes[e.Key] {
|
||||
o.dirty[node] = true
|
||||
o.cleared[node+"|"+e.Key] = true
|
||||
o.dirty.set(node)
|
||||
o.cleared.set(node + "|" + e.Key)
|
||||
o.condAt[node] = at
|
||||
}
|
||||
} else if e.Subject != nil {
|
||||
o.dirty[e.Subject.Machine] = true
|
||||
}
|
||||
if e.Subject != nil {
|
||||
if !cleared {
|
||||
o.dirty.set(e.Subject.Machine)
|
||||
}
|
||||
o.condAt[e.Subject.Machine] = at
|
||||
for _, m := range e.Subject.Also {
|
||||
o.dirty[m] = true
|
||||
if !cleared {
|
||||
o.dirty.set(m)
|
||||
}
|
||||
o.condAt[m] = at
|
||||
}
|
||||
}
|
||||
o.mu.Unlock()
|
||||
o.wake()
|
||||
}
|
||||
|
||||
// take is the conditions read for machine, consumed (one answer is one judging), or false while the kept call is unanswered,
|
||||
// which it starts when none is in flight.
|
||||
func (o *outsideActs) take(machine string) ([]outside.Cond, bool) {
|
||||
// take is the conditions read for machine, or false while the kept call is unanswered, which it starts when none is in flight
|
||||
// (design 47 H2b §829). The answer is kept for the whole pass that first takes it, so every wait judged on the machine in that pass
|
||||
// is judged by it; a later pass reads again, but at a settle's end (settleEnd, the failing check at since) the newest answer serves
|
||||
// when it was received after the failing check and no condition event naming the machine came after it.
|
||||
func (o *outsideActs) take(machine string, since time.Time, settleEnd bool) ([]outside.Cond, bool) {
|
||||
o.mu.Lock()
|
||||
defer o.mu.Unlock()
|
||||
if c, ok := o.answered[machine]; ok {
|
||||
delete(o.answered, machine)
|
||||
return c, true
|
||||
if a := o.answered[machine]; a != nil {
|
||||
if a.takenIn == 0 {
|
||||
a.takenIn = o.pass
|
||||
}
|
||||
if a.takenIn == o.pass || (settleEnd && !a.at.Before(since) && !o.condAt[machine].After(a.at)) {
|
||||
return a.conds, true
|
||||
}
|
||||
}
|
||||
if o.reading[machine] {
|
||||
return nil, false
|
||||
@@ -179,10 +259,10 @@ func (o *outsideActs) take(machine string) ([]outside.Cond, bool) {
|
||||
o.mu.Lock()
|
||||
o.reading[machine] = false
|
||||
if err != nil {
|
||||
o.logf("the conditions of %s are not read (%v): the move waits on %s", machine, err, outside.OnUnread)
|
||||
o.logf("the conditions of %s are not read (%v): its waits stand on %s until a judging on an input reads again", machine, err, outside.OnUnread)
|
||||
} else {
|
||||
o.answered[machine] = conds
|
||||
o.dirty[machine] = true // the kept call answered: the move is judged by it
|
||||
o.answered[machine] = &machineAnswer{conds: conds, at: o.now()}
|
||||
o.dirty.set(machine) // the kept call answered: every wait on the machine is judged by it
|
||||
}
|
||||
o.mu.Unlock()
|
||||
if err == nil {
|
||||
@@ -209,8 +289,16 @@ func (p *passer) outsideReview(ctx context.Context, module, fp string, nodes []s
|
||||
override := map[string]string{}
|
||||
// A wait of another fingerprint of this module is replaced by the newer want.
|
||||
for key, raw := range kept {
|
||||
if w, err := outside.Decode(raw); err == nil && w.Module == module && w.FP != fp {
|
||||
w, err := outside.Decode(raw)
|
||||
switch {
|
||||
case err != nil || w.Module != module:
|
||||
case w.Ending != "":
|
||||
// an end written and not said stands until its say finishes it, whatever the want names now (§831)
|
||||
case w.FP != fp:
|
||||
p.outsideEnd(ctx, key, w, outside.HowReplaced, now)
|
||||
case w.Decided != "" && !slices.Contains(nodes, w.Node):
|
||||
// a decided record of a module no longer placed on its machine goes, with no event (§830 2.)
|
||||
p.outsideEnd(ctx, key, w, "", now)
|
||||
}
|
||||
}
|
||||
for _, node := range nodes {
|
||||
@@ -222,13 +310,15 @@ func (p *passer) outsideReview(ctx context.Context, module, fp string, nodes []s
|
||||
}
|
||||
}
|
||||
h, ok := n.Haves[node][module]
|
||||
sig := fmt.Sprintf("%s|%s|%s", h.Fp, h.Phase, h.Health)
|
||||
run, runs := n.Running[node][module]
|
||||
running := runs && run.Fingerprint == fp && !run.Stopped // §827: the node-engine seat's last running names the wait's fingerprint
|
||||
sig := fmt.Sprintf("%s|%s|%s|%t", h.Fp, h.Phase, h.Health, running)
|
||||
o.mu.Lock()
|
||||
first := !o.started
|
||||
first := o.first
|
||||
changed := o.sigs[node+"."+module] != sig
|
||||
o.sigs[node+"."+module] = sig
|
||||
dirty := o.dirty[node]
|
||||
cleared := prev != nil && prev.Cause != "" && o.cleared[node+"|"+prev.Cause]
|
||||
dirty := o.dirty.is(node)
|
||||
cleared := prev != nil && prev.Cause != "" && o.cleared.is(node+"|"+prev.Cause)
|
||||
o.mu.Unlock()
|
||||
failing, healthy := ok && h.Fp == fp && assign.Failed(h), n.RunsHealthy(node, module, fp)
|
||||
if !failing && !healthy && prev == nil {
|
||||
@@ -239,26 +329,33 @@ func (p *passer) outsideReview(ctx context.Context, module, fp string, nodes []s
|
||||
}
|
||||
due := prev != nil && (prev.Release != "" || (prev.Settling && !now.Before(prev.SettleEnds)))
|
||||
var d outside.Decision
|
||||
if prev != nil && !(first || changed || dirty || due) {
|
||||
if prev != nil && prev.Ending != "" {
|
||||
// An end written and not said: it is said again under its id until the bus takes it, and that finishes the wait (§831).
|
||||
d = outside.Judge(prev, node, module, fp, outside.Facts{})
|
||||
p.outsideEnd(ctx, key, *prev, prev.Ending, now)
|
||||
} else if prev != nil && !(first || changed || dirty || due) {
|
||||
// nothing to judge by: the wait stands as kept; the bound's ask is made when it has run
|
||||
d = outside.Decision{Wait: prev, Waiting: prev.Standing() || prev.Settling, Own: prev.Decided == outside.HowFailed || prev.Decided == outside.HowOwnFailure,
|
||||
Counted: prev.Decided == outside.HowGoOn}
|
||||
if prev.Standing() && !now.Before(prev.ClockFrom.Add(o.bound)) {
|
||||
if prev.Standing() && running && prev.Ask != "" {
|
||||
w := *prev
|
||||
w.Ask = ""
|
||||
d.Withdraw, d.Wait = true, &w
|
||||
} else if prev.Standing() && !running && !now.Before(prev.ClockFrom.Add(o.bound)) {
|
||||
d.Ask = true
|
||||
}
|
||||
} else {
|
||||
f := outside.Facts{Now: now, Failing: failing, Healthy: healthy, Node: node, KeeperSelf: keeperSelf, Bound: o.bound, Settle: o.settle,
|
||||
Moved: func(owner string) bool { return moved(owner, node) }, CauseCleared: cleared}
|
||||
if failing && !keeperSelf {
|
||||
f.Conds, f.Read = o.take(node)
|
||||
Moved: func(owner string) bool { return moved(owner, node) }, CauseCleared: cleared, Running: running}
|
||||
if failing && !keeperSelf && (prev == nil || prev.Decided == "") { // a decided record reads nothing (§829 3.)
|
||||
settleEnd := prev != nil && prev.Settling && !now.Before(prev.SettleEnds)
|
||||
since := now
|
||||
if prev != nil {
|
||||
since = prev.Since
|
||||
}
|
||||
f.Conds, f.Read = o.take(node, since, settleEnd)
|
||||
}
|
||||
d = outside.Judge(prev, node, module, fp, f)
|
||||
o.mu.Lock()
|
||||
delete(o.dirty, node)
|
||||
if prev != nil {
|
||||
delete(o.cleared, node+"|"+prev.Cause)
|
||||
}
|
||||
o.mu.Unlock()
|
||||
}
|
||||
switch {
|
||||
case d.Waiting:
|
||||
@@ -266,11 +363,8 @@ func (p *passer) outsideReview(ctx context.Context, module, fp string, nodes []s
|
||||
case d.Counted:
|
||||
override[node] = nodeengineclient.HealthOK
|
||||
}
|
||||
p.outsideApply(ctx, key, hex, node, module, fp, prev, d, now)
|
||||
p.outsideApply(ctx, key, hex, node, module, fp, prev, d, now, running)
|
||||
}
|
||||
o.mu.Lock()
|
||||
o.started = true
|
||||
o.mu.Unlock()
|
||||
if len(override) == 0 {
|
||||
return n
|
||||
}
|
||||
@@ -313,14 +407,14 @@ func (p *passer) outsideAnswered(w *outside.Wait, node, module, fp string) bool
|
||||
}
|
||||
|
||||
// outsideApply keeps what a judging came to: the wait's record, its events, its finding and its ask.
|
||||
func (p *passer) outsideApply(ctx context.Context, key, hex, node, module, fp string, prev *outside.Wait, d outside.Decision, now time.Time) {
|
||||
func (p *passer) outsideApply(ctx context.Context, key, hex, node, module, fp string, prev *outside.Wait, d outside.Decision, now time.Time, running bool) {
|
||||
o := p.outside
|
||||
read := p.w.metaOf(buckets.Waits(), key).revision
|
||||
switch {
|
||||
case prev != nil && prev.Ending != "":
|
||||
return // its end is owed, and its say finishes it (outsideReview)
|
||||
case d.End != "":
|
||||
p.outsideEnd(ctx, key, *prev, d.End, now)
|
||||
if d.Wait != nil {
|
||||
p.keepWait(ctx, key, *d.Wait)
|
||||
}
|
||||
return
|
||||
case d.Wait == nil:
|
||||
if prev != nil {
|
||||
@@ -330,14 +424,24 @@ func (p *passer) outsideApply(ctx context.Context, key, hex, node, module, fp st
|
||||
}
|
||||
w := *d.Wait
|
||||
if d.Held {
|
||||
body := p.outsideBody(w)
|
||||
if err := p.wantsSay(meshwants.EventWaitHeld, body, key+"."+w.On+"."+w.ClockFrom.UTC().Format(time.RFC3339Nano)); err != nil {
|
||||
p.logf("the wait of %s on %s is not said, and is said at the next pass: %v", module, node, err)
|
||||
// The record is written with `held-said` raised first, by compare-and-set on the revision the judging read, and the event
|
||||
// is owed under the id it names only once that write took (§832 3.); a lost race is judged again at the next pass.
|
||||
w.HeldSaid++
|
||||
if !p.keepWaitAt(ctx, key, w, read) {
|
||||
p.logf("the wait of %s on %s at %s is not written, so its wait-held is not owed yet", module, node, fp)
|
||||
return
|
||||
}
|
||||
p.wantsOwe(waitOrder(key, w.ClockFrom), meshwants.EventWaitHeld, p.outsideBody(w), waitEventID(node, module, hex, "held."+strconv.Itoa(w.HeldSaid), w.ClockFrom), nil)
|
||||
p.outsideFinding(w, true)
|
||||
}
|
||||
if d.Withdraw {
|
||||
if ask, err := asks.OutsideAskKey(node, module, fp); err == nil {
|
||||
p.remove(ctx, buckets.Asks(), ask)
|
||||
}
|
||||
p.logf("the ask about %s on %s at %s is withdrawn: the module runs its wanted build, and the wait stands on %s", module, node, fp, w.On)
|
||||
}
|
||||
if d.Ask && w.Ask == "" {
|
||||
p.logf("the operator is asked about %s on %s at %s: its wait on %s is past %s and the module does not run its wanted build", module, node, fp, w.On, o.bound)
|
||||
if id := p.outsideAsk(ctx, node, module, fp, w, now); id != "" {
|
||||
w.Ask = id
|
||||
}
|
||||
@@ -350,11 +454,16 @@ func (p *passer) outsideApply(ctx context.Context, key, hex, node, module, fp st
|
||||
}
|
||||
}
|
||||
o.mu.Unlock()
|
||||
if w.Settling {
|
||||
p.wakeAt(w.SettleEnds, now)
|
||||
} else if w.Standing() {
|
||||
p.wakeAt(w.ClockFrom.Add(o.bound), now)
|
||||
// The one deadline timer is armed at a settle's end or a wait's bound only while that time is still to come, and the bound
|
||||
// only while the module does not run its wanted build (design 47 H2b §828): past it nothing is armed, and the wait is judged
|
||||
// again only on an input.
|
||||
var at time.Time
|
||||
if w.Settling && now.Before(w.SettleEnds) {
|
||||
at = w.SettleEnds
|
||||
} else if w.Standing() && !running && now.Before(w.ClockFrom.Add(o.bound)) {
|
||||
at = w.ClockFrom.Add(o.bound)
|
||||
}
|
||||
p.wakeSet("wait."+key, at)
|
||||
p.keepWait(ctx, key, w)
|
||||
}
|
||||
}
|
||||
@@ -370,7 +479,37 @@ func containsString(l []string, s string) bool {
|
||||
|
||||
// keepWait writes the wait's record.
|
||||
func (p *passer) keepWait(ctx context.Context, key string, w outside.Wait) {
|
||||
p.put(ctx, buckets.Waits(), key, func() ([]byte, error) { return outside.Encode(w) })
|
||||
p.keepWaitAt(ctx, key, w, p.w.metaOf(buckets.Waits(), key).revision)
|
||||
}
|
||||
|
||||
// keepWaitAt writes the wait's record by compare-and-set on revision, the one read (0: the key is new), and says whether it took: a
|
||||
// record that moved past it (a hand act, another write) is not overwritten, and its newer value stands (design 47 H2b §832 3.).
|
||||
func (p *passer) keepWaitAt(ctx context.Context, key string, w outside.Wait, revision uint64) bool {
|
||||
value, err := outside.Encode(w)
|
||||
if err != nil {
|
||||
p.logf("%s %s is not written: %v", buckets.Waits(), key, err)
|
||||
return false
|
||||
}
|
||||
raw := p.w.value(buckets.Waits(), key)
|
||||
if raw != nil && bytes.Equal(raw, value) {
|
||||
return true // it stands as it is to be
|
||||
}
|
||||
kv := p.kvs[buckets.Waits()]
|
||||
if raw == nil || revision == 0 {
|
||||
revision, err = kv.Create(ctx, key, value)
|
||||
} else {
|
||||
revision, err = kv.Update(ctx, key, value, revision)
|
||||
}
|
||||
if err != nil {
|
||||
if errors.Is(err, jetstream.ErrKeyExists) || errors.Is(err, jetstream.ErrKeyRevisionMismatch) || isWrongSequence(err) {
|
||||
p.logf("the wait %s is not written: its record moved past the revision this pass read; the next pass judges it again", key)
|
||||
} else if !errors.Is(err, context.Canceled) {
|
||||
p.logf("%s %s could not be written: %v", buckets.Waits(), key, err)
|
||||
}
|
||||
return false
|
||||
}
|
||||
p.w.putEntry(buckets.Waits(), key, value, revision, p.clock())
|
||||
return true
|
||||
}
|
||||
|
||||
func (p *passer) outsideBody(w outside.Wait) meshwants.Wait {
|
||||
@@ -380,17 +519,47 @@ func (p *passer) outsideBody(w outside.Wait) meshwants.Wait {
|
||||
Words: fmt.Sprintf("%s on %s waits on %s", w.Module, w.Node, w.On)}
|
||||
}
|
||||
|
||||
// outsideEnd ends a wait: its wait-ended with how (none for a settle, which was never said), its finding and ask taken away, and
|
||||
// its record deleted unless the end decided it (the caller keeps that record).
|
||||
// outsideEnd ends a wait (design 47 H2b §831): a standing wait's end, `how`, is written into its record (`ending`) before it is said,
|
||||
// and said before anything of the wait goes; only once the bus has taken `wait-ended` are its ask and finding taken away and the
|
||||
// record written decided or deleted (outside.EndedAs). While the say is owed the record, its ask and its finding stand. A wait that
|
||||
// was never said (a settle, a decided one) and a `how` of "" end at once and delete the record.
|
||||
func (p *passer) outsideEnd(ctx context.Context, key string, w outside.Wait, how string, now time.Time) {
|
||||
if w.Standing() && how != "" {
|
||||
body := p.outsideBody(w)
|
||||
body.How = how
|
||||
if err := p.wantsSay(meshwants.EventWaitEnded, body, key+"."+how+"."+now.UTC().Format(time.RFC3339Nano)); err != nil {
|
||||
p.logf("the end of the wait of %s on %s is not said, and is said at the next pass: %v", w.Module, w.Node, err)
|
||||
if how == "" || !(w.Standing() || w.Ending != "") {
|
||||
p.outsideEnded(ctx, key, w, nil)
|
||||
return
|
||||
}
|
||||
if w.Ending == "" {
|
||||
w.Ending = how
|
||||
if !p.keepWaitAt(ctx, key, w, p.w.metaOf(buckets.Waits(), key).revision) {
|
||||
p.logf("the end of %s on %s (%s) is not written, so it is not said", w.Module, w.Node, how)
|
||||
return
|
||||
}
|
||||
}
|
||||
body := p.outsideBody(w)
|
||||
body.How = how
|
||||
done := context.WithoutCancel(ctx)
|
||||
hex := key[strings.LastIndex(key, ".")+1:]
|
||||
p.wantsOwe(waitOrder(key, w.ClockFrom), meshwants.EventWaitEnded, body, waitEventID(w.Node, w.Module, hex, "ended."+how, w.ClockFrom), func() {
|
||||
p.outsideEnded(done, key, w, outside.EndedAs(w, how))
|
||||
})
|
||||
if w.Ending != "" && p.waitEndingKept(key) {
|
||||
p.logf("the end of %s on %s (%s) is not said yet: its ask, its finding and its record stand", w.Module, w.Node, how)
|
||||
}
|
||||
}
|
||||
|
||||
// waitEndingKept says the record under key still holds an end not yet finished.
|
||||
func (p *passer) waitEndingKept(key string) bool {
|
||||
raw := p.w.value(buckets.Waits(), key)
|
||||
if raw == nil {
|
||||
return false
|
||||
}
|
||||
w, err := outside.Decode(raw)
|
||||
return err == nil && w.Ending != ""
|
||||
}
|
||||
|
||||
// outsideEnded is what the bus taking a wait's end lets go: its finding, its ask and its timer, and the record, written decided or
|
||||
// deleted.
|
||||
func (p *passer) outsideEnded(ctx context.Context, key string, w outside.Wait, decided *outside.Wait) {
|
||||
p.outsideFinding(w, false)
|
||||
if ask, err := asks.OutsideAskKey(w.Node, w.Module, w.FP); err == nil {
|
||||
p.remove(ctx, buckets.Asks(), ask)
|
||||
@@ -400,6 +569,11 @@ func (p *passer) outsideEnd(ctx context.Context, key string, w outside.Wait, how
|
||||
p.outside.causes[w.Cause] = removeString(p.outside.causes[w.Cause], w.Node)
|
||||
p.outside.mu.Unlock()
|
||||
}
|
||||
p.wakeSet("wait."+key, time.Time{}) // a wait that ended arms nothing
|
||||
if decided != nil {
|
||||
p.keepWait(ctx, key, *decided)
|
||||
return
|
||||
}
|
||||
p.remove(ctx, buckets.Waits(), key)
|
||||
}
|
||||
|
||||
@@ -451,10 +625,13 @@ func (p *passer) outsideAsk(ctx context.Context, node, module, fp string, w outs
|
||||
return ""
|
||||
}
|
||||
|
||||
// wakeAt makes a pass when t comes: the settle's end and the bound are the waits' own times, the one wake (no polling).
|
||||
func (p *passer) wakeAt(t, now time.Time) {
|
||||
if p.outside == nil || p.outside.wake == nil {
|
||||
return
|
||||
}
|
||||
time.AfterFunc(max(t.Sub(now), 0)+time.Millisecond, p.outside.wake)
|
||||
// waitOrder is the order the events of one wait are said in: its key `<node>.<module>.<fingerprint>` and its clock-from (§832 1.).
|
||||
func waitOrder(key string, clockFrom time.Time) string {
|
||||
return "wait." + key + "." + clockFrom.UTC().Format(time.RFC3339Nano)
|
||||
}
|
||||
|
||||
// waitEventID is the message id of a wait's event: `<node>.<module>.<fingerprint>.<what>.<clock-from>`, the fingerprint the 64 hex
|
||||
// its record's key holds, the names escaped by keys.EscapeName, the time RFC 3339 with nanoseconds in UTC (§832 3.; H-A-831).
|
||||
func waitEventID(node, module, hex, what string, clockFrom time.Time) string {
|
||||
return keys.EscapeName(node) + "." + keys.EscapeName(module) + "." + hex + "." + what + "." + clockFrom.UTC().Format(time.RFC3339Nano)
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -15,6 +17,8 @@ import (
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-assigner/asks"
|
||||
mdc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient"
|
||||
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/catalogkey"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-teller/tellerevents"
|
||||
|
||||
"mesh-delivery-assigner/internal/assign"
|
||||
"mesh-delivery-assigner/internal/buckets"
|
||||
@@ -31,9 +35,19 @@ type outsideRig struct {
|
||||
unread bool
|
||||
events []string
|
||||
bodies []meshwants.Wait
|
||||
ids []string
|
||||
// refuse makes the bus refuse the next n says, as a publish it does not take.
|
||||
refuse int
|
||||
found map[string]bool
|
||||
woke chan struct{}
|
||||
health string
|
||||
// notRunning: the node-engine seat's last running does not name the module at the fingerprint (it is not running its wanted build).
|
||||
notRunning bool
|
||||
// reads counts the conditions reads a judging started.
|
||||
reads int
|
||||
// gate, when set, holds each read unanswered until the test sends one token: a read answers only when the test lets it, so no
|
||||
// answer arrives in the middle of a pass the test is still judging.
|
||||
gate chan struct{}
|
||||
}
|
||||
|
||||
func newOutsideRig(t *testing.T) *outsideRig {
|
||||
@@ -42,12 +56,21 @@ func newOutsideRig(t *testing.T) *outsideRig {
|
||||
r.p.now = func() time.Time { return r.now }
|
||||
r.p.w.put(buckets.Asks(), "x", nil)
|
||||
r.p.outside = newOutsideActs(func(key string, body any) (json.RawMessage, error) {
|
||||
if r.gate != nil {
|
||||
<-r.gate
|
||||
}
|
||||
r.reads++
|
||||
if r.unread {
|
||||
return nil, context.DeadlineExceeded
|
||||
}
|
||||
return json.Marshal(map[string]any{"conditions": r.conds})
|
||||
}, func() { r.woke <- struct{}{} }, func(string, ...any) {}, 30*time.Minute, 90*time.Second)
|
||||
r.p.publishWants = func(event string, body any, id string) error {
|
||||
if r.refuse > 0 {
|
||||
r.refuse--
|
||||
return context.DeadlineExceeded
|
||||
}
|
||||
r.ids = append(r.ids, id)
|
||||
r.events = append(r.events, event)
|
||||
r.bodies = append(r.bodies, body.(meshwants.Wait))
|
||||
return nil
|
||||
@@ -68,12 +91,17 @@ func (r *outsideRig) review(keeperSelf bool, moved func(string, string) bool) as
|
||||
"ace": {"nats": {Fp: fpTest, Phase: nodeengineclient.PhaseRunning, Health: r.health}}}}
|
||||
healthy := r.health == nodeengineclient.HealthOK
|
||||
n.Running = map[string]map[string]nodeengine.Running{"ace": {"nats": {Node: "ace", Module: "nats", Fingerprint: fpTest, Healthy: &healthy}}}
|
||||
if r.notRunning {
|
||||
n.Running = nil
|
||||
}
|
||||
if moved == nil {
|
||||
moved = func(string, string) bool { return false }
|
||||
}
|
||||
r.p.outside.beginPass(r.p.clock)
|
||||
out := r.p.outsideReview(context.Background(), "nats", fpTest, []string{"ace"}, n, keeperSelf, moved)
|
||||
select {
|
||||
case <-r.woke: // the read was answered: the next pass judges by it
|
||||
r.p.outside.beginPass(r.p.clock)
|
||||
out = r.p.outsideReview(context.Background(), "nats", fpTest, []string{"ace"}, n, keeperSelf, moved)
|
||||
case <-time.After(50 * time.Millisecond):
|
||||
}
|
||||
@@ -165,9 +193,197 @@ func TestTheWaitOnAnOutsideCause(t *testing.T) {
|
||||
t.Errorf("the keeper's own failing check waits: %s %v", healthOf(n), r2.events)
|
||||
}
|
||||
})
|
||||
t.Run("the operator is asked only while the module does not run its wanted build: kept with no ask when it runs, withdrawn when it comes to run, raised at once when it stops (§827)", func(t *testing.T) {
|
||||
key, _ := asks.OutsideAskKey("ace", "nats", fpTest)
|
||||
for _, unread := range []bool{false, true} {
|
||||
r := newOutsideRig(t)
|
||||
r.unread = unread
|
||||
r.cond("machine.hub.silent", "ace")
|
||||
r.review(false, nil)
|
||||
if unread {
|
||||
r.now = r.now.Add(90 * time.Second)
|
||||
r.review(false, nil)
|
||||
}
|
||||
r.now = r.now.Add(31 * time.Minute)
|
||||
r.p.outside.Heard("mesh.seat.mesh-conditions.event.condition-changed", []byte(`{"key":"machine.hub.silent","subject":{"id":"hub","scope":"machine","machine":"hub","also":["ace"]}}`))
|
||||
<-r.woke
|
||||
r.review(false, nil)
|
||||
if r.p.w.value(buckets.Asks(), key) != nil || len(r.found) != 1 || r.wait().Ask != "" || !r.wait().Standing() {
|
||||
t.Fatalf("unread %v: running past the bound is asked or loses its finding: ask %v findings %v wait %+v", unread, r.p.w.value(buckets.Asks(), key) != nil, r.found, r.wait())
|
||||
}
|
||||
}
|
||||
r := newOutsideRig(t)
|
||||
r.notRunning = true
|
||||
r.cond("machine.hub.silent", "ace")
|
||||
r.review(false, nil)
|
||||
r.now = r.now.Add(31 * time.Minute)
|
||||
r.p.outside.Heard("mesh.seat.mesh-conditions.event.condition-changed", []byte(`{"key":"machine.hub.silent","subject":{"id":"hub","scope":"machine","machine":"hub","also":["ace"]}}`))
|
||||
<-r.woke
|
||||
r.review(false, nil)
|
||||
if r.p.w.value(buckets.Asks(), key) == nil || r.wait().Ask == "" {
|
||||
t.Fatalf("a module not running its wanted build past the bound is not asked: %+v", r.wait())
|
||||
}
|
||||
events := len(r.events)
|
||||
r.notRunning, r.now = false, r.now.Add(time.Minute) // it comes to run
|
||||
r.review(false, nil)
|
||||
if r.p.w.value(buckets.Asks(), key) != nil || r.wait().Ask != "" || len(r.events) != events || len(r.found) != 1 {
|
||||
t.Fatalf("the ask stands after the module came to run, or the wait ended: events %v wait %+v", r.events, r.wait())
|
||||
}
|
||||
r.notRunning, r.now = true, r.now.Add(time.Minute) // it stops again, past the bound
|
||||
r.review(false, nil)
|
||||
if r.p.w.value(buckets.Asks(), key) == nil || r.wait().Ask == "" {
|
||||
t.Fatalf("the ask is not raised at once when the module stops running past the bound: %+v", r.wait())
|
||||
}
|
||||
})
|
||||
t.Run("the bound is armed once, only while to come and the module does not run; past it a wait is judged again only on an input (§828)", func(t *testing.T) {
|
||||
armed := func(r *outsideRig) bool {
|
||||
r.p.wakes.mu.Lock()
|
||||
defer r.p.wakes.mu.Unlock()
|
||||
for k := range r.p.wakes.at {
|
||||
if strings.HasPrefix(k, "wait.") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
input := func(r *outsideRig) {
|
||||
r.p.outside.Heard("mesh.seat.mesh-conditions.event.condition-changed", []byte(`{"key":"machine.hub.silent","subject":{"id":"hub","scope":"machine","machine":"hub","also":["ace"]}}`))
|
||||
<-r.woke
|
||||
}
|
||||
for _, notRunning := range []bool{false, true} {
|
||||
r := newOutsideRig(t)
|
||||
r.notRunning = notRunning
|
||||
r.cond("machine.hub.silent", "ace")
|
||||
r.review(false, nil)
|
||||
if armed(r) != notRunning { // a running module's bound is no deadline; a module not running has its bound to come
|
||||
t.Fatalf("notRunning %v: the bound's timer armed = %v before the bound", notRunning, armed(r))
|
||||
}
|
||||
// AC-828c (H-A-872): the rig counts the reads it answers; passes while nothing changes make none
|
||||
standing := r.reads
|
||||
for range 3 {
|
||||
r.now = r.now.Add(time.Minute)
|
||||
r.review(false, nil)
|
||||
}
|
||||
if r.reads != standing {
|
||||
t.Errorf("notRunning %v: three passes with nothing changed made %d reads", notRunning, r.reads-standing)
|
||||
}
|
||||
r.now = r.now.Add(31 * time.Minute)
|
||||
input(r)
|
||||
r.review(false, nil)
|
||||
if armed(r) {
|
||||
t.Fatalf("notRunning %v: a timer stands past the bound", notRunning)
|
||||
}
|
||||
reads := r.reads
|
||||
r.review(false, nil) // nothing changed: not judged again
|
||||
if r.reads != reads {
|
||||
t.Errorf("notRunning %v: a wait past its bound was judged again with no input (%d reads, then %d)", notRunning, reads, r.reads)
|
||||
}
|
||||
if notRunning {
|
||||
// AC-828b: the ask is raised and nothing is armed; its lapse, heard on the teller's ask-ended, raises it again under a new asking
|
||||
key, _ := asks.OutsideAskKey("ace", "nats", fpTest)
|
||||
raw := r.p.w.value(buckets.Asks(), key)
|
||||
_, ask, err := assign.DecodeAsk(key, raw)
|
||||
if err != nil || raw == nil {
|
||||
t.Fatalf("AC-828b: no ask stands past the bound: %v", err)
|
||||
}
|
||||
value, why := assign.AskedAgain(tellerevents.Ended{Key: key, Ask: ask.ID, Outcome: "expired"}, raw, nil, r.now)
|
||||
_, again, derr := assign.DecodeAsk(key, value)
|
||||
if why != "" || derr != nil || again.ID == ask.ID {
|
||||
t.Errorf("AC-828b: the lapse of %s wrote %q (%v), new ask %q", ask.ID, why, derr, again.ID)
|
||||
}
|
||||
}
|
||||
input(r) // a condition raised on M judges it again
|
||||
r.review(false, nil)
|
||||
if r.reads == reads {
|
||||
t.Errorf("notRunning %v: a condition event on the machine did not judge the wait again", notRunning)
|
||||
}
|
||||
}
|
||||
})
|
||||
// Design 47 H2b §828 (H-A-846, AC-828d): a tier's deadline, a wait's bound and an owed event's next are each a time the pass is to
|
||||
// wake at; one timer stands, armed at the earliest, and a later one arms nothing.
|
||||
t.Run("a tier's deadline, a wait's bound and an owed event's next stand on one timer, armed at the earliest (AC-828d)", func(t *testing.T) {
|
||||
r := newOutsideRig(t)
|
||||
var arms []time.Duration
|
||||
stopped := 0
|
||||
r.p.after = func(d time.Duration, _ func()) func() bool {
|
||||
arms = append(arms, d)
|
||||
return func() bool { stopped++; return true }
|
||||
}
|
||||
r.p.wake = func() {}
|
||||
r.p.wakeSet("wait.ace.nats", r.now.Add(30*time.Minute))
|
||||
r.p.wakeSet("tiers", r.now.Add(10*time.Minute))
|
||||
r.p.wakeSet("owed", r.now.Add(20*time.Minute))
|
||||
if len(arms) != 2 || arms[1] != 10*time.Minute+time.Millisecond || stopped != 1 {
|
||||
t.Fatalf("armed %v, stopped %d: the timer is not armed at the earliest of the three, one standing", arms, stopped)
|
||||
}
|
||||
r.p.wakeSet("wait.ace.nats", r.now.Add(40*time.Minute)) // a later time moves nothing
|
||||
if len(arms) != 2 || stopped != 1 {
|
||||
t.Errorf("a later time armed again: %v, stopped %d", arms, stopped)
|
||||
}
|
||||
r.p.wakeSet("tiers", time.Time{}) // the earliest goes: the timer is armed at the next earliest
|
||||
if len(arms) != 3 || arms[2] != 20*time.Minute+time.Millisecond || stopped != 2 {
|
||||
t.Errorf("after the earliest went: armed %v, stopped %d", arms, stopped)
|
||||
}
|
||||
})
|
||||
t.Run("one read of a machine's conditions serves every wait judged on it in one pass, a decided one reads nothing, a settle's end uses the newest answer (§829)", func(t *testing.T) {
|
||||
both := func(r *outsideRig) assign.Nodes {
|
||||
n := assign.Nodes{Online: map[string]bool{"ace": true}, Haves: map[string]map[string]nodeengine.HaveByNodeModuleValue{"ace": {}}}
|
||||
for _, m := range []string{"nats", "web", "db"} {
|
||||
n.Haves["ace"][m] = nodeengine.HaveByNodeModuleValue{Fp: fpTest, Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthFailed}
|
||||
}
|
||||
return n
|
||||
}
|
||||
judge := func(r *outsideRig, modules ...string) {
|
||||
r.p.outside.beginPass(r.p.clock)
|
||||
for _, m := range modules {
|
||||
r.p.outsideReview(context.Background(), m, fpTest, []string{"ace"}, both(r), false, func(string, string) bool { return false })
|
||||
}
|
||||
}
|
||||
r := newOutsideRig(t)
|
||||
r.gate = make(chan struct{}, 4)
|
||||
r.cond("machine.hub.unreachable", "ace")
|
||||
hex, _ := catalogkey.KeyPart(fpTest)
|
||||
decided, _ := outside.Encode(outside.Wait{Node: "ace", Module: "db", FP: fpTest, Since: r.now, ClockFrom: r.now, Decided: outside.HowGoOn})
|
||||
r.p.w.put(buckets.Waits(), outside.Key("ace", "db", hex), decided)
|
||||
judge(r, "nats", "web", "db") // the first judgings start the one read
|
||||
r.gate <- struct{}{} // the read is answered only now
|
||||
<-r.woke
|
||||
judge(r, "nats", "web", "db") // the pass the answer wakes: every wait on the machine is judged by it
|
||||
if r.reads != 1 || len(r.events) != 2 || r.bodies[0].On != "unreachable:hub" || r.bodies[1].On != "unreachable:hub" {
|
||||
t.Fatalf("two waits and a decided one, one pass: %d reads, events %v bodies %+v", r.reads, r.events, r.bodies)
|
||||
}
|
||||
// a settle's end: no cause open, the answer read in it ends own-failure, never on conditions-unread
|
||||
r2 := newOutsideRig(t)
|
||||
r2.gate = make(chan struct{}, 4)
|
||||
judge(r2, "nats") // settle starts, read starts
|
||||
r2.gate <- struct{}{}
|
||||
<-r2.woke
|
||||
judge(r2, "nats") // the answer: no cause open, a settle
|
||||
r2.now = r2.now.Add(91 * time.Second)
|
||||
judge(r2, "nats") // the settle's end: the answer read before it was received after the failing check and no condition came since
|
||||
if r2.reads != 1 || r2.wait().Decided != outside.HowOwnFailure {
|
||||
t.Fatalf("the settle's end read again (%d reads) or did not end own-failure: %+v", r2.reads, r2.wait())
|
||||
}
|
||||
// a restart: the answer is gone, a settle's end starts a read
|
||||
r3 := newOutsideRig(t)
|
||||
r3.gate = make(chan struct{}, 4)
|
||||
judge(r3, "nats")
|
||||
r3.gate <- struct{}{}
|
||||
<-r3.woke
|
||||
judge(r3, "nats")
|
||||
r3.p.outside = newOutsideActs(r3.p.outside.call, r3.p.outside.wake, func(string, ...any) {}, 30*time.Minute, 90*time.Second)
|
||||
r3.now = r3.now.Add(91 * time.Second)
|
||||
judge(r3, "nats")
|
||||
r3.gate <- struct{}{}
|
||||
<-r3.woke // the read it started is answered
|
||||
if r3.reads != 2 {
|
||||
t.Errorf("a settle's end after a restart did not start a read: %d reads", r3.reads)
|
||||
}
|
||||
})
|
||||
t.Run("past the bound the operator is asked; Go on counts it healthy and Count as failed holds it, each said ended", func(t *testing.T) {
|
||||
for how, want := range map[string]string{assign.OptionGoOn: nodeengineclient.HealthOK, assign.OptionFailed: nodeengineclient.HealthFailed} {
|
||||
r := newOutsideRig(t)
|
||||
r.notRunning = true
|
||||
r.cond("machine.hub.silent", "ace")
|
||||
r.review(false, nil)
|
||||
r.now = r.now.Add(31 * time.Minute)
|
||||
@@ -203,6 +419,190 @@ func TestTheWaitOnAnOutsideCause(t *testing.T) {
|
||||
}
|
||||
}
|
||||
})
|
||||
// Design 47 H2b §831 (1984/AC-831a to AC-831d): an end is written into the record before it is said, and nothing of the wait goes
|
||||
// before the bus took it.
|
||||
t.Run("an end is written before it is said: the record stays ending with its ask and finding while the say is owed, then is decided; a restart says it again, no wait-held (§831)", func(t *testing.T) {
|
||||
askKey, _ := asks.OutsideAskKey("ace", "nats", fpTest)
|
||||
waitKey := outside.Key("ace", "nats", strings.TrimPrefix(fpTest, "src2:"))
|
||||
ended := func(r *outsideRig) (n int) {
|
||||
for _, e := range r.events {
|
||||
if e == meshwants.EventWaitEnded {
|
||||
n++
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
// asked at the bound, then the operator's Go on, the say of the end refused once
|
||||
start := func() *outsideRig {
|
||||
r := newOutsideRig(t)
|
||||
r.notRunning = true
|
||||
r.cond("machine.hub.silent", "ace")
|
||||
r.review(false, nil)
|
||||
r.now = r.now.Add(31 * time.Minute)
|
||||
r.p.outside.Heard("mesh.seat.mesh-conditions.event.condition-changed", []byte(`{"key":"machine.hub.silent","subject":{"id":"hub","scope":"machine","machine":"hub","also":["ace"]}}`))
|
||||
<-r.woke
|
||||
r.review(false, nil)
|
||||
_, ask, err := assign.DecodeAsk(askKey, r.p.w.value(buckets.Asks(), askKey))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
v, _ := mdc.EncodeAnswer(mdc.Answer{Option: assign.OptionGoOn, Warrant: ask.ID + "@2026-11-11T10:32:00Z", Words: "the operator"})
|
||||
r.p.w.put(buckets.Answers, askKey, v)
|
||||
r.refuse = 1
|
||||
r.review(false, nil)
|
||||
return r
|
||||
}
|
||||
r := start()
|
||||
if w := r.wait(); w.Ending != outside.HowGoOn || w.Decided != "" || outside.StateOf(w) != "ending:go-on" || r.p.w.value(buckets.Asks(), askKey) == nil || len(r.found) != 1 || ended(r) != 0 {
|
||||
t.Fatalf("AC-831a: with the say refused the record is %+v (%s), ask %v findings %v, ended %d", w, outside.StateOf(r.wait()), r.p.w.value(buckets.Asks(), askKey) != nil, r.found, ended(r))
|
||||
}
|
||||
r.now = r.p.owedNext()
|
||||
r.p.sayOwed()
|
||||
if w := r.wait(); w.Decided != outside.HowGoOn || w.Ending != "" || r.p.w.value(buckets.Asks(), askKey) != nil || len(r.found) != 0 || ended(r) != 1 {
|
||||
t.Errorf("AC-831b: once said the record is %+v, ask %v, findings %v, ended %d", w, r.p.w.value(buckets.Asks(), askKey) != nil, r.found, ended(r))
|
||||
}
|
||||
// AC-831c: a restart between the two (the owed events are lost with the process) says the end again under its id
|
||||
r = start()
|
||||
held := len(r.ids)
|
||||
r.p.owed.list = nil
|
||||
r.p.outside.started = false
|
||||
r.now = r.now.Add(time.Minute)
|
||||
r.review(false, nil)
|
||||
if w := r.wait(); w.Decided != outside.HowGoOn || ended(r) != 1 || len(r.ids) != held+1 || !strings.Contains(r.ids[len(r.ids)-1], ".ended.go-on.") || r.events[len(r.events)-1] != meshwants.EventWaitEnded {
|
||||
t.Errorf("AC-831c: after a restart the record is %+v, events %v", w, r.events)
|
||||
}
|
||||
// AC-831d: the bus took the end and the process went before the record's write: the end is said again, then the rest is done
|
||||
w := r.wait()
|
||||
w.Decided, w.Ending = "", outside.HowGoOn
|
||||
raw, _ := outside.Encode(w)
|
||||
r.p.w.put(buckets.Waits(), waitKey, raw)
|
||||
r.p.w.put(buckets.Asks(), askKey, []byte(`{}`))
|
||||
r.p.outside.started = false
|
||||
r.now = r.now.Add(time.Minute)
|
||||
r.review(false, nil)
|
||||
if w := r.wait(); w.Decided != outside.HowGoOn || w.Ending != "" || r.p.w.value(buckets.Asks(), askKey) != nil || ended(r) != 2 {
|
||||
t.Errorf("AC-831d: after the restart the record is %+v, ask %v, ended %d", w, r.p.w.value(buckets.Asks(), askKey) != nil, ended(r))
|
||||
}
|
||||
})
|
||||
// Design 47 H2b §832 4. (1984/AC-832e): a start says `wait-held` again for every standing wait under its held-said, and no
|
||||
// `wait-held` for a settle or a record with `ending`.
|
||||
t.Run("a start says wait-held again for a standing wait under the id first said (§832 4.)", func(t *testing.T) {
|
||||
r := newOutsideRig(t)
|
||||
r.cond("machine.hub.unreachable", "ace")
|
||||
r.review(false, nil)
|
||||
if len(r.ids) != 1 {
|
||||
t.Fatalf("ids %v", r.ids)
|
||||
}
|
||||
r.p.owed.list = nil // the memory of the process is gone
|
||||
r.p.startWaitsSaid = false
|
||||
r.p.startSays(context.Background())
|
||||
if len(r.ids) != 2 || r.ids[1] != r.ids[0] || r.events[1] != meshwants.EventWaitHeld {
|
||||
t.Errorf("AC-832e: the start said %v %v, want wait-held again under %s", r.events, r.ids, r.ids[0])
|
||||
}
|
||||
r.p.startWaitsSaid = false
|
||||
w := r.wait()
|
||||
w.Ending = outside.HowHealthy
|
||||
r.p.keepWait(context.Background(), outside.Key("ace", "nats", strings.TrimPrefix(fpTest, "src2:")), w)
|
||||
r.p.startSays(context.Background())
|
||||
if r.events[len(r.events)-1] != meshwants.EventWaitEnded || len(r.ids) != 3 {
|
||||
t.Errorf("AC-832e: a record with ending said %v, want only its end", r.events)
|
||||
}
|
||||
})
|
||||
// Design 47 H2b §832 6. (1984/AC-832h, AC-832i, AC-832j, AC-832k, AC-832s): past event-unsaid-after an owed event is a finding, cleared
|
||||
// when said; assigner_owed_say says one now; assigner_owed_drop of a wait-ended does the rest of the wait's end; the tools call the
|
||||
// seat's verbs and say so when the program is stopped.
|
||||
t.Run("an owed event is the finding event-unsaid past event-unsaid-after, said by hand or dropped with what waited on it; the tools call the verbs (§832 6.)", func(t *testing.T) {
|
||||
r := newOutsideRig(t)
|
||||
r.p.wake = func() {}
|
||||
r.p.owed.unsaid = 5 * time.Minute
|
||||
r.p.findings.Keys = func() ([]string, error) {
|
||||
var ks []string
|
||||
for k := range r.found {
|
||||
ks = append(ks, k)
|
||||
}
|
||||
return ks, nil
|
||||
}
|
||||
r.notRunning = true
|
||||
r.cond("machine.hub.silent", "ace")
|
||||
r.refuse = 100
|
||||
r.review(false, nil)
|
||||
owed := r.p.owedAll()
|
||||
if len(owed) != 1 || len(r.found) != 1 {
|
||||
t.Fatalf("owed %+v findings %v", owed, r.found)
|
||||
}
|
||||
r.now = r.now.Add(6 * time.Minute)
|
||||
r.p.owedFindings()
|
||||
key := unsaidKey(owed[0].ID)
|
||||
if !r.found[strings.TrimPrefix(key, "")] || strings.Contains(key, "src2:") || strings.Contains(key, "T") {
|
||||
t.Fatalf("AC-832h: findings %v, want %s (the id with times as Unix nanoseconds)", r.found, key)
|
||||
}
|
||||
// AC-832k: a pass that would make the id owed already makes nothing
|
||||
r.review(false, nil)
|
||||
if got := r.p.owedAll(); len(got) != 1 {
|
||||
t.Errorf("AC-832k: owed %+v after another pass", got)
|
||||
}
|
||||
// AC-832i: said by hand at once; the finding is cleared with it (AC-832h)
|
||||
r.refuse = 0
|
||||
said, err := r.p.owedSay(owed[0].ID)
|
||||
if err != nil || said.ID != owed[0].ID || len(r.p.owedAll()) != 0 || r.found[key] || len(r.events) != 1 || r.events[0] != meshwants.EventWaitHeld {
|
||||
t.Fatalf("AC-832i: said %+v (%v), owed %d, events %v, findings %v", said, err, len(r.p.owedAll()), r.events, r.found)
|
||||
}
|
||||
// AC-832h: a restart no longer owes it, so the first pass clears what the bucket holds
|
||||
r.found[key] = true
|
||||
r.p.owedFindings()
|
||||
if r.found[key] {
|
||||
t.Error("AC-832h: a finding of an event no longer owed stands")
|
||||
}
|
||||
// AC-832j: the drop of the wait-held owed before a wait-ended drops both, and the wait is decided go-on, its ask and finding gone
|
||||
askKey, _ := asks.OutsideAskKey("ace", "nats", fpTest)
|
||||
r.now = r.now.Add(31 * time.Minute)
|
||||
r.p.outside.Heard("mesh.seat.mesh-conditions.event.condition-changed", []byte(`{"key":"machine.hub.silent","subject":{"id":"hub","scope":"machine","machine":"hub","also":["ace"]}}`))
|
||||
<-r.woke
|
||||
r.review(false, nil)
|
||||
_, ask, err := assign.DecodeAsk(askKey, r.p.w.value(buckets.Asks(), askKey))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r.refuse = 100
|
||||
w := r.wait()
|
||||
w.HeldSaid++ // a new wait-held the bus refuses, then the end
|
||||
r.p.keepWait(context.Background(), outside.Key("ace", "nats", strings.TrimPrefix(fpTest, "src2:")), w)
|
||||
r.p.wantsOwe(waitOrder(outside.Key("ace", "nats", strings.TrimPrefix(fpTest, "src2:")), w.ClockFrom), meshwants.EventWaitHeld, r.p.outsideBody(w),
|
||||
waitEventID("ace", "nats", strings.TrimPrefix(fpTest, "src2:"), "held."+strconv.Itoa(w.HeldSaid), w.ClockFrom), nil)
|
||||
v, _ := mdc.EncodeAnswer(mdc.Answer{Option: assign.OptionGoOn, Warrant: ask.ID + "@2026-11-11T10:32:00Z", Words: "the operator"})
|
||||
r.p.w.put(buckets.Answers, askKey, v)
|
||||
r.review(false, nil)
|
||||
owed = r.p.owedAll()
|
||||
if len(owed) != 2 || r.wait().Ending != outside.HowGoOn {
|
||||
t.Fatalf("AC-832j: owed %+v, wait %+v", owed, r.wait())
|
||||
}
|
||||
dropped, err := r.p.owedDrop(owed[0].ID)
|
||||
if err != nil || len(dropped) != 2 || r.wait().Decided != outside.HowGoOn || r.p.w.value(buckets.Asks(), askKey) != nil || len(r.p.owedAll()) != 0 {
|
||||
t.Errorf("AC-832j: the drop answered %+v (%v); wait %+v, ask %v", dropped, err, r.wait(), r.p.w.value(buckets.Asks(), askKey) != nil)
|
||||
}
|
||||
if _, err := r.p.owedDrop("no such id"); err == nil {
|
||||
t.Error("AC-832j: an id not owed was dropped")
|
||||
}
|
||||
// AC-832s: each tool answers through its verb; with the program stopped each says the verb is unanswered
|
||||
var verbs []string
|
||||
tools := owedTools(func(verb string, in any) (json.RawMessage, error) {
|
||||
verbs = append(verbs, verb)
|
||||
return json.RawMessage(`{"events":[]}`), nil
|
||||
})
|
||||
for _, tool := range tools {
|
||||
if _, err := tool.Run(map[string]any{"id": "x", "why": "y"}); err != nil {
|
||||
t.Errorf("AC-832s: %s: %v", tool.Name, err)
|
||||
}
|
||||
}
|
||||
if len(verbs) != 3 || !strings.HasSuffix(verbs[0], "."+meshwants.VerbOwed) || !strings.HasSuffix(verbs[1], "."+meshwants.VerbOwedSay) || !strings.HasSuffix(verbs[2], "."+meshwants.VerbOwedDrop) {
|
||||
t.Errorf("AC-832s: the tools called %v", verbs)
|
||||
}
|
||||
for _, tool := range owedTools(func(string, any) (json.RawMessage, error) { return nil, errors.New("no answer") }) {
|
||||
if _, err := tool.Run(map[string]any{"id": "x", "why": "y"}); err == nil || !strings.Contains(err.Error(), "does not answer the verb") {
|
||||
t.Errorf("AC-832s: %s with the program stopped answered %v", tool.Name, err)
|
||||
}
|
||||
}
|
||||
})
|
||||
t.Run("a newer want ends the wait replaced, and a restart judges it again", func(t *testing.T) {
|
||||
r := newOutsideRig(t)
|
||||
r.cond("machine.hub.unreachable", "ace")
|
||||
@@ -213,6 +613,93 @@ func TestTheWaitOnAnOutsideCause(t *testing.T) {
|
||||
t.Errorf("events %v", r.events)
|
||||
}
|
||||
})
|
||||
t.Run("an event the bus refuses is owed under one id and said again in order, at 2s, 4s, doubling to the pace's end (§832 1., 2.)", func(t *testing.T) {
|
||||
r := newOutsideRig(t)
|
||||
var armed []time.Duration
|
||||
r.p.wake = func() {}
|
||||
r.p.after = func(d time.Duration, f func()) func() bool {
|
||||
armed = append(armed, d)
|
||||
return func() bool { return true }
|
||||
}
|
||||
r.p.owed.last = 8 * time.Second
|
||||
r.cond("machine.hub.unreachable", "ace")
|
||||
r.refuse = 3 // the wait-held is refused now, and at its first two says again
|
||||
r.review(false, nil)
|
||||
if len(r.events) != 0 {
|
||||
t.Fatalf("a refused event was said: %v", r.events)
|
||||
}
|
||||
// the wait ends while its wait-held is owed: the end is owed behind it, never tried before it
|
||||
r.conds, r.health, r.now = nil, nodeengineclient.HealthOK, r.now.Add(time.Minute)
|
||||
r.review(false, nil)
|
||||
if len(r.events) != 0 || len(r.p.owed.list) != 2 {
|
||||
t.Fatalf("events %v owed %d, want the held and the end owed in order", r.events, len(r.p.owed.list))
|
||||
}
|
||||
heldID, endID := r.p.owed.list[0].id, r.p.owed.list[1].id
|
||||
for _, want := range []struct {
|
||||
tries int
|
||||
delay time.Duration
|
||||
}{{1, 4 * time.Second}, {2, 8 * time.Second}} {
|
||||
r.now = r.p.owedNext()
|
||||
if r.p.sayOwed() || r.p.owed.list[0].tries != want.tries || r.p.owed.list[0].next.Sub(r.now) != want.delay {
|
||||
t.Fatalf("try %d: said %v owed %+v, want the next delay %v", want.tries, r.events, r.p.owed.list[0], want.delay)
|
||||
}
|
||||
}
|
||||
if d := r.p.owed.list[0].next.Sub(r.now); d != 8*time.Second {
|
||||
t.Errorf("the third delay %v, want 8s (the pace's end)", d)
|
||||
}
|
||||
r.now = r.p.owedNext()
|
||||
if !r.p.sayOwed() {
|
||||
t.Fatal("the bus took nothing")
|
||||
}
|
||||
if len(r.events) != 2 || r.events[0] != meshwants.EventWaitHeld || r.events[1] != meshwants.EventWaitEnded || r.ids[0] != heldID || r.ids[1] != endID || len(r.p.owed.list) != 0 {
|
||||
t.Errorf("events %v ids %v, owed %d: want held then ended under the ids first owed (%s, %s)", r.events, r.ids, len(r.p.owed.list), heldID, endID)
|
||||
}
|
||||
if !strings.Contains(heldID, ".held.1.") || !strings.Contains(endID, ".ended.healthy.") || len(armed) == 0 {
|
||||
t.Errorf("ids %s %s, armed %v", heldID, endID, armed)
|
||||
}
|
||||
})
|
||||
t.Run("an on going from A to B and back to A says three wait-held under three ids; a name with a dot is escaped (§832 3.; H-A-831)", func(t *testing.T) {
|
||||
r := newOutsideRig(t)
|
||||
r.cond("machine.hub.unreachable", "ace")
|
||||
r.review(false, nil)
|
||||
for _, key := range []string{"machine.hub.network", "machine.hub.unreachable"} {
|
||||
r.conds = nil
|
||||
r.cond(key, "ace")
|
||||
r.now = r.now.Add(time.Minute)
|
||||
r.p.outside.Heard("mesh.seat.mesh-conditions.event.condition-raised", []byte(`{"key":"`+key+`","subject":{"id":"hub","scope":"machine","machine":"hub","also":["ace"]}}`))
|
||||
<-r.woke
|
||||
r.review(false, nil)
|
||||
}
|
||||
seen := map[string]bool{}
|
||||
for _, id := range r.ids {
|
||||
seen[id] = true
|
||||
}
|
||||
if len(r.ids) != 3 || len(seen) != 3 {
|
||||
t.Errorf("wait-held ids %v, want three different", r.ids)
|
||||
}
|
||||
if id := waitEventID("a.b", "m.x", "00ff", "held.1", r.now); !strings.HasPrefix(id, "a=2eb.m=2ex.00ff.held.1.") {
|
||||
t.Errorf("id %q holds a dot unescaped", id)
|
||||
}
|
||||
})
|
||||
t.Run("held-said and ending are written by compare-and-set: a record that moved past the read is not overwritten and owes no event (§832 3., review r1 finding 2)", func(t *testing.T) {
|
||||
r := newOutsideRig(t)
|
||||
r.cond("machine.hub.unreachable", "ace")
|
||||
r.review(false, nil)
|
||||
kv := r.p.kvs[buckets.Waits()].(*memKV)
|
||||
for key := range kv.values {
|
||||
kv.revs[key] += 100 // a rival write: the world still holds the revision it read
|
||||
}
|
||||
before := len(r.ids)
|
||||
r.conds = nil
|
||||
r.cond("machine.hub.network", "ace")
|
||||
r.now = r.now.Add(time.Minute)
|
||||
r.p.outside.Heard("mesh.seat.mesh-conditions.event.condition-raised", []byte(`{"key":"machine.hub.network","subject":{"id":"hub","scope":"machine","machine":"hub","also":["ace"]}}`))
|
||||
<-r.woke
|
||||
r.review(false, nil)
|
||||
if len(r.ids) != before || r.wait().HeldSaid != 1 {
|
||||
t.Errorf("a held write that lost the race owed %v and left held-said %d", r.ids[before:], r.wait().HeldSaid)
|
||||
}
|
||||
})
|
||||
t.Run("its bounds are read at the start from the files the manifest declares (A-112)", func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
write := func(name, content string) string {
|
||||
@@ -279,4 +766,128 @@ func TestTheToolsReadAndReleaseAnOutsideWait(t *testing.T) {
|
||||
if r.bodies[len(r.bodies)-1].How != "go-on" || n.Haves["ace"]["nats"].Health != nodeengineclient.HealthOK {
|
||||
t.Errorf("last %+v health %s", r.bodies[len(r.bodies)-1], n.Haves["ace"]["nats"].Health)
|
||||
}
|
||||
// Design 47 H2b §830 (1984/AC-830a to AC-830c): the state is derived from the record, a decided record lives until its fingerprint
|
||||
// runs healthy or is replaced, and assigner_wait_drop drops it by hand.
|
||||
t.Run("assigner_waits derives the states; a decided record goes when healthy or replaced, with no second end; assigner_wait_drop drops it (§830)", func(t *testing.T) {
|
||||
stateOf := func(r *outsideRig) (states []string) {
|
||||
s := newPutTools(memStore{waitsState: &memKV{values: map[string][]byte{}}}, func(string, any) (json.RawMessage, error) { return nil, nil })
|
||||
for k, v := range r.p.w.read(buckets.Waits()) {
|
||||
s.st.put(waitsState, k, v)
|
||||
}
|
||||
got, err := s.doWaits(map[string]any{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, w := range got.(map[string]any)["waits"].([]any) {
|
||||
states = append(states, w.(waitSaid).State)
|
||||
}
|
||||
return states
|
||||
}
|
||||
askKey, _ := asks.OutsideAskKey("ace", "nats", fpTest)
|
||||
heard := `{"key":"machine.hub.silent","subject":{"id":"hub","scope":"machine","machine":"hub","also":["ace"]}}`
|
||||
// a settle, then own-failure
|
||||
r := newOutsideRig(t)
|
||||
r.review(false, nil)
|
||||
if got := stateOf(r); len(got) != 1 || got[0] != "settling" {
|
||||
t.Fatalf("AC-830a: a settle is %v", got)
|
||||
}
|
||||
r.now = r.now.Add(2 * time.Minute)
|
||||
r.p.outside.Heard("mesh.seat.mesh-conditions.event.condition-raised", []byte(heard))
|
||||
<-r.woke
|
||||
r.review(false, nil)
|
||||
if got := stateOf(r); len(got) != 1 || got[0] != "decided:own-failure" {
|
||||
t.Errorf("AC-830a: a settle's end is %v", got)
|
||||
}
|
||||
// waiting, asked past the bound, decided go-on
|
||||
r = newOutsideRig(t)
|
||||
r.notRunning = true
|
||||
r.cond("machine.hub.silent", "ace")
|
||||
r.review(false, nil)
|
||||
if got := stateOf(r); len(got) != 1 || got[0] != "waiting" {
|
||||
t.Fatalf("AC-830a: a standing wait is %v", got)
|
||||
}
|
||||
r.now = r.now.Add(31 * time.Minute)
|
||||
r.p.outside.Heard("mesh.seat.mesh-conditions.event.condition-changed", []byte(heard))
|
||||
<-r.woke
|
||||
r.review(false, nil)
|
||||
if got := stateOf(r); len(got) != 1 || got[0] != "asked" {
|
||||
t.Fatalf("AC-830a: a wait past its bound is %v", got)
|
||||
}
|
||||
_, ask, _ := assign.DecodeAsk(askKey, r.p.w.value(buckets.Asks(), askKey))
|
||||
v, _ := mdc.EncodeAnswer(mdc.Answer{Option: assign.OptionGoOn, Warrant: ask.ID + "@2026-11-11T10:32:00Z", Words: "the operator"})
|
||||
r.p.w.put(buckets.Answers, askKey, v)
|
||||
r.review(false, nil)
|
||||
if got := stateOf(r); len(got) != 1 || got[0] != "decided:go-on" || r.wait().On != "silent:hub" || r.wait().Since.IsZero() {
|
||||
t.Fatalf("AC-830a: a Go on is %v, record %+v", got, r.wait())
|
||||
}
|
||||
// AC-830b: a want naming another fingerprint deletes it, with no second end; a healthy module deletes it too
|
||||
ended := func() (n int) {
|
||||
for _, e := range r.events {
|
||||
if e == meshwants.EventWaitEnded {
|
||||
n++
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
before := ended()
|
||||
n := assign.Nodes{Online: map[string]bool{"ace": true}, Haves: map[string]map[string]nodeengine.HaveByNodeModuleValue{}}
|
||||
saved := r.p.w.value(buckets.Waits(), outside.Key("ace", "nats", strings.TrimPrefix(fpTest, "src2:")))
|
||||
r.p.outsideReview(context.Background(), "nats", "src2:"+strings.Repeat("c", 64), []string{"ace"}, n, false, func(string, string) bool { return false })
|
||||
if len(r.p.w.read(buckets.Waits())) != 0 || ended() != before {
|
||||
t.Errorf("AC-830b: a decided record of another fingerprint stands (%v) or ends again (%d)", stateOf(r), ended()-before)
|
||||
}
|
||||
restore := func() {
|
||||
_, _ = r.p.kvs[buckets.Waits()].Put(context.Background(), outside.Key("ace", "nats", strings.TrimPrefix(fpTest, "src2:")), saved)
|
||||
r.p.w.put(buckets.Waits(), outside.Key("ace", "nats", strings.TrimPrefix(fpTest, "src2:")), saved)
|
||||
}
|
||||
restore()
|
||||
r.notRunning, r.health = false, nodeengineclient.HealthOK
|
||||
r.review(false, nil)
|
||||
if len(r.p.w.read(buckets.Waits())) != 0 || ended() != before {
|
||||
t.Errorf("AC-830b: a decided record of a module running healthy stands (%v) or ends again", stateOf(r))
|
||||
}
|
||||
restore()
|
||||
r.notRunning, r.health = true, nodeengineclient.HealthFailed
|
||||
r.p.outsideReview(context.Background(), "nats", fpTest, nil, n, false, func(string, string) bool { return false })
|
||||
if len(r.p.w.read(buckets.Waits())) != 0 {
|
||||
t.Errorf("AC-830b: a decided record of a module no longer placed on its machine stands (%v)", stateOf(r))
|
||||
}
|
||||
// AC-830c: assigner_wait_drop drops a decided record, and the next failing check there is a new wait
|
||||
key := outside.Key("ace", "nats", strings.TrimPrefix(fpTest, "src2:"))
|
||||
st := memStore{waitsState: &memKV{values: map[string][]byte{key: saved}}}
|
||||
var acts []string
|
||||
act := func(verb string, body any) (json.RawMessage, error) {
|
||||
raw, _ := json.Marshal(body)
|
||||
acts = append(acts, string(raw))
|
||||
return json.RawMessage(`{"ok":true,"log":"logged"}`), nil
|
||||
}
|
||||
if _, err := dropWait(st, act, key, "", "person.jochen"); err == nil {
|
||||
t.Error("AC-830c: a drop with no why is taken")
|
||||
}
|
||||
if _, err := dropWait(st, act, key, "the hub is back", "person.jochen"); err != nil || len(st[waitsState].values) != 0 || len(acts) != 1 || !strings.Contains(acts[0], waitDropTool+" "+key) {
|
||||
t.Fatalf("AC-830c: the drop answered %v, left %d, acts %v", err, len(st[waitsState].values), acts)
|
||||
}
|
||||
standing, _ := outside.Encode(outside.Wait{Node: "ace", Module: "nats", FP: fpTest, Since: r.now, ClockFrom: r.now})
|
||||
st[waitsState].values[key] = standing
|
||||
if _, err := dropWait(st, act, key, "x", "person.jochen"); err == nil || len(st[waitsState].values) != 1 {
|
||||
t.Error("AC-830c: a wait that stands is dropped")
|
||||
}
|
||||
// the record gone, the next failing check there is held as a new wait
|
||||
held := 0
|
||||
for _, e := range r.events {
|
||||
if e == meshwants.EventWaitHeld {
|
||||
held++
|
||||
}
|
||||
}
|
||||
r.review(false, nil)
|
||||
after := 0
|
||||
for _, e := range r.events {
|
||||
if e == meshwants.EventWaitHeld {
|
||||
after++
|
||||
}
|
||||
}
|
||||
if after != held+1 || r.wait().Decided != "" {
|
||||
t.Errorf("AC-830c: after the drop the next failing check is not held as a new wait: held %d then %d, %+v", held, after, r.wait())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ const waitsState = buckets.WaitsState
|
||||
type waitSaid struct {
|
||||
Key string `json:"key"`
|
||||
outside.Wait
|
||||
// State is derived from the record at the read (design 47 H2b §830 1.): settling, waiting, asked, ending:<how> or decided:<how>.
|
||||
State string `json:"state"`
|
||||
// Settling's end is in the record; Ends is when the bound runs from clock-from, empty for a settle.
|
||||
BoundEnds string `json:"bound-ends,omitempty"`
|
||||
}
|
||||
@@ -50,7 +52,7 @@ func (s *putTools) doWaits(args map[string]any) (any, error) {
|
||||
if err != nil || (arg(args, "node") != "" && w.Node != arg(args, "node")) || (arg(args, "module") != "" && w.Module != arg(args, "module")) {
|
||||
continue
|
||||
}
|
||||
said := waitSaid{Key: key, Wait: w}
|
||||
said := waitSaid{Key: key, Wait: w, State: outside.StateOf(w)}
|
||||
if w.Standing() {
|
||||
if d, err := time.ParseDuration(w.Bound); err == nil {
|
||||
said.BoundEnds = w.ClockFrom.Add(d).UTC().Format("2006-01-02T15:04:05Z")
|
||||
@@ -86,7 +88,7 @@ func (s *putTools) doReleaseWait(args map[string]any, by string) (any, error) {
|
||||
if err != nil || !found {
|
||||
continue
|
||||
}
|
||||
if c, err := outside.Decode(raw); err == nil && c.Decided == "" {
|
||||
if c, err := outside.Decode(raw); err == nil && c.Decided == "" && c.Ending == "" {
|
||||
key, w = k, c
|
||||
}
|
||||
}
|
||||
@@ -114,7 +116,9 @@ func (s *putTools) doReleaseWait(args map[string]any, by string) (any, error) {
|
||||
func (s *putTools) waitsTool() stdio.Tool {
|
||||
return stdio.Tool{Name: toolWaits, Description: "Every wait of the delivery and where it stands: a moved module's failing health check on a " +
|
||||
"machine whose open conditions name a cause outside the delivery (design 47 G §706), with its module, machine, fingerprint, the " +
|
||||
"condition's key, what it stands `on`, its clock-from, bound, its ask and its state; a settle shows as settling with its end. Narrowed by " +
|
||||
"condition's key, what it stands `on`, its clock-from, bound, its ask and its state, derived from the record: settling (with its end), " +
|
||||
"waiting, asked, ending:<how> (an end not said yet) or decided:<how> (a decided record lives until its fingerprint runs healthy, " +
|
||||
"a want names another one or the module is no longer placed there, and answers its last `on` and `since`). Narrowed by " +
|
||||
"machine or module. Read-only.",
|
||||
Input: schema(map[string]string{"node": "one machine", "module": "one module"}, nil), Run: s.doWaits}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,231 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// An event the bus refuses is owed in order and said again, never dropped (design 47 H §832 1., 2.; H-A-777, H-A-801): the
|
||||
// events the assigner says on the seat mesh-wants (`wanted`, `pipeline-wanted`, `wait-held`, `wait-ended`) are kept in its memory
|
||||
// when the bus refuses them or does not acknowledge them, in the order they were made within one wait, one pipeline or one want,
|
||||
// and the first of each order is said again on the one deadline timer under the message id fixed when it was first owed.
|
||||
|
||||
// The defaults of the settings say-again-pace-first and say-again-pace-max (design 47 H §832 2.).
|
||||
const (
|
||||
defaultSayAgainFirst = 2 * time.Second
|
||||
defaultSayAgainMax = time.Minute
|
||||
)
|
||||
|
||||
// owedEvent is one event owed: what the bus was to be told, and where its saying again stands.
|
||||
type owedEvent struct {
|
||||
order, event string
|
||||
body any
|
||||
id string
|
||||
firstOwed time.Time
|
||||
tries int
|
||||
next time.Time
|
||||
// taken is what waited on the bus taking it (a record kept until then); nil for none. It runs once, at the say or at a drop.
|
||||
taken func()
|
||||
}
|
||||
|
||||
// owedKept is the events owed, in the order they were made; the memory of the process, never the bus that refused them.
|
||||
type owedKept struct {
|
||||
mu sync.Mutex
|
||||
list []*owedEvent
|
||||
first, last time.Duration // the setting's pace; zero: the defaults
|
||||
unsaid time.Duration // the setting event-unsaid-after; zero: its default
|
||||
}
|
||||
|
||||
func (o *owedKept) pace() (first, max time.Duration) {
|
||||
first, max = o.first, o.last
|
||||
if first <= 0 {
|
||||
first = defaultSayAgainFirst
|
||||
}
|
||||
if max <= 0 {
|
||||
max = defaultSayAgainMax
|
||||
}
|
||||
return first, max
|
||||
}
|
||||
|
||||
func (o *owedKept) has(id string) bool {
|
||||
return slices.ContainsFunc(o.list, func(e *owedEvent) bool { return e.id == id })
|
||||
}
|
||||
|
||||
func (o *owedKept) ordered(order string) bool {
|
||||
return slices.ContainsFunc(o.list, func(e *owedEvent) bool { return e.order == order })
|
||||
}
|
||||
|
||||
// owedSetting is a setting kept as a Go duration, read at the start from the file the manifest declares; zero, its default,
|
||||
// for a file missing or empty.
|
||||
func owedSetting(getenv func(string) string) (first, max time.Duration, err error) {
|
||||
if first, err = durationFile(getenv("MESH_ASSIGNER_SAY_AGAIN_PACE_FIRST_FILE")); err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
max, err = durationFile(getenv("MESH_ASSIGNER_SAY_AGAIN_PACE_MAX_FILE"))
|
||||
return first, max, err
|
||||
}
|
||||
|
||||
// wantsOwe says one event of the seat mesh-wants, and owes it when the bus does not take it: an id already owed makes nothing, an
|
||||
// event whose order has an earlier one owed is owed behind it and not tried, and one the bus refuses is kept with `first-owed`,
|
||||
// `tries` and `next`. taken runs once the bus has taken the event (at once when it takes it now). With no bus, nothing is said.
|
||||
func (p *passer) wantsOwe(order, event string, body any, id string, taken func()) {
|
||||
if p.publishWants == nil {
|
||||
if taken != nil {
|
||||
taken()
|
||||
}
|
||||
return
|
||||
}
|
||||
o := &p.owed
|
||||
o.mu.Lock()
|
||||
defer o.mu.Unlock()
|
||||
if o.has(id) {
|
||||
return
|
||||
}
|
||||
first, _ := o.pace()
|
||||
now := p.clock().UTC()
|
||||
e := &owedEvent{order: order, event: event, body: body, id: id, firstOwed: now, next: now.Add(first), taken: taken}
|
||||
if o.ordered(order) {
|
||||
o.list = append(o.list, e)
|
||||
p.logf("%s %s is owed behind an earlier event of its order %s", event, id, order)
|
||||
return
|
||||
}
|
||||
if err := p.publishWants(event, body, id); err != nil {
|
||||
o.list = append(o.list, e)
|
||||
p.logf("%s %s is not said and is owed, said again from %s: %v", event, id, e.next.Format(time.RFC3339Nano), err)
|
||||
return
|
||||
}
|
||||
if taken != nil {
|
||||
taken()
|
||||
}
|
||||
}
|
||||
|
||||
// sayOwed says again each owed event whose time has come, the first of each order and then the next of that order once it is taken
|
||||
// (§832 2.): a refusal doubles the delay up to say-again-pace-max. It answers whether the bus took any.
|
||||
func (p *passer) sayOwed() bool {
|
||||
if p.publishWants == nil {
|
||||
return false
|
||||
}
|
||||
o := &p.owed
|
||||
o.mu.Lock()
|
||||
defer o.mu.Unlock()
|
||||
now := p.clock().UTC()
|
||||
first, max := o.pace()
|
||||
said, blocked, freed := false, map[string]bool{}, map[string]bool{}
|
||||
for i := 0; i < len(o.list); {
|
||||
e := o.list[i]
|
||||
if blocked[e.order] {
|
||||
i++
|
||||
continue
|
||||
}
|
||||
if e.next.After(now) && !freed[e.order] { // the next of an order is said once the one before it is taken
|
||||
blocked[e.order] = true
|
||||
i++
|
||||
continue
|
||||
}
|
||||
if err := p.publishWants(e.event, e.body, e.id); err != nil {
|
||||
e.tries++
|
||||
delay := first
|
||||
for n := 0; n < e.tries && delay < max; n++ {
|
||||
delay *= 2
|
||||
}
|
||||
e.next = now.Add(min(delay, max))
|
||||
p.logf("%s %s is not said again (try %d), said again from %s: %v", e.event, e.id, e.tries, e.next.Format(time.RFC3339Nano), err)
|
||||
blocked[e.order] = true
|
||||
i++
|
||||
continue
|
||||
}
|
||||
p.logf("%s %s is said again (try %d)", e.event, e.id, e.tries+1)
|
||||
o.list = slices.Delete(o.list, i, i+1)
|
||||
if e.taken != nil {
|
||||
e.taken()
|
||||
}
|
||||
said, freed[e.order] = true, true
|
||||
}
|
||||
return said
|
||||
}
|
||||
|
||||
// owedNext is the earliest time an owed event is to be said again, the first of its order only; zero for none.
|
||||
func (p *passer) owedNext() time.Time {
|
||||
o := &p.owed
|
||||
o.mu.Lock()
|
||||
defer o.mu.Unlock()
|
||||
var next time.Time
|
||||
seen := map[string]bool{}
|
||||
for _, e := range o.list {
|
||||
if seen[e.order] {
|
||||
continue
|
||||
}
|
||||
seen[e.order] = true
|
||||
if next.IsZero() || e.next.Before(next) {
|
||||
next = e.next
|
||||
}
|
||||
}
|
||||
return next
|
||||
}
|
||||
|
||||
// wakes are the times a pass is to be made at by itself, by source: the tiers' earliest deadline, each wait's bound or settle end,
|
||||
// and the owed events' earliest `next`. One timer stands, armed at the earliest (H-A-846; principle 7).
|
||||
type wakes struct {
|
||||
mu sync.Mutex
|
||||
at map[string]time.Time
|
||||
stop func() bool
|
||||
armed time.Time
|
||||
}
|
||||
|
||||
// wakeSet records the time source is to wake the pass at (zero: none) and arms the one timer at the earliest recorded.
|
||||
func (p *passer) wakeSet(source string, at time.Time) {
|
||||
wake := p.wake
|
||||
if wake == nil && p.outside != nil {
|
||||
wake = p.outside.wake
|
||||
}
|
||||
if wake == nil {
|
||||
return
|
||||
}
|
||||
w := &p.wakes
|
||||
w.mu.Lock()
|
||||
defer w.mu.Unlock()
|
||||
if w.at == nil {
|
||||
w.at = map[string]time.Time{}
|
||||
}
|
||||
if at.IsZero() {
|
||||
delete(w.at, source)
|
||||
} else {
|
||||
w.at[source] = at
|
||||
}
|
||||
var earliest time.Time
|
||||
for _, t := range w.at {
|
||||
if earliest.IsZero() || t.Before(earliest) {
|
||||
earliest = t
|
||||
}
|
||||
}
|
||||
if earliest.Equal(w.armed) && w.stop != nil {
|
||||
return
|
||||
}
|
||||
if w.stop != nil {
|
||||
w.stop()
|
||||
w.stop = nil
|
||||
}
|
||||
w.armed = earliest
|
||||
if earliest.IsZero() {
|
||||
return
|
||||
}
|
||||
d := max(earliest.Sub(p.clock()), 0) + time.Millisecond
|
||||
fire := func() {
|
||||
w.mu.Lock()
|
||||
for k, t := range w.at {
|
||||
if !t.After(earliest) {
|
||||
delete(w.at, k) // heard: a pass that still needs it sets it again
|
||||
}
|
||||
}
|
||||
w.armed, w.stop = time.Time{}, nil
|
||||
w.mu.Unlock()
|
||||
wake()
|
||||
}
|
||||
if p.after != nil {
|
||||
w.stop = p.after(d, fire)
|
||||
return
|
||||
}
|
||||
t := time.AfterFunc(d, fire)
|
||||
w.stop = t.Stop
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||
mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
||||
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
"git.novox.be/novox/mesh-sdk/go/views"
|
||||
|
||||
"mesh-delivery-assigner/internal/assign"
|
||||
)
|
||||
|
||||
// The owed events' reading and steering (design 47 H2b §832 6., H-A-847, H-A-869): the seat mesh-wants' verbs `owed`, `owed-say` and
|
||||
// `owed-drop` are answered by the assigner's program, which keeps the owed events in its memory, and the tools assigner_owed,
|
||||
// assigner_owed_say and assigner_owed_drop call them. Past `event-unsaid-after` an owed event is the finding `event-unsaid`.
|
||||
|
||||
const (
|
||||
owedTool = "assigner_owed"
|
||||
owedSayTool = "assigner_owed_say"
|
||||
owedDropTool = "assigner_owed_drop"
|
||||
// kindEventUnsaid is the finding of an event owed for event-unsaid-after, scope delivery, id the message id made a key.
|
||||
kindEventUnsaid = "event-unsaid"
|
||||
// defaultEventUnsaidAfter is the setting event-unsaid-after's default.
|
||||
defaultEventUnsaidAfter = 5 * time.Minute
|
||||
)
|
||||
|
||||
func (o *owedKept) unsaidFor() time.Duration {
|
||||
if o.unsaid > 0 {
|
||||
return o.unsaid
|
||||
}
|
||||
return defaultEventUnsaidAfter
|
||||
}
|
||||
|
||||
// owedSeen is e as the seat's verbs answer it.
|
||||
func owedSeen(e *owedEvent) meshwants.OwedEvent {
|
||||
return meshwants.OwedEvent{ID: e.id, FirstOwed: e.firstOwed, Next: e.next, Tries: int64(e.tries)}
|
||||
}
|
||||
|
||||
// owedAll is every owed event, in the order they were made.
|
||||
func (p *passer) owedAll() []meshwants.OwedEvent {
|
||||
o := &p.owed
|
||||
o.mu.Lock()
|
||||
defer o.mu.Unlock()
|
||||
out := make([]meshwants.OwedEvent, 0, len(o.list))
|
||||
for _, e := range o.list {
|
||||
out = append(out, owedSeen(e))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// owedSay says the first owed event of id's order now, its delay set back to say-again-pace-first; it answers the event said, or the
|
||||
// refusal of the bus (the event stays owed, said again from say-again-pace-first on).
|
||||
func (p *passer) owedSay(id string) (meshwants.OwedEvent, error) {
|
||||
if p.publishWants == nil {
|
||||
return meshwants.OwedEvent{}, errors.New("the assigner has no bus to say it on")
|
||||
}
|
||||
o := &p.owed
|
||||
o.mu.Lock()
|
||||
at := slicesIndex(o.list, id)
|
||||
if at < 0 {
|
||||
o.mu.Unlock()
|
||||
return meshwants.OwedEvent{}, fmt.Errorf("no event is owed under %q: assigner_owed lists them", id)
|
||||
}
|
||||
var e *owedEvent
|
||||
for _, c := range o.list {
|
||||
if c.order == o.list[at].order {
|
||||
e = c
|
||||
break
|
||||
}
|
||||
}
|
||||
first, _ := o.pace()
|
||||
now := p.clock().UTC()
|
||||
if err := p.publishWants(e.event, e.body, e.id); err != nil {
|
||||
e.tries, e.next = 0, now.Add(first)
|
||||
o.mu.Unlock()
|
||||
return owedSeen(e), fmt.Errorf("the bus did not take %s %s: %w; it stays owed, said again from %s", e.event, e.id, err, e.next.Format(time.RFC3339))
|
||||
}
|
||||
seen := owedSeen(e)
|
||||
o.list = slicesDelete(o.list, e)
|
||||
o.mu.Unlock()
|
||||
p.logf("%s %s is said by hand", e.event, e.id)
|
||||
if e.taken != nil {
|
||||
e.taken()
|
||||
}
|
||||
p.owedFindings()
|
||||
if p.wake != nil {
|
||||
p.wake()
|
||||
}
|
||||
return seen, nil
|
||||
}
|
||||
|
||||
// owedDrop drops the owed event id and every event owed behind it in its order, doing for each what the bus taking it would have
|
||||
// done (its taken), then clears their findings; it answers the events dropped, the named one first.
|
||||
func (p *passer) owedDrop(id string) ([]meshwants.OwedEvent, error) {
|
||||
o := &p.owed
|
||||
o.mu.Lock()
|
||||
at := slicesIndex(o.list, id)
|
||||
if at < 0 {
|
||||
o.mu.Unlock()
|
||||
return nil, fmt.Errorf("no event is owed under %q: assigner_owed lists them", id)
|
||||
}
|
||||
order := o.list[at].order
|
||||
var dropped []*owedEvent
|
||||
var kept []*owedEvent
|
||||
for i, e := range o.list {
|
||||
if e.order == order && i >= at {
|
||||
dropped = append(dropped, e)
|
||||
continue
|
||||
}
|
||||
kept = append(kept, e)
|
||||
}
|
||||
o.list = kept
|
||||
o.mu.Unlock()
|
||||
seen := make([]meshwants.OwedEvent, 0, len(dropped))
|
||||
for _, e := range dropped {
|
||||
seen = append(seen, owedSeen(e))
|
||||
p.logf("%s %s is dropped by hand, with what waited on it done", e.event, e.id)
|
||||
if e.taken != nil {
|
||||
e.taken()
|
||||
}
|
||||
}
|
||||
p.owedFindings()
|
||||
if p.wake != nil {
|
||||
p.wake()
|
||||
}
|
||||
return seen, nil
|
||||
}
|
||||
|
||||
func slicesIndex(list []*owedEvent, id string) int {
|
||||
for i, e := range list {
|
||||
if e.id == id {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
func slicesDelete(list []*owedEvent, e *owedEvent) []*owedEvent {
|
||||
out := list[:0:0]
|
||||
for _, c := range list {
|
||||
if c != e {
|
||||
out = append(out, c)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
var (
|
||||
unsaidFp = regexp.MustCompile(`src2:([0-9a-f]{64})`)
|
||||
unsaidTime = regexp.MustCompile(`\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d+)?Z`)
|
||||
)
|
||||
|
||||
// unsaidID is a message id as the finding's id: each fingerprint as its 64 hex digits without `src2:` and each time as Unix
|
||||
// nanoseconds (design 47 H2b §832 6.); assign.KeyID makes it a key.
|
||||
func unsaidID(id string) string {
|
||||
id = unsaidFp.ReplaceAllString(id, "$1")
|
||||
return unsaidTime.ReplaceAllStringFunc(id, func(s string) string {
|
||||
t, err := time.Parse(time.RFC3339Nano, s)
|
||||
if err != nil {
|
||||
return s
|
||||
}
|
||||
return strconv.FormatInt(t.UnixNano(), 10)
|
||||
})
|
||||
}
|
||||
|
||||
func unsaidKey(id string) string {
|
||||
return views.FindingKey(mcc.ScopeDelivery, assign.KeyID(unsaidID(id)), kindEventUnsaid)
|
||||
}
|
||||
|
||||
// owedFindings writes the finding `event-unsaid` of each event owed for event-unsaid-after, and clears, from the bucket's keys read
|
||||
// now, every one of an event no longer owed: said, dropped, or not owed again after a restart (H-A-722).
|
||||
func (p *passer) owedFindings() {
|
||||
have, ok := p.findingKeys("the finding event-unsaid")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
o := &p.owed
|
||||
o.mu.Lock()
|
||||
now, after := p.clock().UTC(), o.unsaidFor()
|
||||
owed := map[string]bool{}
|
||||
var raise []*owedEvent
|
||||
for _, e := range o.list {
|
||||
if now.Sub(e.firstOwed) < after {
|
||||
continue
|
||||
}
|
||||
owed[unsaidKey(e.id)] = true
|
||||
raise = append(raise, e)
|
||||
}
|
||||
o.mu.Unlock()
|
||||
for _, e := range raise {
|
||||
key := unsaidKey(e.id)
|
||||
if have[key] {
|
||||
continue
|
||||
}
|
||||
summary := fmt.Sprintf("%s %s has been owed since %s and the bus does not take it", e.event, e.id, e.firstOwed.Format(time.RFC3339))
|
||||
f := assign.Observed{Scope: mcc.ScopeDelivery, ID: unsaidID(e.id), Kind: kindEventUnsaid, Severity: mcseat.FindingSeverityWarning,
|
||||
Summary: summary, Headline: "An event of the delivery is not said",
|
||||
Explanation: summary + ". The assigner says it again on its own pace; assigner_owed lists what is owed, assigner_owed_say says one now and assigner_owed_drop drops one the bus will never take.",
|
||||
Needs: "Nothing, unless the bus keeps refusing it.", Source: "assigner." + kindEventUnsaid}
|
||||
if err := p.findings.Put(f.Finding(now)); err != nil {
|
||||
p.logf("the finding %s is not written: %v", key, err)
|
||||
}
|
||||
}
|
||||
var gone []string
|
||||
for key := range have {
|
||||
if strings.HasPrefix(key, mcc.ScopeDelivery+".") && strings.HasSuffix(key, "."+kindEventUnsaid) && !owed[key] {
|
||||
gone = append(gone, key)
|
||||
}
|
||||
}
|
||||
sort.Strings(gone)
|
||||
for _, key := range gone {
|
||||
if err := p.findings.Delete(key); err != nil {
|
||||
p.logf("the finding %s is not cleared: %v", key, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// owedVerbs are the process's handlers of the seat mesh-wants' verbs owed, owed-say and owed-drop; record writes the hand act of a
|
||||
// drop in the log first.
|
||||
func owedVerbs(p *passer, record func(meshhandactsclient.Request) error) map[string]process.SeatHandler {
|
||||
return map[string]process.SeatHandler{
|
||||
meshwants.VerbOwed: func(string, json.RawMessage) (any, error) {
|
||||
return meshwants.OwedAnswer{Events: p.owedAll()}, nil
|
||||
},
|
||||
meshwants.VerbOwedSay: func(_ string, raw json.RawMessage) (any, error) {
|
||||
var in meshwants.OwedSayInput
|
||||
if err := json.Unmarshal(raw, &in); err != nil {
|
||||
return nil, fmt.Errorf("the arguments are not JSON: %w", err)
|
||||
}
|
||||
e, err := p.owedSay(in.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return meshwants.OwedSayAnswer{Event: e}, nil
|
||||
},
|
||||
meshwants.VerbOwedDrop: func(caller string, raw json.RawMessage) (any, error) {
|
||||
var in meshwants.OwedDropInput
|
||||
if err := json.Unmarshal(raw, &in); err != nil {
|
||||
return nil, fmt.Errorf("the arguments are not JSON: %w", err)
|
||||
}
|
||||
if in.ID == "" || strings.TrimSpace(in.Why) == "" {
|
||||
return nil, errors.New("name the owed event's id and why it is dropped")
|
||||
}
|
||||
if err := record(meshhandactsclient.Request{What: owedDropTool + " " + in.ID, Why: in.Why + " (" + caller + ")", Cause: "owed-event-drop"}); err != nil {
|
||||
return nil, fmt.Errorf("the hand act is not recorded, so nothing is dropped: %w", err)
|
||||
}
|
||||
dropped, err := p.owedDrop(in.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return meshwants.OwedDropAnswer{Dropped: dropped}, nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// owedTools are the module's tools of the owed events, each calling its verb of the seat mesh-wants; with the program stopped each
|
||||
// says the verb is unanswered.
|
||||
func owedTools(ask func(string, any) (json.RawMessage, error)) []stdio.Tool {
|
||||
call := func(verb string, in any) (any, error) {
|
||||
raw, err := ask("seat:"+meshwants.Seat+"."+verb, in)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the assigner's program does not answer the verb %s of the seat %s (it is stopped or starting): %w", verb, meshwants.Seat, err)
|
||||
}
|
||||
var out any
|
||||
if err := json.Unmarshal(raw, &out); err != nil {
|
||||
return nil, fmt.Errorf("%s answered what is not JSON: %w", verb, err)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
return []stdio.Tool{
|
||||
{Name: owedTool, Description: "The events the assigner says on the seat mesh-wants that the bus refused or did not acknowledge, owed in order and said " +
|
||||
"again under the same id (design 47 H2b §832): each with its id, when it was first owed, how many times it was said again and when it is said next; past " +
|
||||
"event-unsaid-after each is the finding event-unsaid. Read-only.",
|
||||
Input: schema(map[string]string{}, nil),
|
||||
Run: func(map[string]any) (any, error) { return call(meshwants.VerbOwed, meshwants.OwedInput{}) }},
|
||||
{Name: owedSayTool, Description: "Say the first owed event of an id's order now (design 47 H2b §832 6.), its delay set back to say-again-pace-first; answers the event said, " +
|
||||
"or the bus's refusal, the event staying owed.",
|
||||
Input: schema(map[string]string{"id": "an owed event's message id, as assigner_owed lists it"}, []string{"id"}),
|
||||
Run: func(a map[string]any) (any, error) {
|
||||
return call(meshwants.VerbOwedSay, meshwants.OwedSayInput{ID: arg(a, "id")})
|
||||
}},
|
||||
{Name: owedDropTool, Description: "Drop an owed event the bus will never take, with every event owed behind it in its order (design 47 H2b §832 6.), doing for each what " +
|
||||
"the bus taking it would have done: a tier-late writes tier-late-said, a running deletes the progress key, a wait-ended does the rest of the wait's end, a removal " +
|
||||
"deletes its mark; then its finding is cleared. Written in the hand-act log first.",
|
||||
Input: schema(map[string]string{"id": "an owed event's message id", "why": "why it is dropped"}, []string{"id", "why"}),
|
||||
Run: func(a map[string]any) (any, error) {
|
||||
return call(meshwants.VerbOwedDrop, meshwants.OwedDropInput{ID: arg(a, "id"), Why: arg(a, "why")})
|
||||
}},
|
||||
}
|
||||
}
|
||||
@@ -80,6 +80,8 @@ type passer struct {
|
||||
// nodeFailed is, by node and module, the words of the condition last raised for a failure that is the node's own (ADR 0557
|
||||
// §1, issue 1496): raised once per words, cleared once when it ends.
|
||||
nodeFailed map[string]string
|
||||
// startSaid says the start's saying again was made (startsays.go).
|
||||
startSaid, startWaitsSaid bool
|
||||
// callsCleared says the first pass cleared the conditions of refused controller calls a previous process raised
|
||||
// (clearStaleCalls): the assigner makes no such call now (issue 774).
|
||||
callsCleared bool
|
||||
@@ -115,11 +117,20 @@ type passer struct {
|
||||
// entries are the catalog entries by fingerprint asked of the seat mesh-catalog's verb `entry` (design 47 G §614, A-217): a
|
||||
// held revert's running entry and its want's (revert.go); nil: no revert is asked about.
|
||||
entries *meshcatalogclient.Entries
|
||||
// tierBound is the setting tier-bound (design 47 H §751; zero: its default), and tierTimer the one timer that wakes the pass at
|
||||
// the earliest tier's deadline (tiers.go), made with tierWake; nil tierWake sets no timer.
|
||||
// tierBound is the setting tier-bound (design 47 H §751; zero: its default). wake makes a pass; wakes are the times the one
|
||||
// timer wakes it at, armed at the earliest (owed.go, H-A-846), made with after (nil: time.AfterFunc; a test's seam); nil wake
|
||||
// sets no timer.
|
||||
tierBound time.Duration
|
||||
tierWake func()
|
||||
tierTimer *time.Timer
|
||||
wake func()
|
||||
wakes wakes
|
||||
after func(time.Duration, func()) func() bool
|
||||
// tierHolds are, by pipeline, what holds its tier progress at its tier, read by the last pass (tiers.go, why.go).
|
||||
tierHolds map[string]tierHold
|
||||
// owed are the events of the seat mesh-wants the bus refused, owed in order and said again (owed.go, design 47 H §832).
|
||||
owed owedKept
|
||||
// putHeld is the put waits whose wait-held is owed and not yet taken, by put key: their record is written once it is taken, and
|
||||
// a put that ends meanwhile still owes its wait-ended behind it (design 47 H2b §832 1., 4.).
|
||||
putHeld putHeldOwed
|
||||
// passStall is the setting pass-stall-seconds (passstall.go; zero: its default): a pass still running after it says which phase
|
||||
// it is in (design 47 H2 H-A-635).
|
||||
passStall time.Duration
|
||||
@@ -158,12 +169,20 @@ func (p *passer) pass(ctx context.Context) {
|
||||
watch := p.watchPass(start) // a pass past pass-stall-seconds says which phase it is in (design 47 H2 H-A-635)
|
||||
defer func() {
|
||||
watch.end()
|
||||
p.wakeSet("owed", p.owedNext())
|
||||
p.logf("the pass took %s", time.Since(start).Round(time.Millisecond)) // design 47 H-A-259
|
||||
}()
|
||||
if p.outside != nil {
|
||||
p.outside.beginPass(p.clock)
|
||||
}
|
||||
p.sayOwed()
|
||||
p.owedFindings() // an event owed for event-unsaid-after is raised, one no longer owed is cleared (§832 6.)
|
||||
watch.in(phaseAssignmentsSeat)
|
||||
p.assignmentsSeat(ctx)
|
||||
watch.in(phaseKeptGraph)
|
||||
if held := p.keepGraph(ctx); held == "" {
|
||||
held := p.keepGraph(ctx)
|
||||
p.startSays(ctx)
|
||||
if held == "" {
|
||||
watch.in(phaseWants)
|
||||
p.wants(ctx)
|
||||
watch.in(phasePassSaid)
|
||||
@@ -286,7 +305,11 @@ func (p *passer) wants(ctx context.Context) {
|
||||
for node, fp := range out.Unversioned {
|
||||
unversioned[assign.UnversionedKey(name, node)] = unversionedWant{module: name, node: node, fp: fp}
|
||||
}
|
||||
p.sayWhy(ctx, name, m.Nodes, wantWhy{Branch: g.branch, Fp: target.Fp, Version: target.Version, Pipeline: target.Pipeline, Step: whyStep(ok)}, wantedOf, &out)
|
||||
why := wantWhy{Branch: g.branch, Fp: target.Fp, Version: target.Version, Pipeline: target.Pipeline, Step: whyStep(ok)}
|
||||
if !ok {
|
||||
why, _ = p.heldByTier(name, g.branch, why)
|
||||
}
|
||||
p.sayWhy(ctx, name, m.Nodes, why, wantedOf, &out)
|
||||
if ok {
|
||||
p.yeses(ctx, name, m, wantedOf, &out)
|
||||
}
|
||||
@@ -362,8 +385,23 @@ func (p *passer) putWant(ctx context.Context, node, module string, want mwc.Want
|
||||
fp = before.Fp
|
||||
}
|
||||
}
|
||||
// The want-revision `wanted` says is the revision of the want's key it says; for a removal, of the write it removes (§832 3.).
|
||||
removes := p.w.metaOf(buckets.Wants(), key).revision
|
||||
// A removal is written before it is said (§832 4., H-A-843): its mark, the fingerprint and the want-revision of the write it
|
||||
// removes, is kept in the state `written` before the removing want is written, and goes once the bus has taken the event.
|
||||
var taken func()
|
||||
if want.Removed && removes != 0 && p.ends != nil {
|
||||
if !p.markRemoval(node, module, fp, removes) {
|
||||
return
|
||||
}
|
||||
taken = func() { p.dropRemovalMark(node, module) }
|
||||
}
|
||||
if p.wantWritten(ctx, node, module, key, want) {
|
||||
p.sayWanted(node, module, fp, want.Pipeline, want.Removed)
|
||||
revision := removes
|
||||
if !want.Removed {
|
||||
revision = p.w.metaOf(buckets.Wants(), key).revision
|
||||
}
|
||||
p.sayWanted(node, module, fp, want.Pipeline, want.Removed, revision, time.Time{}, taken)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient/heard"
|
||||
mpr "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||
"git.novox.be/novox/mesh-sdk/go/busretry"
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
@@ -235,6 +236,26 @@ func TestAnAnswerCountsOnlyForTheAskingItAnswered(t *testing.T) {
|
||||
if _, err := readEngineReads(memStore{engineReadsState: &memKV{values: state}}, "g14"); err == nil {
|
||||
t.Error("assigner_engine_reads answers a node it holds no key of")
|
||||
}
|
||||
// Design 47 H2b §836 1., 4. (review r1, part 1 finding 7): a Start that answers nil with a durable not bound says nothing
|
||||
// is heard; what waits on live events is done by the hub's OnAllHeard, and the reads' finding stands while its pattern is
|
||||
// unheard and goes once the hub's list holds it no more.
|
||||
lives := 0
|
||||
readsLive(func() { lives++ }, t.Logf)()
|
||||
if lives != 1 {
|
||||
t.Errorf("OnAllHeard made the seat list live %d times, want 1", lives)
|
||||
}
|
||||
finds := map[string]bool{}
|
||||
unheard := readsUnheard(heard.Writer{Observer: "assigner", Logf: t.Logf,
|
||||
Put: func(key string, _ []byte) error { finds[key] = true; return nil },
|
||||
Delete: func(key string) error { delete(finds, key); return nil }}, t.Logf)
|
||||
unheard([]process.Unheard{{Pattern: enginereads.SubjectPrefix + "*", Stream: process.EventsStream, Why: "not composed"}})
|
||||
if len(finds) != 1 {
|
||||
t.Errorf("the reads' pattern unheard wrote %v, want one finding", finds)
|
||||
}
|
||||
unheard([]process.Unheard{{Pattern: "mesh.seat.other.event.x", Stream: "SEAT_other_x", Why: "no stream carries it"}})
|
||||
if len(finds) != 0 {
|
||||
t.Errorf("a list without the reads' pattern left %v", finds)
|
||||
}
|
||||
// The event's node is its subject's last token, and what does not hold is no event.
|
||||
now := time.Now().Format(time.RFC3339Nano)
|
||||
for _, row := range []struct {
|
||||
@@ -444,7 +465,8 @@ func putOfTheBus(t *testing.T) {
|
||||
before, _ := nodeengineclient.EncodeHave(nodeengine.HaveByNodeModuleValue{Fp: meshcatalogclient.SourcePrefix2 + strings.Repeat("a", 64), Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK})
|
||||
world(buckets.Have, hkey, before)
|
||||
|
||||
// Issue 1966: newest is asked of the indexer's first view of modules, never read from its bus state.
|
||||
// The tool asks nobody for newest (design 47 H2b §833): the program resolves it. The indexer's view is asked only for the
|
||||
// older-than-newest of the puts listed (issue 1966).
|
||||
indexer := &fakeIndexer{views: map[string]map[string][]byte{"mesh-delivery-indexer.modules": {"mesh-catalog": mod, "nats": mod}}}
|
||||
s := newPutTools(memStore{putsState: putsKV}, func(key string, body any) (json.RawMessage, error) {
|
||||
if raw, ok, err := indexer.answer(key, body); ok {
|
||||
@@ -456,19 +478,19 @@ func putOfTheBus(t *testing.T) {
|
||||
was := answerWithin
|
||||
answerWithin = 0
|
||||
defer func() { answerWithin = was }()
|
||||
if _, err := s.doPut(map[string]any{"node": "novox", "module": "nats", "version": "fd497ab8ffff", "why": "x"}, "shanks.node-tools"); err == nil {
|
||||
t.Error("a prefix of a fingerprint was taken: a put names the whole fingerprint (A-181)")
|
||||
// Design 47 H2b §833, §834: the tool reads nothing; it takes newest, a whole fingerprint, or its first 12 hex digits as asked.
|
||||
prefix := meshcatalogclient.SourcePrefix2 + "fd497ab80000"
|
||||
for _, ok := range []string{"newest", fp, prefix, strings.ToUpper(prefix)} {
|
||||
if _, err := s.version("nats", ok); err != nil {
|
||||
t.Errorf("%q is a version: %v", ok, err)
|
||||
}
|
||||
}
|
||||
if _, err := s.version("nats", "fd497ab80000"); err == nil {
|
||||
t.Error("the prefix of the fingerprint built was read: a put names the whole fingerprint (A-181)")
|
||||
for _, bad := range []string{"fd497ab80000", meshcatalogclient.SourcePrefix2 + "fd497ab800", "main", ""} {
|
||||
if _, err := s.version("nats", bad); err == nil {
|
||||
t.Errorf("%q was taken as a version", bad)
|
||||
}
|
||||
}
|
||||
if got, err := s.version("nats", "newest"); err != nil || got != fp || indexer.asks["mesh-delivery-indexer.modules"] != 2 {
|
||||
t.Errorf("newest reads %q, %v, asking %d pages of the indexer's first view (want its 2)", got, err, indexer.asks["mesh-delivery-indexer.modules"])
|
||||
}
|
||||
if _, err := s.version("ghost", "newest"); err == nil || !strings.Contains(err.Error(), "holds no module ghost") {
|
||||
t.Errorf("newest of a module the indexer does not hold: %v", err)
|
||||
}
|
||||
ans, err := s.doPut(map[string]any{"node": "novox", "module": "nats", "version": fp, "hold": "true", "why": "the bus's user list"}, "shanks.node-tools")
|
||||
ans, err := s.doPut(map[string]any{"node": "novox", "module": "nats", "version": prefix, "hold": "true", "why": "the bus's user list"}, "shanks.node-tools")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -486,8 +508,8 @@ func putOfTheBus(t *testing.T) {
|
||||
}
|
||||
return got
|
||||
}
|
||||
if got := step(); got.Step != puts.Compose || !strings.Contains(got.Words, "no composition") {
|
||||
t.Fatalf("the first pass left the put at %s: %s", got.Step, got.Words)
|
||||
if got := step(); got.Step != puts.Compose || !strings.Contains(got.Words, "no composition") || got.FP != fp {
|
||||
t.Fatalf("the first pass left the put at %s (%s) at %q: it resolves the prefix to the whole fingerprint %s", got.Step, got.Words, got.FP, fp)
|
||||
}
|
||||
select {
|
||||
case call := <-bus.calls:
|
||||
@@ -594,6 +616,45 @@ func putOfTheBus(t *testing.T) {
|
||||
if string(wantsKV.values["want.novox.nats"]) != string(oldWant) {
|
||||
t.Errorf("a want was written for a put released meanwhile: %s", wantsKV.values["want.novox.nats"])
|
||||
}
|
||||
// §833, H-A-862: newest is the end kept for the node's branch, whatever newer build the trunk has; none kept is refused
|
||||
// naming the branch and the words of the tool's description. §834: a prefix two builds share is refused naming both.
|
||||
trunkNewer := meshcatalogclient.SourcePrefix2 + strings.Repeat("9", 64)
|
||||
// AC-833: the trunk's newest build of nats, which passed no pipeline, is placed in the world beside the end kept below.
|
||||
newer, _ := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Fp2: trunkNewer, Repository: "novox/mesh-catalog", Commit: strings.Repeat("d", 40)})
|
||||
putModuleRaw(p.w, trunkBranch, "nats", newer)
|
||||
newerBuilt, _ := json.Marshal(builds.BuildEnded{Module: "nats", Fingerprint: trunkNewer, Outcome: builds.BuildDone})
|
||||
if p.w.ends.put(newerBuilt) != nil {
|
||||
t.Fatal("the newer build is not heard")
|
||||
}
|
||||
p.ends = newPipelineEnds(newMemEnds(), func() {}, t.Logf)
|
||||
p.ends.trunk = p.w.trunkName
|
||||
if _, err := s.doPut(map[string]any{"node": "novox", "module": "nats", "version": "newest", "why": "the newest that passed"}, "shanks.node-tools"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := step(); got.Step != puts.Refused || !strings.Contains(got.Words, "no version of nats passed a pipeline: name a fingerprint, or read assigner_written") || !strings.Contains(got.Words, trunkBranch) {
|
||||
t.Fatalf("newest with no end kept stands at %s: %s", got.Step, got.Words)
|
||||
}
|
||||
end, _ := json.Marshal(End{Pipeline: "main.7", Source: 7, Seq: 1, Fp: fp, Version: "2.10.1", Rank: 1})
|
||||
p.ends.st.(*memEnds).vals[endKey("nats", trunkBranch)] = end
|
||||
p.w.put(buckets.Puts(), pkey, putsKV.values[pkey])
|
||||
if _, err := s.doPut(map[string]any{"node": "novox", "module": "nats", "version": "newest", "why": "again"}, "shanks.node-tools"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := step(); got.FP != fp || got.FP == trunkNewer || !strings.Contains(got.Steps[0].Words+got.Steps[1].Words, "which newest resolves to") {
|
||||
t.Fatalf("newest with an end kept at %s stands at %s at %q: %s (the trunk's %s passed no pipeline)", fp, got.Step, got.FP, got.Words, trunkNewer)
|
||||
}
|
||||
for _, other := range []string{"1", "2"} {
|
||||
two, _ := json.Marshal(builds.BuildEnded{Module: "nats", Fingerprint: fp[:len(fp)-1] + other, Outcome: builds.BuildDone})
|
||||
if p.w.ends.put(two) != nil {
|
||||
t.Fatal("a build is not heard")
|
||||
}
|
||||
}
|
||||
if _, err := s.doPut(map[string]any{"node": "novox", "module": "nats", "version": meshcatalogclient.SourcePrefix2 + "fd497ab80000", "why": "shared prefix"}, "shanks.node-tools"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := step(); got.Step != puts.Refused || strings.Count(got.Words, "fd497ab80000") < 3 {
|
||||
t.Fatalf("a prefix three builds share stands at %s: %s", got.Step, got.Words)
|
||||
}
|
||||
}
|
||||
|
||||
// 1906 note 28: an ask outlives its fingerprint. Each pass takes away the hold, restore and record asks of a module whose
|
||||
@@ -1092,6 +1153,16 @@ func TestAWantsNeedsAreReadFromItsEntryAndNeverWaitedFor(t *testing.T) {
|
||||
if _, read := p.missingNeeds(ctx, value, words, gone); read {
|
||||
t.Error("an entry not found is read")
|
||||
}
|
||||
// Design 47 H §872 (1984/AC-872b): a need `word:<path>` of a word the take-in set aside (the indexer's, in the form of the manifest
|
||||
// reads) holds the want on a machine whose node-engine's words lack it, and lets it be written on one whose words hold it.
|
||||
const need = "word:build.artifacts.race"
|
||||
racing := meshcatalog.ModulesByModuleValue{Fp2: held, Needs: []string{"want:version", need}}
|
||||
if missing, read := p.missingNeeds(ctx, racing, words, held); !read || !slices.Equal(missing, []string{need}) {
|
||||
t.Errorf("AC-872b: a node-engine whose words lack %s: missing %v (read %v), want the want held for it", need, missing, read)
|
||||
}
|
||||
if missing, read := p.missingNeeds(ctx, racing, append([]string{need}, words...), held); !read || len(missing) != 0 {
|
||||
t.Errorf("AC-872b: a node-engine whose words hold %s: missing %v (read %v), want the want written", need, missing, read)
|
||||
}
|
||||
}
|
||||
|
||||
// H-A-698 (2): the why of a want held awaiting its entry names the ask: its state, how often it was asked again and its last failure.
|
||||
|
||||
@@ -194,7 +194,7 @@ func (e *pipelineEnds) take(p mpr.PipelineEnded) (bool, error) {
|
||||
var kept []tierMover
|
||||
versioned := map[string]bool{}
|
||||
defer func() {
|
||||
if err := e.startTiers(p.Pipeline, p.Source, kept, versioned); err != nil {
|
||||
if err := e.startTiers(p.Pipeline, p.Source, p.Seq, kept, versioned); err != nil {
|
||||
e.logf("the tier progress of %s is not written: %v", p.Pipeline, err)
|
||||
}
|
||||
}()
|
||||
@@ -210,6 +210,13 @@ func (e *pipelineEnds) take(p mpr.PipelineEnded) (bool, error) {
|
||||
m.Version = v
|
||||
}
|
||||
}
|
||||
if v, ok := e.releasedAt(m.Module, m.Fingerprint); m.Version != "" && ok && v != m.Version {
|
||||
// A version released from another build is no version of this mover (design 47 H2b §835 2.): it is not kept, the mover
|
||||
// is held `no-version` for the pass to find the version released at its own fingerprint (§826 1.).
|
||||
e.logf("%s: %s at %s names version %s, released from another build; the version released at its own fingerprint is %s: taken at the next pass",
|
||||
p.Pipeline, m.Module, m.Fingerprint, m.Version, v)
|
||||
m.Version = ""
|
||||
}
|
||||
if m.Version == "" {
|
||||
// The runner writes a mover's version at its release's version-released, and says this end again once it does
|
||||
// (H-A-270 (1), (2)): the skip is said, never silent.
|
||||
@@ -219,35 +226,79 @@ func (e *pipelineEnds) take(p mpr.PipelineEnded) (bool, error) {
|
||||
continue
|
||||
}
|
||||
versioned[m.Module] = true
|
||||
key := endKey(m.Module, p.Branch)
|
||||
for {
|
||||
raw, rev, err := e.st.get(key)
|
||||
if err != nil {
|
||||
return changed, err
|
||||
}
|
||||
if raw != nil {
|
||||
var kept End
|
||||
if err := json.Unmarshal(raw, &kept); err == nil && compareVersion(m.Version, kept.Version) <= 0 {
|
||||
break // an older version, or this one again
|
||||
}
|
||||
}
|
||||
value, err := json.Marshal(End{Pipeline: p.Pipeline, Source: p.Source, Seq: p.Seq, Fp: m.Fingerprint, Version: m.Version, Rank: max(m.Tier, 1)})
|
||||
if err != nil {
|
||||
return changed, err
|
||||
}
|
||||
if err := e.st.swap(key, value, rev); errors.Is(err, errSwapped) {
|
||||
continue
|
||||
} else if err != nil {
|
||||
return changed, err
|
||||
}
|
||||
did, err := e.keepEnd(p.Pipeline, p.Branch, p.Source, p.Seq, m.Module, m.Fingerprint, m.Version, max(m.Tier, 1))
|
||||
if err != nil {
|
||||
return changed, err
|
||||
}
|
||||
if did {
|
||||
changed = true
|
||||
kept = append(kept, tierMover{Module: m.Module, Fp: m.Fingerprint, Tier: max(m.Tier, 1)})
|
||||
break
|
||||
}
|
||||
}
|
||||
return changed, nil
|
||||
}
|
||||
|
||||
// releasedAt is releasedOf, false when no lookup is set.
|
||||
func (e *pipelineEnds) releasedAt(module, fp string) (string, bool) {
|
||||
if e.releasedOf == nil {
|
||||
return "", false
|
||||
}
|
||||
return e.releasedOf(module, fp)
|
||||
}
|
||||
|
||||
// keepEnd keeps the end of a passed mover, version and all, as the newest of its module on branch, by compare-and-set: an older
|
||||
// version, or the same one again, writes nothing, the same one from another pipeline whose want was never written excepted
|
||||
// (design 47 H2b §825 2.). It says whether the key changed. The pipeline's end (take) and a pass that finds a `no-version`
|
||||
// mover's version released (§826 1.) keep it so.
|
||||
func (e *pipelineEnds) keepEnd(pipeline, branch string, source, seq int64, module, fp, version string, rank int64) (bool, error) {
|
||||
key := endKey(module, branch)
|
||||
for {
|
||||
raw, rev, err := e.st.get(key)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if raw != nil {
|
||||
var kept End
|
||||
if err := json.Unmarshal(raw, &kept); err == nil {
|
||||
c := compareVersion(version, kept.Version)
|
||||
if c < 0 || (c == 0 && !e.stranded(kept, pipeline, fp)) {
|
||||
return false, nil // an older version, or this one again
|
||||
}
|
||||
if c == 0 {
|
||||
e.logf("%s: %s at %s is kept again from %s: the want of %s, whose progress is at tier %d of %d, was never written",
|
||||
pipeline, module, version, pipeline, kept.Pipeline, e.tierOf(kept.Pipeline), kept.Rank)
|
||||
}
|
||||
}
|
||||
}
|
||||
value, err := json.Marshal(End{Pipeline: pipeline, Source: source, Seq: seq, Fp: fp, Version: version, Rank: rank})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if err := e.st.swap(key, value, rev); errors.Is(err, errSwapped) {
|
||||
continue
|
||||
} else if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// stranded says the end kept at the same fingerprint and version, from another pipeline, never had its want written: that
|
||||
// pipeline's progress still stands below the end's rank (design 47 H2b §825 2.). The pipeline now ended carries the mover again.
|
||||
func (e *pipelineEnds) stranded(kept End, pipeline, fp string) bool {
|
||||
if kept.Pipeline == "" || kept.Pipeline == pipeline || kept.Fp != fp {
|
||||
return false
|
||||
}
|
||||
t, _, ok := e.tiersOf(kept.Pipeline)
|
||||
return ok && t.Tier < kept.Rank
|
||||
}
|
||||
|
||||
// tierOf is the tier a pipeline's progress stands at, 0 when it has none.
|
||||
func (e *pipelineEnds) tierOf(pipeline string) int64 {
|
||||
t, _, _ := e.tiersOf(pipeline)
|
||||
return t.Tier
|
||||
}
|
||||
|
||||
// noSeqOnce says, once per module and pipeline, that the end kept for module from pipeline carries no sequence and writes
|
||||
// no want, naming the recovery (H-A-504 second addendum).
|
||||
func (e *pipelineEnds) noSeqOnce(module, pipeline string) {
|
||||
@@ -360,7 +411,7 @@ func (e *pipelineEnds) branchOf(module, placed string) string {
|
||||
|
||||
// writtenTools is the tool assigner_written: every key of the state written, with its end.
|
||||
func writtenTools(st store) []stdio.Tool {
|
||||
return []stdio.Tool{{Name: writtenTool, Description: "the pipeline ends the assigner's wants follow: per module and watched branch, the newest version released whose pipeline passed, with its pipeline and rank; per pipeline whose wants are written tier by tier, its tier progress (tier, since, movers, and clock-from and paused-from: the time tier-bound counts from, and when a pause of the count by an ask of the operator began); with why, why each want is what it is (as assigner_why).",
|
||||
return []stdio.Tool{{Name: writtenTool, Description: "the pipeline ends the assigner's wants follow: per module and watched branch, the newest version released whose pipeline passed, with its pipeline and rank; per pipeline whose wants are written tier by tier, its tier progress (tier, since, movers, and clock-from and paused-from: the time tier-bound counts from, and when a pause of the count by an ask of the operator began; tier-late-at, the time any tier was first found past tier-bound, and tier-late-said, the time the bus took pipeline-wanted tier-late: a key with the first and not the second holds a tier-late still to be said); per removal written and not yet said (removal.<node>.<module>), its mark: node, module, the fingerprint and the want-revision of the write it removes; with why, why each want is what it is (as assigner_why).",
|
||||
Input: schema(map[string]string{"why": "true: why each want is what it is", "module": "with why: a module's name", "node": "with why: a node's name"}, nil, "why"),
|
||||
Run: func(args map[string]any) (any, error) {
|
||||
if args["why"] == true || args["why"] == "true" {
|
||||
@@ -387,6 +438,13 @@ func writtenTools(st store) []stdio.Tool {
|
||||
}
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(k, removalPrefix) { // a removal written and not said, its mark (startsays.go)
|
||||
var m removalMark
|
||||
if json.Unmarshal(raw, &m) == nil {
|
||||
out[k] = m
|
||||
}
|
||||
continue
|
||||
}
|
||||
var e End
|
||||
if json.Unmarshal(raw, &e) == nil {
|
||||
out[k] = e
|
||||
@@ -417,7 +475,7 @@ func (e *pipelineEnds) registered(reg mpcat.Registration, gone bool) {
|
||||
prefix := keys.EscapeName(reg.Module) + "."
|
||||
for _, k := range kept {
|
||||
rest, ok := strings.CutPrefix(k, prefix)
|
||||
if !ok || isTierKey(k) || strings.HasPrefix(k, whyPrefix) {
|
||||
if !ok || isTierKey(k) || strings.HasPrefix(k, whyPrefix) || strings.HasPrefix(k, removalPrefix) {
|
||||
continue
|
||||
}
|
||||
branch, err := keys.UnescapeName(rest)
|
||||
|
||||
@@ -97,6 +97,14 @@ func TestThePassedVersionIsKept(t *testing.T) {
|
||||
ended("main", 5, pass, mover("web", "fp1", "0.1.2", 1, ok))}, &End{Pipeline: "main.6", Source: 6, Seq: 206, Fp: "fp2", Version: "0.1.3", Rank: 1}},
|
||||
{"a newer version replaces", []mpr.PipelineEnded{ended("main", 5, pass, mover("web", "fp1", "0.1.2", 1, ok)),
|
||||
ended("main", 6, pass, mover("web", "fp2", "0.1.10", 1, ok))}, &End{Pipeline: "main.6", Source: 6, Seq: 206, Fp: "fp2", Version: "0.1.10", Rank: 1}},
|
||||
// Design 47 H2b §825: the same version again, from a later pipeline, is kept when the earlier pipeline's progress never
|
||||
// reached the mover's tier (its want was never written), and otherwise nothing is written.
|
||||
{"a later pipeline carrying a stranded mover at its kept version keeps it again", []mpr.PipelineEnded{
|
||||
ended("main", 5, pass, mover("db", "fp9", "0.3.0", 1, ok), mover("web", "fp1", "0.1.2", 2, ok)),
|
||||
ended("main", 6, pass, mover("web", "fp1", "0.1.2", 1, ok))}, &End{Pipeline: "main.6", Source: 6, Seq: 206, Fp: "fp1", Version: "0.1.2", Rank: 1}},
|
||||
{"one whose earlier pipeline's progress reached the tier writes nothing", []mpr.PipelineEnded{
|
||||
ended("main", 5, pass, mover("web", "fp1", "0.1.2", 1, ok)),
|
||||
ended("main", 6, pass, mover("web", "fp1", "0.1.2", 1, ok))}, &End{Pipeline: "main.5", Source: 5, Seq: 205, Fp: "fp1", Version: "0.1.2", Rank: 1}},
|
||||
// H-A-485: an again pipeline's end is kept as a take-in's; a key of no form the runner's seat defines is refused, nothing kept.
|
||||
{"an again pipeline keeps its version", []mpr.PipelineEnded{func() mpr.PipelineEnded {
|
||||
p := ended("main", 5, pass, mover("web", "fp1", "0.1.2", 2, ok))
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
)
|
||||
|
||||
// progressDropTool drops one pipeline's tier progress by hand (design 47 H2b §824 7.): a key whose tier never runs (a version that
|
||||
// never comes) stands, said by `tier-late`, until a later pipeline carries its movers or a person drops it. The act is recorded in
|
||||
// the hand-act log first; the key is deleted, and the pass that finds its pipeline no longer followed clears its `tier-late`
|
||||
// from the findings bucket (H-A-722). Nothing is said on the seat `mesh-wants`: the gate's record ended failed at `tier-late`.
|
||||
const progressDropTool = "assigner_progress_drop"
|
||||
|
||||
// dropProgress deletes the tier progress of pipeline, the act first recorded through the seat mesh-hand-acts.
|
||||
func dropProgress(st seatStore, ask func(string, any) (json.RawMessage, error), pipeline, why, by string) (any, error) {
|
||||
switch {
|
||||
case pipeline == "":
|
||||
return nil, errors.New("name the pipeline whose tier progress is dropped")
|
||||
case !isTierKey(tierKey(pipeline)):
|
||||
return nil, fmt.Errorf("%q is no pipeline's key of a form the seat defines", pipeline)
|
||||
case why == "":
|
||||
return nil, errors.New("a tier progress dropped by hand says why")
|
||||
case by == "" || by == stdio.Unproven:
|
||||
return nil, errors.New("a tier progress dropped by hand names who drops it, and the runtime proved no caller")
|
||||
}
|
||||
key := tierKey(pipeline)
|
||||
raw, _, found, err := st.get(writtenState, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !found {
|
||||
return nil, fmt.Errorf("the assigner holds no tier progress under %s: assigner_written lists them", key)
|
||||
}
|
||||
taken, err := meshhandactsclient.Recorder{Ask: ask}.Record(meshhandactsclient.Request{What: progressDropTool + " " + key, Why: why + " (" + by + ")", Cause: "tier-progress-drop"})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the drop of %s is not recorded, so the progress stays: %w", key, err)
|
||||
}
|
||||
if err := st.del(writtenState, key); err != nil {
|
||||
return nil, fmt.Errorf("the tier progress %s is not dropped: %w", key, err)
|
||||
}
|
||||
return map[string]any{"key": key, "dropped": json.RawMessage(raw), "by": by, "hand-act": taken.Log}, nil
|
||||
}
|
||||
|
||||
// progressDropTools is the tool over the runtime's states.
|
||||
func progressDropTools(st seatStore, ask func(string, any) (json.RawMessage, error)) []stdio.Tool {
|
||||
return []stdio.Tool{{Name: progressDropTool, Description: "Drop one pipeline's tier progress by hand (design 47 H2b §824 7.): the key pipeline.<pipeline> of the state written " +
|
||||
"is deleted, for a progress whose tier never runs (a version that never comes) and no later pipeline carries; the finding tier-late of that pipeline is cleared by the next pass, and nothing " +
|
||||
"is said on the seat mesh-wants. Recorded as a hand act first; refused with no progress under the key.",
|
||||
Input: schema(map[string]string{"pipeline": "the pipeline's key, <branch>.<revision> or its again form", "why": "why the progress is dropped"}, []string{"pipeline", "why"}),
|
||||
Run: func(a map[string]any) (any, error) {
|
||||
return dropProgress(st, ask, arg(a, "pipeline"), arg(a, "why"), stdio.CallerOf(a))
|
||||
}}}
|
||||
}
|
||||
@@ -138,6 +138,12 @@ func (p *passer) puts(ctx context.Context) {
|
||||
world := p.putWorld(node, module, put, manifest, assigned[node])
|
||||
world.Snapshot, world.Snapshotting, world.SnapshotFailed = p.acts.state(id)
|
||||
next := assign.StepPut(world)
|
||||
if puts.Unresolved(put.FP) && puts.Whole(next.Put.FP) {
|
||||
// The first step resolved the version (H-A-848, H-A-862): the rest is read at the fingerprint it named.
|
||||
world = p.putWorld(node, module, next.Put, manifest, assigned[node])
|
||||
world.Snapshot, world.Snapshotting, world.SnapshotFailed = p.acts.state(id)
|
||||
next = assign.StepPut(world)
|
||||
}
|
||||
// The bus's want is written only for the act the operator's yes bound (ADR 0546 clause 8).
|
||||
if next.Put.Step == puts.Wanted && put.Step != puts.Wanted && world.Bus && next.Put.Ask != "" {
|
||||
if err := p.performs(next.Put.Ask, assign.PutAct(node, module, next.Put.FP, next.Put.Composed)); err != nil {
|
||||
@@ -183,6 +189,19 @@ func (p *passer) putWorld(node, module string, put puts.Put, manifest catalogue.
|
||||
if e, ok := p.w.ends.endOf(module, put.FP); ok { // the build's end heard (A-181): none heard, no state
|
||||
w.Build, w.BuildWords = e.Outcome, e.Error
|
||||
}
|
||||
if puts.Unresolved(put.FP) {
|
||||
for _, e := range p.w.ends.doneStarting(module, put.FP) {
|
||||
v, _ := p.w.releasedOf(module, e.Fingerprint)
|
||||
w.Matches = append(w.Matches, assign.PutMatch{FP: e.Fingerprint, Version: v})
|
||||
}
|
||||
w.Branch = p.w.trunkName()
|
||||
if p.ends.following() {
|
||||
w.Branch = p.ends.branchOf(module, p.w.placedBranches()[module][node])
|
||||
}
|
||||
if end, ok := p.ends.endOf(module, w.Branch); ok {
|
||||
w.BranchEnd = end.Fp
|
||||
}
|
||||
}
|
||||
w.Version, _ = p.w.releasedOf(module, put.FP) // matched by its build's parts, as the pass matches a mover's (H-A-490 addendum)
|
||||
w.Composed, w.Granted = p.composedFor(node, module, put.FP)
|
||||
if d := w.Composed; d != nil {
|
||||
@@ -278,7 +297,7 @@ func (p *passer) performs(key string, act occ.Act) error {
|
||||
|
||||
// samePut says two puts say the same: their step, words and what they found.
|
||||
func samePut(a, b puts.Put) bool {
|
||||
return a.Step == b.Step && a.Words == b.Words && a.Composed == b.Composed && a.Ask == b.Ask && a.Snapshot == b.Snapshot
|
||||
return a.FP == b.FP && a.Step == b.Step && a.Words == b.Words && a.Composed == b.Composed && a.Ask == b.Ask && a.Snapshot == b.Snapshot
|
||||
}
|
||||
|
||||
// writePut writes a put's next value over the one the pass read, by compare-and-set, unless the tool has put again or
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||
@@ -48,6 +49,29 @@ type putWaiting struct {
|
||||
Put puts.Put `json:"put"`
|
||||
}
|
||||
|
||||
// putHeldOwed is the put waits whose wait-held is owed, by put key (in memory: a restart owes what the kept state implies).
|
||||
type putHeldOwed struct {
|
||||
mu sync.Mutex
|
||||
m map[string]putWaiting
|
||||
}
|
||||
|
||||
func (h *putHeldOwed) set(key string, w putWaiting) {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
if h.m == nil {
|
||||
h.m = map[string]putWaiting{}
|
||||
}
|
||||
h.m[key] = w
|
||||
}
|
||||
|
||||
func (h *putHeldOwed) drop(key, id string) {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
if h.m[key].ID == id {
|
||||
delete(h.m, key)
|
||||
}
|
||||
}
|
||||
|
||||
// saidPutWaits is every put wait the state put-waits holds, by key; a value that does not decode is said and left.
|
||||
func (p *passer) saidPutWaits() map[string]putWaiting {
|
||||
out := map[string]putWaiting{}
|
||||
@@ -59,6 +83,13 @@ func (p *passer) saidPutWaits() map[string]putWaiting {
|
||||
}
|
||||
out[key] = w
|
||||
}
|
||||
p.putHeld.mu.Lock()
|
||||
for key, w := range p.putHeld.m {
|
||||
if _, kept := out[key]; !kept {
|
||||
out[key] = w // its wait-held is owed: its end is owed behind it
|
||||
}
|
||||
}
|
||||
p.putHeld.mu.Unlock()
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -88,11 +119,11 @@ func (p *passer) putWaits(ctx context.Context, all map[string]map[string]puts.Pu
|
||||
}
|
||||
body := putWaitBody(node, module, was.Put)
|
||||
body.How = how
|
||||
if err := p.wantsSay(meshwants.EventWaitEnded, body, was.ID+".put."+how); err != nil {
|
||||
p.logf("the end of the put %s's wait is not said, and is said at the next pass: %v", key, err)
|
||||
continue
|
||||
}
|
||||
p.remove(ctx, buckets.PutWaits(), key)
|
||||
// The kept record stays until the bus has taken the end, so a restart says it again (§832 4.; H-A-830).
|
||||
p.wantsOwe(putWaitOrder(node, module), meshwants.EventWaitEnded, body, was.ID+".put."+how, func() {
|
||||
p.putHeld.drop(key, was.ID)
|
||||
p.remove(ctx, buckets.PutWaits(), key)
|
||||
})
|
||||
delete(waiting, key)
|
||||
}
|
||||
for module, byNode := range all {
|
||||
@@ -105,12 +136,17 @@ func (p *passer) putWaits(ctx context.Context, all map[string]map[string]puts.Pu
|
||||
if w, said := waiting[key]; said && w.ID == id {
|
||||
continue
|
||||
}
|
||||
if err := p.wantsSay(meshwants.EventWaitHeld, putWaitBody(node, module, put), id+".put"); err != nil {
|
||||
p.logf("the put %s's wait is not said, and is said at the next pass: %v", key, err)
|
||||
continue
|
||||
}
|
||||
kept := putWaiting{ID: id, Put: put}
|
||||
p.put(ctx, buckets.PutWaits(), key, func() ([]byte, error) { return json.Marshal(kept) })
|
||||
// The record is written once the bus has taken the wait-held, never while it is only owed: after a restart a record
|
||||
// that stands reads as said (§832 4., 1.; H-A-830).
|
||||
kept, done := putWaiting{ID: id, Put: put}, context.WithoutCancel(ctx)
|
||||
p.putHeld.set(key, kept)
|
||||
p.wantsOwe(putWaitOrder(node, module), meshwants.EventWaitHeld, putWaitBody(node, module, put), id+".put", func() {
|
||||
p.putHeld.drop(key, id)
|
||||
p.put(done, buckets.PutWaits(), key, func() ([]byte, error) { return json.Marshal(kept) })
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// putWaitOrder is the order the events of a put's wait are said in: its `<node>.<module>` (design 47 H §832 1.; H-A-830).
|
||||
func putWaitOrder(node, module string) string { return "put-wait." + node + "." + module }
|
||||
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -89,4 +90,29 @@ func TestAPutWithoutHoldIsSaidAsAWait(t *testing.T) {
|
||||
if a := answerOf("ace", "web", held); !a.Since.Equal(at.Add(time.Minute)) || a.Bound != "" {
|
||||
t.Errorf("a held put answers since %v, bound %q", a.Since, a.Bound)
|
||||
}
|
||||
// Design 47 H §832 (H-A-830): the bus refuses the wait-held once, then the put ends; the end is owed behind the held, and the kept
|
||||
// record stays until the bus took the end. Both are said after, in that order, under main's ids.
|
||||
refused := true
|
||||
events, bodies = nil, nil
|
||||
var ids []string
|
||||
p.publishWants = func(event string, body any, id string) error {
|
||||
if refused {
|
||||
return context.DeadlineExceeded
|
||||
}
|
||||
events, bodies, ids = append(events, event), append(bodies, body.(meshwants.Wait)), append(ids, id)
|
||||
return nil
|
||||
}
|
||||
fresh := puts.Put{FP: fpTest, Why: "a try again", At: at.Add(3 * time.Hour)}.Said(at.Add(3*time.Hour), puts.Wanted, "the want is written")
|
||||
p.putWaits(ctx, map[string]map[string]puts.Put{"db": {"g14": fresh}})
|
||||
p.putWaits(ctx, map[string]map[string]puts.Put{"db": {"g14": fresh.Said(at.Add(4*time.Hour), puts.Done, "runs")}})
|
||||
if len(events) != 0 || kept.values["g14.db"] != nil {
|
||||
t.Fatalf("a refused say was kept as said: %v, record %q (the record is written once the bus took the wait-held, review r1 finding 3)", events, kept.values["g14.db"])
|
||||
}
|
||||
refused = false
|
||||
p.after = nil
|
||||
p.owed.list[0].next = p.clock()
|
||||
if !p.sayOwed() || len(events) != 2 || events[0] != meshwants.EventWaitHeld || events[1] != meshwants.EventWaitEnded ||
|
||||
!strings.HasSuffix(ids[0], ".put") || !strings.HasSuffix(ids[1], ".put."+putWaitRan) || kept.values["g14.db"] != nil {
|
||||
t.Errorf("the owed said %v under %v, record %q", events, ids, kept.values["g14.db"])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"slices"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
mwc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient"
|
||||
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
|
||||
"mesh-delivery-assigner/internal/buckets"
|
||||
"mesh-delivery-assigner/internal/outside"
|
||||
)
|
||||
|
||||
// A start says again what its kept state implies (design 47 H2b §832 4., H-A-843, H-A-859): what was owed in memory is gone after a
|
||||
// restart, so the first pass that has an assignment graph revision kept says again, under the same ids and in each order's order,
|
||||
// `wait-ended` for a record with `ending` (§831), `wait-held` for every standing wait under its `held-said`, and per node and module
|
||||
// the removal its mark holds, then `wanted` for the want written. `pipeline-wanted` `tier-late` and `running` are said again by the
|
||||
// tier progress's own pass (§824), which owes them whenever its keys say so.
|
||||
|
||||
// removalPrefix is the prefix of a removal's mark in the state `written`: `removal.<node>.<module>`.
|
||||
const removalPrefix = "removal."
|
||||
|
||||
// removalMark is a removal written before it is said: the fingerprint and the want-revision of the write it removes. A mark holds
|
||||
// the newest removal of its node and module, the one a consumer needs.
|
||||
type removalMark struct {
|
||||
Node string `json:"node"`
|
||||
Module string `json:"module"`
|
||||
Fp string `json:"fp"`
|
||||
WantRevision uint64 `json:"want-revision"`
|
||||
}
|
||||
|
||||
func removalKey(node, module string) string {
|
||||
return removalPrefix + keys.EscapeName(node) + "." + keys.EscapeName(module)
|
||||
}
|
||||
|
||||
// markRemoval keeps the mark of the removal of the want of module on node, which stands at revision, before the removing want is
|
||||
// written; false (said in the journal) when it could not be kept, so the removal is not made.
|
||||
func (p *passer) markRemoval(node, module, fp string, revision uint64) bool {
|
||||
raw, err := json.Marshal(removalMark{Node: node, Module: module, Fp: fp, WantRevision: revision})
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
key := removalKey(node, module)
|
||||
for range 2 {
|
||||
held, rev, err := p.ends.st.get(key)
|
||||
if err != nil {
|
||||
p.logf("the mark of the removal of %s on %s cannot be read, so the removal waits: %v", module, node, err)
|
||||
return false
|
||||
}
|
||||
if held != nil && string(held) == string(raw) {
|
||||
return true
|
||||
}
|
||||
switch err = p.ends.st.swap(key, raw, rev); err {
|
||||
case nil:
|
||||
return true
|
||||
case errSwapped:
|
||||
continue
|
||||
}
|
||||
p.logf("the mark of the removal of %s on %s is not written, so the removal waits: %v", module, node, err)
|
||||
return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// dropRemovalMark deletes the mark of a removal the bus has taken.
|
||||
func (p *passer) dropRemovalMark(node, module string) {
|
||||
if err := p.ends.st.drop(removalKey(node, module)); err != nil {
|
||||
p.logf("the mark of the removal of %s on %s is not deleted: %v", module, node, err)
|
||||
}
|
||||
}
|
||||
|
||||
// startSays is the start pass's saying again: the waits' events at the first pass, and the wants' at the first pass that keeps an
|
||||
// assignment graph revision, each once.
|
||||
func (p *passer) startSays(ctx context.Context) {
|
||||
if !p.startWaitsSaid {
|
||||
p.startWaitsSaid = true
|
||||
p.sayWaitsAgain(ctx)
|
||||
}
|
||||
if p.startSaid {
|
||||
return
|
||||
}
|
||||
if _, _, ok := p.graphKept(); !ok {
|
||||
return
|
||||
}
|
||||
p.startSaid = true
|
||||
p.sayWantsAgain(ctx)
|
||||
}
|
||||
|
||||
// sayWaitsAgain says `wait-ended` again for a record with `ending` (the rest of the end is done once the bus takes it), and
|
||||
// `wait-held` for every standing wait under its `held-said`.
|
||||
func (p *passer) sayWaitsAgain(ctx context.Context) {
|
||||
if p.kvs[buckets.Waits()] == nil {
|
||||
return
|
||||
}
|
||||
kept := p.w.read(buckets.Waits())
|
||||
for _, key := range slices.Sorted(mapKeys(kept)) {
|
||||
w, err := outside.Decode(kept[key])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
hex := key[strings.LastIndex(key, ".")+1:]
|
||||
switch {
|
||||
case w.Ending != "":
|
||||
p.outsideEnd(ctx, key, w, w.Ending, p.clock())
|
||||
case w.Standing():
|
||||
p.wantsOwe(waitOrder(key, w.ClockFrom), meshwants.EventWaitHeld, p.outsideBody(w), waitEventID(w.Node, w.Module, hex, "held."+strconv.Itoa(w.HeldSaid), w.ClockFrom), nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func mapKeys[M ~map[string]V, V any](m M) func(func(string) bool) {
|
||||
return func(yield func(string) bool) {
|
||||
for k := range m {
|
||||
if !yield(k) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sayWantsAgain says, per node and module, the removal its mark holds (the removing want written first when the want's key still
|
||||
// holds the revision the mark names), then `wanted` for the want written, carrying the key's write time as its `at`.
|
||||
func (p *passer) sayWantsAgain(ctx context.Context) {
|
||||
marks := map[string]removalMark{}
|
||||
if p.ends != nil {
|
||||
ks, err := p.ends.st.keys()
|
||||
if err != nil {
|
||||
p.logf("the removal marks cannot be listed: %v", err)
|
||||
}
|
||||
sort.Strings(ks)
|
||||
for _, k := range ks {
|
||||
if !strings.HasPrefix(k, removalPrefix) {
|
||||
continue
|
||||
}
|
||||
raw, _, err := p.ends.st.get(k)
|
||||
var m removalMark
|
||||
if err != nil || raw == nil || json.Unmarshal(raw, &m) != nil {
|
||||
continue
|
||||
}
|
||||
if key, err := mwc.WantKey(m.Node, m.Module); err == nil {
|
||||
marks[key] = m
|
||||
}
|
||||
}
|
||||
}
|
||||
wants := p.w.read(buckets.Wants())
|
||||
seen := map[string]bool{}
|
||||
keysOf := slices.Sorted(mapKeys(wants))
|
||||
for k := range marks {
|
||||
if _, ok := wants[k]; !ok {
|
||||
keysOf = append(keysOf, k)
|
||||
}
|
||||
}
|
||||
sort.Strings(keysOf)
|
||||
for _, key := range keysOf {
|
||||
if seen[key] {
|
||||
continue
|
||||
}
|
||||
seen[key] = true
|
||||
node, module, err := mwc.ParseWantKey(key)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if m, ok := marks[key]; ok {
|
||||
if meta := p.w.metaOf(buckets.Wants(), key); wants[key] != nil && meta.revision == m.WantRevision {
|
||||
p.wantWritten(ctx, node, module, key, mwc.Want{Removed: true, Words: "the removal is written from its mark, at a start (design 47 H2b §832 4.)"})
|
||||
}
|
||||
p.sayWanted(node, module, m.Fp, "", true, m.WantRevision, p.w.metaOf(buckets.Wants(), key).at, func() { p.dropRemovalMark(node, module) })
|
||||
}
|
||||
raw := p.w.value(buckets.Wants(), key)
|
||||
if raw == nil {
|
||||
continue
|
||||
}
|
||||
want, err := mwc.DecodeWant(raw)
|
||||
if err != nil || want.Removed {
|
||||
continue
|
||||
}
|
||||
meta := p.w.metaOf(buckets.Wants(), key)
|
||||
p.sayWanted(node, module, want.Fp, want.Pipeline, false, meta.revision, meta.at, nil)
|
||||
}
|
||||
}
|
||||
@@ -26,10 +26,11 @@ import (
|
||||
// writes the wants of its first tier's movers; once each of them runs at the mover's fingerprint (the node-engine seat's
|
||||
// `running`, H-A-40) on every present placing machine, it writes the next tier's, and so on. The tier progress is the key
|
||||
// `pipeline.<branch>.<source>` of the state written, `{tier, since, movers}`; a tier counts placed movers only, and a machine away
|
||||
// is not waited for. A tier whose movers do not all run within `tier-bound` ends the delivery loudly: no later tier is written,
|
||||
// the finding `tier-late` (scope delivery, id the pipeline) is raised naming the movers and machines not running, and
|
||||
// `pipeline-wanted` says outcome tier-late; once every tier runs it says outcome running and the key goes (H-A-75). tier-late
|
||||
// clears when the late movers run or a later passed pipeline moves them (H-A-56).
|
||||
// is not waited for. A tier whose movers do not all run within `tier-bound` is found late: the finding `tier-late` (scope delivery, id
|
||||
// the pipeline) is raised naming the movers and machines not running, and `pipeline-wanted` says outcome tier-late, on which the
|
||||
// delivery record ends failed; the next tier is written once the late tier runs (design 47 H2b §824), and once every tier runs
|
||||
// `pipeline-wanted` says outcome running and the key goes (H-A-75). tier-late clears when the late movers run or a later passed
|
||||
// pipeline moves them (H-A-56).
|
||||
|
||||
// tierPrefix starts the key of a pipeline's tier progress in the state written.
|
||||
const tierPrefix = "pipeline."
|
||||
@@ -57,12 +58,20 @@ type tierProgress struct {
|
||||
Since time.Time `json:"since"`
|
||||
Movers []tierMover `json:"movers"`
|
||||
Source int64 `json:"source,omitempty"`
|
||||
// Seq is the sequence of the pipeline-ended the progress was written from, the run of the wants of a `no-version` mover the pass
|
||||
// finds released (design 47 H2b §826 1., H-A-845); zero in a progress kept before the field.
|
||||
Seq int64 `json:"seq,omitempty"`
|
||||
// ClockFrom is the time tier-bound counts from, in Since's form: Since when the progress starts, moved later by each
|
||||
// pause; absent reads as Since (design 47 H2 H-A-627).
|
||||
ClockFrom time.Time `json:"clock-from,omitzero"`
|
||||
// PausedFrom is the time the standing pause began: a key of the state asks names a mover of the tier that is not running,
|
||||
// and the count stands still. Absent while the bound counts (H-A-627).
|
||||
PausedFrom time.Time `json:"paused-from,omitzero"`
|
||||
// TierLateAt is the time any tier of the pipeline was first found past tier-bound, written before the finding is raised and
|
||||
// `pipeline-wanted` `tier-late` said; TierLateSaid the time the bus took that event. A key with the first and not the second
|
||||
// holds a `tier-late` still to be said. Both go into every later tier's progress (design 47 H2b §824 2.).
|
||||
TierLateAt time.Time `json:"tier-late-at,omitzero"`
|
||||
TierLateSaid time.Time `json:"tier-late-said,omitzero"`
|
||||
}
|
||||
|
||||
// clockFrom is the time tier-bound counts from; Since in a progress kept before the field.
|
||||
@@ -92,7 +101,7 @@ func isTierKey(key string) bool {
|
||||
// lowest of theirs, since now (H-A-277 (1)). A pipeline heard again adds to the progress that stands each mover it does not hold,
|
||||
// at the mover's tier, and marks versioned each held mover whose version is now written (H-A-270, H-A-273): its want is written
|
||||
// when the progress reaches its tier, or at once when that tier ran already, never out of tier order.
|
||||
func (e *pipelineEnds) startTiers(pipeline string, source int64, movers []tierMover, versioned map[string]bool) error {
|
||||
func (e *pipelineEnds) startTiers(pipeline string, source, seq int64, movers []tierMover, versioned map[string]bool) error {
|
||||
for {
|
||||
t, rev, ok := e.tiersOf(pipeline)
|
||||
if !ok {
|
||||
@@ -104,9 +113,12 @@ func (e *pipelineEnds) startTiers(pipeline string, source int64, movers []tierMo
|
||||
first = min(first, m.Tier)
|
||||
}
|
||||
at := e.clock().UTC()
|
||||
t = tierProgress{Tier: first, Since: at, ClockFrom: at, Source: source}
|
||||
t = tierProgress{Tier: first, Since: at, ClockFrom: at, Source: source, Seq: seq}
|
||||
}
|
||||
moved := false
|
||||
if t.Seq == 0 && seq > 0 {
|
||||
t.Seq, moved = seq, true
|
||||
}
|
||||
for i := range t.Movers {
|
||||
if t.Movers[i].NoVersion && versioned[t.Movers[i].Module] {
|
||||
t.Movers[i].NoVersion, moved = false, true
|
||||
@@ -194,6 +206,8 @@ func (p *passer) tiers(n assign.Nodes, placedOn func(module, branch string) []st
|
||||
}
|
||||
}
|
||||
defer p.clearTierLate(followed)
|
||||
have, readable := p.findingKeys("the finding tier-late")
|
||||
p.tierHolds = map[string]tierHold{}
|
||||
for _, key := range ks {
|
||||
if !isTierKey(key) {
|
||||
continue
|
||||
@@ -204,17 +218,32 @@ func (p *passer) tiers(n assign.Nodes, placedOn func(module, branch string) []st
|
||||
continue
|
||||
}
|
||||
branch, number := pk.Branch, strconv.FormatInt(pk.Revision, 10)
|
||||
findingKey := views.FindingKey(mcc.ScopeDelivery, assign.KeyID(pipeline), kindTierLate)
|
||||
for {
|
||||
t, rev, ok := p.ends.tiersOf(pipeline)
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
// A key the earlier rule left holds neither field: it counts as said when the findings bucket holds a tier-late of its
|
||||
// pipeline, and both fields are written from that finding's time (H-A-722, H-A-828).
|
||||
if t.TierLateAt.IsZero() && readable && have[findingKey] {
|
||||
at := p.tierLateSince(findingKey, now)
|
||||
t.TierLateAt, t.TierLateSaid = at, at
|
||||
err := p.writeTier(key, t, rev, "tier-late-at")
|
||||
if err == nil || errors.Is(err, errSwapped) {
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
if p.takeReleased(key, pipeline, branch, t, rev) {
|
||||
continue // a version found released: its end is kept and the mark gone, read the progress again
|
||||
}
|
||||
notRunning := p.notRunning(n, placedOn, pipeline, branch, t, t.Tier)
|
||||
// The count stands still while an ask of the operator names a mover of the tier that is not running (H-A-627): the first
|
||||
// pass that finds one writes paused-from, the first that finds none moves clock-from later by the time it stood still.
|
||||
clock := t.clockFrom()
|
||||
paused := pausedBy(standing, t, notRunning)
|
||||
if paused && t.PausedFrom.IsZero() && now.Before(clock.Add(bound)) {
|
||||
if paused && t.PausedFrom.IsZero() && now.Before(clock.Add(bound)) && len(notRunning) > 0 {
|
||||
t.PausedFrom = now
|
||||
if now.Before(t.Since) {
|
||||
t.PausedFrom = t.Since // never earlier than the progress's own start
|
||||
@@ -240,21 +269,51 @@ func (p *passer) tiers(n assign.Nodes, placedOn func(module, branch string) []st
|
||||
}
|
||||
break
|
||||
}
|
||||
if !t.PausedFrom.IsZero() {
|
||||
runs := len(notRunning) == 0
|
||||
if !runs {
|
||||
p.tierHolds[pipeline] = tierHold{tier: t.Tier, mover: notRunning[0].Module, late: !t.TierLateAt.IsZero(), pipeline: pipeline}
|
||||
}
|
||||
late := !runs && t.PausedFrom.IsZero() && !now.Before(clock.Add(bound))
|
||||
if !runs && !t.PausedFrom.IsZero() {
|
||||
if !t.TierLateAt.IsZero() && t.TierLateSaid.IsZero() {
|
||||
p.sayTierLate(key, pipeline, branch, number, t, notRunning) // owed still: said while the tier is paused too (§824 2., §832 4.)
|
||||
}
|
||||
break // paused: no lateness, and no timer armed
|
||||
}
|
||||
late := !now.Before(clock.Add(bound))
|
||||
if late {
|
||||
p.tierLate(pipeline, branch, number, t, notRunning)
|
||||
// Lateness is written before it is said: the field, the finding, the event (§824 2.).
|
||||
if t.TierLateAt.IsZero() {
|
||||
t.TierLateAt = now
|
||||
if err := p.writeTier(key, t, rev, "tier-late-at"); err == nil || errors.Is(err, errSwapped) {
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
p.raiseTierLate(pipeline, t, notRunning, have, readable)
|
||||
if t.TierLateSaid.IsZero() {
|
||||
p.sayTierLate(key, pipeline, branch, number, t, notRunning)
|
||||
}
|
||||
break
|
||||
}
|
||||
if len(notRunning) > 0 {
|
||||
if !t.TierLateAt.IsZero() && t.TierLateSaid.IsZero() {
|
||||
p.sayTierLate(key, pipeline, branch, number, t, notRunning) // owed still: said before any running of this pipeline
|
||||
}
|
||||
if !runs {
|
||||
if d := clock.Add(bound); next.IsZero() || d.Before(next) {
|
||||
next = d
|
||||
}
|
||||
break
|
||||
}
|
||||
// The tier runs: the next tier's wants are written, or every tier ran.
|
||||
// The tier runs, whether or not it was found late: the finding is cleared, and the next tier's wants are written, or
|
||||
// every tier ran.
|
||||
if readable && have[findingKey] {
|
||||
if err := p.findings.Delete(findingKey); err != nil {
|
||||
p.logf("the finding %s is not cleared, so the next tier of %s is not written yet: %v", findingKey, pipeline, err)
|
||||
break
|
||||
}
|
||||
delete(have, findingKey)
|
||||
p.logf("the finding %s is cleared: tier %d runs", findingKey, t.Tier)
|
||||
}
|
||||
later := int64(0)
|
||||
for _, m := range t.Movers {
|
||||
if m.Tier > t.Tier && (later == 0 || m.Tier < later) {
|
||||
@@ -262,14 +321,17 @@ func (p *passer) tiers(n assign.Nodes, placedOn func(module, branch string) []st
|
||||
}
|
||||
}
|
||||
if later == 0 {
|
||||
if err := p.ends.st.drop(key); err != nil {
|
||||
p.logf("the tier progress %s is not deleted: %v", key, err)
|
||||
break
|
||||
}
|
||||
p.sayPipelineWanted(pipeline, branch, number, t.Source, meshwants.PipelineWantedOutcomeRunning, nil)
|
||||
// The last tier runs: `running` is said, and the key goes once the bus has taken it, never before (§824 1.).
|
||||
p.sayPipelineWantedTaken(pipeline, branch, number, t.Source, meshwants.PipelineWantedOutcomeRunning, nil, func() {
|
||||
if err := p.ends.st.drop(key); err != nil {
|
||||
p.logf("the tier progress %s is not deleted: %v", key, err)
|
||||
}
|
||||
})
|
||||
break
|
||||
}
|
||||
value, err := json.Marshal(tierProgress{Tier: later, Since: now, ClockFrom: now, Movers: t.Movers, Source: t.Source})
|
||||
moved := t
|
||||
moved.Tier, moved.Since, moved.ClockFrom, moved.PausedFrom = later, now, now, time.Time{}
|
||||
value, err := json.Marshal(moved)
|
||||
if err == nil {
|
||||
err = p.ends.st.swap(key, value, rev)
|
||||
}
|
||||
@@ -286,6 +348,46 @@ func (p *passer) tiers(n assign.Nodes, placedOn func(module, branch string) []st
|
||||
return next
|
||||
}
|
||||
|
||||
// takeReleased looks up, for each mover of t marked `no-version`, the version released of its module's build at its fingerprint,
|
||||
// whichever pipeline or source released it, matched by the build's parts, from what the assigner hears and with no call (design 47
|
||||
// H2b §826 1.). One found is kept as a passed mover's end naming this pipeline, with its source and the progress's seq (H-A-845),
|
||||
// and its mark goes; one whose kept end names another fingerprint is left to notRunning (§826 2.). It says whether the progress
|
||||
// was written, for the caller to read it again; a mover whose version is not found stays held, and a progress with no seq
|
||||
// (kept before the field) says why it cannot be taken.
|
||||
func (p *passer) takeReleased(key, pipeline, branch string, t tierProgress, rev uint64) bool {
|
||||
if p.ends.releasedOf == nil {
|
||||
return false
|
||||
}
|
||||
changed := false
|
||||
for i, m := range t.Movers {
|
||||
if !m.NoVersion {
|
||||
continue
|
||||
}
|
||||
v, ok := p.ends.releasedOf(m.Module, m.Fp)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if end, kept := p.ends.endOf(m.Module, branch); kept && end.Fp != m.Fp {
|
||||
continue // a later pipeline moved it on
|
||||
}
|
||||
if t.Seq <= 0 {
|
||||
p.logf("pipeline %s: %s at %s has its version %s released, and is not taken: the progress carries no seq, the run its want would carry; the runner's end-again of %s writes it", pipeline, m.Module, m.Fp, v, pipeline)
|
||||
continue
|
||||
}
|
||||
if _, err := p.ends.keepEnd(pipeline, branch, t.Source, t.Seq, m.Module, m.Fp, v, max(m.Tier, 1)); err != nil {
|
||||
p.logf("pipeline %s: the end of %s at %s is not kept: %v", pipeline, m.Module, m.Fp, err)
|
||||
continue
|
||||
}
|
||||
t.Movers[i].NoVersion, changed = false, true
|
||||
p.logf("pipeline %s: %s at %s has its version %s released: taken at this pass", pipeline, m.Module, m.Fp, v)
|
||||
}
|
||||
if !changed {
|
||||
return false
|
||||
}
|
||||
err := p.writeTier(key, t, rev, "no-version")
|
||||
return err == nil || errors.Is(err, errSwapped)
|
||||
}
|
||||
|
||||
// notRunning is, of tier's movers in t whose kept end still names pipeline, those not running at their fingerprint on a present
|
||||
// placing machine, with those machines. A mover a later pipeline moved counts as run; one placed nowhere counts as run.
|
||||
func (p *passer) notRunning(n assign.Nodes, placedOn func(module, branch string) []string, pipeline, branch string, t tierProgress, tier int64) []meshwants.NotRunning {
|
||||
@@ -294,6 +396,9 @@ func (p *passer) notRunning(n assign.Nodes, placedOn func(module, branch string)
|
||||
if m.Tier != tier {
|
||||
continue
|
||||
}
|
||||
if end, ok := p.ends.endOf(m.Module, branch); m.NoVersion && ok && end.Fp != m.Fp {
|
||||
continue // a later pipeline moved a mover with no version on to another fingerprint: it counts as run (§826 2.)
|
||||
}
|
||||
if m.NoVersion {
|
||||
// A mover whose version is not yet written holds its tier, under the tier bound (H-A-277 (1)).
|
||||
machines := []string{}
|
||||
@@ -306,8 +411,8 @@ func (p *passer) notRunning(n assign.Nodes, placedOn func(module, branch string)
|
||||
out = append(out, meshwants.NotRunning{Module: m.Module, Machines: machines})
|
||||
continue
|
||||
}
|
||||
if end, ok := p.ends.endOf(m.Module, branch); !ok || end.Pipeline != pipeline {
|
||||
continue // a later pipeline moved it
|
||||
if end, ok := p.ends.endOf(m.Module, branch); !ok || end.Fp != m.Fp {
|
||||
continue // a later pipeline moved it on to another fingerprint; one kept at its own, by whichever pipeline, is counted by its running (§824 1., §825)
|
||||
}
|
||||
var machines []string
|
||||
for _, node := range placedOn(m.Module, branch) {
|
||||
@@ -327,92 +432,94 @@ func (p *passer) notRunning(n assign.Nodes, placedOn func(module, branch string)
|
||||
return out
|
||||
}
|
||||
|
||||
// tierLate ends a pipeline's delivery at a tier past tier-bound: the finding tier-late is raised and pipeline-wanted says tier-late,
|
||||
// once each; the finding clears once the late movers run or a later pipeline moved them. The progress stays, so no later tier is
|
||||
// written, until no later tier's mover is kept at this pipeline any more.
|
||||
func (p *passer) tierLate(pipeline, branch, number string, t tierProgress, notRunning []meshwants.NotRunning) {
|
||||
o := tierLateFinding(pipeline, t.Tier, notRunning)
|
||||
// raiseTierLate raises the finding tier-late of pipeline naming the late tier, when the findings bucket holds none of the pipeline
|
||||
// (read from the bucket, never from what the process said, H-A-722); a bucket not read raises nothing.
|
||||
func (p *passer) raiseTierLate(pipeline string, t tierProgress, notRunning []meshwants.NotRunning, have map[string]bool, readable bool) {
|
||||
o := tierLateFinding(pipeline, t, notRunning)
|
||||
key := views.FindingKey(o.Scope, assign.KeyID(o.ID), o.Kind)
|
||||
if len(notRunning) > 0 {
|
||||
if !p.said[key+".raised"] {
|
||||
if p.findings.Put != nil {
|
||||
if err := p.findings.Put(o.Finding(p.clock())); err != nil {
|
||||
p.logf("the finding %s is not written: %v", key, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
p.said[key+".raised"] = true
|
||||
delete(p.said, key+".cleared")
|
||||
p.logf("pipeline %s: tier %d is late (tier-bound %s): %s; no later tier is written", pipeline, t.Tier, p.tierBoundOf(), o.Summary)
|
||||
p.sayPipelineWanted(pipeline, branch, number, t.Source, meshwants.PipelineWantedOutcomeTierLate, notRunning)
|
||||
}
|
||||
} else if !p.said[key+".cleared"] {
|
||||
if p.findings.Delete != nil {
|
||||
if err := p.findings.Delete(key); err != nil {
|
||||
p.logf("the finding %s is not deleted: %v", key, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
p.said[key+".cleared"] = true
|
||||
delete(p.said, key+".raised")
|
||||
if !readable || have[key] {
|
||||
return
|
||||
}
|
||||
for _, m := range t.Movers {
|
||||
if m.Tier <= t.Tier {
|
||||
continue
|
||||
}
|
||||
if end, ok := p.ends.endOf(m.Module, branch); ok && end.Pipeline == pipeline {
|
||||
return // a later tier's mover still kept at this pipeline: its want stays unwritten
|
||||
}
|
||||
if err := p.findings.Put(o.Finding(p.clock())); err != nil {
|
||||
p.logf("the finding %s is not written: %v", key, err)
|
||||
return
|
||||
}
|
||||
if len(notRunning) == 0 {
|
||||
if err := p.ends.st.drop(tierKey(pipeline)); err != nil {
|
||||
p.logf("the tier progress of %s is not deleted: %v", pipeline, err)
|
||||
have[key] = true
|
||||
p.logf("pipeline %s: tier %d is late (tier-bound %s): %s; the next tier is written once it runs", pipeline, t.Tier, p.tierBoundOf(), o.Summary)
|
||||
}
|
||||
|
||||
// sayTierLate owes `pipeline-wanted` `tier-late` of pipeline once, under its id; once the bus has taken it, the progress's
|
||||
// `tier-late-said` is written (§824 2.). A refused say is owed and said again (§832).
|
||||
func (p *passer) sayTierLate(key, pipeline, branch, number string, t tierProgress, notRunning []meshwants.NotRunning) {
|
||||
p.sayPipelineWantedTaken(pipeline, branch, number, t.Source, meshwants.PipelineWantedOutcomeTierLate, notRunning, func() { p.markTierLateSaid(key, pipeline) })
|
||||
}
|
||||
|
||||
// markTierLateSaid writes `tier-late-said`, the time the bus took the event, by compare-and-set on the key.
|
||||
func (p *passer) markTierLateSaid(key, pipeline string) {
|
||||
for {
|
||||
t, rev, ok := p.ends.tiersOf(pipeline)
|
||||
if !ok || !t.TierLateSaid.IsZero() {
|
||||
return
|
||||
}
|
||||
t.TierLateSaid = p.clock().UTC()
|
||||
if err := p.writeTier(key, t, rev, "tier-late-said"); !errors.Is(err, errSwapped) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// tierLateFinding is the finding tier-late of pipeline's tier, naming the movers and machines not running (design 47 H §751).
|
||||
func tierLateFinding(pipeline string, tier int64, notRunning []meshwants.NotRunning) assign.Observed {
|
||||
// tierLateSince is the time of the finding tier-late a key of the earlier rule stands with, as the findings bucket holds it; now
|
||||
// when it cannot be read (H-A-828).
|
||||
func (p *passer) tierLateSince(findingKey string, now time.Time) time.Time {
|
||||
if p.findings.Get != nil {
|
||||
if f, ok, err := p.findings.Get(findingKey); err == nil && ok && !f.Since.IsZero() {
|
||||
return f.Since.UTC()
|
||||
}
|
||||
}
|
||||
return now
|
||||
}
|
||||
|
||||
// tierLateFinding is the finding tier-late of pipeline's tier, naming the movers and machines not running (design 47 H §751, §824
|
||||
// 3.); a mover with no version is named in §826's words.
|
||||
func tierLateFinding(pipeline string, t tierProgress, notRunning []meshwants.NotRunning) assign.Observed {
|
||||
var named []string
|
||||
for _, nr := range notRunning {
|
||||
if i := slices.IndexFunc(t.Movers, func(m tierMover) bool { return m.Module == nr.Module && m.NoVersion }); i >= 0 {
|
||||
named = append(named, fmt.Sprintf("%s: no version released at %s", nr.Module, t.Movers[i].Fp))
|
||||
continue
|
||||
}
|
||||
named = append(named, fmt.Sprintf("%s on %s", nr.Module, strings.Join(nr.Machines, ", ")))
|
||||
}
|
||||
summary := fmt.Sprintf("pipeline %s: tier %d does not run within tier-bound: %s", pipeline, tier, strings.Join(named, "; "))
|
||||
summary := fmt.Sprintf("pipeline %s: tier %d does not run within tier-bound: %s", pipeline, t.Tier, strings.Join(named, "; "))
|
||||
return assign.Observed{Scope: mcc.ScopeDelivery, ID: pipeline, Kind: kindTierLate, Severity: mcseat.FindingSeverityWarning,
|
||||
Summary: summary, Headline: "A delivery's tier does not run in time",
|
||||
Explanation: summary + ". The assigner writes no later tier of this pipeline; the delivery ends here.",
|
||||
Explanation: summary + ". The delivery record ends failed. The assigner writes the next tier once this tier runs on every present placing machine.",
|
||||
Source: "assigner." + kindTierLate}
|
||||
}
|
||||
|
||||
// sayPipelineWanted says the seat mesh-wants' pipeline-wanted of pipeline, once (its id the pipeline and the outcome): its
|
||||
// revision the number of the pipeline's key `<branch>.<revision>`, its source the one the pipeline-ended named (design 47
|
||||
// H-A-214, H-A-216), the key's number for a progress kept before it held one.
|
||||
// sayPipelineWanted says the seat mesh-wants' pipeline-wanted of pipeline (see sayPipelineWantedTaken), with nothing to do once the
|
||||
// bus has taken it.
|
||||
func (p *passer) sayPipelineWanted(pipeline, branch, number string, source int64, outcome string, notRunning []meshwants.NotRunning) {
|
||||
p.sayPipelineWantedTaken(pipeline, branch, number, source, outcome, notRunning, nil)
|
||||
}
|
||||
|
||||
// sayPipelineWantedTaken owes the seat mesh-wants' pipeline-wanted of pipeline once (its id the pipeline and the outcome): its
|
||||
// revision the number of the pipeline's key `<branch>.<revision>`, its source the one the pipeline-ended named (design 47
|
||||
// H-A-214, H-A-216), the key's number for a progress kept before it held one. It is said on the subject of its branch and revision
|
||||
// whatever the pipeline's form, its body naming the pipeline whole (H-A-839); taken runs once the bus has taken it.
|
||||
func (p *passer) sayPipelineWantedTaken(pipeline, branch, number string, source int64, outcome string, notRunning []meshwants.NotRunning, taken func()) {
|
||||
var revision int64
|
||||
_, _ = fmt.Sscan(number, &revision)
|
||||
if source <= 0 {
|
||||
source = revision
|
||||
}
|
||||
body := meshwants.PipelineWantedEvent{V: keys.Version, Pipeline: pipeline, Branch: branch, Source: source, Revision: revision, Outcome: outcome, NotRunning: notRunning}
|
||||
event := meshwants.EventPipelineWanted + "." + pipeline
|
||||
if err := p.wantsSay(event, body, "pipeline-wanted."+pipeline+"."+outcome); err != nil {
|
||||
p.logf("pipeline-wanted of %s is not said: %v", pipeline, err)
|
||||
}
|
||||
event := meshwants.EventPipelineWanted + "." + keys.EscapeName(branch) + "." + number
|
||||
p.wantsOwe("pipeline."+pipeline, event, body, "pipeline-wanted."+pipeline+"."+outcome, taken)
|
||||
}
|
||||
|
||||
// tierDeadline sets the one timer that wakes the pass at the earliest tier's deadline (H-A-56); zero stops it.
|
||||
func (p *passer) tierDeadline(at time.Time) {
|
||||
if p.tierWake == nil {
|
||||
return
|
||||
}
|
||||
if p.tierTimer != nil {
|
||||
p.tierTimer.Stop()
|
||||
}
|
||||
if at.IsZero() {
|
||||
return
|
||||
}
|
||||
p.tierTimer = time.AfterFunc(max(at.Sub(p.clock()), 0), p.tierWake)
|
||||
}
|
||||
// tierDeadline sets the earliest tier's deadline the one timer wakes the pass at (H-A-56, H-A-846); zero for none.
|
||||
func (p *passer) tierDeadline(at time.Time) { p.wakeSet("tiers", at) }
|
||||
|
||||
// tierBoundSetting is the setting tier-bound in minutes (design 47 H §751), read at the start from the file the manifest declares
|
||||
// with the content ${config:tier-bound}; zero, its default, for a file missing or empty.
|
||||
|
||||
@@ -11,8 +11,10 @@ import (
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||
mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
|
||||
mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
||||
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
mwc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
@@ -56,7 +58,7 @@ func TestAPipelinesWantsAreWrittenTierByTier(t *testing.T) {
|
||||
var said []meshwants.PipelineWanted
|
||||
p.publishWants = func(event string, body any, _ string) error {
|
||||
if b, ok := body.(meshwants.PipelineWantedEvent); ok {
|
||||
if event != "pipeline-wanted."+pipeline {
|
||||
if event != "pipeline-wanted."+trunkBranch+".5" { // H-A-839: the subject of its branch and revision, an again pipeline's too
|
||||
t.Errorf("pipeline-wanted said as %s", event)
|
||||
}
|
||||
said = append(said, b)
|
||||
@@ -186,6 +188,281 @@ func TestAPipelinesWantsAreWrittenTierByTier(t *testing.T) {
|
||||
t.Error("a consumer's want is written after its provider's tier was late")
|
||||
}
|
||||
}
|
||||
// Design 47 H2b §824 (H-A-828, H-A-858): a delivery whose tier passed tier-bound goes on once that tier runs.
|
||||
t.Run("a late tier goes on once it runs", func(t *testing.T) {
|
||||
db, web := meshcatalogclient.SourcePrefix2+strings.Repeat("d", 64), meshcatalogclient.SourcePrefix2+strings.Repeat("c", 64)
|
||||
pipeline := trunkBranch + ".5"
|
||||
r := newTierRig(t, db, web, pipeline)
|
||||
wanted := func(module string) bool {
|
||||
key, _ := mwc.WantKey("g14", module)
|
||||
_, ok := r.wantsKV.values[key]
|
||||
return ok
|
||||
}
|
||||
run := func(module, fp string) {
|
||||
raw, _ := json.Marshal(nodeengine.Running{Node: "g14", Module: module, Fingerprint: fp})
|
||||
if err := r.p.w.hearRunning("running.g14."+module, raw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
r.pass(30 * time.Minute)
|
||||
prog, _, _ := r.p.ends.tiersOf(pipeline)
|
||||
if len(r.said) != 1 || r.said[0].Outcome != meshwants.PipelineWantedOutcomeTierLate || len(r.findings) != 1 || prog.TierLateAt.IsZero() || prog.TierLateSaid.IsZero() {
|
||||
t.Fatalf("AC-824a: at minute 30 said %+v findings %v progress %+v", r.said, r.findings, prog)
|
||||
}
|
||||
// AC-824c: a restart between the two keeps both fields
|
||||
r.restart()
|
||||
if prog, _, _ := r.p.ends.tiersOf(pipeline); prog.TierLateAt.IsZero() || prog.TierLateSaid.IsZero() {
|
||||
t.Fatalf("AC-824c: a restart lost the fields: %+v", prog)
|
||||
}
|
||||
run("db", db)
|
||||
r.pass(45 * time.Minute)
|
||||
if !wanted("web") || len(r.findings) != 0 {
|
||||
t.Fatalf("AC-824a: at minute 45 the consumer's want is %v, findings %v", wanted("web"), r.findings)
|
||||
}
|
||||
// AC-824b: a second tier found late raises the finding naming it and says no second pipeline-wanted
|
||||
r.pass(76 * time.Minute)
|
||||
f := r.findings["delivery."+assign.KeyID(pipeline)+".tier-late"]
|
||||
if len(r.said) != 1 || !strings.Contains(f.Summary, "tier 2 does not run") {
|
||||
t.Errorf("AC-824b: said %+v, finding %+v", r.said, f)
|
||||
}
|
||||
run("web", web)
|
||||
r.pass(77 * time.Minute)
|
||||
if len(r.said) != 2 || r.said[1].Outcome != meshwants.PipelineWantedOutcomeRunning || len(r.findings) != 0 {
|
||||
t.Errorf("AC-824a: running said %+v, findings %v", r.said, r.findings)
|
||||
}
|
||||
if _, _, ok := r.p.ends.tiersOf(pipeline); ok {
|
||||
t.Error("the key stands after running was taken")
|
||||
}
|
||||
})
|
||||
// Design 47 H2b §825, §824 1. (review r1 finding 1, AC-825a): a mover a later pipeline carries at its own fingerprint is kept
|
||||
// again under that pipeline, and the earlier progress goes on once it runs, never before.
|
||||
t.Run("a mover kept again by a later pipeline at its own fingerprint is counted by its running", func(t *testing.T) {
|
||||
db, web := meshcatalogclient.SourcePrefix2+strings.Repeat("d", 64), meshcatalogclient.SourcePrefix2+strings.Repeat("c", 64)
|
||||
pipeline := trunkBranch + ".5"
|
||||
r := newTierRig(t, db, web, pipeline)
|
||||
later := ended(trunkBranch, 6, mpr.PipelineEndedOutcomePassed, mover("web", web, "0.1.2", 1, mpr.StepResultOutcomePassed))
|
||||
if _, err := r.p.ends.take(later); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if end, ok := r.p.ends.endOf("web", trunkBranch); !ok || end.Pipeline != trunkBranch+".6" || end.Fp != web {
|
||||
t.Fatalf("AC-825a: web's end = %+v (%v), want kept again by main.6", end, ok)
|
||||
}
|
||||
run := func(module, fp string) {
|
||||
raw, _ := json.Marshal(nodeengine.Running{Node: "g14", Module: module, Fingerprint: fp})
|
||||
if err := r.p.w.hearRunning("running.g14."+module, raw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
saidOf := func(revision int64) (n int) {
|
||||
for _, b := range r.said {
|
||||
if b.Revision == revision && b.Outcome == meshwants.PipelineWantedOutcomeRunning {
|
||||
n++
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
r.pass(30 * time.Second)
|
||||
// AC-825a, first half: web's want is written in main.6's own tier, naming main.6 and rank 1
|
||||
wkey, _ := mwc.WantKey("g14", "web")
|
||||
if w, err := mwc.DecodeWant(r.wantsKV.values[wkey]); err != nil || w.Pipeline != trunkBranch+".6" || w.Rank != 1 || w.Fp != web {
|
||||
t.Fatalf("AC-825a: web's want is %+v (%v), want it written by main.6 at rank 1", w, err)
|
||||
}
|
||||
run("db", db)
|
||||
r.pass(time.Minute)
|
||||
r.pass(2 * time.Minute)
|
||||
if prog, _, ok := r.p.ends.tiersOf(pipeline); !ok || prog.Tier != 2 || saidOf(5) != 0 {
|
||||
t.Fatalf("AC-825a: main.5 says running while web does not run: progress %+v (%v), said %+v", prog, ok, r.said)
|
||||
}
|
||||
run("web", web)
|
||||
r.pass(3 * time.Minute)
|
||||
if saidOf(5) != 1 {
|
||||
t.Errorf("AC-825a: main.5 does not say running once web runs: %+v", r.said)
|
||||
}
|
||||
})
|
||||
t.Run("an end naming a rebuild's version is kept no-version, then takes the version released at its own fingerprint (§835 2.)", func(t *testing.T) {
|
||||
db, web := meshcatalogclient.SourcePrefix2+strings.Repeat("d", 64), meshcatalogclient.SourcePrefix2+strings.Repeat("c", 64)
|
||||
r := &tierRig{t: t, start: time.Date(2026, 11, 27, 4, 0, 0, 0, time.UTC), findings: map[string]mcseat.Finding{}, ends: newMemEnds(), db: db, web: web}
|
||||
r.now = r.start
|
||||
r.build()
|
||||
r.p.ends.releasedOf = r.p.w.releasedOf
|
||||
release := func(source int64, version, digest string) {
|
||||
rel, _ := json.Marshal(meshcatalog.VersionReleasedEvent{Module: "db", Source: source, Version: version, Artifacts: []meshcatalog.VersionArtifact{{Artifact: "db:image", Digest: digest}}})
|
||||
if err := r.p.w.released.put(rel); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
built, _ := json.Marshal(builds.BuildEnded{Module: "db", Fingerprint: db, Outcome: builds.BuildDone, Made: map[string]string{"image": "sha256:7"}})
|
||||
if err := r.p.w.ends.put(built); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
release(4, "0.2.0", "sha256:7") // the build at db's fingerprint
|
||||
release(5, "0.2.1", "sha256:8") // a rebuild of the same source
|
||||
e := ended(trunkBranch, 5, mpr.PipelineEndedOutcomePassed, mover("db", db, "0.2.1", 1, mpr.StepResultOutcomePassed))
|
||||
e.Source = 4
|
||||
if _, err := r.p.ends.take(e); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
prog, _, _ := r.p.ends.tiersOf(trunkBranch + ".5")
|
||||
if _, ok := r.p.ends.endOf("db", trunkBranch); ok || len(prog.Movers) != 1 || !prog.Movers[0].NoVersion {
|
||||
t.Fatalf("the rebuild's version was kept: end %v progress %+v", ok, prog)
|
||||
}
|
||||
r.pass(time.Minute)
|
||||
if end, ok := r.p.ends.endOf("db", trunkBranch); !ok || end.Version != "0.2.0" || end.Fp != db || end.Seq != 205 {
|
||||
t.Fatalf("the end kept after the pass = %+v (%v)", end, ok)
|
||||
}
|
||||
})
|
||||
// Design 47 H2b §832 6. (1984/AC-832j): dropping an owed tier-late writes tier-late-said, and an owed running deletes the progress key.
|
||||
t.Run("assigner_owed_drop of an owed tier-late writes tier-late-said, and of an owed running deletes the progress key", func(t *testing.T) {
|
||||
db, web := meshcatalogclient.SourcePrefix2+strings.Repeat("d", 64), meshcatalogclient.SourcePrefix2+strings.Repeat("c", 64)
|
||||
pipeline := trunkBranch + ".5"
|
||||
r := newTierRig(t, db, web, pipeline)
|
||||
r.refuse = true
|
||||
r.pass(30 * time.Minute)
|
||||
owed := r.p.owedAll()
|
||||
if len(owed) != 1 || !strings.HasPrefix(owed[0].ID, "pipeline-wanted."+pipeline+".tier-late") {
|
||||
t.Fatalf("AC-832j: owed %+v", owed)
|
||||
}
|
||||
dropped, err := r.p.owedDrop(owed[0].ID)
|
||||
prog, _, _ := r.p.ends.tiersOf(pipeline)
|
||||
if err != nil || len(dropped) != 1 || prog.TierLateSaid.IsZero() || len(r.p.owedAll()) != 0 {
|
||||
t.Fatalf("AC-832j: the drop of tier-late answered %+v (%v), progress %+v", dropped, err, prog)
|
||||
}
|
||||
for i, m := range []struct{ module, fp string }{{"db", db}, {"web", web}} {
|
||||
raw, _ := json.Marshal(nodeengine.Running{Node: "g14", Module: m.module, Fingerprint: m.fp})
|
||||
_ = r.p.w.hearRunning("running.g14."+m.module, raw)
|
||||
r.pass(time.Duration(31+i) * time.Minute)
|
||||
}
|
||||
owed = r.p.owedAll()
|
||||
if len(owed) != 1 || !strings.HasSuffix(owed[0].ID, ".running") {
|
||||
t.Fatalf("AC-832j: owed %+v, want running", owed)
|
||||
}
|
||||
if _, err := r.p.owedDrop(owed[0].ID); err != nil || r.ends.vals[tierKey(pipeline)] != nil {
|
||||
t.Errorf("AC-832j: the drop of running left the progress key %v (%v)", r.ends.vals[tierKey(pipeline)] != nil, err)
|
||||
}
|
||||
})
|
||||
t.Run("a tier-late the bus refuses is said again after a restart, before running, and the key stands until running is taken", func(t *testing.T) {
|
||||
db, web := meshcatalogclient.SourcePrefix2+strings.Repeat("d", 64), meshcatalogclient.SourcePrefix2+strings.Repeat("c", 64)
|
||||
pipeline := trunkBranch + ".5"
|
||||
r := newTierRig(t, db, web, pipeline)
|
||||
r.refuse = true
|
||||
r.pass(30 * time.Minute)
|
||||
prog, _, _ := r.p.ends.tiersOf(pipeline)
|
||||
if len(r.said) != 0 || prog.TierLateAt.IsZero() || !prog.TierLateSaid.IsZero() {
|
||||
t.Fatalf("AC-824d: a refused say was taken: said %+v progress %+v", r.said, prog)
|
||||
}
|
||||
r.restart()
|
||||
r.refuse = false
|
||||
for _, m := range []struct{ module, fp string }{{"db", db}, {"web", web}} {
|
||||
raw, _ := json.Marshal(nodeengine.Running{Node: "g14", Module: m.module, Fingerprint: m.fp})
|
||||
_ = r.p.w.hearRunning("running.g14."+m.module, raw)
|
||||
}
|
||||
r.pass(31 * time.Minute)
|
||||
r.pass(32 * time.Minute)
|
||||
if len(r.said) != 2 || r.said[0].Outcome != meshwants.PipelineWantedOutcomeTierLate || r.said[1].Outcome != meshwants.PipelineWantedOutcomeRunning {
|
||||
t.Errorf("AC-824d: said %+v, want tier-late then running", r.said)
|
||||
}
|
||||
if want := []string{"pipeline-wanted." + pipeline + ".tier-late", "pipeline-wanted." + pipeline + ".running"}; !slices.Equal(r.ids, want) {
|
||||
t.Errorf("AC-824d: said under %v, want the ids %v", r.ids, want)
|
||||
}
|
||||
})
|
||||
// Design 47 H2b §824 2., §832 4. (review r1 finding 5): a tier-late owed and lost to a restart is said at the start pass even
|
||||
// while the tier its key stands at is paused.
|
||||
t.Run("a tier-late owed is said at a start while the tier is paused", func(t *testing.T) {
|
||||
db, web := meshcatalogclient.SourcePrefix2+strings.Repeat("d", 64), meshcatalogclient.SourcePrefix2+strings.Repeat("c", 64)
|
||||
pipeline := trunkBranch + ".5"
|
||||
r := newTierRig(t, db, web, pipeline)
|
||||
r.refuse = true
|
||||
r.pass(30 * time.Minute) // tier 1 late: tier-late-at written, the say refused
|
||||
raw, _ := json.Marshal(nodeengine.Running{Node: "g14", Module: "db", Fingerprint: db})
|
||||
_ = r.p.w.hearRunning("running.g14.db", raw)
|
||||
r.pass(31 * time.Minute) // tier 1 runs: tier 2's progress carries the fields
|
||||
akey, _ := asks.RecordAskKey("g14", "web", "sha256:"+strings.Repeat("a", 64))
|
||||
r.p.w.put(buckets.Asks(), akey, []byte(`{}`))
|
||||
r.pass(32 * time.Minute)
|
||||
prog, _, _ := r.p.ends.tiersOf(pipeline)
|
||||
if prog.Tier != 2 || prog.PausedFrom.IsZero() || prog.TierLateAt.IsZero() || !prog.TierLateSaid.IsZero() {
|
||||
t.Fatalf("tier 2 is not paused holding an owed tier-late: %+v", prog)
|
||||
}
|
||||
r.restart()
|
||||
r.refuse = false
|
||||
r.p.w.put(buckets.Asks(), akey, []byte(`{}`))
|
||||
r.pass(33 * time.Minute)
|
||||
if len(r.said) != 1 || r.said[0].Outcome != meshwants.PipelineWantedOutcomeTierLate {
|
||||
t.Errorf("a start pass says %+v while its tier is paused, want the owed tier-late", r.said)
|
||||
}
|
||||
})
|
||||
t.Run("a key of the earlier rule with a tier-late in the bucket says no second one; a tier past its bound pauses for no later ask; a refused clear holds the next tier", func(t *testing.T) {
|
||||
db, web := meshcatalogclient.SourcePrefix2+strings.Repeat("d", 64), meshcatalogclient.SourcePrefix2+strings.Repeat("c", 64)
|
||||
pipeline := trunkBranch + ".5"
|
||||
r := newTierRig(t, db, web, pipeline)
|
||||
since := r.start.Add(-time.Hour)
|
||||
r.findings["delivery."+assign.KeyID(pipeline)+".tier-late"] = mcseat.Finding{Scope: "delivery", ID: pipeline, Kind: kindTierLate, Since: since}
|
||||
r.pass(31 * time.Minute)
|
||||
prog, _, _ := r.p.ends.tiersOf(pipeline)
|
||||
if len(r.said) != 0 || !prog.TierLateAt.Equal(since) || !prog.TierLateSaid.Equal(since) {
|
||||
t.Fatalf("AC-824e: said %+v progress %+v, want both fields at the finding's since", r.said, prog)
|
||||
}
|
||||
// AC-824h: the tier is past its bound, so a later ask pauses nothing
|
||||
akey, _ := asks.RecordAskKey("g14", "db", "sha256:"+strings.Repeat("a", 64))
|
||||
r.p.w.put(buckets.Asks(), akey, []byte(`{}`))
|
||||
r.pass(32 * time.Minute)
|
||||
if prog, _, _ := r.p.ends.tiersOf(pipeline); !prog.PausedFrom.IsZero() {
|
||||
t.Errorf("AC-824h: a paused-from after the bound: %+v", prog)
|
||||
}
|
||||
// AC-824n: the clear refused once holds the next tier's progress
|
||||
r.deleteRefused = 1
|
||||
raw, _ := json.Marshal(nodeengine.Running{Node: "g14", Module: "db", Fingerprint: db})
|
||||
_ = r.p.w.hearRunning("running.g14.db", raw)
|
||||
r.pass(33 * time.Minute)
|
||||
if prog, _, _ := r.p.ends.tiersOf(pipeline); prog.Tier != 1 {
|
||||
t.Fatalf("AC-824n: tier 2's progress is written while the clear is refused: %+v", prog)
|
||||
}
|
||||
r.pass(34 * time.Minute)
|
||||
if prog, _, _ := r.p.ends.tiersOf(pipeline); prog.Tier != 2 || prog.TierLateAt.IsZero() {
|
||||
t.Errorf("AC-824n: the next pass, with the clear taken, writes tier 2 and carries the fields: %+v", prog)
|
||||
}
|
||||
})
|
||||
// Design 47 H2b §824 6., 7. (H-A-844): a want waiting on its tier says held-by-tier, naming the pipeline, the tier and the mover that
|
||||
// holds it; assigner_progress_drop deletes a progress whose version never comes, in the hand-act log.
|
||||
t.Run("a want waiting on its tier says held-by-tier, and a progress is dropped by hand", func(t *testing.T) {
|
||||
db, web := meshcatalogclient.SourcePrefix2+strings.Repeat("d", 64), meshcatalogclient.SourcePrefix2+strings.Repeat("c", 64)
|
||||
pipeline := trunkBranch + ".5"
|
||||
r := newTierRig(t, db, web, pipeline)
|
||||
r.pass(31 * time.Minute)
|
||||
why, ok := r.p.heldByTier("web", trunkBranch, wantWhy{})
|
||||
if !ok || why.Step != whyHeldByTier || why.Pipeline != pipeline || why.Tier != 1 || why.Holder != "db" || !why.TierLate {
|
||||
t.Errorf("AC-824l: the why of web is %+v (%v), want held-by-tier naming %s, tier 1, db, late", why, ok, pipeline)
|
||||
}
|
||||
if _, ok := r.p.heldByTier("nothing", trunkBranch, wantWhy{}); ok {
|
||||
t.Error("AC-824l: a module with no kept end is held by a tier")
|
||||
}
|
||||
key := tierKey(pipeline)
|
||||
st := memStore{writtenState: &memKV{values: map[string][]byte{key: r.ends.vals[key]}}}
|
||||
var asked []string
|
||||
ask := func(verb string, body any) (json.RawMessage, error) {
|
||||
raw, _ := json.Marshal(body)
|
||||
asked = append(asked, string(raw))
|
||||
return json.RawMessage(`{}`), nil
|
||||
}
|
||||
if _, err := dropProgress(st, ask, pipeline, "its version never comes", "person.jochen"); err != nil || len(st[writtenState].values) != 0 || len(asked) != 1 ||
|
||||
!strings.Contains(asked[0], progressDropTool+" "+key) {
|
||||
t.Errorf("AC-824g: the drop answered %v, left %v, asked %v", err, st[writtenState].values, asked)
|
||||
}
|
||||
if _, err := dropProgress(st, ask, pipeline, "again", "person.jochen"); err == nil {
|
||||
t.Error("a progress no longer there was dropped")
|
||||
}
|
||||
// the pass that finds the pipeline no longer followed clears its tier-late
|
||||
delete(r.ends.vals, key)
|
||||
r.pass(32 * time.Minute)
|
||||
if len(r.findings) != 0 || len(r.said) != 1 {
|
||||
t.Errorf("AC-824g: findings %v, said %+v after the drop", r.findings, r.said)
|
||||
}
|
||||
prog := tierProgress{TierLateAt: r.start, TierLateSaid: r.start.Add(time.Minute)}
|
||||
raw, _ := json.Marshal(prog)
|
||||
if !strings.Contains(string(raw), `"tier-late-at"`) || !strings.Contains(string(raw), `"tier-late-said"`) {
|
||||
t.Errorf("AC-824j: the progress holds %s", raw)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// H-A-270, H-A-273, H-A-277 (1): a pipeline's tier progress holds every passed mover, versioned or not, and a tier with a mover
|
||||
@@ -196,11 +473,27 @@ func TestALateMoverHoldsItsTier(t *testing.T) {
|
||||
versions map[string]string // a pipeline-ended taken, each mover's version ("": none yet)
|
||||
runs string // or: this module runs on g14
|
||||
wanted string // then: the modules wanted, in order of the list
|
||||
released string // or: the version of db's build released under another source (heard, no pipeline names it)
|
||||
later bool // or: a later pipeline moves db on to another fingerprint
|
||||
late bool // or: tier-bound passes with the findings read
|
||||
}
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
steps []step
|
||||
}{
|
||||
{"a version released under another source is taken at the next pass (H-A-845: its end carries the seq)", []step{
|
||||
{versions: map[string]string{"db": "", "web": "0.1.2", "api": "0.3.0"}, wanted: ""},
|
||||
{released: "0.2.0", wanted: "db"},
|
||||
{runs: "db", wanted: "db,web"},
|
||||
}},
|
||||
{"a mover a later pipeline moved on counts as run", []step{
|
||||
{versions: map[string]string{"db": "", "web": "0.1.2", "api": "0.3.0"}, wanted: ""},
|
||||
{later: true, wanted: "db,web"},
|
||||
}},
|
||||
{"a version that never comes holds the tier, named with its fingerprint, and writes no later want", []step{
|
||||
{versions: map[string]string{"db": "", "web": "0.1.2", "api": "0.3.0"}, wanted: ""},
|
||||
{late: true, wanted: ""},
|
||||
}},
|
||||
{"the lowest tier's version comes last", []step{
|
||||
{versions: map[string]string{"db": "", "web": "0.1.2", "api": "0.3.0"}, wanted: ""},
|
||||
{versions: map[string]string{"db": "0.2.0", "web": "0.1.2", "api": "0.3.0"}, wanted: "db"},
|
||||
@@ -239,7 +532,44 @@ func TestALateMoverHoldsItsTier(t *testing.T) {
|
||||
p.w.mu.Unlock()
|
||||
p.ends = newPipelineEnds(newMemEnds(), func() {}, t.Logf)
|
||||
p.ends.trunk, p.ends.now = p.w.trunkName, func() time.Time { return now }
|
||||
p.ends.releasedOf = p.w.releasedOf
|
||||
found := map[string]mcseat.Finding{}
|
||||
p.findings = assign.Findings{Put: func(f mcseat.Finding) error { found[views.FindingKey(f.Scope, f.ID, f.Kind)] = f; return nil },
|
||||
Keys: func() ([]string, error) { return slices.Collect(maps.Keys(found)), nil },
|
||||
Get: func(key string) (mcseat.Finding, bool, error) { f, ok := found[key]; return f, ok, nil },
|
||||
Delete: func(key string) error { delete(found, key); return nil }}
|
||||
for i, s := range c.steps {
|
||||
switch {
|
||||
case s.released != "":
|
||||
rel, _ := json.Marshal(meshcatalog.VersionReleasedEvent{Module: "db", Source: 9, Version: s.released, Artifacts: []meshcatalog.VersionArtifact{{Artifact: "db:image", Digest: "sha256:7"}}})
|
||||
built, _ := json.Marshal(builds.BuildEnded{Module: "db", Fingerprint: fps["db"], Outcome: builds.BuildDone, Made: map[string]string{"image": "sha256:7"}})
|
||||
if err := p.w.released.put(rel); err != nil || p.w.ends.put(built) != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
case s.later:
|
||||
other := meshcatalogclient.SourcePrefix2 + strings.Repeat("9", 64)
|
||||
e := ended(trunkBranch, 6, mpr.PipelineEndedOutcomePassed, mover("db", other, "0.2.1", 1, mpr.StepResultOutcomePassed))
|
||||
if _, err := p.ends.take(e); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
case s.late:
|
||||
now = now.Add(time.Hour)
|
||||
}
|
||||
if s.late {
|
||||
now = now.Add(time.Minute)
|
||||
p.wants(context.Background())
|
||||
f, ok := found[views.FindingKey(mcc.ScopeDelivery, assign.KeyID(trunkBranch+".5"), kindTierLate)]
|
||||
if !ok || !strings.Contains(f.Summary, "db: no version released at "+fps["db"]) {
|
||||
t.Fatalf("step %d: the finding tier-late = %+v (%v)", i+1, f, ok)
|
||||
}
|
||||
}
|
||||
if s.released != "" {
|
||||
now = now.Add(time.Minute)
|
||||
p.wants(context.Background())
|
||||
if end, ok := p.ends.endOf("db", trunkBranch); !ok || end.Pipeline != trunkBranch+".5" || end.Seq != 205 || end.Version != s.released {
|
||||
t.Fatalf("step %d: the end kept for db = %+v (%v)", i+1, end, ok)
|
||||
}
|
||||
}
|
||||
if s.versions != nil {
|
||||
var movers []mpr.MoverEnded
|
||||
for _, m := range []string{"db", "web", "api"} {
|
||||
@@ -248,7 +578,7 @@ func TestALateMoverHoldsItsTier(t *testing.T) {
|
||||
if _, err := p.ends.take(ended(trunkBranch, 5, mpr.PipelineEndedOutcomePassed, movers...)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
} else if s.runs != "" {
|
||||
raw, _ := json.Marshal(nodeengine.Running{Node: "g14", Module: s.runs, Fingerprint: fps[s.runs]})
|
||||
if err := p.w.hearRunning("running.g14."+s.runs, raw); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -310,3 +640,83 @@ func (r *refusingEnds) swap(string, []byte, uint64) error {
|
||||
}
|
||||
return errors.New("the bucket is full")
|
||||
}
|
||||
|
||||
// tierRig is one pass loop of a pipeline of db (tier 1) and web (tier 2) on g14 with the findings of a bucket the test reads, and a
|
||||
// restart that makes a new passer on the same kept progress (the process's memory gone).
|
||||
type tierRig struct {
|
||||
t *testing.T
|
||||
p *passer
|
||||
start time.Time
|
||||
now time.Time
|
||||
wantsKV *memKV
|
||||
findings map[string]mcseat.Finding
|
||||
said []meshwants.PipelineWanted
|
||||
ids []string // the message id of each pipeline-wanted taken, beside said
|
||||
refuse bool
|
||||
deleteRefused int
|
||||
ends *memEnds
|
||||
db, web string
|
||||
}
|
||||
|
||||
func newTierRig(t *testing.T, db, web, pipeline string) *tierRig {
|
||||
r := &tierRig{t: t, start: time.Date(2026, 11, 27, 4, 0, 0, 0, time.UTC), findings: map[string]mcseat.Finding{}, ends: newMemEnds(), db: db, web: web}
|
||||
r.now = r.start
|
||||
r.build()
|
||||
e := ended(trunkBranch, 5, mpr.PipelineEndedOutcomePassed, mover("db", db, "0.2.0", 1, mpr.StepResultOutcomePassed), mover("web", web, "0.1.2", 2, mpr.StepResultOutcomePassed))
|
||||
e.Source, e.Pipeline = 4, pipeline
|
||||
if _, err := r.p.ends.take(e); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r.pass(0)
|
||||
return r
|
||||
}
|
||||
|
||||
// build makes the passer over the kept state: a start of the process.
|
||||
func (r *tierRig) build() {
|
||||
t := r.t
|
||||
r.wantsKV = &memKV{values: map[string][]byte{}}
|
||||
p := newPasser(kvSet{buckets.Wants(): r.wantsKV, buckets.Asks(): &memKV{values: map[string][]byte{}}}, r.start)
|
||||
p.now = func() time.Time { return r.now }
|
||||
p.say = func(oc.Condition) error { return nil }
|
||||
p.findings = assign.Findings{Put: func(f mcseat.Finding) error { r.findings[views.FindingKey(f.Scope, f.ID, f.Kind)] = f; return nil },
|
||||
Keys: func() ([]string, error) { return slices.Collect(maps.Keys(r.findings)), nil },
|
||||
Get: func(key string) (mcseat.Finding, bool, error) { f, ok := r.findings[key]; return f, ok, nil },
|
||||
Delete: func(key string) error {
|
||||
if r.deleteRefused > 0 {
|
||||
r.deleteRefused--
|
||||
return errors.New("the bucket is full")
|
||||
}
|
||||
delete(r.findings, key)
|
||||
return nil
|
||||
}}
|
||||
p.publishWants = func(event string, body any, id string) error {
|
||||
if r.refuse {
|
||||
return errors.New("the bus refuses")
|
||||
}
|
||||
if b, ok := body.(meshwants.PipelineWantedEvent); ok {
|
||||
r.said, r.ids = append(r.said, b), append(r.ids, id)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
for i, m := range []struct{ name, fp string }{{"db", r.db}, {"web", r.web}} {
|
||||
digest := strings.Repeat(string(rune('e'+i)), 64)
|
||||
mod, _ := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Fp2: m.fp, Manifest: digest, Repository: "novox/" + m.name, Commit: strings.Repeat("1", 40), Path: meshcatalogclient.RootPath})
|
||||
putModuleRaw(p.w, trunkBranch, m.name, mod)
|
||||
p.w.manifests[digest] = parsed{module: m.name, manifest: catalogue.Manifest{Module: m.name}}
|
||||
}
|
||||
placeOn(t, p.w, "g14", "db", "web")
|
||||
p.w.mu.Lock()
|
||||
p.w.runningHeard = true
|
||||
p.w.mu.Unlock()
|
||||
p.ends = newPipelineEnds(r.ends, func() {}, t.Logf)
|
||||
p.ends.trunk, p.ends.now = p.w.trunkName, func() time.Time { return r.now }
|
||||
r.p = p
|
||||
}
|
||||
|
||||
func (r *tierRig) restart() { r.build() }
|
||||
|
||||
// pass makes one pass at minutes after the start.
|
||||
func (r *tierRig) pass(minutes time.Duration) {
|
||||
r.now = r.start.Add(minutes)
|
||||
r.p.wants(context.Background())
|
||||
}
|
||||
|
||||
@@ -74,33 +74,18 @@ func (s *putTools) hear(key string, value []byte) {
|
||||
// fullFP is a fingerprint of the new form, whole.
|
||||
var fullFP = regexp.MustCompile(`^src2:[0-9a-f]{64}$`)
|
||||
|
||||
// version reads the version a put names: newest (the indexer's fingerprint at the trunk) or a whole fingerprint (design 47 G A-181:
|
||||
// a put names the whole fingerprint, the builder's builds being no bucket to list).
|
||||
// prefixFP is a fingerprint's first 12 to 63 hex digits behind src2:.
|
||||
var prefixFP = regexp.MustCompile(`^src2:[0-9a-f]{12,64}$`)
|
||||
|
||||
// version reads the version a put names: newest, or a fingerprint whole or by its first 12 hex digits. The tool reads nothing:
|
||||
// the program resolves newest to the end kept for the node's branch, and a prefix among the builds it hears, at the put's first
|
||||
// step (design 47 H2b §833, §834; H-A-848, H-A-862).
|
||||
func (s *putTools) version(module, version string) (string, error) {
|
||||
v := strings.ToLower(strings.TrimSpace(version))
|
||||
switch {
|
||||
case v == "newest":
|
||||
// Asked of the indexer's first view of modules, never read from its bus state (ADR 0596, ADR 0621; issue 1966).
|
||||
mods, err := indexerView(s.ask, indexerModules)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("the indexer's modules cannot be read: %w", err)
|
||||
}
|
||||
raw, found := mods[module]
|
||||
if !found {
|
||||
return "", fmt.Errorf("the indexer holds no module %s at the trunk", module)
|
||||
}
|
||||
m, err := meshcatalogclient.DecodeModule(raw)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("the indexer's %s cannot be read: %w", module, err)
|
||||
}
|
||||
if m.Fp2 == "" {
|
||||
return "", fmt.Errorf("the indexer holds no fingerprint of the new form for %s: %s", module, m.None2)
|
||||
}
|
||||
return m.Fp2, nil
|
||||
case fullFP.MatchString(v):
|
||||
if v == puts.Newest || fullFP.MatchString(v) || prefixFP.MatchString(v) {
|
||||
return v, nil
|
||||
}
|
||||
return "", fmt.Errorf("%q is no version: newest, a fingerprint (src2: and 64 hex digits) whole", version)
|
||||
return "", fmt.Errorf("%q is no version of %s: newest (the version whose pipeline passed), or a fingerprint (src2: and 64 hex digits, or at least its first 12)", version, module)
|
||||
}
|
||||
|
||||
// putAnswer is what assigner_put and assigner_puts answer of one put.
|
||||
@@ -155,7 +140,7 @@ func (s *putTools) doPut(args map[string]any, by string) (any, error) {
|
||||
return nil, fmt.Errorf("the put of %s on %s cannot be read: %w", module, node, err)
|
||||
} else if found {
|
||||
if before, err := puts.Decode(raw); err == nil && !puts.Ended(before.Step) {
|
||||
if before.FP == fp && before.Hold == hold {
|
||||
if (before.FP == fp || (puts.Unresolved(fp) && fp != puts.Newest && strings.HasPrefix(before.FP, fp))) && before.Hold == hold {
|
||||
a := answerOf(node, module, before)
|
||||
a.Follow = followPut(node, module)
|
||||
return a, nil
|
||||
@@ -332,7 +317,7 @@ func (s *putTools) tools() []stdio.Tool {
|
||||
Input: schema(map[string]string{
|
||||
"node": "the machine, where the module is assigned",
|
||||
"module": "the module",
|
||||
"version": "newest, a fingerprint (src2: and 64 hex digits), or at least its first 12 hex digits",
|
||||
"version": "newest (the version of the node's branch whose pipeline passed), a fingerprint (src2: and 64 hex digits), or at least its first 12 hex digits",
|
||||
"hold": "\"true\": the want stays at this version until released; \"false\" (the default): the rules move it again once it runs",
|
||||
"why": "why, kept with the put and said in any ask",
|
||||
}, []string{"node", "module", "version", "why"}, "hold"),
|
||||
@@ -410,11 +395,14 @@ func serveTools() error {
|
||||
keeper := &inputKeeper{vals: stateobjects.ForState(buckets.InputsState), now: time.Now, logf: func(string, ...any) {}}
|
||||
tools = append(tools, inputsRead(keeper), inputsDrop(keeper, stdio.Ask))
|
||||
tools = append(tools, validateTools(stdio.Ask)...) // judge a pipeline's candidate on request, through the seat mesh-wants' verb validate (H-A-727)
|
||||
tools = append(tools, owedTools(stdio.Ask)...) // the owed events, through the seat mesh-wants' verbs (§832 6.)
|
||||
tools = append(tools, compositionsTools(stdio.Ask)...) // the composition runs' read and drop, through their verbs (§728)
|
||||
tools = append(tools, viewTools(os.Getenv, keptSource, time.Now)...)
|
||||
// What each node's engine reads, as the assigner uses it: its own state engine-reads (design 47 H-A-104).
|
||||
tools = append(tools, engineReadsTools(runtimeStore{})...)
|
||||
tools = append(tools, writtenTools(runtimeStore{})...)
|
||||
tools = append(tools, progressDropTools(runtimeStore{}, stdio.Ask)...) // a tier progress whose tier never runs (§824 7.)
|
||||
tools = append(tools, waitDropTools(runtimeStore{}, stdio.Ask)...) // a decided wait record (§830 2.)
|
||||
tools = append(tools, whyTools(runtimeStore{})...)
|
||||
tools = append(tools, askAgainTools(runtimeStore{}, stdio.Ask, time.Now)...)
|
||||
tools = append(tools, wantDropTools(runtimeStore{}, stdio.Ask)...)
|
||||
|
||||
@@ -137,13 +137,12 @@ func TestTheValidateStepRefusesAManifestProblemAndACycle(t *testing.T) {
|
||||
keeper := testKeeper(&objectsMem{objs: map[string][]byte{}}, time.Now)
|
||||
runs := newCompositionRuns(newRunsMem(), defaultRunSettings, time.Now, t.Logf)
|
||||
var held []string // the wait-helds of the reader ask-left said, what each waits on and its id (H-A-630 (5), H-A-632)
|
||||
runs.say = func(event string, body any, id string) error {
|
||||
runs.owe = func(_, event string, body any, id string) {
|
||||
if w := body.(meshwants.Wait); event == meshwants.EventWaitHeld && strings.Contains(id, ".ask-left.") {
|
||||
mu.Lock()
|
||||
held = append(held, w.On+" ("+id+")")
|
||||
mu.Unlock()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
r := &compositionRun{runs: runs, keeper: keeper, reads: &compositionReads{}, call: asKept(call), callFile: callFile, own: context.Background(), now: time.Now, logf: t.Logf,
|
||||
put: func(_ context.Context, a buildstep.StepAsk) error {
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
|
||||
"mesh-delivery-assigner/internal/outside"
|
||||
)
|
||||
|
||||
// waitDropTool drops one decided wait record by hand (design 47 H2b §830 2.): a wait that ended `go-on`, `failed` or `own-failure`
|
||||
// keeps its record in the state `waits` until its fingerprint runs healthy, so a check that goes on failing there is not held again;
|
||||
// dropping it makes the next failing check there a new wait. The act is recorded in the hand-act log first; only a decided record is
|
||||
// dropped (a wait that stands is released by assigner_release).
|
||||
const waitDropTool = "assigner_wait_drop"
|
||||
|
||||
// dropWait deletes the decided record under key, the act first recorded through the seat mesh-hand-acts.
|
||||
func dropWait(st seatStore, ask func(string, any) (json.RawMessage, error), key, why, by string) (any, error) {
|
||||
switch {
|
||||
case key == "":
|
||||
return nil, errors.New("name the wait's key, <node>.<module>.<fingerprint>: assigner_waits lists them")
|
||||
case why == "":
|
||||
return nil, errors.New("a wait dropped by hand says why")
|
||||
case by == "" || by == stdio.Unproven:
|
||||
return nil, errors.New("a wait dropped by hand names who drops it, and the runtime proved no caller")
|
||||
}
|
||||
raw, _, found, err := st.get(waitsState, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !found {
|
||||
return nil, fmt.Errorf("the assigner holds no wait under %s: assigner_waits lists them", key)
|
||||
}
|
||||
w, err := outside.Decode(raw)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s holds no wait on an outside cause: %w", key, err)
|
||||
}
|
||||
if w.Decided == "" {
|
||||
return nil, fmt.Errorf("the wait %s is %s, not decided: assigner_release takes a wait that stands, and an end not said is said by the assigner (assigner_owed)", key, outside.StateOf(w))
|
||||
}
|
||||
taken, err := meshhandactsclient.Recorder{Ask: ask}.Record(meshhandactsclient.Request{What: waitDropTool + " " + key, Why: why + " (" + by + ")", Cause: "outside-wait-drop"})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the drop of %s is not recorded, so the wait stays: %w", key, err)
|
||||
}
|
||||
if err := st.del(waitsState, key); err != nil {
|
||||
return nil, fmt.Errorf("the wait %s is not dropped: %w", key, err)
|
||||
}
|
||||
return map[string]any{"key": key, "dropped": json.RawMessage(raw), "by": by, "hand-act": taken.Log}, nil
|
||||
}
|
||||
|
||||
// waitDropTools is the tool over the runtime's states.
|
||||
func waitDropTools(st seatStore, ask func(string, any) (json.RawMessage, error)) []stdio.Tool {
|
||||
return []stdio.Tool{{Name: waitDropTool, Description: "Drop one decided wait record by hand (design 47 H2b §830 2.): the key <node>.<module>.<fingerprint> of the state waits, " +
|
||||
"of a wait that ended go-on, failed or own-failure, so the next failing check of that module there is held as a new wait. Recorded as a hand act first; " +
|
||||
"refused for a wait that stands or whose end is not said (assigner_release takes the first).",
|
||||
Input: schema(map[string]string{"key": "the wait's key as assigner_waits answers it", "why": "why the record is dropped"}, []string{"key", "why"}),
|
||||
Run: func(a map[string]any) (any, error) {
|
||||
return dropWait(st, ask, arg(a, "key"), arg(a, "why"), stdio.CallerOf(a))
|
||||
}}}
|
||||
}
|
||||
@@ -29,6 +29,9 @@ const whyTool = "assigner_why"
|
||||
const (
|
||||
whyNoPipeline = "no-passed-pipeline" // no version of the module released on the branch passed its pipeline: the want written stays
|
||||
whyPassed = "passed-pipeline" // the want names the newest version released on the branch whose pipeline passed (design 47 H §750)
|
||||
// whyHeldByTier: the module's end is kept, and its pipeline's tier progress has not reached its rank; the why names the
|
||||
// pipeline, the tier that runs and the mover that holds it, and whether that tier was found late (§824 6., H-A-507, H-A-844).
|
||||
whyHeldByTier = "held-by-tier"
|
||||
)
|
||||
|
||||
// whyStep is the step that decided a want: a passed pipeline's version, or none yet.
|
||||
@@ -39,6 +42,32 @@ func whyStep(passed bool) string {
|
||||
return whyNoPipeline
|
||||
}
|
||||
|
||||
// heldByTier is the why of module's want on branch when its end is kept and its pipeline's tier progress has not reached its rank;
|
||||
// false when no end is kept (then the step is no-passed-pipeline, H-A-507) or the tier is written.
|
||||
func (p *passer) heldByTier(module, branch string, w wantWhy) (wantWhy, bool) {
|
||||
if p.ends == nil {
|
||||
return w, false
|
||||
}
|
||||
end, ok := p.ends.endOf(module, p.ends.branchOf(module, branch))
|
||||
if !ok || p.ends.tierWritten(end) {
|
||||
return w, false
|
||||
}
|
||||
w.Step, w.Pipeline, w.Fp, w.Version = whyHeldByTier, end.Pipeline, end.Fp, end.Version
|
||||
if h, ok := p.tierHolds[end.Pipeline]; ok {
|
||||
w.Tier, w.Holder, w.TierLate = h.tier, h.mover, h.late
|
||||
}
|
||||
return w, true
|
||||
}
|
||||
|
||||
// tierHold is what holds a pipeline's tier progress at its tier: the first mover of that tier not running, and whether the tier was
|
||||
// found late; kept by the pass that read it, for the whys of the wants that wait on the tier.
|
||||
type tierHold struct {
|
||||
tier int64
|
||||
mover string
|
||||
late bool
|
||||
pipeline string
|
||||
}
|
||||
|
||||
// wantWhy is one key's value.
|
||||
type wantWhy struct {
|
||||
At time.Time `json:"at"`
|
||||
@@ -48,6 +77,11 @@ type wantWhy struct {
|
||||
Version string `json:"version,omitempty"`
|
||||
Pipeline string `json:"pipeline,omitempty"`
|
||||
Step string `json:"step"`
|
||||
// Tier, Holder and TierLate say, for held-by-tier, the tier that runs, the mover that holds it and whether that tier was found
|
||||
// late (design 47 H2b §824 6.).
|
||||
Tier int64 `json:"tier,omitempty"`
|
||||
Holder string `json:"holder,omitempty"`
|
||||
TierLate bool `json:"tier-late,omitempty"`
|
||||
// Before is the want that stood before the pass, After the one the pass wrote (none: it kept Before).
|
||||
Before *mwc.Want `json:"before,omitempty"`
|
||||
After *mwc.Want `json:"after,omitempty"`
|
||||
|
||||
@@ -3,6 +3,7 @@ package assign
|
||||
import (
|
||||
"fmt"
|
||||
"mesh-delivery-assigner/internal/assignment"
|
||||
"mesh-delivery-assigner/internal/outside"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -52,13 +53,18 @@ func OutsideAsk(key, about, node, module, fp, cause string, since time.Time, ask
|
||||
// id `<node>.<module>`, severity warning, naming the module, the machine and the cause by its condition's key, and needing
|
||||
// nothing, so it is sent to no one: the operator's one message is the ask at the bound.
|
||||
func WaitsOutsideFinding(node, module, causeKey, on string, at time.Time) Observed {
|
||||
needs := "Nothing for you to do."
|
||||
if on == outside.OnUnread {
|
||||
// A read that failed leaves the wait standing until an input judges it again (design 47 H2b §829 5.): the way through is named.
|
||||
needs = "The conditions of " + node + " could not be read: ask assigner_release for " + module + " on " + node + " with how rejudge to judge it again now."
|
||||
}
|
||||
return Observed{Scope: "delivery", ID: node + "." + module, Kind: "delivery-waits-outside", Machine: node,
|
||||
Severity: "warning",
|
||||
Summary: fmt.Sprintf("%s on %s waits on %s (the condition %s)", module, node, on, causeKey),
|
||||
Headline: fmt.Sprintf("%s on %s waits on an outside cause", module, node),
|
||||
Explanation: fmt.Sprintf("The health check of %s fails on %s while %s is open, which is outside the delivery. The delivery "+
|
||||
"waits, judges again when it clears and goes on by itself.", module, node, causeKey),
|
||||
Needs: "Nothing for you to do.", Source: "assigner.delivery-waits-outside"}
|
||||
Needs: needs, Source: "assigner.delivery-waits-outside"}
|
||||
}
|
||||
|
||||
// The options of the record ask (ADR 0539 §14) and of the backup ask (§16).
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-teller/tellerevents"
|
||||
"mesh-delivery-assigner/internal/assignment"
|
||||
"mesh-delivery-assigner/internal/outside"
|
||||
"mesh-delivery-assigner/internal/puts"
|
||||
"regexp"
|
||||
"slices"
|
||||
@@ -217,6 +218,16 @@ func theBackupAskIsValid(t *testing.T) {
|
||||
// 1952/WM6: the assigner's conditions are findings.
|
||||
func TestTheAssignersConditions(t *testing.T) {
|
||||
t.Run("1952/WM6: each said condition is a finding, its clear deletes it, said straight only with no findings bucket", saidConditionsAreFindings)
|
||||
// Design 47 H2b §829 5. (review r1 finding 6): a wait on conditions-unread names the way through; any other wait needs nothing.
|
||||
t.Run("the finding of a wait on conditions-unread names assigner_release with rejudge", func(t *testing.T) {
|
||||
at := time.Date(2026, 11, 27, 4, 0, 0, 0, time.UTC)
|
||||
if o := WaitsOutsideFinding("ace", "nats", "", outside.OnUnread, at); !strings.Contains(o.Needs, "assigner_release") || !strings.Contains(o.Needs, "rejudge") {
|
||||
t.Errorf("a wait on conditions-unread needs %q", o.Needs)
|
||||
}
|
||||
if o := WaitsOutsideFinding("ace", "nats", "machine.hub.unreachable", "unreachable:hub", at); o.Needs != "Nothing for you to do." {
|
||||
t.Errorf("a wait on a cause needs %q", o.Needs)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 1952/WM6 (ADR 0564 §2, issue 1952 note 16): every condition the assigner says is a finding in its own bucket, under
|
||||
|
||||
@@ -136,7 +136,9 @@ type Findings struct {
|
||||
Put func(f mcseat.Finding) error
|
||||
Delete func(key string) error
|
||||
Keys func() ([]string, error)
|
||||
Now func() time.Time
|
||||
// Get reads one finding's value by its key, false when none stands (design 47 H2b H-A-828); nil reads none.
|
||||
Get func(key string) (mcseat.Finding, bool, error)
|
||||
Now func() time.Time
|
||||
}
|
||||
|
||||
// Say is say with each condition written as a finding (or its finding deleted), which the condition keeper carries, the
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient"
|
||||
mwc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient"
|
||||
"mesh-delivery-assigner/internal/puts"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
occ "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/clients/operatorchannelclient"
|
||||
@@ -56,6 +57,43 @@ type PutWorld struct {
|
||||
// ends on it, never on the have.
|
||||
Running *nodeengine.Running
|
||||
Now time.Time
|
||||
// Matches are the done builds of the module the assigner hears whose fingerprint starts with the put's prefix, with the
|
||||
// version released at each ("" none); Branch is the watched branch the pass uses for the module on the node and
|
||||
// BranchEnd the fingerprint of the end kept there ("" when none is kept). They resolve a put's version at its first
|
||||
// step (design 47 H2b §833, §834; H-A-848, H-A-862).
|
||||
Matches []PutMatch
|
||||
Branch string
|
||||
BranchEnd string
|
||||
}
|
||||
|
||||
// PutMatch is one done build that starts with a put's prefix.
|
||||
type PutMatch struct{ FP, Version string }
|
||||
|
||||
// resolvePut is the put with its version resolved to the whole fingerprint, or the words that refuse it (design 47 H2b §833,
|
||||
// §834): newest is the end kept for the node's branch, a prefix the one done build that starts with it.
|
||||
func resolvePut(w PutWorld) (puts.Put, string) {
|
||||
p := w.Put
|
||||
asked := p.FP
|
||||
if asked == puts.Newest {
|
||||
if w.BranchEnd == "" {
|
||||
return p, fmt.Sprintf("no version of %s passed a pipeline: name a fingerprint, or read assigner_written (the end of branch %s is the one read)", w.Module, w.Branch)
|
||||
}
|
||||
p.FP = w.BranchEnd
|
||||
} else {
|
||||
switch len(w.Matches) {
|
||||
case 0:
|
||||
return p, fmt.Sprintf("no build of %s that the assigner hears is done at a fingerprint starting %s: name another fingerprint", w.Module, asked)
|
||||
case 1:
|
||||
p.FP = w.Matches[0].FP
|
||||
default:
|
||||
var each []string
|
||||
for _, m := range w.Matches {
|
||||
each = append(each, fmt.Sprintf("%s (%s)", short(m.FP), m.Version))
|
||||
}
|
||||
return p, fmt.Sprintf("%s names more than one build of %s: %s; name more of the fingerprint", asked, w.Module, strings.Join(each, ", "))
|
||||
}
|
||||
}
|
||||
return p.Said(w.Now, p.Step, fmt.Sprintf("the put of %s names %s, which %s resolves to", w.Module, p.FP, asked)), ""
|
||||
}
|
||||
|
||||
// PutNext is what a step decides: the put as it stands after it, and the acts the pass does for it.
|
||||
@@ -78,6 +116,13 @@ func StepPut(w PutWorld) PutNext {
|
||||
say := func(step, format string, args ...any) PutNext {
|
||||
return PutNext{Put: p.Said(w.Now, step, fmt.Sprintf(format, args...))}
|
||||
}
|
||||
if puts.Unresolved(p.FP) {
|
||||
resolved, refused := resolvePut(w)
|
||||
if refused != "" {
|
||||
return PutNext{Put: p.Said(w.Now, puts.Refused, refused)}
|
||||
}
|
||||
p = resolved
|
||||
}
|
||||
fp := short(p.FP)
|
||||
if !w.Assigned {
|
||||
return say(puts.Refused, "%s is not assigned to %s: a put moves a module where it stands assigned (propose its assignments first)", w.Module, w.Node)
|
||||
|
||||
@@ -105,14 +105,19 @@ type Wait struct {
|
||||
// Settling: no outside cause was open at the failing check; the judgement is held until SettleEnds.
|
||||
Settling bool `json:"settling,omitempty"`
|
||||
SettleEnds time.Time `json:"settle-ends,omitempty"`
|
||||
// Ask is the id of the asking made at the bound, and State where the wait stands in words (settling, waiting, asked).
|
||||
Ask string `json:"ask,omitempty"`
|
||||
State string `json:"state,omitempty"`
|
||||
// Ask is the id of the asking made at the bound. Where the wait stands in words is derived at the read, never kept (StateOf).
|
||||
Ask string `json:"ask,omitempty"`
|
||||
// Release is a release by hand not taken up yet: go-on, failed or rejudge, by By and why Why.
|
||||
Release string `json:"release,omitempty"`
|
||||
By string `json:"by,omitempty"`
|
||||
Why string `json:"why,omitempty"`
|
||||
// Decided is `go-on` or `failed` once the wait ended so.
|
||||
// HeldSaid counts the wait-held the wait was the record of, raised by one in the write that makes a new one, so an `on` back at
|
||||
// an earlier cause makes a new message id (design 47 H §832 3.).
|
||||
HeldSaid int `json:"held-said,omitempty"`
|
||||
// Ending is the `how` of an end written and not yet said (design 47 H2b §831): the record stands with its ask and finding until the
|
||||
// bus has taken `wait-ended`, and is judged no more.
|
||||
Ending string `json:"ending,omitempty"`
|
||||
// Decided is `go-on`, `failed` or `own-failure` once the wait ended so and its end was said.
|
||||
Decided string `json:"decided,omitempty"`
|
||||
}
|
||||
|
||||
@@ -135,7 +140,43 @@ func Decode(raw []byte) (Wait, error) {
|
||||
}
|
||||
|
||||
// Standing says a wait is said (`wait-held`) and not only settling, nor decided.
|
||||
func (w Wait) Standing() bool { return !w.Settling && w.Decided == "" }
|
||||
func (w Wait) Standing() bool { return !w.Settling && w.Decided == "" && w.Ending == "" }
|
||||
|
||||
// The states of a wait as `assigner_waits` says them, derived from the record (design 47 H2b §830 1.).
|
||||
const (
|
||||
StateSettling = "settling"
|
||||
StateWaiting = "waiting"
|
||||
StateAsked = "asked"
|
||||
StateEnding = "ending:"
|
||||
StateDecided = "decided:"
|
||||
)
|
||||
|
||||
// StateOf derives where a wait stands from its record: `settling`, `waiting` (standing, no ask), `asked` (standing, with its ask),
|
||||
// `ending:<how>` (an end not yet said) or `decided:<how>`.
|
||||
func StateOf(w Wait) string {
|
||||
switch {
|
||||
case w.Decided != "":
|
||||
return StateDecided + w.Decided
|
||||
case w.Ending != "":
|
||||
return StateEnding + w.Ending
|
||||
case w.Settling:
|
||||
return StateSettling
|
||||
case w.Ask != "":
|
||||
return StateAsked
|
||||
}
|
||||
return StateWaiting
|
||||
}
|
||||
|
||||
// EndedAs is the record a wait's end leaves once `wait-ended` was said (design 47 H2b §831): the wait decided for `go-on`, `failed` and
|
||||
// `own-failure`, nil (the record is deleted) for `healthy`, `cleared` and `replaced`.
|
||||
func EndedAs(w Wait, how string) *Wait {
|
||||
switch how {
|
||||
case HowGoOn, HowFailed, HowOwnFailure:
|
||||
w.Release, w.Ask, w.Ending, w.Settling, w.SettleEnds, w.Decided = "", "", "", false, time.Time{}, how
|
||||
return &w
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Facts are what a judging reads: the module's check on the node at the wait's fingerprint (Failing, Healthy), the keeper's
|
||||
// conditions as read now (Read false: the kept call is unanswered), whether the module holds the seat mesh-conditions itself,
|
||||
@@ -153,8 +194,11 @@ type Facts struct {
|
||||
CauseCleared bool
|
||||
// KeeperSelf: the module holds the seat mesh-conditions, which cannot answer for its own failing check.
|
||||
KeeperSelf bool
|
||||
Bound time.Duration
|
||||
Settle time.Duration
|
||||
// Running: the node-engine seat's last `running` for the module on the node names the wait's fingerprint and does not say it
|
||||
// stopped, whatever its health says (design 47 H2b §827): the operator is asked only while it is false.
|
||||
Running bool
|
||||
Bound time.Duration
|
||||
Settle time.Duration
|
||||
}
|
||||
|
||||
// Decision is what a judging comes to.
|
||||
@@ -169,12 +213,18 @@ type Decision struct {
|
||||
Own, Counted, Waiting bool
|
||||
// Ask: the bound has run from clock-from, so the operator is asked.
|
||||
Ask bool
|
||||
// Withdraw: the module runs its wanted build while its ask stands, so the ask is withdrawn and the wait's Ask written empty (§827 2.).
|
||||
Withdraw bool
|
||||
// Due is when the judging is due again by itself (the settle's end); zero for none.
|
||||
Due time.Time
|
||||
}
|
||||
|
||||
// Judge is one judging of the check at the node (§706). prev is the kept wait of that module at that fingerprint, nil for none.
|
||||
func Judge(prev *Wait, node, module, fp string, f Facts) Decision {
|
||||
if prev != nil && prev.Ending != "" {
|
||||
// An end written and not yet said: the record is judged no more and makes no wait-held (§831); the end's say finishes it.
|
||||
return Decision{Wait: prev, Own: prev.Ending == HowFailed || prev.Ending == HowOwnFailure, Counted: prev.Ending == HowGoOn}
|
||||
}
|
||||
if prev != nil && prev.Decided != "" {
|
||||
// Decided by the operator: it holds for this fingerprint until the module runs healthy.
|
||||
if f.Healthy {
|
||||
@@ -236,14 +286,14 @@ func Judge(prev *Wait, node, module, fp string, f Facts) Decision {
|
||||
if prev != nil && prev.Settling {
|
||||
next = *prev
|
||||
} else {
|
||||
next.Settling, next.SettleEnds, next.State = true, f.Now.Add(f.Settle), "settling"
|
||||
next.Settling, next.SettleEnds = true, f.Now.Add(f.Settle)
|
||||
}
|
||||
if f.Now.Before(next.SettleEnds) {
|
||||
return Decision{Wait: &next, Waiting: true, Due: next.SettleEnds}
|
||||
}
|
||||
next.Settling, next.SettleEnds = false, time.Time{}
|
||||
}
|
||||
next.On, next.Cause, next.Settling, next.State = OnUnread, "", false, "waiting"
|
||||
next.On, next.Cause, next.Settling = OnUnread, "", false
|
||||
return stand(prev, next, f)
|
||||
}
|
||||
causes := Causes(f.Conds, node, f.Moved)
|
||||
@@ -256,7 +306,7 @@ func Judge(prev *Wait, node, module, fp string, f Facts) Decision {
|
||||
}
|
||||
}
|
||||
}
|
||||
next.On, next.Cause, next.Settling, next.SettleEnds, next.State = c.On, c.Key, false, time.Time{}, "waiting"
|
||||
next.On, next.Cause, next.Settling, next.SettleEnds = c.On, c.Key, false, time.Time{}
|
||||
return stand(prev, next, f)
|
||||
}
|
||||
if standing {
|
||||
@@ -274,7 +324,7 @@ func Judge(prev *Wait, node, module, fp string, f Facts) Decision {
|
||||
}
|
||||
return Decision{Wait: prev, Waiting: true, Due: prev.SettleEnds}
|
||||
}
|
||||
next.Settling, next.SettleEnds, next.State, next.On, next.Cause = true, f.Now.Add(f.Settle), "settling", "", ""
|
||||
next.Settling, next.SettleEnds, next.On, next.Cause = true, f.Now.Add(f.Settle), "", ""
|
||||
return Decision{Wait: &next, Waiting: true, Due: next.SettleEnds}
|
||||
}
|
||||
|
||||
@@ -287,9 +337,14 @@ func stand(prev *Wait, next Wait, f Facts) Decision {
|
||||
if prev != nil && prev.Standing() {
|
||||
next.Ask = prev.Ask
|
||||
}
|
||||
if f.Bound > 0 && !f.Now.Before(next.ClockFrom.Add(f.Bound)) {
|
||||
switch {
|
||||
case f.Running:
|
||||
// §827: a module that runs its wanted build is asked about nothing; an ask that stands is withdrawn, the wait stands.
|
||||
if prev != nil && prev.Standing() && prev.Ask != "" {
|
||||
d.Withdraw, next.Ask = true, ""
|
||||
}
|
||||
case f.Bound > 0 && !f.Now.Before(next.ClockFrom.Add(f.Bound)):
|
||||
d.Ask = true
|
||||
next.State = "asked"
|
||||
}
|
||||
d.Wait = &next
|
||||
return d
|
||||
|
||||
@@ -138,6 +138,30 @@ func TestJudge(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}},
|
||||
{"a module running its wanted build past the bound has no ask; one that came to run has its ask withdrawn; its end carries none (§827)", func(t *testing.T) {
|
||||
_, w := step(nil, facts(t0, hub))
|
||||
f := facts(t0.Add(30*time.Minute), hub)
|
||||
f.Running = true
|
||||
if d, _ := step(w, f); d.Ask || d.Withdraw || d.End != "" {
|
||||
t.Fatalf("running past the bound: %+v", d)
|
||||
}
|
||||
d, asked := step(w, facts(t0.Add(30*time.Minute), hub))
|
||||
if !d.Ask {
|
||||
t.Fatalf("not running past the bound: %+v", d)
|
||||
}
|
||||
asked.Ask = "the-ask"
|
||||
if d, kept := step(asked, f); d.Ask || !d.Withdraw || kept.Ask != "" || !kept.Standing() || d.End != "" {
|
||||
t.Errorf("withdrawn: %+v %+v", d, kept)
|
||||
}
|
||||
f.Conds = nil
|
||||
if d, _ := step(asked, f); d.End != HowOwnFailure || d.Ask {
|
||||
t.Errorf("no cause open: %+v", d)
|
||||
}
|
||||
f.Failing, f.Healthy = false, true
|
||||
if d, _ := step(asked, f); d.End != HowCleared || d.Ask || d.Withdraw {
|
||||
t.Errorf("cleared: %+v", d)
|
||||
}
|
||||
}},
|
||||
{"a release to judge again changes nothing by itself", func(t *testing.T) {
|
||||
_, w := step(nil, facts(t0, hub))
|
||||
w.Release = HowRejudge
|
||||
|
||||
@@ -112,9 +112,28 @@ func (p Put) StandsSince() time.Time {
|
||||
|
||||
var digestForm = regexp.MustCompile(`^sha256:[0-9a-f]{64}$`)
|
||||
|
||||
// Newest is the version a put names to take the newest version whose pipeline passed on the node's branch (design 47 H2b
|
||||
// §833); the program resolves it at the put's first step (H-A-862), as it resolves a prefix of a fingerprint (§834, H-A-848).
|
||||
const Newest = "newest"
|
||||
|
||||
var prefixForm = regexp.MustCompile(`^src2:[0-9a-f]{12,64}$`)
|
||||
|
||||
// Whole says fp is a whole fingerprint of the new form.
|
||||
func Whole(fp string) bool {
|
||||
_, err := catalogkey.KeyPart(fp)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// Unresolved says fp is what a put names before its first step resolves it: Newest, or src2: and 12 to 63 hex digits.
|
||||
func Unresolved(fp string) bool {
|
||||
return fp == Newest || (prefixForm.MatchString(fp) && !Whole(fp))
|
||||
}
|
||||
|
||||
func (p Put) check() error {
|
||||
if _, err := catalogkey.KeyPart(p.FP); err != nil {
|
||||
return fmt.Errorf("puts: a put's fingerprint: %w", err)
|
||||
if !Unresolved(p.FP) {
|
||||
if _, err := catalogkey.KeyPart(p.FP); err != nil {
|
||||
return fmt.Errorf("puts: a put's fingerprint: %w", err)
|
||||
}
|
||||
}
|
||||
if p.Why == "" {
|
||||
return fmt.Errorf("puts: a put says why")
|
||||
|
||||
@@ -104,7 +104,7 @@ func TestManifest(t *testing.T) {
|
||||
// revision, entry and difference from its revisions kept as objects in the old section, form 1, capped at 512 MiB.
|
||||
if len(m.Claims) != 2 || m.Claims[0].Name != meshmoduleassigner.Seat || m.Claims[0].At() != catalogue.ScopeMesh ||
|
||||
!slices.Equal(m.Claims[0].Serves, []string{"assignments", "proposals", "propose", "withdraw", "again", "placement"}) ||
|
||||
m.Claims[1].Name != meshwants.Seat || m.Claims[1].At() != catalogue.ScopeMesh || !slices.Equal(m.Claims[1].Serves, []string{"upgrade", "bus", "revision", "entry", "difference", "input", "compositions", "compositions-drop", "validate", "keep-now", "drop"}) {
|
||||
m.Claims[1].Name != meshwants.Seat || m.Claims[1].At() != catalogue.ScopeMesh || !slices.Equal(m.Claims[1].Serves, []string{"upgrade", "bus", "revision", "entry", "difference", "input", "compositions", "compositions-drop", "validate", "keep-now", "drop", "owed", "owed-say", "owed-drop"}) {
|
||||
t.Errorf("the assigner claims %+v, want mesh-module-assigner with its five verbs and mesh-wants with its five", m.Claims)
|
||||
}
|
||||
if len(m.Objects) != 1 || m.Objects[0].Name != "assignment-revisions" || m.Objects[0].MaxMiB != 512 || m.Objects[0].Form != 1 {
|
||||
@@ -116,7 +116,7 @@ func TestManifest(t *testing.T) {
|
||||
// which lists and asks again what each node's engine reads.
|
||||
if !slices.Equal(m.Tools, []string{"assigner_put", "assigner_release", "assigner_puts", "assigner_waits", "assigner_inputs", "assigner_inputs_drop", "assigner_compositions", "assigner_compositions_drop", "assignments", "seat-holders", "wants", "asks",
|
||||
"assigner_read_assignments", "assigner_read_seat_holders", "assigner_read_wants", "assigner_read_findings", "assigner_read_differences", "assigner_read_copies",
|
||||
"assigner_first_views", "assigner_first_view_again", "assigner_engine_reads", "assigner_seat_list", "assigner_seat_list_again", "assigner_ask_again", "assigner_written", "assigner_why", "assigner_want_drop", "assigner_assignment_drop", "assigner_asks", "assigner_ask_drop", "assigner_keep_now", "assigner_validate_before", "assigner_validate"}) {
|
||||
"assigner_first_views", "assigner_first_view_again", "assigner_engine_reads", "assigner_seat_list", "assigner_seat_list_again", "assigner_ask_again", "assigner_written", "assigner_progress_drop", "assigner_wait_drop", "assigner_owed", "assigner_owed_say", "assigner_owed_drop", "assigner_why", "assigner_want_drop", "assigner_assignment_drop", "assigner_asks", "assigner_ask_drop", "assigner_keep_now", "assigner_validate_before", "assigner_validate"}) {
|
||||
t.Errorf("the assigner serves tools %v, want its three put tools, three first views, six read tools, assigner_engine_reads, the seat list's two (ADR 0636 §7) assigner_ask_again (ADR 0668 §5), assigner_why (design 47 G A-439) and assigner_assignment_drop after assigner_want_drop (design 47 H2 H-A-509)", m.Tools)
|
||||
}
|
||||
if m.RunsAs != m.Module || m.SecretsOwner != m.RunsAs {
|
||||
@@ -186,7 +186,7 @@ func TestManifest(t *testing.T) {
|
||||
}
|
||||
file, _ := os.ReadFile("module.json")
|
||||
if err := json.Unmarshal(file, &raw); err != nil || raw.Config["outside-wait-minutes"].Default != float64(30) || raw.Config["outside-settle-seconds"].Default != float64(90) ||
|
||||
raw.Config["ask-operator-for"].Default != "take-off,remove-node,stops" || len(raw.Config) != 18 || raw.Config["tier-bound"].Default != float64(30) || raw.Config["entry-asks"].Default != float64(5) || raw.Config["reads-bound"].Default != float64(8) ||
|
||||
raw.Config["ask-operator-for"].Default != "take-off,remove-node,stops" || len(raw.Config) != 21 || raw.Config["tier-bound"].Default != float64(30) || raw.Config["entry-asks"].Default != float64(5) || raw.Config["reads-bound"].Default != float64(8) ||
|
||||
raw.Config["composition-runs-cap-mib"].Default != float64(16) || raw.Config["composition-runs-kept"].Default != "24h" ||
|
||||
raw.Config["composition-step-bound"].Default != "30m" || raw.Config["run-untaken-bound"].Default != "24h" || raw.Config["blame-tries"].Default != float64(20) ||
|
||||
// design 47 H2 H-A-628 (3): the bound of a run's wait for a package's publish, the builder's default
|
||||
@@ -194,7 +194,11 @@ func TestManifest(t *testing.T) {
|
||||
// design 47 H2 H-A-635: the bound a pass runs before it says which phase it is in
|
||||
raw.Config["pass-stall-seconds"].Default != float64(60) ||
|
||||
// design 47 H2 §775, H-A-381 (2): the taken key's bound and the kept-call pace, runtime settings
|
||||
raw.Config["ask-taken-bound"].Default != "10m" || raw.Config["kept-call-pace-first"].Default != "1s" || raw.Config["kept-call-pace-max"].Default != "30s" || raw.Config["compose-ask-bound"].Default != "10s" || raw.Config["keeping-retry"].Default != "30s" {
|
||||
raw.Config["ask-taken-bound"].Default != "10m" || raw.Config["kept-call-pace-first"].Default != "1s" || raw.Config["kept-call-pace-max"].Default != "30s" || raw.Config["compose-ask-bound"].Default != "10s" || raw.Config["keeping-retry"].Default != "30s" ||
|
||||
// design 47 H §832 2.: the pace an owed event is said again at
|
||||
raw.Config["say-again-pace-first"].Default != "2s" || raw.Config["say-again-pace-max"].Default != "1m" ||
|
||||
// design 47 H2b §832 6.: how long an event may stay owed before it is the finding event-unsaid
|
||||
raw.Config["event-unsaid-after"].Default != "5m" {
|
||||
t.Errorf("config = %+v (%v), want outside-wait-minutes of 30, outside-settle-seconds of 90 and ask-operator-for of take-off,remove-node,stops (A-425a)", raw.Config, err)
|
||||
}
|
||||
for _, f := range []struct{ env, path, key string }{
|
||||
@@ -207,17 +211,24 @@ func TestManifest(t *testing.T) {
|
||||
{"MESH_ASSIGNER_COMPOSITION_STEP_BOUND_FILE", "${dir:state}/composition-step-bound", "composition-step-bound"},
|
||||
{"MESH_ASSIGNER_RUN_UNTAKEN_BOUND_FILE", "${dir:state}/run-untaken-bound", "run-untaken-bound"},
|
||||
{"MESH_ASSIGNER_BLAME_TRIES_FILE", "${dir:state}/blame-tries", "blame-tries"},
|
||||
{"MESH_ASSIGNER_PACKAGE_WAIT_FILE", "${dir:state}/package-wait-minutes", "package-wait-minutes"}, // design 47 H2 H-A-628 (3)
|
||||
{"MESH_ASSIGNER_PASS_STALL_FILE", "${dir:state}/pass-stall-seconds", "pass-stall-seconds"}, // design 47 H2 H-A-635
|
||||
{"MESH_ASSIGNER_TIER_BOUND_FILE", "${dir:state}/tier-bound", "tier-bound"}, // design 47 H §751
|
||||
{"MESH_ASSIGNER_ENTRY_ASKS_FILE", "${dir:state}/entry-asks", "entry-asks"}, // design 47 H H-A-60
|
||||
{"MESH_ASSIGNER_READS_BOUND_FILE", "${dir:state}/reads-bound", "reads-bound"}, // design 47 H2 H-A-708 (3)
|
||||
{"MESH_ASSIGNER_PACKAGE_WAIT_FILE", "${dir:state}/package-wait-minutes", "package-wait-minutes"}, // design 47 H2 H-A-628 (3)
|
||||
{"MESH_ASSIGNER_PASS_STALL_FILE", "${dir:state}/pass-stall-seconds", "pass-stall-seconds"}, // design 47 H2 H-A-635
|
||||
{"MESH_ASSIGNER_TIER_BOUND_FILE", "${dir:state}/tier-bound", "tier-bound"}, // design 47 H §751
|
||||
{"MESH_ASSIGNER_ENTRY_ASKS_FILE", "${dir:state}/entry-asks", "entry-asks"}, // design 47 H H-A-60
|
||||
{"MESH_ASSIGNER_READS_BOUND_FILE", "${dir:state}/reads-bound", "reads-bound"}, // design 47 H2 H-A-708 (3)
|
||||
{"MESH_ASSIGNER_SAY_AGAIN_PACE_FIRST_FILE", "${dir:state}/say-again-pace-first", "say-again-pace-first"}, // design 47 H §832 2.
|
||||
{"MESH_ASSIGNER_SAY_AGAIN_PACE_MAX_FILE", "${dir:state}/say-again-pace-max", "say-again-pace-max"},
|
||||
{"MESH_ASSIGNER_EVENT_UNSAID_AFTER_FILE", "${dir:state}/event-unsaid-after", "event-unsaid-after"}, // design 47 H2b §832 6.
|
||||
} {
|
||||
if !strings.Contains(string(file), `"`+f.env+`": "`+f.path+`"`) || !strings.Contains(string(file), `"path": "`+f.path+`"`) ||
|
||||
!strings.Contains(string(file), `"content": "${config:`+f.key+`}"`) {
|
||||
t.Errorf("the setting %s is not a file %s the env names as %s", f.key, f.path, f.env)
|
||||
}
|
||||
}
|
||||
// design 47 H2b §824 (review r1 finding 7): the setting's words say what a late tier does now, not the rule §824 replaces
|
||||
if strings.Contains(string(file), "writes no later tier") || !strings.Contains(string(file), "writes the next tier once that tier runs") {
|
||||
t.Errorf("the description of tier-bound states the rule design 47 H2b section 824 replaces")
|
||||
}
|
||||
if strings.Contains(string(file), `": "${config:outside-`) && strings.Contains(string(file), `"MESH_ASSIGNER_OUTSIDE_WAIT_MINUTES"`) {
|
||||
t.Errorf("the process's env still carries a setting")
|
||||
}
|
||||
|
||||
@@ -31,7 +31,10 @@
|
||||
"compositions-drop",
|
||||
"validate",
|
||||
"keep-now",
|
||||
"drop"
|
||||
"drop",
|
||||
"owed",
|
||||
"owed-say",
|
||||
"owed-drop"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -136,6 +139,11 @@
|
||||
"assigner_seat_list_again",
|
||||
"assigner_ask_again",
|
||||
"assigner_written",
|
||||
"assigner_progress_drop",
|
||||
"assigner_wait_drop",
|
||||
"assigner_owed",
|
||||
"assigner_owed_say",
|
||||
"assigner_owed_drop",
|
||||
"assigner_why",
|
||||
"assigner_want_drop",
|
||||
"assigner_assignment_drop",
|
||||
@@ -194,7 +202,7 @@
|
||||
},
|
||||
"tier-bound": {
|
||||
"type": "number",
|
||||
"description": "minutes each tier of a pipeline's movers has to run on every present placing machine before the assigner writes the next tier's wants; a tier that does not run within it ends the delivery with the finding tier-late and writes no later tier (design 47 H section 751).",
|
||||
"description": "minutes each tier of a pipeline's movers has to run on every present placing machine before the assigner writes the next tier's wants; a tier that does not run within it is found late: the finding tier-late is raised and pipeline-wanted says tier-late, on which the delivery record ends failed, and the assigner writes the next tier once that tier runs (design 47 H2b section 824).",
|
||||
"minimum": 1,
|
||||
"maximum": 10080,
|
||||
"trusted": false,
|
||||
@@ -250,6 +258,24 @@
|
||||
"trusted": false,
|
||||
"default": 10
|
||||
},
|
||||
"say-again-pace-first": {
|
||||
"type": "string",
|
||||
"description": "the first wait before the assigner says again an event of the seat mesh-wants that the bus refused or did not acknowledge, under the same message id, doubling at each try to say-again-pace-max, a Go duration (design 47 H section 832 2.).",
|
||||
"trusted": false,
|
||||
"default": "2s"
|
||||
},
|
||||
"say-again-pace-max": {
|
||||
"type": "string",
|
||||
"description": "the longest wait between two says again of an owed event, a Go duration (design 47 H section 832 2.).",
|
||||
"trusted": false,
|
||||
"default": "1m"
|
||||
},
|
||||
"event-unsaid-after": {
|
||||
"type": "string",
|
||||
"description": "how long an event of the seat mesh-wants may stay owed before it is the finding event-unsaid, a Go duration (design 47 H2b section 832 6.).",
|
||||
"trusted": false,
|
||||
"default": "5m"
|
||||
},
|
||||
"pass-stall-seconds": {
|
||||
"type": "number",
|
||||
"description": "seconds a pass of the assigner may run before it says in the journal which phase it is in, and again at each further bound until it ends (design 47 H2 H-A-635).",
|
||||
@@ -413,6 +439,30 @@
|
||||
"mode": "0600",
|
||||
"content": "${config:package-wait-minutes}"
|
||||
},
|
||||
{
|
||||
"id": "say-again-pace-first",
|
||||
"type": "file",
|
||||
"path": "${dir:state}/say-again-pace-first",
|
||||
"owner": "mesh-delivery-assigner",
|
||||
"mode": "0600",
|
||||
"content": "${config:say-again-pace-first}"
|
||||
},
|
||||
{
|
||||
"id": "say-again-pace-max",
|
||||
"type": "file",
|
||||
"path": "${dir:state}/say-again-pace-max",
|
||||
"owner": "mesh-delivery-assigner",
|
||||
"mode": "0600",
|
||||
"content": "${config:say-again-pace-max}"
|
||||
},
|
||||
{
|
||||
"id": "event-unsaid-after",
|
||||
"type": "file",
|
||||
"path": "${dir:state}/event-unsaid-after",
|
||||
"owner": "mesh-delivery-assigner",
|
||||
"mode": "0600",
|
||||
"content": "${config:event-unsaid-after}"
|
||||
},
|
||||
{
|
||||
"id": "pass-stall-seconds",
|
||||
"type": "file",
|
||||
@@ -451,7 +501,10 @@
|
||||
"MESH_ASSIGNER_RUN_UNTAKEN_BOUND_FILE": "${dir:state}/run-untaken-bound",
|
||||
"MESH_ASSIGNER_BLAME_TRIES_FILE": "${dir:state}/blame-tries",
|
||||
"MESH_ASSIGNER_PACKAGE_WAIT_FILE": "${dir:state}/package-wait-minutes",
|
||||
"MESH_ASSIGNER_PASS_STALL_FILE": "${dir:state}/pass-stall-seconds"
|
||||
"MESH_ASSIGNER_PASS_STALL_FILE": "${dir:state}/pass-stall-seconds",
|
||||
"MESH_ASSIGNER_SAY_AGAIN_PACE_FIRST_FILE": "${dir:state}/say-again-pace-first",
|
||||
"MESH_ASSIGNER_SAY_AGAIN_PACE_MAX_FILE": "${dir:state}/say-again-pace-max",
|
||||
"MESH_ASSIGNER_EVENT_UNSAID_AFTER_FILE": "${dir:state}/event-unsaid-after"
|
||||
},
|
||||
"user": "mesh-delivery-assigner",
|
||||
"health": {
|
||||
|
||||
@@ -178,6 +178,20 @@ func (w sweepWiring) Adopt(f *views.Follower, seatName, event string, hear func(
|
||||
return nil
|
||||
}
|
||||
|
||||
// AdoptEvent registers a seat's event on the wrapped reader before its Start, as the branch follower asks of a wiring that has a hub
|
||||
// to refuse a pattern registered after it (design 47 H2b §836 3., H-A-854): without it the first branch followed after Start
|
||||
// registers catalog-revision too late.
|
||||
func (w sweepWiring) AdoptEvent(seat, event string, hear func(context.Context, []byte) error) error {
|
||||
ew, ok := w.Wiring.(interface {
|
||||
AdoptEvent(seat, event string, hear func(context.Context, []byte) error) error
|
||||
})
|
||||
if !ok {
|
||||
// Said, not passed over: the event would be registered by none, so it would be heard by none (design 47 H2b §836 3.).
|
||||
return fmt.Errorf("the events %q of the seat %s are not registered: the builder's reader cannot adopt an event before its start", event, seat)
|
||||
}
|
||||
return ew.AdoptEvent(seat, event, hear)
|
||||
}
|
||||
|
||||
// Follow follows a plain view through the wrapped wiring (meshcatalogclient's SeatHolders, A-298).
|
||||
func (w sweepWiring) Follow(owner, state, tool string) (func() map[string]json.RawMessage, error) {
|
||||
f, ok := w.Wiring.(interface {
|
||||
|
||||
@@ -32,6 +32,7 @@ import (
|
||||
"github.com/nats-io/nats.go"
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient/heard"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
sweep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshartifactsweep"
|
||||
@@ -583,15 +584,14 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
reader.Start(ctx, js, cred, process.AwaitBucket(ctx, js, conn, builds.StateBucket(cred.Module, views.StatusState), "builder_first_views reads nothing and builder_first_view_again is not heard", logger.Printf))
|
||||
// Every part has registered: the hub pulls the module's durable. Where the consumer is not there yet the builder says so
|
||||
// and binds it at a later change (heard.Writer; ADR 0615 §5).
|
||||
_ = notHeard.Bind(eventsStream, sweep.EventArtifactsGone+", the registry seats' words, the views and manifest-reads-changed are not heard until the builder starts again", func() error {
|
||||
if err := hub.Start(ctx, js, cred); err != nil {
|
||||
return err
|
||||
}
|
||||
// And the kept seat events it handles (the build seats' toolchain-reported, the seat mesh-catalog's
|
||||
// version-released), each on its own stream: the tool runner reads its own twin there (lead answer A-397).
|
||||
hub.StartKept(ctx, js, cred)
|
||||
return nil
|
||||
})
|
||||
// Start's nil says the hub started, never that anything is heard: EVENTS is heard when the hub's unheard list names no EVENTS
|
||||
// entry, else not heard with the hub's reason (design 47 H2b H-A-877). One Start binds every pattern's stream, the kept seat
|
||||
// events' too (the build seats' toolchain-reported, the seat mesh-catalog's version-released) (§836 1.).
|
||||
eventsConsequence := sweep.EventArtifactsGone + ", the registry seats' words, the views and manifest-reads-changed are not heard until the builder starts again"
|
||||
hub.OnUnheard(eventsUnheard(notHeard, eventsConsequence))
|
||||
if err := hub.Start(ctx, js, cred); err != nil {
|
||||
notHeard.NotHeard(eventsStream, eventsConsequence, err)
|
||||
}
|
||||
go func() { <-ctx.Done(); hub.Stop() }()
|
||||
// A person asks a key's build again with builder_ask_again, which writes the reasks state (issue 1945): watched, as
|
||||
// every other input. The builder asks again by itself without it.
|
||||
@@ -691,3 +691,17 @@ func toolchainWaitOf(path string) (time.Duration, error) {
|
||||
}
|
||||
return time.Duration(n) * time.Minute, nil
|
||||
}
|
||||
|
||||
// eventsUnheard is the hub's word of what it does not hear, as the builder's finding family-not-heard of EVENTS: heard when the
|
||||
// list names no EVENTS entry, else not heard with the hub's reason (design 47 H2b H-A-877; Start's nil says only that it started).
|
||||
func eventsUnheard(w heard.Writer, consequence string) func([]process.Unheard) {
|
||||
return func(list []process.Unheard) {
|
||||
for _, u := range list {
|
||||
if u.Stream == eventsStream {
|
||||
w.NotHeard(eventsStream, consequence, errors.New(u.Why))
|
||||
return
|
||||
}
|
||||
}
|
||||
w.Heard(eventsStream)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,6 +396,26 @@ func aFailedTrunkBuildIsAFinding(t *testing.T) {
|
||||
if _, ok := st.vals[unheardKey]; ok {
|
||||
t.Error("a consumer bound leaves family-not-heard")
|
||||
}
|
||||
// H-A-877: the hub's Start answers nil once started; EVENTS is heard only when the hub's unheard list names no EVENTS entry.
|
||||
hubSays := eventsUnheard(notHeard, "a branch's end is not heard")
|
||||
for _, row := range []struct {
|
||||
name string
|
||||
list []process.Unheard
|
||||
finding bool
|
||||
}{
|
||||
{"EVENTS unbound", []process.Unheard{{Pattern: "mesh.seat.x.event.>", Stream: "EVENTS", Why: "consumer not found"}}, true},
|
||||
{"a kept stream only", []process.Unheard{{Pattern: "mesh.seat.y.event.z", Stream: "SEAT_y_z", Why: "refused"}}, false},
|
||||
{"all heard", nil, false},
|
||||
} {
|
||||
hubSays(row.list)
|
||||
got, err := decodeFinding(st.vals[unheardKey])
|
||||
if row.finding && (err != nil || !strings.Contains(got.Summary, "consumer not found")) {
|
||||
t.Errorf("%s: the finding = %+v, %v", row.name, got, err)
|
||||
}
|
||||
if _, ok := st.vals[unheardKey]; ok != row.finding {
|
||||
t.Errorf("%s: finding present = %v, want %v", row.name, ok, row.finding)
|
||||
}
|
||||
}
|
||||
// DLV-B9, the old form's window: one counted node reading only the first form holds it; seven days on it is
|
||||
// old-form-held about that node; the node stating the newest form closes it, said once, the finding cleared; a
|
||||
// retired node dropped by hand leaves the count.
|
||||
|
||||
@@ -48,6 +48,12 @@ func (w processWiring) Adopt(f *views.Follower, seat, event string, hear func(co
|
||||
}
|
||||
func (w processWiring) Drop(owner, state string) error { return w.r.Drop(owner, state) }
|
||||
|
||||
// AdoptEvent registers a seat's event on the process reader before its Start, with a handler that has nothing to do: the
|
||||
// event's one subscription is made at Start and every follower adopted on it later shares it (design 47 H2b §836 3.).
|
||||
func (w processWiring) AdoptEvent(seat, event string, hear func(context.Context, []byte) error) error {
|
||||
return w.r.AdoptEvent(seat, event, hear)
|
||||
}
|
||||
|
||||
// ReaderWiring wires Branches on a bundle's reader.
|
||||
func ReaderWiring(r *views.Reader) Wiring { return readerWiring{r} }
|
||||
|
||||
@@ -100,6 +106,16 @@ func NewBranches(w Wiring, call Call) (*Branches, error) {
|
||||
b.Registrations.Follower.Changed = func(string, json.RawMessage, bool, time.Time) { b.reconcile() }
|
||||
b.source = sourcebranches.New(sourcebranches.Call(call))
|
||||
b.source.Follower.Changed = func(string, json.RawMessage, bool, time.Time) { b.reconcile() }
|
||||
// The event of a branch's view is registered here, before the reader's Start: the hub refuses a pattern first
|
||||
// registered after Start (design 47 H2b §836 3.; H-A-854, H-A-861), and a branch first followed later adopts its view on
|
||||
// this one subscription (a wiring that has no hub to refuse, a bundle's reader, subscribes it at its own Start).
|
||||
if ew, ok := w.(interface {
|
||||
AdoptEvent(seat, event string, hear func(context.Context, []byte) error) error
|
||||
}); ok {
|
||||
if err := ew.AdoptEvent(seat.Seat, seat.EventCatalogRevision, func(context.Context, []byte) error { return nil }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if err := w.Adopt(b.Registrations.Follower, seat.Seat, seat.EventRegistrationChanged, b.hearRegistration); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -28,6 +28,29 @@ type fakeWiring struct {
|
||||
follows []string
|
||||
values map[string]map[string]json.RawMessage
|
||||
followed chan string
|
||||
// events are the seat events adopted, by `<seat>.<event>`; started says the hub has started: it refuses an event
|
||||
// adopted for the first time after that (design 47 H2b §836 3.).
|
||||
events map[string]bool
|
||||
started bool
|
||||
}
|
||||
|
||||
// AdoptEvent is the process reader's AdoptEvent: the event is heard on the one subscription the followers on it share.
|
||||
func (w *fakeWiring) AdoptEvent(seat, event string, _ func(context.Context, []byte) error) error {
|
||||
w.mu.Lock()
|
||||
defer w.mu.Unlock()
|
||||
return w.eventLocked(seat, event)
|
||||
}
|
||||
|
||||
func (w *fakeWiring) eventLocked(seat, event string) error {
|
||||
name := seat + "." + event
|
||||
if w.events == nil {
|
||||
w.events = map[string]bool{}
|
||||
}
|
||||
if !w.events[name] && w.started {
|
||||
return fmt.Errorf("the pattern %s is registered after Start", name)
|
||||
}
|
||||
w.events[name] = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *fakeWiring) Follow(owner, state, tool string) (func() map[string]json.RawMessage, error) {
|
||||
@@ -46,9 +69,12 @@ func (w *fakeWiring) Follow(owner, state, tool string) (func() map[string]json.R
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (w *fakeWiring) Adopt(f *views.Follower, _, _ string, hear func(context.Context, []byte) error) error {
|
||||
func (w *fakeWiring) Adopt(f *views.Follower, seat, event string, hear func(context.Context, []byte) error) error {
|
||||
w.mu.Lock()
|
||||
defer w.mu.Unlock()
|
||||
if err := w.eventLocked(seat, event); err != nil {
|
||||
return err
|
||||
}
|
||||
name := f.Owner + "." + f.State
|
||||
if w.adopted[name] != nil {
|
||||
return fmt.Errorf("%s is followed already", name)
|
||||
@@ -164,6 +190,11 @@ func TestBranchesFollowSourceThenRegistrations(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b.Logf = func(format string, args ...any) { said <- fmt.Sprintf(format, args...) }
|
||||
// design 47 H2b §836 3. (H-A-854, H-A-861): the hub is started now and refuses a pattern first registered after it,
|
||||
// so a branch followed from here on hears its catalog-revision only if NewBranches adopted the event before.
|
||||
w.mu.Lock()
|
||||
w.started = true
|
||||
w.mu.Unlock()
|
||||
adopted := make(chan string, 8)
|
||||
b.Adopted = func(branch string, c *Catalog) {
|
||||
if c.Branch == branch {
|
||||
|
||||
@@ -18,6 +18,13 @@ func rep(c string) string { return strings.Repeat(c, 64) }
|
||||
// values (the golden texts are its output; the field order is the contract's now, so values are compared decoded), and the
|
||||
// refusals it made.
|
||||
func TestWantsAreWhatTheEarlierCodecWrote(t *testing.T) {
|
||||
// Review r1 part 1 item 5 (design 47 H2b §832 6.): owed-say's description says no act is written in a hand-act log, which no
|
||||
// line gives and the assigner does not do.
|
||||
t.Run("owed-say's description names no hand-act log", func(t *testing.T) {
|
||||
if d := seat.VerbDescription(seat.VerbOwedSay); d == "" || strings.Contains(d, "hand-act") {
|
||||
t.Errorf("owed-say's description is %q, want one that names no hand-act log", d)
|
||||
}
|
||||
})
|
||||
a, b, c, d := "src2:"+rep("a"), "src2:"+rep("b"), "sha256:"+rep("c"), "sha256:"+rep("d")
|
||||
sameJSON := func(t *testing.T, got []byte, want string) {
|
||||
t.Helper()
|
||||
|
||||
@@ -20,7 +20,7 @@ const Form = 4
|
||||
// whose fields changed while its forms did not (design 47 H2 §780).
|
||||
const (
|
||||
generatedForms = "4"
|
||||
generatedFieldsDigest = "Ask=6cb8b82e2fbe AskTakenEvent=6d5d3da7ac39 AsksByAssignmentsProposalValue=0bb5682c7b3b AsksByBackupNodeModuleFingerprintValue=0bb5682c7b3b AsksByHoldModuleFingerprintValue=0bb5682c7b3b AsksByOutsideNodeModuleFingerprintValue=0bb5682c7b3b AsksByRecordNodeModuleDigestValue=0bb5682c7b3b AsksByRestoreNodeModuleFingerprintValue=0bb5682c7b3b AsksByRevertNodeModuleFingerprintValue=0bb5682c7b3b AssignmentEntry=7d2549782eb2 AssignmentRevision=72c8701f7314 AssignmentRevisionCapabilitiesItem=0c89b0717762 AssignmentRevisionEvent=7faff968ce44 AssignmentRevisionsByCandidateGroupHeadsValue=8553b390118d AssignmentRevisionsByEntryDigestValue=4e5ee7a23e5b AssignmentRevisionsByTrunkRevisionValue=8553b390118d BusAnswer=7538f2f5e68e CatalogOf=7a4646fdbea7 Change=28d1f3c5cd32 ChangeAfterItem=30d718c21581 CompositionReader=5a943c1f8ef1 CompositionRun=2a08fc65e2d0 CompositionRunProgram=5a1202df3497 CompositionRunWaits=9cd147ddfc06 CompositionsAnswer=f8bca93c7f9c CompositionsByGroupHeadsValue=9428965fab8f CompositionsDropAnswer=52803700282a Difference=4011cff516b1 DifferenceAnswer=629237aa39f0 DifferenceEvent=49066d0dff6d DifferenceRefusedItem=0e9caa83ace7 DifferencesByNodeModuleValue=a22487ffadfd DropAnswer=7538f2f5e68e Edge=a71709025a08 EntryAnswer=05adebad70d6 Fill=80f442916429 FillingEvent=5bd4df78ed84 FullEvent=5bd4df78ed84 Held=15abbd6a1a33 HeldCandidate=04872f6afbfa InputAnswer=cd41ee65565d KeepNowAnswer=9962ab9fc051 NodeEntryRef=3888ae847653 NotRunning=279b628db0ec PipelineWanted=e1e379c21e59 PipelineWantedEvent=59946b31ab7d PolicyChangedEvent=7538f2f5e68e RevisionAnswer=39002c770cbd RoomEvent=5bd4df78ed84 Shared=c981cf6aa860 SharedAskedBy=c9b30cc4d0d0 StepAccept=18efeefb6c34 StepEnded=edd08ab1a18b StepEndedEvent=207787118dac StepProgressEvent=8215e490ea8d StepRun=b975f402601a UpgradeAnswer=7538f2f5e68e ValidateAnswer=484ec1cfda14 ValidateAnswerProblemsItem=728518b4dc83 Wait=951500be820c WaitEndedEvent=2bf6d38041c0 WaitHeldEvent=2bf6d38041c0 WantedEvent=58cf7a9f646b WantsByHeldModuleFingerprintValue=ff14aa998a5d WantsByWantNodeModuleValue=ab7c6799fd5d WantsByWantNodeNodeValue=a737a2108d53"
|
||||
generatedFieldsDigest = "Ask=6cb8b82e2fbe AskTakenEvent=6d5d3da7ac39 AsksByAssignmentsProposalValue=0bb5682c7b3b AsksByBackupNodeModuleFingerprintValue=0bb5682c7b3b AsksByHoldModuleFingerprintValue=0bb5682c7b3b AsksByOutsideNodeModuleFingerprintValue=0bb5682c7b3b AsksByRecordNodeModuleDigestValue=0bb5682c7b3b AsksByRestoreNodeModuleFingerprintValue=0bb5682c7b3b AsksByRevertNodeModuleFingerprintValue=0bb5682c7b3b AssignmentEntry=7d2549782eb2 AssignmentRevision=72c8701f7314 AssignmentRevisionCapabilitiesItem=0c89b0717762 AssignmentRevisionEvent=7faff968ce44 AssignmentRevisionsByCandidateGroupHeadsValue=8553b390118d AssignmentRevisionsByEntryDigestValue=4e5ee7a23e5b AssignmentRevisionsByTrunkRevisionValue=8553b390118d BusAnswer=7538f2f5e68e CatalogOf=7a4646fdbea7 Change=28d1f3c5cd32 ChangeAfterItem=30d718c21581 CompositionReader=5a943c1f8ef1 CompositionRun=2a08fc65e2d0 CompositionRunProgram=5a1202df3497 CompositionRunWaits=9cd147ddfc06 CompositionsAnswer=f8bca93c7f9c CompositionsByGroupHeadsValue=9428965fab8f CompositionsDropAnswer=52803700282a Difference=4011cff516b1 DifferenceAnswer=629237aa39f0 DifferenceEvent=49066d0dff6d DifferenceRefusedItem=0e9caa83ace7 DifferencesByNodeModuleValue=a22487ffadfd DropAnswer=7538f2f5e68e Edge=a71709025a08 EntryAnswer=05adebad70d6 Fill=80f442916429 FillingEvent=5bd4df78ed84 FullEvent=5bd4df78ed84 Held=15abbd6a1a33 HeldCandidate=04872f6afbfa InputAnswer=cd41ee65565d KeepNowAnswer=9962ab9fc051 NodeEntryRef=3888ae847653 NotRunning=279b628db0ec OwedAnswer=e77cff288ccc OwedDropAnswer=61c48a9eb982 OwedEvent=f03369beb6e7 OwedSayAnswer=958f6f7adf11 PipelineWanted=e1e379c21e59 PipelineWantedEvent=59946b31ab7d PolicyChangedEvent=7538f2f5e68e RevisionAnswer=39002c770cbd RoomEvent=5bd4df78ed84 Shared=c981cf6aa860 SharedAskedBy=c9b30cc4d0d0 StepAccept=18efeefb6c34 StepEnded=edd08ab1a18b StepEndedEvent=207787118dac StepProgressEvent=8215e490ea8d StepRun=b975f402601a UpgradeAnswer=7538f2f5e68e ValidateAnswer=484ec1cfda14 ValidateAnswerProblemsItem=728518b4dc83 Wait=951500be820c WaitEndedEvent=2bf6d38041c0 WaitHeldEvent=2bf6d38041c0 WantedEvent=fba5f15bf46d WantsByHeldModuleFingerprintValue=ff14aa998a5d WantsByWantNodeModuleValue=ab7c6799fd5d WantsByWantNodeNodeValue=a737a2108d53"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -35,6 +35,9 @@ const (
|
||||
VerbValidate = "validate"
|
||||
VerbKeepNow = "keep-now"
|
||||
VerbDrop = "drop"
|
||||
VerbOwed = "owed"
|
||||
VerbOwedSay = "owed-say"
|
||||
VerbOwedDrop = "owed-drop"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -59,7 +62,7 @@ const (
|
||||
|
||||
// Verbs is every verb the seat serves, in its definition's order: a new copy each call.
|
||||
func Verbs() []string {
|
||||
return []string{VerbUpgrade, VerbBus, VerbRevision, VerbEntry, VerbDifference, VerbInput, VerbCompositions, VerbCompositionsDrop, VerbValidate, VerbKeepNow, VerbDrop}
|
||||
return []string{VerbUpgrade, VerbBus, VerbRevision, VerbEntry, VerbDifference, VerbInput, VerbCompositions, VerbCompositionsDrop, VerbValidate, VerbKeepNow, VerbDrop, VerbOwed, VerbOwedSay, VerbOwedDrop}
|
||||
}
|
||||
|
||||
// VerbDescription is a verb's description as the seat's definition says it, "" for a verb the seat does not serve or
|
||||
@@ -88,6 +91,12 @@ func VerbDescription(verb string) string {
|
||||
return "Keep the assignment graph's revisions now, by hand (design 47 H2 §813 (2); H-A-417): written in the hand-act log first by the module's tool assigner_keep_now, then the keeping runs at once on the pass's newest computed revision; answers the revision kept, or the fault the keeping met."
|
||||
case VerbDrop:
|
||||
return "End an ask on the seat's work queue for a caller that no longer waits for it (its step ended by its bound): one waiting is ended dropped when it is pulled, one taken is cancelled; both end the step could-not-run, its why naming the drop and who asked it, so no holder works on it after (design 47 H2 §778; ADR 0664 §4)."
|
||||
case VerbOwed:
|
||||
return "Every event the assigner says on this seat that the bus refused or did not acknowledge and still owes (design 47 H2b §832 6.): its message id, when it was first owed, how many times it was said again and when it is said again next."
|
||||
case VerbOwedSay:
|
||||
return "Say the first owed event of one id's order now, its delay set back to the first pace (design 47 H2b §832 6.)."
|
||||
case VerbOwedDrop:
|
||||
return "Drop an owed event the bus will never take, with every event owed behind it in its order, doing for each what the bus taking it would have done, then clear its finding (design 47 H2b §832 6.); the act and why are written in the hand-act log first."
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -991,7 +1000,19 @@ type NotRunning struct {
|
||||
Module string `json:"module"`
|
||||
}
|
||||
|
||||
// PipelineWanted is a pipeline's wants written to the end, said once: running when every tier's movers run on every present placing machine, tier-late when a tier passed tier-bound (design 47 H §751, H-A-56, H-A-72, H-A-75).
|
||||
// OwedEvent is an event the assigner says on this seat that the bus refused or did not acknowledge, owed in order and said again under the same id (design 47 H2b section 832 1., 2.).
|
||||
type OwedEvent struct {
|
||||
// when the event was first owed
|
||||
FirstOwed time.Time `json:"first-owed"`
|
||||
// the event's message id, fixed when it was first owed
|
||||
ID string `json:"id"`
|
||||
// when it is said again
|
||||
Next time.Time `json:"next"`
|
||||
// how many times the assigner said it again
|
||||
Tries int64 `json:"tries"`
|
||||
}
|
||||
|
||||
// PipelineWanted is a pipeline's wants written to the end, said at most twice, tier-late then running: running when every tier's movers run on every present placing machine, tier-late when a tier passed tier-bound (design 47 H §751, H-A-56, H-A-72, H-A-75).
|
||||
type PipelineWanted struct {
|
||||
Branch string `json:"branch"`
|
||||
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
|
||||
@@ -1373,6 +1394,47 @@ type DropInput struct {
|
||||
// DropAnswer is what drop answers.
|
||||
type DropAnswer = map[string]any
|
||||
|
||||
// OwedInput is what owed takes.
|
||||
type OwedInput struct {
|
||||
}
|
||||
|
||||
// OwedAnswer is what owed answers.
|
||||
type OwedAnswer struct {
|
||||
Events []OwedEvent `json:"events"`
|
||||
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
|
||||
Form int64 `json:"form,omitempty"`
|
||||
}
|
||||
|
||||
// OwedSayInput is what owed-say takes.
|
||||
type OwedSayInput struct {
|
||||
// the owed event's message id
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
// OwedSayAnswer is what owed-say answers.
|
||||
type OwedSayAnswer struct {
|
||||
// the event said
|
||||
Event OwedEvent `json:"event"`
|
||||
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
|
||||
Form int64 `json:"form,omitempty"`
|
||||
}
|
||||
|
||||
// OwedDropInput is what owed-drop takes.
|
||||
type OwedDropInput struct {
|
||||
// the owed event's message id
|
||||
ID string `json:"id"`
|
||||
// why, written with the caller the runtime proves in the hand-act log
|
||||
Why string `json:"why"`
|
||||
}
|
||||
|
||||
// OwedDropAnswer is what owed-drop answers.
|
||||
type OwedDropAnswer struct {
|
||||
// the events dropped, the named one first
|
||||
Dropped []OwedEvent `json:"dropped"`
|
||||
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
|
||||
Form int64 `json:"form,omitempty"`
|
||||
}
|
||||
|
||||
// StepAccept is the body of step.
|
||||
type StepAccept = StepRun
|
||||
|
||||
@@ -1424,6 +1486,8 @@ type WantedEvent struct {
|
||||
Revision int64 `json:"revision"`
|
||||
Source int64 `json:"source,omitempty"`
|
||||
V int64 `json:"v"`
|
||||
// the revision of the want's key in the state wants that the event says; for a removal, of the write it removes (design 47 H section 832 3.)
|
||||
WantRevision int64 `json:"want-revision,omitempty"`
|
||||
}
|
||||
|
||||
// PipelineWantedEvent is the body of the event pipeline-wanted.
|
||||
@@ -1698,6 +1762,33 @@ func DecodeDropAnswer(raw []byte) (DropAnswer, int, error) {
|
||||
return v, formRead(raw), nil
|
||||
}
|
||||
|
||||
// DecodeOwedAnswer reads a OwedAnswer as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
|
||||
func DecodeOwedAnswer(raw []byte) (OwedAnswer, int, error) {
|
||||
var v OwedAnswer
|
||||
if err := json.Unmarshal(raw, &v); err != nil {
|
||||
return v, 0, err
|
||||
}
|
||||
return v, formRead(raw), nil
|
||||
}
|
||||
|
||||
// DecodeOwedSayAnswer reads a OwedSayAnswer as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
|
||||
func DecodeOwedSayAnswer(raw []byte) (OwedSayAnswer, int, error) {
|
||||
var v OwedSayAnswer
|
||||
if err := json.Unmarshal(raw, &v); err != nil {
|
||||
return v, 0, err
|
||||
}
|
||||
return v, formRead(raw), nil
|
||||
}
|
||||
|
||||
// DecodeOwedDropAnswer reads a OwedDropAnswer as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
|
||||
func DecodeOwedDropAnswer(raw []byte) (OwedDropAnswer, int, error) {
|
||||
var v OwedDropAnswer
|
||||
if err := json.Unmarshal(raw, &v); err != nil {
|
||||
return v, 0, err
|
||||
}
|
||||
return v, formRead(raw), nil
|
||||
}
|
||||
|
||||
// DecodePolicyChangedEvent reads a PolicyChangedEvent as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
|
||||
func DecodePolicyChangedEvent(raw []byte) (PolicyChangedEvent, int, error) {
|
||||
var v PolicyChangedEvent
|
||||
|
||||
@@ -25,9 +25,11 @@ func TestFixtures(t *testing.T) {
|
||||
}, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-wants\\.event\\.assignment-revision$")},
|
||||
{name: "a difference worked out", subject: "mesh.seat.mesh-wants.event.difference", given: "{\"changes\":1,\"from\":40,\"nodes\":[\"n1\"],\"source\":3589,\"to\":41,\"v\":1}", wire: "{\"changes\":1,\"from\":40,\"nodes\":[\"n1\"],\"source\":3589,\"to\":41,\"v\":1}",
|
||||
decode: func(b []byte) (any, error) { var v DifferenceEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-wants\\.event\\.difference$")},
|
||||
{name: "an entry wanted from a passed pipeline, naming it", subject: "mesh.seat.mesh-wants.event.wanted.n1.xclip", given: "{\"at\":\"2026-11-09T19:00:00Z\",\"fp\":\"src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56\",\"module\":\"xclip\",\"node\":\"n1\",\"pipeline\":\"main.3589\",\"revision\":40,\"source\":3589,\"v\":1}", wire: "{\"at\":\"2026-11-09T19:00:00Z\",\"fp\":\"src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56\",\"module\":\"xclip\",\"node\":\"n1\",\"pipeline\":\"main.3589\",\"revision\":40,\"source\":3589,\"v\":1}",
|
||||
{name: "an entry wanted from a passed pipeline, naming it", subject: "mesh.seat.mesh-wants.event.wanted.n1.xclip", given: "{\"at\":\"2026-11-09T19:00:00Z\",\"fp\":\"src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56\",\"module\":\"xclip\",\"node\":\"n1\",\"pipeline\":\"main.3589\",\"revision\":40,\"source\":3589,\"v\":1,\"want-revision\":7}", wire: "{\"at\":\"2026-11-09T19:00:00Z\",\"fp\":\"src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56\",\"module\":\"xclip\",\"node\":\"n1\",\"pipeline\":\"main.3589\",\"revision\":40,\"source\":3589,\"v\":1,\"want-revision\":7}",
|
||||
decode: func(b []byte) (any, error) { var v WantedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-wants\\.event\\.wanted\\.[^.*> ]+\\.[^.*> ]+$")},
|
||||
{name: "a want removed, its node left or its module unplaced", subject: "mesh.seat.mesh-wants.event.wanted.n1.xclip", given: "{\"at\":\"2026-11-09T19:05:00Z\",\"fp\":\"src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56\",\"module\":\"xclip\",\"node\":\"n1\",\"removed\":true,\"revision\":41,\"v\":1}", wire: "{\"at\":\"2026-11-09T19:05:00Z\",\"fp\":\"src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56\",\"module\":\"xclip\",\"node\":\"n1\",\"removed\":true,\"revision\":41,\"v\":1}",
|
||||
{name: "a want written before want-revision, carrying none", subject: "mesh.seat.mesh-wants.event.wanted.n1.xclip", given: "{\"at\":\"2026-11-09T19:00:00Z\",\"fp\":\"src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56\",\"module\":\"xclip\",\"node\":\"n1\",\"pipeline\":\"main.3589\",\"revision\":40,\"source\":3589,\"v\":1}", wire: "{\"at\":\"2026-11-09T19:00:00Z\",\"fp\":\"src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56\",\"module\":\"xclip\",\"node\":\"n1\",\"pipeline\":\"main.3589\",\"revision\":40,\"source\":3589,\"v\":1}",
|
||||
decode: func(b []byte) (any, error) { var v WantedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-wants\\.event\\.wanted\\.[^.*> ]+\\.[^.*> ]+$")},
|
||||
{name: "a want removed, its node left or its module unplaced", subject: "mesh.seat.mesh-wants.event.wanted.n1.xclip", given: "{\"at\":\"2026-11-09T19:05:00Z\",\"fp\":\"src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56\",\"module\":\"xclip\",\"node\":\"n1\",\"removed\":true,\"revision\":41,\"v\":1,\"want-revision\":8}", wire: "{\"at\":\"2026-11-09T19:05:00Z\",\"fp\":\"src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56\",\"module\":\"xclip\",\"node\":\"n1\",\"removed\":true,\"revision\":41,\"v\":1,\"want-revision\":8}",
|
||||
decode: func(b []byte) (any, error) { var v WantedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-wants\\.event\\.wanted\\.[^.*> ]+\\.[^.*> ]+$")},
|
||||
{name: "a pipeline's wants all run", subject: "mesh.seat.mesh-wants.event.pipeline-wanted.main.3590", given: "{\"branch\":\"main\",\"outcome\":\"running\",\"pipeline\":\"main.3590\",\"revision\":3590,\"source\":3589,\"v\":1}", wire: "{\"branch\":\"main\",\"outcome\":\"running\",\"pipeline\":\"main.3590\",\"revision\":3590,\"source\":3589,\"v\":1}",
|
||||
decode: func(b []byte) (any, error) { var v PipelineWantedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-wants\\.event\\.pipeline-wanted\\.[^.*> ]+\\.[^.*> ]+$")},
|
||||
@@ -169,6 +171,18 @@ func TestFixtures(t *testing.T) {
|
||||
decode: func(b []byte) (any, error) { var v ValidateAnswer; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
{name: "validate answers a run still running", subject: "", given: "{\"outcome\":\"running\",\"started\":\"2026-11-25T17:00:00Z\"}", wire: "{\"outcome\":\"running\",\"started\":\"2026-11-25T17:00:00Z\"}",
|
||||
decode: func(b []byte) (any, error) { var v ValidateAnswer; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
{name: "owed asks every owed event", subject: "", given: "{}", wire: "{}",
|
||||
decode: func(b []byte) (any, error) { var v OwedInput; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
{name: "owed answers each owed event with its first-owed, tries and next", subject: "", given: "{\"events\":[{\"first-owed\":\"2026-11-27T10:00:05Z\",\"id\":\"wait-ended.n1.xclip.3b9f.ended.released.2026-11-27T10:00:00Z\",\"next\":\"2026-11-27T10:00:13Z\",\"tries\":2}]}", wire: "{\"events\":[{\"first-owed\":\"2026-11-27T10:00:05Z\",\"id\":\"wait-ended.n1.xclip.3b9f.ended.released.2026-11-27T10:00:00Z\",\"next\":\"2026-11-27T10:00:13Z\",\"tries\":2}]}",
|
||||
decode: func(b []byte) (any, error) { var v OwedAnswer; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
{name: "owed-say takes an id", subject: "", given: "{\"id\":\"wait-ended.n1.xclip.3b9f.ended.released.2026-11-27T10:00:00Z\"}", wire: "{\"id\":\"wait-ended.n1.xclip.3b9f.ended.released.2026-11-27T10:00:00Z\"}",
|
||||
decode: func(b []byte) (any, error) { var v OwedSayInput; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
{name: "owed-say answers the event said", subject: "", given: "{\"event\":{\"first-owed\":\"2026-11-27T10:00:05Z\",\"id\":\"wait-ended.n1.xclip.3b9f.ended.released.2026-11-27T10:00:00Z\",\"next\":\"2026-11-27T10:00:13Z\",\"tries\":2}}", wire: "{\"event\":{\"first-owed\":\"2026-11-27T10:00:05Z\",\"id\":\"wait-ended.n1.xclip.3b9f.ended.released.2026-11-27T10:00:00Z\",\"next\":\"2026-11-27T10:00:13Z\",\"tries\":2}}",
|
||||
decode: func(b []byte) (any, error) { var v OwedSayAnswer; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
{name: "owed-drop takes an id and why", subject: "", given: "{\"id\":\"wait-ended.n1.xclip.3b9f.ended.released.2026-11-27T10:00:00Z\",\"why\":\"the bus will never take it\"}", wire: "{\"id\":\"wait-ended.n1.xclip.3b9f.ended.released.2026-11-27T10:00:00Z\",\"why\":\"the bus will never take it\"}",
|
||||
decode: func(b []byte) (any, error) { var v OwedDropInput; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
{name: "owed-drop answers the events dropped", subject: "", given: "{\"dropped\":[{\"first-owed\":\"2026-11-27T10:00:05Z\",\"id\":\"wait-ended.n1.xclip.3b9f.ended.released.2026-11-27T10:00:00Z\",\"next\":\"2026-11-27T10:00:13Z\",\"tries\":2}]}", wire: "{\"dropped\":[{\"first-owed\":\"2026-11-27T10:00:05Z\",\"id\":\"wait-ended.n1.xclip.3b9f.ended.released.2026-11-27T10:00:00Z\",\"next\":\"2026-11-27T10:00:13Z\",\"tries\":2}]}",
|
||||
decode: func(b []byte) (any, error) { var v OwedDropAnswer; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
}
|
||||
for _, c := range cases {
|
||||
v, err := c.decode([]byte(c.given))
|
||||
|
||||
@@ -37,6 +37,22 @@
|
||||
"name": "an entry wanted from a passed pipeline, naming it",
|
||||
"of": "event:wanted",
|
||||
"subject": "mesh.seat.mesh-wants.event.wanted.n1.xclip",
|
||||
"given": {
|
||||
"v": 1,
|
||||
"node": "n1",
|
||||
"module": "xclip",
|
||||
"fp": "src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56",
|
||||
"revision": 40,
|
||||
"source": 3589,
|
||||
"at": "2026-11-09T19:00:00Z",
|
||||
"pipeline": "main.3589",
|
||||
"want-revision": 7
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "a want written before want-revision, carrying none",
|
||||
"of": "event:wanted",
|
||||
"subject": "mesh.seat.mesh-wants.event.wanted.n1.xclip",
|
||||
"given": {
|
||||
"v": 1,
|
||||
"node": "n1",
|
||||
@@ -59,7 +75,8 @@
|
||||
"fp": "src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56",
|
||||
"revision": 41,
|
||||
"removed": true,
|
||||
"at": "2026-11-09T19:05:00Z"
|
||||
"at": "2026-11-09T19:05:00Z",
|
||||
"want-revision": 8
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -328,5 +328,65 @@
|
||||
"outcome": "running",
|
||||
"started": "2026-11-25T17:00:00Z"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "owed asks every owed event",
|
||||
"of": "verb:owed.input",
|
||||
"given": {}
|
||||
},
|
||||
{
|
||||
"name": "owed answers each owed event with its first-owed, tries and next",
|
||||
"of": "verb:owed.answer",
|
||||
"given": {
|
||||
"events": [
|
||||
{
|
||||
"id": "wait-ended.n1.xclip.3b9f.ended.released.2026-11-27T10:00:00Z",
|
||||
"first-owed": "2026-11-27T10:00:05Z",
|
||||
"tries": 2,
|
||||
"next": "2026-11-27T10:00:13Z"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "owed-say takes an id",
|
||||
"of": "verb:owed-say.input",
|
||||
"given": {
|
||||
"id": "wait-ended.n1.xclip.3b9f.ended.released.2026-11-27T10:00:00Z"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "owed-say answers the event said",
|
||||
"of": "verb:owed-say.answer",
|
||||
"given": {
|
||||
"event": {
|
||||
"id": "wait-ended.n1.xclip.3b9f.ended.released.2026-11-27T10:00:00Z",
|
||||
"first-owed": "2026-11-27T10:00:05Z",
|
||||
"tries": 2,
|
||||
"next": "2026-11-27T10:00:13Z"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "owed-drop takes an id and why",
|
||||
"of": "verb:owed-drop.input",
|
||||
"given": {
|
||||
"id": "wait-ended.n1.xclip.3b9f.ended.released.2026-11-27T10:00:00Z",
|
||||
"why": "the bus will never take it"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "owed-drop answers the events dropped",
|
||||
"of": "verb:owed-drop.answer",
|
||||
"given": {
|
||||
"dropped": [
|
||||
{
|
||||
"id": "wait-ended.n1.xclip.3b9f.ended.released.2026-11-27T10:00:00Z",
|
||||
"first-owed": "2026-11-27T10:00:05Z",
|
||||
"tries": 2,
|
||||
"next": "2026-11-27T10:00:13Z"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@@ -437,6 +437,95 @@
|
||||
"description": "whether the ask was held here"
|
||||
},
|
||||
"class": "act"
|
||||
},
|
||||
{
|
||||
"name": "owed",
|
||||
"class": "read",
|
||||
"description": "Every event the assigner says on this seat that the bus refused or did not acknowledge and still owes (design 47 H2b §832 6.): its message id, when it was first owed, how many times it was said again and when it is said again next.",
|
||||
"input": {
|
||||
"type": "object",
|
||||
"properties": {}
|
||||
},
|
||||
"answer": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"events": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/defs/OwedEvent"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"events"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "owed-say",
|
||||
"class": "act",
|
||||
"description": "Say the first owed event of one id's order now, its delay set back to the first pace (design 47 H2b §832 6.).",
|
||||
"input": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string",
|
||||
"description": "the owed event's message id"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"answer": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"event": {
|
||||
"$ref": "#/defs/OwedEvent",
|
||||
"description": "the event said"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"event"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "owed-drop",
|
||||
"class": "act",
|
||||
"description": "Drop an owed event the bus will never take, with every event owed behind it in its order, doing for each what the bus taking it would have done, then clear its finding (design 47 H2b §832 6.); the act and why are written in the hand-act log first.",
|
||||
"input": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string",
|
||||
"description": "the owed event's message id"
|
||||
},
|
||||
"why": {
|
||||
"type": "string",
|
||||
"description": "why, written with the caller the runtime proves in the hand-act log"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"why"
|
||||
]
|
||||
},
|
||||
"answer": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"dropped": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/defs/OwedEvent"
|
||||
},
|
||||
"description": "the events dropped, the named one first"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"dropped"
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"accepts": [
|
||||
@@ -578,6 +667,10 @@
|
||||
"revision": {
|
||||
"type": "integer"
|
||||
},
|
||||
"want-revision": {
|
||||
"type": "integer",
|
||||
"description": "the revision of the want's key in the state wants that the event says; for a removal, of the write it removes (design 47 H section 832 3.)"
|
||||
},
|
||||
"source": {
|
||||
"type": "integer"
|
||||
},
|
||||
@@ -1941,7 +2034,7 @@
|
||||
},
|
||||
"PipelineWanted": {
|
||||
"type": "object",
|
||||
"description": "a pipeline's wants written to the end, said once: running when every tier's movers run on every present placing machine, tier-late when a tier passed tier-bound (design 47 H §751, H-A-56, H-A-72, H-A-75)",
|
||||
"description": "a pipeline's wants written to the end, said at most twice, tier-late then running: running when every tier's movers run on every present placing machine, tier-late when a tier passed tier-bound (design 47 H §751, H-A-56, H-A-72, H-A-75)",
|
||||
"properties": {
|
||||
"v": {
|
||||
"type": "integer"
|
||||
@@ -2002,6 +2095,36 @@
|
||||
"module",
|
||||
"machines"
|
||||
]
|
||||
},
|
||||
"OwedEvent": {
|
||||
"type": "object",
|
||||
"description": "an event the assigner says on this seat that the bus refused or did not acknowledge, owed in order and said again under the same id (design 47 H2b section 832 1., 2.)",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string",
|
||||
"description": "the event's message id, fixed when it was first owed"
|
||||
},
|
||||
"first-owed": {
|
||||
"type": "string",
|
||||
"format": "date-time",
|
||||
"description": "when the event was first owed"
|
||||
},
|
||||
"tries": {
|
||||
"type": "integer",
|
||||
"description": "how many times the assigner said it again"
|
||||
},
|
||||
"next": {
|
||||
"type": "string",
|
||||
"format": "date-time",
|
||||
"description": "when it is said again"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"first-owed",
|
||||
"tries",
|
||||
"next"
|
||||
]
|
||||
}
|
||||
},
|
||||
"acts": [
|
||||
|
||||
@@ -16,6 +16,9 @@ export declare const verbs: {
|
||||
readonly validate: "validate";
|
||||
readonly keepNow: "keep-now";
|
||||
readonly drop: "drop";
|
||||
readonly owed: "owed";
|
||||
readonly owedSay: "owed-say";
|
||||
readonly owedDrop: "owed-drop";
|
||||
};
|
||||
|
||||
export declare const accepts: {
|
||||
@@ -436,7 +439,19 @@ export interface NotRunning {
|
||||
"module": string;
|
||||
}
|
||||
|
||||
/** a pipeline's wants written to the end, said once: running when every tier's movers run on every present placing machine, tier-late when a tier passed tier-bound (design 47 H §751, H-A-56, H-A-72, H-A-75) */
|
||||
/** an event the assigner says on this seat that the bus refused or did not acknowledge, owed in order and said again under the same id (design 47 H2b section 832 1., 2.) */
|
||||
export interface OwedEvent {
|
||||
/** when the event was first owed */
|
||||
"first-owed": string;
|
||||
/** the event's message id, fixed when it was first owed */
|
||||
"id": string;
|
||||
/** when it is said again */
|
||||
"next": string;
|
||||
/** how many times the assigner said it again */
|
||||
"tries": number;
|
||||
}
|
||||
|
||||
/** a pipeline's wants written to the end, said at most twice, tier-late then running: running when every tier's movers run on every present placing machine, tier-late when a tier passed tier-bound (design 47 H §751, H-A-56, H-A-72, H-A-75) */
|
||||
export interface PipelineWanted {
|
||||
"branch": string;
|
||||
/** is the form of what this value carries, left out while it is 1 (design 47 H2 §780). */
|
||||
@@ -754,6 +769,47 @@ export interface DropInput {
|
||||
/** is what drop answers. */
|
||||
export type DropAnswer = Record<string, unknown>;
|
||||
|
||||
/** is what owed takes. */
|
||||
export interface OwedInput {
|
||||
}
|
||||
|
||||
/** is what owed answers. */
|
||||
export interface OwedAnswer {
|
||||
"events": OwedEvent[];
|
||||
/** is the form of what this value carries, left out while it is 1 (design 47 H2 §780). */
|
||||
"form"?: number;
|
||||
}
|
||||
|
||||
/** is what owed-say takes. */
|
||||
export interface OwedSayInput {
|
||||
/** the owed event's message id */
|
||||
"id": string;
|
||||
}
|
||||
|
||||
/** is what owed-say answers. */
|
||||
export interface OwedSayAnswer {
|
||||
/** the event said */
|
||||
"event": OwedEvent;
|
||||
/** is the form of what this value carries, left out while it is 1 (design 47 H2 §780). */
|
||||
"form"?: number;
|
||||
}
|
||||
|
||||
/** is what owed-drop takes. */
|
||||
export interface OwedDropInput {
|
||||
/** the owed event's message id */
|
||||
"id": string;
|
||||
/** why, written with the caller the runtime proves in the hand-act log */
|
||||
"why": string;
|
||||
}
|
||||
|
||||
/** is what owed-drop answers. */
|
||||
export interface OwedDropAnswer {
|
||||
/** the events dropped, the named one first */
|
||||
"dropped": OwedEvent[];
|
||||
/** is the form of what this value carries, left out while it is 1 (design 47 H2 §780). */
|
||||
"form"?: number;
|
||||
}
|
||||
|
||||
/** is the body of step. */
|
||||
export type StepAccept = StepRun;
|
||||
|
||||
@@ -805,6 +861,8 @@ export interface WantedEvent {
|
||||
"revision": number;
|
||||
"source"?: number;
|
||||
"v": number;
|
||||
/** the revision of the want's key in the state wants that the event says; for a removal, of the write it removes (design 47 H section 832 3.) */
|
||||
"want-revision"?: number;
|
||||
}
|
||||
|
||||
/** is the body of the event pipeline-wanted. */
|
||||
|
||||
@@ -16,6 +16,9 @@ export const verbs = {
|
||||
validate: "validate",
|
||||
keepNow: "keep-now",
|
||||
drop: "drop",
|
||||
owed: "owed",
|
||||
owedSay: "owed-say",
|
||||
owedDrop: "owed-drop",
|
||||
};
|
||||
|
||||
export const accepts = {
|
||||
|
||||
@@ -68,6 +68,7 @@ accounts {
|
||||
"$KV.mod_mesh-delivery-forge-bridge_performed_b1.>"
|
||||
"$KV.mod_mesh-delivery-forge-bridge_findings_b1.>"
|
||||
"$JS.API.STREAM.NAMES"
|
||||
"$JS.API.STREAM.INFO.EVENTS"
|
||||
"$JS.API.CONSUMER.CREATE.EVENTS"
|
||||
"$JS.API.CONSUMER.CREATE.EVENTS.>"
|
||||
"$JS.API.CONSUMER.DELETE.EVENTS.>"
|
||||
@@ -126,6 +127,7 @@ accounts {
|
||||
"mesh.assignment.n1.mesh-delivery-forge-bridge"
|
||||
"mesh.mod.mesh-delivery-forge-bridge.call.>"
|
||||
"mesh.mod.mesh-delivery-forge-bridge.tool.>"
|
||||
"mesh.seat.mesh-grants.event.durables-composed.n1.mesh-delivery-forge-bridge"
|
||||
] }
|
||||
allow_responses: true
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
|
||||
"mesh-delivery-indexer/internal/index"
|
||||
@@ -21,6 +22,8 @@ type entryAnswer struct {
|
||||
Paths map[string][]string `json:"paths"`
|
||||
Fp string `json:"fp,omitempty"`
|
||||
ManifestDigest string `json:"manifest-digest,omitempty"`
|
||||
// the entry's edges, each with its kind, the word it comes from and why (design 47 H §870, H-A-851)
|
||||
Edges []meshcatalog.Edge `json:"edges,omitempty"`
|
||||
}
|
||||
|
||||
// entryReadTool is indexer_entry (H-A-204; tools-are-how-a-module-is-spoken-to) over the indexer's catalog-revisions objects:
|
||||
@@ -29,8 +32,8 @@ type entryAnswer struct {
|
||||
func entryReadTool(o index.Objects) stdio.Tool {
|
||||
return stdio.Tool{Name: index.EntryPinsTool,
|
||||
Description: "Read one module's catalog graph entry pins: the packages it builds against with the version each is pinned to " +
|
||||
"(an empty version while none is published), the paths each artifact is built from, its fingerprint and its manifest " +
|
||||
"digest, at the newest trunk revision or at a trunk revision given; a small answer, for when the revision whole is too " +
|
||||
"(an empty version while none is published), the paths each artifact is built from, its fingerprint, its manifest " +
|
||||
"digest and its edges (kind, the word or event each comes from, why), at the newest trunk revision or at a trunk revision given; a small answer, for when the revision whole is too " +
|
||||
"large for the bus (H-A-204).",
|
||||
Input: map[string]any{"type": "object", "required": []string{"module"}, "properties": map[string]any{
|
||||
"module": map[string]any{"type": "string", "description": "the module whose entry is read"},
|
||||
@@ -50,7 +53,7 @@ func entryReadTool(o index.Objects) stdio.Tool {
|
||||
return nil, err
|
||||
}
|
||||
out := entryAnswer{Module: e.Module, Revision: rev.Revision, Packages: e.Packages, Paths: map[string][]string{},
|
||||
Fp: e.Fp, ManifestDigest: e.ManifestDigest}
|
||||
Fp: e.Fp, ManifestDigest: e.ManifestDigest, Edges: e.Edges}
|
||||
if out.Packages == nil {
|
||||
out.Packages = map[string]string{}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,11 @@ func TestEntryTool(t *testing.T) {
|
||||
Packages: map[string]string{"git.novox.be/novox/mesh-sdk/go": "v0.1.26"}}, meshcatalog.CatalogEntry{Module: "other", Fp: "src2:o"})
|
||||
keep(9, meshcatalog.CatalogEntry{Module: "mesh-grants", Fp: "src2:new", ManifestDigest: "sha256:b", Inputs: paths,
|
||||
Packages: map[string]string{"git.novox.be/novox/mesh-sdk/go": "v0.1.27", "busgrants": ""}})
|
||||
// 1984/AC-870d (H-A-838, H-A-851): the entry's word edge and event edge are answered with kind 6, their word and why.
|
||||
edges := []meshcatalog.Edge{
|
||||
{Kind: 6, From: "engine:program", To: "mesh-grants:program", Word: "word:build.artifacts.race", Why: "new at the revision: mesh-grants"},
|
||||
{Kind: 6, From: "emitter:program", To: "mesh-grants:program", Word: "emitter.made", Why: "new at the revision: emitter"}}
|
||||
keep(5, meshcatalog.CatalogEntry{Module: "mesh-grants", Fp: "src2:edges", Edges: edges})
|
||||
tool := entryReadTool(o)
|
||||
if tool.Name != "indexer_entry" {
|
||||
t.Fatalf("name %s", tool.Name)
|
||||
@@ -71,6 +76,8 @@ func TestEntryTool(t *testing.T) {
|
||||
Packages: map[string]string{"git.novox.be/novox/mesh-sdk/go": "v0.1.27", "busgrants": ""}, Paths: paths.Paths}, ""},
|
||||
{"given", map[string]any{"module": "mesh-grants", "revision": float64(7)}, entryAnswer{Module: "mesh-grants", Revision: 7, Fp: "src2:old", ManifestDigest: "sha256:a",
|
||||
Packages: map[string]string{"git.novox.be/novox/mesh-sdk/go": "v0.1.26"}, Paths: paths.Paths}, ""},
|
||||
{"edges", map[string]any{"module": "mesh-grants", "revision": float64(5)}, entryAnswer{Module: "mesh-grants", Revision: 5, Fp: "src2:edges",
|
||||
Packages: map[string]string{}, Paths: map[string][]string{}, Edges: edges}, ""},
|
||||
{"given as digits, no paths", map[string]any{"module": "other", "revision": "7"}, entryAnswer{Module: "other", Revision: 7, Fp: "src2:o",
|
||||
Packages: map[string]string{}, Paths: map[string][]string{}}, ""},
|
||||
{"not in the newest", map[string]any{"module": "other"}, entryAnswer{}, "holds no module other"},
|
||||
|
||||
@@ -655,14 +655,16 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
if err := registry.Restart(ctx); err != nil {
|
||||
logger.Printf("the open changes of the registrations are not all read again at the start: %v", err)
|
||||
}
|
||||
_ = notHeard.Bind(process.EventsStream, "no package's series moves, no warrant for a change of a registration is heard, no node's manifest-reads-changed and no assignments view is heard until the indexer starts again", func() error {
|
||||
if err := startHearing(ctx, hub, js, cred); err != nil {
|
||||
stopped = cmp.Or(stopped, err)
|
||||
return err
|
||||
}
|
||||
// Start's nil says the hub started, never that anything is heard (design 47 H2b §836 1., 4.; H-A-877): the shared events
|
||||
// stream is heard when the hub's unheard list names no entry of it, and not heard, with the hub's reason, when it does.
|
||||
const eventsConsequence = "no package's series moves, no warrant for a change of a registration is heard, no node's manifest-reads-changed and no assignments view is heard until the indexer starts again"
|
||||
hub.OnUnheard(markEventsHeard(notHeard, eventsConsequence))
|
||||
if err := startHearing(ctx, hub, js, cred); err != nil {
|
||||
stopped = cmp.Or(stopped, err)
|
||||
notHeard.NotHeard(process.EventsStream, eventsConsequence, err)
|
||||
} else {
|
||||
go func() { <-ctx.Done(); hub.Stop() }()
|
||||
return nil
|
||||
})
|
||||
}
|
||||
hearNamed(ctx, js, cred, notHeard, named, logger.Printf)
|
||||
hearRuns(ctx, js, cred, notHeard, ix, logger.Printf)
|
||||
// The consumer of every branch the registrations watch, bound now, and of a newly watched one on the indexer's own
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient/heard"
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
"git.novox.be/novox/mesh-sdk/go/views"
|
||||
|
||||
@@ -107,19 +108,14 @@ func ptr[T any](v T) *T { return &v }
|
||||
// noWire is a finding writer that is none: a non-nil WireWriter for the test of which emitter is made.
|
||||
type noWire struct{ views.WireWriter }
|
||||
|
||||
// startedHub records which of an event hub's starts were asked.
|
||||
// startedHub is an event hub whose Start answers startErr.
|
||||
type startedHub struct {
|
||||
startErr error
|
||||
kept bool
|
||||
}
|
||||
|
||||
func (h *startedHub) Start(context.Context, jetstream.JetStream, process.Account) error {
|
||||
return h.startErr
|
||||
}
|
||||
func (h *startedHub) StartKept(context.Context, jetstream.JetStream, process.Account) int {
|
||||
h.kept = true
|
||||
return 1
|
||||
}
|
||||
|
||||
// H-A-578 (2): an event of a subject the indexer no longer consumes is acknowledged with no work, and the journal says
|
||||
// the subject once, at the first.
|
||||
@@ -135,4 +131,25 @@ func TestASubjectNoLongerConsumedIsAcknowledgedAndSaidOnce(t *testing.T) {
|
||||
if first.acked != 1 || second.acked != 1 || len(said) != 1 || !strings.Contains(said[0], droppedSubjects[0]) {
|
||||
t.Errorf("acked %d and %d, said %q; want both acknowledged and the subject said once", first.acked, second.acked, said)
|
||||
}
|
||||
// H-A-877: the shared events stream is heard when the hub's unheard list names none of it, and not heard, with the hub's
|
||||
// reason, when it does; Start's nil says neither.
|
||||
t.Run("the events stream is marked from the hub's unheard list", func(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
list []process.Unheard
|
||||
put, dele int
|
||||
}{
|
||||
{"no entry of EVENTS", []process.Unheard{{Pattern: "a", Stream: "SEAT_x", Why: "no durable"}}, 0, 1},
|
||||
{"an empty list", nil, 0, 1},
|
||||
{"EVENTS named", []process.Unheard{{Pattern: "a", Stream: process.EventsStream, Why: "no durable"}}, 1, 0},
|
||||
} {
|
||||
var put, dele int
|
||||
w := heard.Writer{Observer: "m", Logf: func(string, ...any) {},
|
||||
Put: func(string, []byte) error { put++; return nil }, Delete: func(string) error { dele++; return nil }}
|
||||
markEventsHeard(w, "consequence")(c.list)
|
||||
if put != c.put || dele != c.dele {
|
||||
t.Errorf("%s: wrote %d and deleted %d findings, want %d and %d", c.name, put, dele, c.put, c.dele)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/nats-io/nats.go"
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient/heard"
|
||||
"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/meshcatalog"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
|
||||
@@ -46,19 +47,27 @@ func sayVersionReleased(conn *nats.Conn, cred process.Account) func(context.Cont
|
||||
// hubStarter is the event hub as startHearing starts it.
|
||||
type hubStarter interface {
|
||||
Start(ctx context.Context, js jetstream.JetStream, cred process.Account) error
|
||||
StartKept(ctx context.Context, js jetstream.JetStream, cred process.Account) int
|
||||
}
|
||||
|
||||
// startHearing binds the indexer's durable on the shared events stream and then, beside it, its durable on each kept seat
|
||||
// event's own stream (SEAT_<seat>_<event>) whose event it handles: package-published and the build seats'
|
||||
// step-ended are never on EVENTS, and its tool runner reads only its own twin there, so the program hears them only so
|
||||
// (design 47 G A-397; mesh-sdk process.EventHub.StartKept).
|
||||
// startHearing starts the event hub once: its Start binds the indexer's durable on the shared events stream and, beside it, its
|
||||
// durable on each kept seat event's own stream (SEAT_<seat>_<event>) whose event it handles, package-published and the build
|
||||
// seats' step-ended being never on EVENTS (design 47 H2b §836 1.; mesh-sdk process.EventHub.Start).
|
||||
func startHearing(ctx context.Context, hub hubStarter, js jetstream.JetStream, cred process.Account) error {
|
||||
if err := hub.Start(ctx, js, cred); err != nil {
|
||||
return err
|
||||
return hub.Start(ctx, js, cred)
|
||||
}
|
||||
|
||||
// markEventsHeard is the hub's OnUnheard hook for the shared events stream (design 47 H2b §836 1., 4.; H-A-877): the stream is
|
||||
// heard when the list names no entry of it, and not heard, with the hub's reason, when it names one.
|
||||
func markEventsHeard(w heard.Writer, consequence string) func([]process.Unheard) {
|
||||
return func(list []process.Unheard) {
|
||||
for _, u := range list {
|
||||
if u.Stream == process.EventsStream {
|
||||
w.NotHeard(process.EventsStream, consequence, errors.New(u.Why))
|
||||
return
|
||||
}
|
||||
}
|
||||
w.Heard(process.EventsStream)
|
||||
}
|
||||
hub.StartKept(ctx, js, cred)
|
||||
return nil
|
||||
}
|
||||
|
||||
// EventDeliveries is how many times the bus gives a message of the indexer's events consumer: the MaxDeliver the grants part
|
||||
|
||||
@@ -152,4 +152,40 @@ func TestAHigherNeedsRulesDerivesTheUnmovedEntriesNeedsAgain(t *testing.T) {
|
||||
if needs, _ := needsOf(2); !slices.Equal(needs, []string{"word:module"}) {
|
||||
t.Errorf("a take-in at unchanged rules derived needs again: %v", needs)
|
||||
}
|
||||
t.Run("a take-in keeps the word edges new against its base (design 47 H2b §870)", rowATakeInKeepsTheWordEdgesNewAgainstItsBase)
|
||||
}
|
||||
|
||||
// Design 47 H §870 (1984/AC-870a): a take-in writes the word edge into the revision it keeps, against its base revision: the
|
||||
// word new at the second take-in orders its mover after the node-engine mover, the one the first take-in named gets none.
|
||||
func rowATakeInKeepsTheWordEdgesNewAgainstItsBase(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ix := &Indexer{Module: testSelf, Revisions: newMemObjects(1 << 20)}
|
||||
engine := wordEntry("engine", map[string]any{"claims": []any{map[string]any{"name": "node-engine"}}}, nil, nil)
|
||||
app := wordEntry("app", map[string]any{}, []string{"word:settings"}, nil)
|
||||
mv := []meshcatalog.TakeInEntry{{Module: "engine"}, {Module: "app"}}
|
||||
if err := ix.KeepBranchEntries(ctx, "main", 1, map[string]meshcatalog.CatalogEntry{"engine": engine, "app": app}, mv); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
app.Needs = []string{"word:settings", "word:build.artifacts.race"}
|
||||
if err := ix.KeepBranchEntries(ctx, "main", 2, map[string]meshcatalog.CatalogEntry{"engine": engine, "app": app}, mv); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
a, err := Revision(ctx, ix.Revisions, nil, meshcatalog.RevisionInput{Branch: "main", Source: 2})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, e := range a.Entries {
|
||||
if e.Module != "app" {
|
||||
continue
|
||||
}
|
||||
var words []string
|
||||
for _, x := range e.Edges {
|
||||
if x.Kind == 6 {
|
||||
words = append(words, x.Word)
|
||||
}
|
||||
}
|
||||
if !slices.Equal(words, []string{"word:build.artifacts.race"}) {
|
||||
t.Errorf("app holds the word edges %v, want only the one new at the base", words)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ import (
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/graph"
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatdef"
|
||||
|
||||
"mesh-delivery-indexer/judge"
|
||||
)
|
||||
|
||||
// The edges of a catalog graph entry (design 47 G §47 to §50, §121; A-208): the indexer writes, in each entry of a revision,
|
||||
@@ -494,3 +496,105 @@ func edgesOfPackages(a meshcatalog.CatalogEntry, all map[string]meshcatalog.Cata
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WithNewEdges adds, to the entries of a take-in's revision, the edges of kind 6 that its movers bring (design 47 H §870,
|
||||
// H-A-838): a word and an event new at the revision, between the artifacts of the movers. base is the entries of the
|
||||
// revision's base (none for a branch's first); entries are not changed.
|
||||
// 1. A word: each need `word:<path>` of a mover A that no entry of base names gives an edge from the artifact of each
|
||||
// mover that holds the seat node-engine, the reader of every manifest word (ADR 0614 §4), to A's.
|
||||
// 2. An event: each `consumes` entry of a mover A that names an event a mover B's manifest emits at the revision and
|
||||
// did not at the base gives an edge from B's artifact to A's.
|
||||
//
|
||||
// An edge's `word` is the need, or `<owner>.<event>`; its `why` says it is new at the revision and names the mover that
|
||||
// brings it. A cycle of these edges with other delivery edges is delivered as one step (graph.RefusedCycle refuses only
|
||||
// one holding a build edge).
|
||||
func WithNewEdges(entries, base map[string]meshcatalog.CatalogEntry, movers []meshcatalog.TakeInEntry) map[string]meshcatalog.CatalogEntry {
|
||||
moved := map[string]bool{}
|
||||
for _, m := range movers {
|
||||
moved[m.Module] = true
|
||||
}
|
||||
baseNeeds := map[string]bool{}
|
||||
for _, b := range base {
|
||||
for _, n := range b.Needs {
|
||||
baseNeeds[n] = true
|
||||
}
|
||||
}
|
||||
var engines []string
|
||||
for _, m := range slices.Sorted(maps.Keys(entries)) {
|
||||
if moved[m] && manifestOf(entries[m]).ClaimsSeat(judge.NodeEngineSeat) {
|
||||
engines = append(engines, m)
|
||||
}
|
||||
}
|
||||
out := maps.Clone(entries)
|
||||
for _, name := range slices.Sorted(maps.Keys(entries)) {
|
||||
if !moved[name] {
|
||||
continue
|
||||
}
|
||||
a := entries[name]
|
||||
to := primaryOf(a)
|
||||
if to == "" {
|
||||
continue
|
||||
}
|
||||
var added []meshcatalog.Edge
|
||||
for _, n := range a.Needs {
|
||||
if !strings.HasPrefix(n, catalogue.ReadWord) || baseNeeds[n] {
|
||||
continue
|
||||
}
|
||||
for _, e := range engines {
|
||||
if from := primaryOf(entries[e]); e != name && from != "" {
|
||||
added = append(added, meshcatalog.Edge{Kind: 6, From: from, To: to, Word: n, Why: "new at the revision: " + name})
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, subject := range a.Consumes {
|
||||
for _, b := range slices.Sorted(maps.Keys(entries)) {
|
||||
from := primaryOf(entries[b])
|
||||
if !moved[b] || b == name || from == "" {
|
||||
continue
|
||||
}
|
||||
for _, ev := range emitsOf(entries[b]) {
|
||||
word := b + "." + ev
|
||||
if eventMatches(subject, word) && !slices.Contains(emitsOf(base[b]), ev) {
|
||||
added = append(added, meshcatalog.Edge{Kind: 6, From: from, To: to, Word: word, Why: "new at the revision: " + b})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(added) == 0 {
|
||||
continue
|
||||
}
|
||||
a.Edges = slices.Clone(a.Edges)
|
||||
for _, x := range added {
|
||||
if !slices.Contains(a.Edges, x) {
|
||||
a.Edges = append(a.Edges, x)
|
||||
}
|
||||
}
|
||||
sortEdges(a.Edges)
|
||||
out[name] = a
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// emitsOf are the events the entry's manifest emits, named locally.
|
||||
func emitsOf(e meshcatalog.CatalogEntry) []string {
|
||||
if len(e.Manifest) == 0 {
|
||||
return nil
|
||||
}
|
||||
return manifestOf(e).Emits
|
||||
}
|
||||
|
||||
// eventMatches says whether a consumed event, `<owner>.<event>` with `*` for one name and `**` for the rest, names word.
|
||||
func eventMatches(pattern, word string) bool {
|
||||
p, w := strings.Split(pattern, "."), strings.Split(word, ".")
|
||||
for i, t := range p {
|
||||
switch {
|
||||
case t == "**":
|
||||
return true
|
||||
case i >= len(w):
|
||||
return false
|
||||
case t != "*" && t != w[i]:
|
||||
return false
|
||||
}
|
||||
}
|
||||
return len(p) == len(w)
|
||||
}
|
||||
|
||||
@@ -70,6 +70,11 @@ func TestAnEntryCarriesItsEdgesOfKindsOneToFourAndSix(t *testing.T) {
|
||||
if got := WithEdges(entries)["app"].Edges; slices.ContainsFunc(got, func(e meshcatalog.Edge) bool { return e.Kind == 1 }) {
|
||||
t.Errorf("edges with a reported empty import set: %+v, want no kind 1", got)
|
||||
}
|
||||
// design 47 H2b §870 (1984/AC-870a to AC-870c): the edges the movers bring, as rows
|
||||
t.Run("a mover with a new word follows the node-engine mover", rowAMoverNeedingANewWordIsOrderedAfterTheNodeEngineMover)
|
||||
t.Run("a consumer of a newly emitted event follows its emitter", rowAConsumerOfANewlyEmittedEventIsOrderedAfterItsEmitter)
|
||||
t.Run("a cycle of a word edge and an event edge is not refused", rowACycleOfAWordEdgeAndAnEventEdgeIsNotRefused)
|
||||
|
||||
}
|
||||
|
||||
// Design 47 G A-208: a revision kept holds each entry with its edges, so the builder and the assigner read them from the entry.
|
||||
@@ -318,3 +323,72 @@ func TestTheTrunkCataloguesHoldNoRefusedCycle(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func wordEntry(module string, manifest map[string]any, needs, consumes []string) meshcatalog.CatalogEntry {
|
||||
manifest["module"], manifest["version"] = module, "1.0.0"
|
||||
return meshcatalog.CatalogEntry{Module: module, Manifest: manifest, Needs: needs, Consumes: consumes,
|
||||
Artifacts: []meshcatalog.Artifact{{Ref: meshcatalog.ArtifactRef(module + ":program"), Language: "go"}}}
|
||||
}
|
||||
|
||||
func kind6Words(e meshcatalog.CatalogEntry) []string {
|
||||
var out []string
|
||||
for _, x := range e.Edges {
|
||||
if x.Kind == 6 {
|
||||
out = append(out, x.From+" "+x.Word+" | "+x.Why)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Design 47 H §870 1., 1984/AC-870a: a mover whose entry needs a word no base entry names gets the edge from the mover that holds
|
||||
// the seat node-engine, and one whose word a base entry names gets none.
|
||||
func rowAMoverNeedingANewWordIsOrderedAfterTheNodeEngineMover(t *testing.T) {
|
||||
engine := wordEntry("engine", map[string]any{"claims": []any{map[string]any{"name": "node-engine"}}}, nil, nil)
|
||||
newer := wordEntry("newer", map[string]any{}, []string{"word:build.artifacts.race"}, nil)
|
||||
known := wordEntry("known", map[string]any{}, []string{"word:settings"}, nil)
|
||||
base := map[string]meshcatalog.CatalogEntry{"old": {Module: "old", Needs: []string{"word:settings"}}}
|
||||
movers := []meshcatalog.TakeInEntry{{Module: "engine"}, {Module: "newer"}, {Module: "known"}}
|
||||
got := WithNewEdges(map[string]meshcatalog.CatalogEntry{"engine": engine, "newer": newer, "known": known}, base, movers)
|
||||
if w := kind6Words(got["newer"]); !slices.Equal(w, []string{"engine:program word:build.artifacts.race | new at the revision: newer"}) {
|
||||
t.Errorf("newer holds %v, want the edge from the node-engine mover", w)
|
||||
}
|
||||
if w := kind6Words(got["known"]); len(w) != 0 {
|
||||
t.Errorf("known holds %v, want no edge: a base entry names its word", w)
|
||||
}
|
||||
if w := kind6Words(got["engine"]); len(w) != 0 {
|
||||
t.Errorf("the node-engine mover holds %v, want none", w)
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 H §870 2., 1984/AC-870b: a consumer of an event its emitter newly emits gets the edge from the emitter, and one
|
||||
// whose emitter emitted it at the base gets none.
|
||||
func rowAConsumerOfANewlyEmittedEventIsOrderedAfterItsEmitter(t *testing.T) {
|
||||
emitter := wordEntry("emitter", map[string]any{"emits": []any{"made", "kept"}}, nil, nil)
|
||||
fresh := wordEntry("fresh", map[string]any{}, nil, []string{"emitter.made"})
|
||||
stale := wordEntry("stale", map[string]any{}, nil, []string{"emitter.kept", "*.nothing"})
|
||||
base := map[string]meshcatalog.CatalogEntry{"emitter": wordEntry("emitter", map[string]any{"emits": []any{"kept"}}, nil, nil)}
|
||||
movers := []meshcatalog.TakeInEntry{{Module: "emitter"}, {Module: "fresh"}, {Module: "stale"}}
|
||||
got := WithNewEdges(map[string]meshcatalog.CatalogEntry{"emitter": emitter, "fresh": fresh, "stale": stale}, base, movers)
|
||||
// AC-870d (H-A-838): kind 6, the event as `word`, "new at the revision" naming the mover as `why`.
|
||||
if w := kind6Words(got["fresh"]); !slices.Equal(w, []string{"emitter:program emitter.made | new at the revision: emitter"}) {
|
||||
t.Errorf("fresh holds %v, want the edge from the emitter", w)
|
||||
}
|
||||
if w := kind6Words(got["stale"]); len(w) != 0 {
|
||||
t.Errorf("stale holds %v, want none: the emitter emitted it at the base", w)
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 H §870 3., 1984/AC-870c: a cycle of a word edge and an event edge is delivered as one step, so it is no refused
|
||||
// cycle (only one holding a build edge is).
|
||||
func rowACycleOfAWordEdgeAndAnEventEdgeIsNotRefused(t *testing.T) {
|
||||
engine := wordEntry("engine", map[string]any{"claims": []any{map[string]any{"name": "node-engine"}}}, nil, []string{"newer.said"})
|
||||
newer := wordEntry("newer", map[string]any{"emits": []any{"said"}}, []string{"word:resources.tool-files"}, nil)
|
||||
movers := []meshcatalog.TakeInEntry{{Module: "engine"}, {Module: "newer"}}
|
||||
got := WithNewEdges(map[string]meshcatalog.CatalogEntry{"engine": engine, "newer": newer}, nil, movers)
|
||||
if len(kind6Words(got["engine"])) != 1 || len(kind6Words(got["newer"])) != 1 {
|
||||
t.Fatalf("edges %v and %v, want one each way", kind6Words(got["engine"]), kind6Words(got["newer"]))
|
||||
}
|
||||
if cycle := graph.RefusedCycle(got); cycle != nil {
|
||||
t.Errorf("refused %v, want one step", cycle)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -421,6 +421,20 @@ func (ix *Indexer) keepBranchEntries(ctx context.Context, branch string, src int
|
||||
if judge.NeedsRules > newest.NeedsRules {
|
||||
entries = withRuleNeeds(entries, movers) // H-A-605 (4): the rules moved since the base, so each unmoved entry is read again
|
||||
}
|
||||
if len(movers) > 0 {
|
||||
// design 47 H §870: the word and event edges the movers bring, new against the revision's base
|
||||
base := map[string]meshcatalog.CatalogEntry{}
|
||||
if newest.Revision > 0 {
|
||||
_, held, _, err := readNewestOf(ctx, ix.Revisions, branch)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("the base catalog graph revision: %w", err)
|
||||
}
|
||||
for _, e := range held {
|
||||
base[e.Module] = e
|
||||
}
|
||||
}
|
||||
entries = WithNewEdges(entries, base, movers)
|
||||
}
|
||||
at := ix.now().UTC()
|
||||
rev, objects, err := CatalogRevisionOf(meshcatalog.CatalogRevision{Revision: number, Kind: "trunk", Branch: branch, Source: src, Call: call.Call,
|
||||
NeedsRules: judge.NeedsRules, CallKind: call.Kind, Module: call.Module, Version: call.Version, Repository: call.Repository, At: &at}, entries)
|
||||
|
||||
@@ -44,10 +44,13 @@ func NamedKey(fingerprint string) string { return keys.EscapeName(fingerprint) }
|
||||
// NamedMember is the member of a node's module in a set.
|
||||
func NamedMember(node, module string) string { return node + "." + module }
|
||||
|
||||
// namedAt is the fingerprint one source last named for a member, and when it said so.
|
||||
// namedAt is the fingerprint one source last named for a member, and when it said so. rev is the `want-revision` a want
|
||||
// carried (0 when it carried none, as an older event or a running build): a want is ordered by it, never by a say's time
|
||||
// (design 47 H2b §832 5.).
|
||||
type namedAt struct {
|
||||
fp string
|
||||
at time.Time
|
||||
fp string
|
||||
at time.Time
|
||||
rev int64
|
||||
}
|
||||
|
||||
// Named keeps the sets. What each member's want and running last named is held in memory only, read again at every start from
|
||||
@@ -65,6 +68,7 @@ type Named struct {
|
||||
want map[string]namedAt
|
||||
run map[string]namedAt
|
||||
gone map[string]time.Time // the want of a member removed (§693), when
|
||||
goneR map[string]int64 // the `want-revision` of the write that removal removed, 0 when it named none
|
||||
reads map[string]bool // the streams read whole at the start
|
||||
ready bool
|
||||
// failed holds the first event that could not be applied while the start read ran: what it named is unknown, so the
|
||||
@@ -77,7 +81,7 @@ func NewNamed(store Store, logf func(string, ...any)) *Named {
|
||||
if logf == nil {
|
||||
logf = func(string, ...any) {}
|
||||
}
|
||||
return &Named{Store: store, Logf: logf, want: map[string]namedAt{}, run: map[string]namedAt{}, gone: map[string]time.Time{}, reads: map[string]bool{}}
|
||||
return &Named{Store: store, Logf: logf, want: map[string]namedAt{}, run: map[string]namedAt{}, gone: map[string]time.Time{}, goneR: map[string]int64{}, reads: map[string]bool{}}
|
||||
}
|
||||
|
||||
// Ready says the two streams were read whole and the sets reconciled with them: until then no entry object is removed, so a
|
||||
@@ -102,7 +106,7 @@ func (n *Named) HearWanted(ctx context.Context, data []byte) error {
|
||||
if e.At != nil {
|
||||
at = *e.At
|
||||
}
|
||||
return n.apply(ctx, NamedMember(e.Node, e.Module), true, e.Fp, at, e.Removed)
|
||||
return n.apply(ctx, NamedMember(e.Node, e.Module), true, e.Fp, at, e.WantRevision, e.Removed)
|
||||
}
|
||||
|
||||
// HearRunning applies one running event: the build it names; a stopped one, or one with no fingerprint, names none (design 47
|
||||
@@ -119,14 +123,14 @@ func (n *Named) HearRunning(ctx context.Context, data []byte) error {
|
||||
if r.Stopped {
|
||||
fp = ""
|
||||
}
|
||||
return n.apply(ctx, NamedMember(r.Node, r.Module), false, fp, r.At, false)
|
||||
return n.apply(ctx, NamedMember(r.Node, r.Module), false, fp, r.At, 0, false)
|
||||
}
|
||||
|
||||
// apply changes what one source names for the member and writes the sets it moves; one at a time, so the two sources never
|
||||
// write one set from a stale view of each other.
|
||||
func (n *Named) apply(ctx context.Context, member string, wanted bool, fp string, at time.Time, removed bool) error {
|
||||
func (n *Named) apply(ctx context.Context, member string, wanted bool, fp string, at time.Time, rev int64, removed bool) error {
|
||||
n.mu.Lock()
|
||||
moved, err := n.applyLocked(ctx, member, wanted, fp, at, removed)
|
||||
moved, err := n.applyLocked(ctx, member, wanted, fp, at, rev, removed)
|
||||
if err != nil && !n.ready && n.failed == nil {
|
||||
n.failed = err
|
||||
}
|
||||
@@ -137,13 +141,17 @@ func (n *Named) apply(ctx context.Context, member string, wanted bool, fp string
|
||||
return err
|
||||
}
|
||||
|
||||
func (n *Named) applyLocked(ctx context.Context, member string, wanted bool, fp string, at time.Time, removed bool) (bool, error) {
|
||||
func (n *Named) applyLocked(ctx context.Context, member string, wanted bool, fp string, at time.Time, rev int64, removed bool) (bool, error) {
|
||||
src := n.run
|
||||
if wanted {
|
||||
src = n.want
|
||||
}
|
||||
old, had := src[member]
|
||||
if had && at.Before(old.at) {
|
||||
// A want that names its `want-revision` is ordered by it against one that names its own, never by the time it was said
|
||||
// (design 47 H2b §832 5.): one at a revision below the held want's changes nothing, and a repeat of it writes nothing new.
|
||||
// An event that names none, or a held one that named none, is ordered by `at`, as a running build is.
|
||||
byRev := wanted && had && rev > 0 && old.rev > 0
|
||||
if byRev && rev < old.rev || !byRev && had && at.Before(old.at) {
|
||||
return false, nil // an event older than the one heard changes nothing
|
||||
}
|
||||
var touched []string
|
||||
@@ -158,22 +166,35 @@ func (n *Named) applyLocked(ctx context.Context, member string, wanted bool, fp
|
||||
delete(n.run, member)
|
||||
}
|
||||
delete(n.want, member)
|
||||
n.gone[member] = at
|
||||
n.gone[member], n.goneR[member] = at, rev
|
||||
touched = append(touched, fp)
|
||||
case !n.gone[member].IsZero() && !at.After(n.gone[member]):
|
||||
case !n.gone[member].IsZero() && n.goneRemoved(member, wanted, at, rev):
|
||||
return false, nil // an event older than the removal of the want it belongs to
|
||||
case fp == "":
|
||||
delete(src, member)
|
||||
default:
|
||||
if wanted {
|
||||
delete(n.gone, member)
|
||||
delete(n.goneR, member)
|
||||
}
|
||||
src[member] = namedAt{fp: fp, at: at}
|
||||
if wanted && rev == 0 && had {
|
||||
rev = old.rev // a want that names no `want-revision` leaves the held revision unchanged (H-A-865, H-A-877)
|
||||
}
|
||||
src[member] = namedAt{fp: fp, at: at, rev: rev}
|
||||
touched = append(touched, fp)
|
||||
}
|
||||
return n.writeSets(ctx, member, touched)
|
||||
}
|
||||
|
||||
// goneRemoved says whether an event is older than the removal of the member's want: a want that names its `want-revision`
|
||||
// is older when its revision does not pass the removed write's, any other event when it was said before the removal.
|
||||
func (n *Named) goneRemoved(member string, wanted bool, at time.Time, rev int64) bool {
|
||||
if wanted && rev > 0 && n.goneR[member] > 0 {
|
||||
return rev <= n.goneR[member]
|
||||
}
|
||||
return !at.After(n.gone[member])
|
||||
}
|
||||
|
||||
// holds says whether either source names fp for the member.
|
||||
func (n *Named) holds(member, fp string) bool {
|
||||
return n.want[member].fp == fp || n.run[member].fp == fp
|
||||
|
||||
@@ -245,6 +245,8 @@ func TestTheIndexerRemovesARevisionOnlyWhenNoRecordPinsItAndItIsNotCurrent(t *te
|
||||
wanted(7, meshwants.PipelineWantedOutcomeRunning)
|
||||
wanted(7, meshwants.PipelineWantedOutcomeRunning) // heard twice: changes nothing more
|
||||
want("the newer release written everywhere", "main.7")
|
||||
wanted(7, meshwants.PipelineWantedOutcomeTierLate) // 1984/AC-832l (design 47 H2b §832 5.): said again after its running, it changes nothing
|
||||
want("a tier-late after its running", "main.7")
|
||||
if v, _, _, _ := ix.Pins.Get(ctx, "main.7"); !slices.Equal(mustRecords(t, v), []string{ReleaseRecord("main", "reader")}) {
|
||||
t.Errorf("the pin of main.7 holds %s, want its release alone", v)
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ type namedEvent struct {
|
||||
module string
|
||||
fp string
|
||||
min int
|
||||
rev int64 // the want-revision a wanted names, 0 for none
|
||||
removed bool
|
||||
stopped bool
|
||||
}
|
||||
@@ -37,7 +38,7 @@ func (e namedEvent) apply(t *testing.T, n *Named) {
|
||||
var data []byte
|
||||
var err error
|
||||
if e.wanted {
|
||||
data, err = json.Marshal(meshwants.WantedEvent{V: 1, Node: e.node, Module: e.module, Fp: e.fp, Revision: 1, Removed: e.removed, At: &at})
|
||||
data, err = json.Marshal(meshwants.WantedEvent{V: 1, Node: e.node, Module: e.module, Fp: e.fp, Revision: 1, WantRevision: e.rev, Removed: e.removed, At: &at})
|
||||
if err == nil {
|
||||
err = n.HearWanted(context.Background(), data)
|
||||
}
|
||||
@@ -77,6 +78,20 @@ func TestNamedHoldsTheMembersWhoseWantOrRunningBuildNamesAFingerprint(t *testing
|
||||
{wanted: true, node: "n1", module: "m", fp: a, min: 1, removed: true}, {node: "n1", module: "m", fp: a, min: 0}}, map[string][]string{a: nil}},
|
||||
{"an event older than the one heard changes nothing", []namedEvent{
|
||||
{wanted: true, node: "n1", module: "m", fp: b, min: 5}, {wanted: true, node: "n1", module: "m", fp: a, min: 4}}, map[string][]string{a: nil, b: {"n1.m"}}},
|
||||
// 1984/AC-832l, AC-832t (design 47 H2b §832 5., H-A-832): a want is ordered by its want-revision, never by a say's time.
|
||||
{"a want at a lower want-revision changes nothing, whatever its time", []namedEvent{
|
||||
{wanted: true, node: "n1", module: "m", fp: b, min: 1, rev: 5}, {wanted: true, node: "n1", module: "m", fp: a, min: 9, rev: 4}}, map[string][]string{a: nil, b: {"n1.m"}}},
|
||||
{"a want at a higher want-revision wins over a later time", []namedEvent{
|
||||
{wanted: true, node: "n1", module: "m", fp: a, min: 9, rev: 4}, {wanted: true, node: "n1", module: "m", fp: b, min: 1, rev: 5}}, map[string][]string{a: nil, b: {"n1.m"}}},
|
||||
{"a repeat of an applied want writes nothing new, under any time", []namedEvent{
|
||||
{wanted: true, node: "n1", module: "m", fp: a, min: 1, rev: 3}, {wanted: true, node: "n1", module: "m", fp: a, min: 8, rev: 3}}, map[string][]string{a: {"n1.m"}, b: nil}},
|
||||
{"a removal of a write below the held want's changes nothing", []namedEvent{
|
||||
{wanted: true, node: "n1", module: "m", fp: a, min: 1, rev: 6}, {wanted: true, node: "n1", module: "m", fp: a, min: 9, rev: 5, removed: true}}, map[string][]string{a: {"n1.m"}}},
|
||||
{"a want written after a removal at a higher want-revision brings the member back, whatever its time", []namedEvent{
|
||||
{wanted: true, node: "n1", module: "m", fp: a, min: 5, rev: 6, removed: true}, {wanted: true, node: "n1", module: "m", fp: a, min: 1, rev: 7}}, map[string][]string{a: {"n1.m"}}},
|
||||
{"a want that names no want-revision leaves the held revision, so a lower one after it changes nothing (H-A-877)", []namedEvent{
|
||||
{wanted: true, node: "n1", module: "m", fp: b, min: 1, rev: 5}, {wanted: true, node: "n1", module: "m", fp: a, min: 2},
|
||||
{wanted: true, node: "n1", module: "m", fp: b, min: 3, rev: 4}}, map[string][]string{a: {"n1.m"}, b: nil}},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
st := newMem()
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
// NeedsRules is the version of the validator's need rules (design 47 H2, H-A-569 (2), H-A-605 (4)): raised with every
|
||||
// change of the rules that derive a need from a manifest. Each catalog revision the indexer writes carries it, and a
|
||||
// take-in derives the rule needs of unmoved entries again only when its own is higher than its base revision's.
|
||||
const NeedsRules = 1
|
||||
const NeedsRules = 2
|
||||
|
||||
// requirementLong is one entry of `requires` in its long form, as catalogue reads it.
|
||||
type requirementLong struct {
|
||||
@@ -123,9 +123,63 @@ func ManifestNeeds(raw []byte) ([]string, error) {
|
||||
for _, s := range seatNamesUsed(top) {
|
||||
used[catalogue.ReadSeat+s] = true
|
||||
}
|
||||
// A word the take-in's read set aside (design 47 H2b §872, H-A-813): the need of a word this reader does not know,
|
||||
// in the form catalogue.ManifestReads() gives one, so a node-engine whose words lack it is held off the entry.
|
||||
for _, path := range UnknownFields(raw) {
|
||||
if word := readWordOf(path); word != "" {
|
||||
used[catalogue.ReadWord+word] = true
|
||||
}
|
||||
}
|
||||
return sortedSet(used), nil
|
||||
}
|
||||
|
||||
// readWordOf is the path SetAside names for a word, `build.artifacts[0].race`, in the form catalogue.ManifestReads() gives
|
||||
// a word: no list index, and no key of a map of the module's own names (a setting's, a requirement's), so
|
||||
// `build.artifacts.race`. Where a path leaves the shape the contract knows, the keys after it are kept as they are.
|
||||
func readWordOf(path string) string {
|
||||
var segments []string
|
||||
for _, seg := range strings.Split(path, ".") {
|
||||
if i := strings.IndexByte(seg, '['); i >= 0 {
|
||||
seg = seg[:i]
|
||||
}
|
||||
if seg != "" {
|
||||
segments = append(segments, seg)
|
||||
}
|
||||
}
|
||||
var t reflect.Type = reflect.TypeOf(catalogue.Manifest{})
|
||||
var out []string
|
||||
for _, seg := range segments {
|
||||
for t != nil {
|
||||
t = deref(t)
|
||||
if k := t.Kind(); k == reflect.Slice || k == reflect.Array {
|
||||
t = t.Elem()
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
switch {
|
||||
case t == nil:
|
||||
out = append(out, seg)
|
||||
case t.Kind() == reflect.Map:
|
||||
t = t.Elem() // a key of the module's own names
|
||||
case t.Kind() == reflect.Struct:
|
||||
if _, custom := wireKeys[t]; custom {
|
||||
out, t = append(out, seg), nil
|
||||
continue
|
||||
}
|
||||
out = append(out, seg)
|
||||
if f, known := structFields(t)[seg]; known {
|
||||
t = f.Type
|
||||
} else {
|
||||
t = nil
|
||||
}
|
||||
default:
|
||||
out, t = append(out, seg), nil
|
||||
}
|
||||
}
|
||||
return strings.Join(out, ".")
|
||||
}
|
||||
|
||||
// ModuleNeeds is ManifestNeeds of a module whose files take their text from templates: what the manifest needs and
|
||||
// what each template's text writes, sorted. A template named and not given is no need.
|
||||
func ModuleNeeds(raw []byte, templates map[string]string) ([]string, error) {
|
||||
|
||||
@@ -19,7 +19,14 @@ func TestManifestNeeds(t *testing.T) {
|
||||
{"a module with no account of its own", `{"module":"g","version":"1"}`, nil,
|
||||
[]string{"word:module"}, []string{"directory-contents-owner"}},
|
||||
{"a word the contract does not know", `{"module":"u","version":"1","newer-word":{"inside":1}}`, nil,
|
||||
[]string{"word:module"}, []string{"word:newer-word"}},
|
||||
[]string{"word:module", "word:newer-word"}, nil},
|
||||
// design 47 H2b §872, 1984/AC-872a: a nested word set aside has its need in the reads' form, without the list index.
|
||||
{"a nested word the contract does not know", `{"module":"u","version":"1","build":{"artifacts":[{"name":"p","language":"go","race":true}]}}`, nil,
|
||||
[]string{"word:module", "word:build.artifacts.race"}, []string{"word:build.artifacts[0].race"}},
|
||||
{"a word beneath a setting's own name", `{"module":"u","version":"1","settings":{"mine":{"type":"string","newer":1}}}`, nil,
|
||||
[]string{"word:settings.newer"}, []string{"word:settings.mine.newer"}},
|
||||
{"every word known", `{"module":"u","version":"1","build":{"artifacts":[{"name":"p","language":"go"}]}}`, nil,
|
||||
[]string{"word:module"}, []string{"word:build.artifacts.race", "word:race"}},
|
||||
{"a template naming a seat's reach", `{"module":"z","version":"1","resources":[{"id":"f","type":"file","template":"files/d.json"}]}`,
|
||||
map[string]string{"files/d.json": `{"x":"${seat:container-image-registry:reach}"}`},
|
||||
[]string{"form:seat-reach"}, nil},
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"maps"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||
)
|
||||
|
||||
// What a mover's own build made is heard, never read from the builder's state (design 47 H §835 1., H-A-849; ADR 0596 §2): the
|
||||
// builder's event build.ended names a done build's parts by digest, kept here by module and fingerprint, so a version-released is
|
||||
// written onto a mover only when its parts are those of the mover's own build.
|
||||
|
||||
// builtParts are the done builds' parts heard, by module and fingerprint.
|
||||
type builtParts struct {
|
||||
mu sync.Mutex
|
||||
parts map[string]map[string]string
|
||||
}
|
||||
|
||||
// put takes one build.ended in: a done build's parts are kept; a failed one made none.
|
||||
func (b *builtParts) put(data []byte) error {
|
||||
var e builds.BuildEnded
|
||||
if err := json.Unmarshal(data, &e); err != nil {
|
||||
return fmt.Errorf("a build.ended that is no end: %w", err)
|
||||
}
|
||||
if e.Module == "" || e.Fingerprint == "" {
|
||||
return fmt.Errorf("a build's end naming no module or fingerprint: %s", data)
|
||||
}
|
||||
if e.Outcome != "" && e.Outcome != builds.BuildDone { // an end said before the outcome was named is a done build's
|
||||
return nil
|
||||
}
|
||||
made := map[string]string{}
|
||||
for name, digest := range e.Made {
|
||||
made[e.Module+":"+name] = digest
|
||||
}
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
if b.parts == nil {
|
||||
b.parts = map[string]map[string]string{}
|
||||
}
|
||||
b.parts[e.Module+"@"+e.Fingerprint] = made
|
||||
return nil
|
||||
}
|
||||
|
||||
// made is what module's done build at fingerprint made, by `<module>:<artifact>`; none for a build not heard.
|
||||
func (b *builtParts) made(module, fingerprint string) map[string]string {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
return b.parts[module+"@"+fingerprint]
|
||||
}
|
||||
|
||||
// madeBy is the fingerprint of module's done build that made exactly parts, empty when none heard did; of several the least, so the
|
||||
// journal line says the same each time.
|
||||
func (b *builtParts) madeBy(module string, parts map[string]string) string {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
var found string
|
||||
for key, made := range b.parts {
|
||||
mod, fp, _ := strings.Cut(key, "@")
|
||||
if mod == module && len(made) > 0 && maps.Equal(made, parts) && (found == "" || fp < found) {
|
||||
found = fp
|
||||
}
|
||||
}
|
||||
return found
|
||||
}
|
||||
|
||||
// hearBuilds reads the builder's stream of build ends whole at the start and then follows it, as the assigner does (design 47 G
|
||||
// A-181): what was built survives the runner's restart. A stream it cannot hear is said, and no release matches a mover until the
|
||||
// runner starts again.
|
||||
func hearBuilds(ctx context.Context, js jetstream.JetStream, acct process.Account, into *builtParts, logf func(string, ...any)) {
|
||||
stream := catalogue.StreamBusName(builds.BuildsStream)
|
||||
cc, err := acct.HearStream(ctx, js, stream, func(m jetstream.Msg) {
|
||||
if err := into.put(m.Data()); err != nil {
|
||||
logf("%s is not kept: %v", m.Subject(), err)
|
||||
}
|
||||
if err := m.Ack(); err != nil {
|
||||
logf("acknowledging %s: %v", m.Subject(), err)
|
||||
}
|
||||
}, logf, process.FromFirst())
|
||||
if err != nil {
|
||||
logf("what the builder built is not heard (%s): no version-released matches a mover until the runner starts again: %v", stream, err)
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
cc.Stop()
|
||||
}()
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
// AC-835c (design 47 H §835 1., H-A-849): a build.ended heard gives the parts of the build at its fingerprint, and only a done one.
|
||||
func TestABuildEndedGivesThePartsOfItsFingerprint(t *testing.T) {
|
||||
var b builtParts
|
||||
for _, e := range []string{
|
||||
`{"module":"app","fingerprint":"src2:aa","outcome":"done","made":{"program":"sha256:aa"}}`,
|
||||
`{"module":"app","fingerprint":"src2:bb","outcome":"failed","error":"x"}`,
|
||||
`{"module":"lib","fingerprint":"src2:cc","made":{"lib":"sha256:cc"}}`,
|
||||
} {
|
||||
if err := b.put([]byte(e)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if got := b.made("app", "src2:aa"); len(got) != 1 || got["app:program"] != "sha256:aa" {
|
||||
t.Errorf("app at src2:aa made %v, want app:program", got)
|
||||
}
|
||||
if got := b.made("app", "src2:bb"); len(got) != 0 {
|
||||
t.Errorf("a failed build made %v, want none", got)
|
||||
}
|
||||
if got := b.made("lib", "src2:cc"); got["lib:lib"] != "sha256:cc" {
|
||||
t.Errorf("an end without an outcome made %v, want a done build's parts", got)
|
||||
}
|
||||
if got := b.made("app", "src2:zz"); got != nil {
|
||||
t.Errorf("a build not heard made %v, want none", got)
|
||||
}
|
||||
if got := b.madeBy("app", map[string]string{"app:program": "sha256:aa"}); got != "src2:aa" {
|
||||
t.Errorf("the build that made app's parts = %q, want src2:aa", got)
|
||||
}
|
||||
if got := b.madeBy("app", map[string]string{"app:program": "sha256:zz"}); got != "" {
|
||||
t.Errorf("the build that made parts no build made = %q, want none", got)
|
||||
}
|
||||
if err := b.put([]byte(`{"module":"app"}`)); err == nil {
|
||||
t.Error("an end naming no fingerprint was kept")
|
||||
}
|
||||
}
|
||||
@@ -145,6 +145,11 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
store := newPipelineStore(ctx, pipelines, logger.Printf)
|
||||
hearer := newHearer(ctx, js, cred, store, kept, say, logger.Printf)
|
||||
hearer.Asker = busAsker{conn: conn, cred: cred}
|
||||
// A release matches a mover only by the parts its own build made, heard on the builder's build.ended (design 47 H §835 1., H-A-849).
|
||||
var built builtParts
|
||||
hearer.Made = built.made
|
||||
hearer.MadeBy = built.madeBy
|
||||
hearBuilds(ctx, js, cred, &built, logger.Printf)
|
||||
hearer.Ager = newAger(ctx, js, cred, store, kept, aged, logger.Printf)
|
||||
// The stores' fill is said before a store is full, and a full one refuses a start (§366).
|
||||
fills := &pipeline.Fills{Read: storeFills(ctx, js, cred, time.Now), Logf: logger.Printf,
|
||||
@@ -468,12 +473,12 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
seats.Follow(seatlist.ProcessBus(calls.Call, hub), nil, logger.Printf)
|
||||
again := bindTakeIns(ctx, js, cred, takeIns.handle, takeInsBound, logger.Printf)
|
||||
bindTakeInsAgain.Store(&again)
|
||||
if err := hub.StartUntilBound(ctx, js, cred, nil, seats.EventsLive); err != nil {
|
||||
// The seat list is read again once the hub hears every pattern, the kept seat events' streams (the steps' ends, G-1 §24)
|
||||
// included (design 47 H2b §836 1., 2.): no timer retries it.
|
||||
hub.OnAllHeard(seats.EventsLive)
|
||||
if err := hub.Start(ctx, js, cred); err != nil {
|
||||
logger.Printf("the consumer %s is not bound yet (%v): bound once the bus makes it", cred.EventConsumerName(), err)
|
||||
}
|
||||
// The steps' ends are kept seat events, each on its own stream (step-ended of the build seats, mesh-builds and
|
||||
// mesh-wants), never on EVENTS: bound here, or no step of any pipeline is ever heard ending (G-1 §24).
|
||||
logger.Printf("the kept seat events heard: %d streams bound", hub.StartKept(ctx, js, cred))
|
||||
stopVerbs, err := answerVerbs(calls, seats, verbs)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -10,6 +10,7 @@ require (
|
||||
|
||||
require (
|
||||
git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient v0.0.0-00010101000000-000000000000
|
||||
git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds v0.0.0-00010101000000-000000000000
|
||||
git.novox.be/novox/mesh-contracts/go/seats/nodeengine v0.0.0-00010101000000-000000000000
|
||||
git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient v0.0.0-00010101000000-000000000000
|
||||
git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient v0.0.0-00010101000000-000000000000
|
||||
|
||||
@@ -2,6 +2,7 @@ package pipeline
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"slices"
|
||||
"strings"
|
||||
@@ -160,6 +161,13 @@ func (m memUnfinished) String() string {
|
||||
// version; one still running, or ended failed, says nothing. A say that failed is said when the version is heard again.
|
||||
func TestAReleasedVersionIsTheMoversVersion(t *testing.T) {
|
||||
h, store, bodies, order := twoMovers(t)
|
||||
// The builder's build.ended of app at src2:aa made one part (design 47 H §835 1., H-A-849); a rebuild at src2:cc made another.
|
||||
h.Made = func(module, fp string) map[string]string {
|
||||
if module == "app" && fp == "src2:aa" {
|
||||
return map[string]string{"app:program": "sha256:aa"}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
other := store[pkey]
|
||||
other.p.Pipeline, other.p.Branch, other.p.Movers = "beta.5", "beta", append([]seat.Mover(nil), other.p.Movers...)
|
||||
store["beta.5"] = other
|
||||
@@ -185,7 +193,36 @@ func TestAReleasedVersionIsTheMoversVersion(t *testing.T) {
|
||||
}
|
||||
return say(subject, body)
|
||||
}
|
||||
ev := catalog.VersionReleasedEvent{Module: "app", Version: "0.4.1", Source: 5}
|
||||
ev := catalog.VersionReleasedEvent{Module: "app", Version: "0.4.1", Source: 5, Artifacts: []catalog.VersionArtifact{{Artifact: "app:program", Digest: "sha256:aa"}}}
|
||||
// A release of a rebuild at the same source (AC-835a): its parts are not what the mover's own build made, so it writes no
|
||||
// version onto the mover of any pipeline of that source.
|
||||
rebuild := catalog.VersionReleasedEvent{Module: "app", Version: "0.4.0", Source: 5, Artifacts: []catalog.VersionArtifact{{Artifact: "app:program", Digest: "sha256:cc"}}}
|
||||
// Its journal line names the two fingerprints: the mover's and the one whose heard build made the release's parts, or says no
|
||||
// build was heard at the mover's (design 47 H §835 1.).
|
||||
var journal []string
|
||||
h.Logf = func(f string, a ...any) { journal = append(journal, fmt.Sprintf(f, a...)) }
|
||||
h.MadeBy = func(module string, parts map[string]string) string {
|
||||
if module == "app" && parts["app:program"] == "sha256:cc" {
|
||||
return "src2:cc"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
if n, err := h.Released(rebuild, ""); n != 0 || err != nil || len(*order) != 0 {
|
||||
t.Fatalf("a rebuild's release wrote %d (%v) and said %v, want nothing", n, err, *order)
|
||||
}
|
||||
if got := strings.Join(journal, "\n"); !strings.Contains(got, "src2:cc made") || !strings.Contains(got, "src2:aa") {
|
||||
t.Errorf("a rebuild's release journal = %q, want both fingerprints", got)
|
||||
}
|
||||
journal = nil
|
||||
madeAt := h.Made
|
||||
h.Made = func(string, string) map[string]string { return nil }
|
||||
if n, _ := h.Released(rebuild, ""); n != 0 || !strings.Contains(strings.Join(journal, "\n"), "no build was heard at the mover's fingerprint src2:aa") {
|
||||
t.Errorf("a release with no build heard at the mover wrote %d, journal %q, want it said", n, journal)
|
||||
}
|
||||
h.Made, journal = madeAt, nil
|
||||
if m, _ := MoverOf(store[pkey].p, "app"); m.Version != "" {
|
||||
t.Fatalf("app's mover = %+v, want no version from a rebuild's release", m)
|
||||
}
|
||||
first, err := h.Released(ev, "main")
|
||||
if err == nil || len(*order) != 0 {
|
||||
t.Fatalf("released wrote %d (%v) and said %v, want the failed say returned", first, err, *order)
|
||||
|
||||
@@ -3,6 +3,8 @@ package pipeline
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"strings"
|
||||
|
||||
catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||
@@ -51,6 +53,13 @@ func (h *Hearer) Released(ev catalog.VersionReleasedEvent, branch string) (int,
|
||||
if i < 0 {
|
||||
break
|
||||
}
|
||||
// A release of another build of the same source is no version of this mover (design 47 H §835 1., H-A-490, H-A-849): its
|
||||
// parts must be what the mover's own build made at its fingerprint.
|
||||
if !h.madeRelease(p.Movers[i], ev) {
|
||||
h.logf("%s: the version %s of %s is not the mover's: %s (the mover keeps no version from it)",
|
||||
key, ev.Version, ev.Module, h.notMade(p.Movers[i], ev))
|
||||
break
|
||||
}
|
||||
if p.Movers[i].Version == ev.Version {
|
||||
// A version heard again says the end of an ended passed pipeline again (H-A-277 (3)): a say that failed after
|
||||
// the version was written is said now; taking it again is a no-op for the holder.
|
||||
@@ -80,6 +89,51 @@ func (h *Hearer) Released(ev catalog.VersionReleasedEvent, branch string) (int,
|
||||
return wrote, nil
|
||||
}
|
||||
|
||||
// notMade says why a release is no mover's, naming the two fingerprints (design 47 H §835 1.): the mover's, and the one whose heard
|
||||
// build made the release's parts, or that no build was heard at the mover's, or at any.
|
||||
func (h *Hearer) notMade(m seat.Mover, ev catalog.VersionReleasedEvent) string {
|
||||
var by string
|
||||
if h.MadeBy != nil {
|
||||
by = h.MadeBy(ev.Module, releasedParts(ev))
|
||||
}
|
||||
switch {
|
||||
case h.Made == nil || len(h.Made(m.Module, m.Fingerprint)) == 0:
|
||||
if by != "" {
|
||||
return fmt.Sprintf("no build was heard at the mover's fingerprint %s; its release's parts are what the build at %s made", m.Fingerprint, by)
|
||||
}
|
||||
return fmt.Sprintf("no build was heard at the mover's fingerprint %s, nor at another that made its release's parts", m.Fingerprint)
|
||||
case by != "":
|
||||
return fmt.Sprintf("its release's parts are what the build at %s made, not the build at the mover's fingerprint %s", by, m.Fingerprint)
|
||||
}
|
||||
return fmt.Sprintf("its release's parts are not what the build at the mover's fingerprint %s made, nor what any build heard made", m.Fingerprint)
|
||||
}
|
||||
|
||||
// releasedParts are the release's parts, each artifact's digest by `<module>:<artifact>`.
|
||||
func releasedParts(ev catalog.VersionReleasedEvent) map[string]string {
|
||||
parts := map[string]string{}
|
||||
for _, a := range ev.Artifacts {
|
||||
ref := string(a.Artifact)
|
||||
if !strings.Contains(ref, ":") {
|
||||
ref = ev.Module + ":" + ref
|
||||
}
|
||||
parts[ref] = a.Digest
|
||||
}
|
||||
return parts
|
||||
}
|
||||
|
||||
// madeRelease says whether the release's parts, each artifact's digest by `<module>:<artifact>`, are exactly what the build at the
|
||||
// mover's fingerprint made, as the assigner matches a release to a build (H-A-490): none known on either side matches nothing.
|
||||
func (h *Hearer) madeRelease(m seat.Mover, ev catalog.VersionReleasedEvent) bool {
|
||||
if h.Made == nil {
|
||||
return false
|
||||
}
|
||||
made := h.Made(m.Module, m.Fingerprint)
|
||||
if len(made) == 0 {
|
||||
return false
|
||||
}
|
||||
return maps.Equal(releasedParts(ev), made)
|
||||
}
|
||||
|
||||
// sayEndedAgain says p's pipeline-ended again when p ended passed (H-A-270 (2), H-A-277 (2)): only a passed end writes a want,
|
||||
// so a superseded, cancelled or failed one is not said again.
|
||||
func (h *Hearer) sayEndedAgain(key string, p seat.Pipeline, ev catalog.VersionReleasedEvent) error {
|
||||
|
||||
@@ -164,6 +164,12 @@ type Hearer struct {
|
||||
Where func(ask string) (string, *oc.Warrant, error)
|
||||
Logf func(string, ...any)
|
||||
Now func() time.Time
|
||||
// Made is what a done build of module at fingerprint made, each artifact's digest by `<module>:<artifact>`, as the builder's
|
||||
// build.ended says it (design 47 H §835 1., H-A-849); nil, or no part, when no such end is heard: a release then matches no mover.
|
||||
Made func(module, fingerprint string) map[string]string
|
||||
// MadeBy is the fingerprint whose heard done build of module made exactly parts (`<module>:<artifact>` to digest), empty when
|
||||
// none did: the journal line of a release that is no mover's names it (design 47 H §835 1.).
|
||||
MadeBy func(module string, parts map[string]string) string
|
||||
// KeptRevision says whether the catalog still keeps a branch's revision, as Verbs.RevisionHeld does: nil when it does, an error
|
||||
// wrapping ErrRevisionGone when it answers it gone (H-A-599); nil reads none and leaves a held step waiting.
|
||||
KeptRevision func(branch string, revision int64) error
|
||||
|
||||
@@ -99,7 +99,7 @@ func TestManifest(t *testing.T) {
|
||||
"node-build-go.step-progress", "node-build-node.step-progress", "node-build-image.step-progress", "mesh-wants.step-ended", "mesh-wants.step-progress",
|
||||
// H-A-514 addendum: the seat mesh-builds says step-progress of a build step that builds or waits for a package.
|
||||
"mesh-builds.step-progress", "node-engine.running", "mesh-catalog.registration-changed",
|
||||
"mesh-catalog.catalog-revision", "mesh-catalog.version-released", "mesh-conditions.findings-asked", "mesh-delivery.recovery-merged",
|
||||
"mesh-catalog.catalog-revision", "mesh-catalog.version-released", "mesh-delivery-builder.build.ended.**", "mesh-conditions.findings-asked", "mesh-delivery.recovery-merged",
|
||||
// A-186: the seat list its write verbs' callers are checked against, heard as it changes.
|
||||
"mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed",
|
||||
// §647 as A-466z amends it: no holder is read from the seat-holders view.
|
||||
|
||||
@@ -74,6 +74,7 @@
|
||||
"mesh-catalog.registration-changed",
|
||||
"mesh-catalog.catalog-revision",
|
||||
"mesh-catalog.version-released",
|
||||
"mesh-delivery-builder.build.ended.**",
|
||||
"mesh-conditions.findings-asked",
|
||||
"mesh-delivery.recovery-merged",
|
||||
"mesh-catalog.seat-definition-changed",
|
||||
|
||||
@@ -25,8 +25,10 @@ import (
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
mpr "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatdef"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-view/viewstate"
|
||||
|
||||
@@ -81,6 +83,9 @@ func user(name string, pub, sub []string) string {
|
||||
`, name, q(pub), q(append([]string{"_INBOX." + name + ".>"}, sub...)))
|
||||
}
|
||||
|
||||
// keptEnded is the stream of the seat mesh-pipeline-runner's kept event pipeline-ended.
|
||||
var keptEnded = seatdef.KeptStream(mpr.Seat, seatdef.Message{Name: mpr.EventPipelineEnded})
|
||||
|
||||
const (
|
||||
tellerAnswers = "mesh-delivery-teller_answers"
|
||||
tellerAsked = "mesh-delivery-teller_asked"
|
||||
@@ -110,6 +115,11 @@ func fullConf(dir string) string {
|
||||
// The finding writer finds the stream of the keeper's findings-asked (design 47 G §384): the bed has none, so it is
|
||||
// said and the findings stay in the state.
|
||||
teller = append(teller, "$JS.API.STREAM.NAMES")
|
||||
// pipeline-ended is a kept seat event on a stream of its own, with the teller's durable the grants part composes (design 47
|
||||
// H2b §836 1.); the teller tells a widening through the seat operator-channel's notify.
|
||||
teller = append(teller, "$JS.API.STREAM.INFO."+keptEnded, "$JS.API.STREAM.INFO.EVENTS", "$JS.API.CONSUMER.INFO."+keptEnded+"."+tellerConsumer,
|
||||
"$JS.API.CONSUMER.MSG.NEXT."+keptEnded+"."+tellerConsumer, "$JS.ACK."+keptEnded+"."+tellerConsumer+".>",
|
||||
"mesh.seat.operator-channel.call.notify", "mesh.seat.operator-channel.call.notify.>")
|
||||
// The manifest's emits (ADR 0596 §2; design 47 G A-175: its answers as its views family) and its marks state (A-178).
|
||||
teller = append(teller, "mesh.mod.mesh-delivery-teller.event.answered", "mesh.mod.mesh-delivery-teller.event.ask-ended", "mesh.mod.mesh-delivery-teller.event.views.answers")
|
||||
teller = append(teller, keepsOf(bucketsOf(tellerModule).marks)...)
|
||||
@@ -139,7 +149,8 @@ accounts {
|
||||
}
|
||||
}
|
||||
`, filepath.Join(dir, "js"),
|
||||
user("n1.mesh-delivery-teller", teller, nil),
|
||||
// The hub's wake on the grants part's durables-composed for this module (design 47 H2b §836 2.).
|
||||
user("n1.mesh-delivery-teller", teller, []string{"mesh.seat.mesh-grants.event.durables-composed.n1.mesh-delivery-teller"}),
|
||||
user("n1.mesh-delivery-view", view, nil),
|
||||
user("n1.mesh-delivery-assigner", assigner, nil))
|
||||
}
|
||||
@@ -206,6 +217,13 @@ func startFull(t *testing.T) *fullBed {
|
||||
AckPolicy: jetstream.AckExplicitPolicy}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
endedSubjects := []string{"mesh.seat." + mpr.Seat + ".event." + mpr.EventPipelineEnded, "mesh.seat." + mpr.Seat + ".event." + mpr.EventPipelineEnded + ".>"}
|
||||
if _, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: keptEnded, Subjects: endedSubjects}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := js.CreateOrUpdateConsumer(ctx, keptEnded, process.Account{Node: "n1", Module: tellerModule}.SeatEventConsumerConfig(endedSubjects, false)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// The assigner as the owner of its asks: its read tool and its views family (ADR 0615).
|
||||
viewstest.Serve(t, ctx, js, ctl, assignerModule, "asks", assignerModule+"."+meshwants.StateAsks, tellerConsumer)
|
||||
// The view as the owner of its answers, as the teller follows them (A-175, A-178).
|
||||
@@ -487,6 +505,45 @@ func TestTellerCarriesAnAskAndWritesTheAnswer(t *testing.T) { // 1343/AC1, AC2
|
||||
if err != nil || string(raw.Data) != `{"id":"`+ask2.ID+`"}` {
|
||||
t.Errorf("the ask taken away was not cancelled: %v %v\n%s", raw, err, logs.String())
|
||||
}
|
||||
// A pipeline-ended carrying a widening, a kept seat event the teller's one Start binds, is told once on every channel
|
||||
// (design 47 H2b §836 1., G §335, acceptance test 121): one message through the seat operator-channel's notify.
|
||||
told := make(chan map[string]any, 4)
|
||||
sub, err := b.ctl.Subscribe("mesh.seat.operator-channel.call.notify.>", func(m *nats.Msg) {
|
||||
var body map[string]any
|
||||
_ = json.Unmarshal(m.Data, &body)
|
||||
told <- body
|
||||
_ = m.Respond([]byte(`{"result":{},"node":"n0"}`))
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = sub.Unsubscribe() })
|
||||
end, _ := json.Marshal(mpr.PipelineEnded{Branch: "release", Movers: []mpr.MoverEnded{{Module: "plex", Commit: "0123456789abcdef", Widens: []mpr.Widening{{What: "grant", Name: "seat:mesh-wants.input"}}}}})
|
||||
if _, err := b.js.Publish(b.ctx, "mesh.seat."+mpr.Seat+".event."+mpr.EventPipelineEnded+".release.7", end); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
select {
|
||||
case body := <-told:
|
||||
if s, _ := body["summary"].(string); !strings.Contains(s, "plex 0123456 on release widens grant seat:mesh-wants.input") {
|
||||
t.Errorf("the widening was told as %v", body)
|
||||
}
|
||||
case <-time.After(15 * time.Second):
|
||||
t.Fatalf("no widening was told after a pipeline-ended carrying one\n%s", logs.String())
|
||||
}
|
||||
// Once, shown without waiting: a second, different widening is published; the next message told is the second one's, so the
|
||||
// first was not told twice (a duplicate would be in the channel before it).
|
||||
end2, _ := json.Marshal(mpr.PipelineEnded{Branch: "release", Movers: []mpr.MoverEnded{{Module: "plex", Commit: "fedcba9876543210", Widens: []mpr.Widening{{What: "grant", Name: "seat:mesh-grants.input"}}}}})
|
||||
if _, err := b.js.Publish(b.ctx, "mesh.seat."+mpr.Seat+".event."+mpr.EventPipelineEnded+".release.8", end2); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
select {
|
||||
case body := <-told:
|
||||
if s, _ := body["summary"].(string); !strings.Contains(s, "plex fedcba9 on release widens grant seat:mesh-grants.input") {
|
||||
t.Errorf("the next message told was %v, want the second widening's", body)
|
||||
}
|
||||
case <-time.After(15 * time.Second):
|
||||
t.Fatalf("the second widening was not told\n%s", logs.String())
|
||||
}
|
||||
}
|
||||
|
||||
// TestTellerFillsAnAskFromTheViewsAnswerOnce starts the program against the bus with the permissions above: the assigner's
|
||||
|
||||
@@ -35,6 +35,7 @@ import (
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-view/viewstate"
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatdef"
|
||||
"git.novox.be/novox/mesh-sdk/go/views"
|
||||
"git.novox.be/novox/mesh-sdk/go/views/viewstest"
|
||||
"github.com/nats-io/nats-server/v2/server"
|
||||
@@ -84,6 +85,10 @@ type catalogHolder struct {
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
// seatEventSubjects are the seat events the stream EVENTS carries in a test: all of them, unless a test keeps one apart on a
|
||||
// stream of its own, as the mesh keeps a kept seat event (design 47 H2b §836 1.).
|
||||
var seatEventSubjects = []string{"mesh.seat.*.event.>"}
|
||||
|
||||
func serveCatalog(t testing.TB, ctx context.Context, js jetstream.JetStream, nc *nats.Conn) *catalogHolder {
|
||||
t.Helper()
|
||||
h := &catalogHolder{t: t, js: js, ctx: ctx, rev: 1, entries: map[string]meshcatalog.CatalogEntry{
|
||||
@@ -96,7 +101,7 @@ func serveCatalog(t testing.TB, ctx context.Context, js jetstream.JetStream, nc
|
||||
}
|
||||
info := events.CachedInfo().Config
|
||||
if !slices.Contains(info.Subjects, "mesh.seat.*.event.>") {
|
||||
info.Subjects = append(info.Subjects, "mesh.seat.*.event.>")
|
||||
info.Subjects = append(info.Subjects, seatEventSubjects...)
|
||||
if _, err := js.UpdateStream(ctx, info); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -814,6 +819,26 @@ func TestProcessWholeSaysTheSourceRevisionIsDelivered(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// The runner's step-ended is a kept seat event on a stream of its own, never on EVENTS (design 47 H2b §836 1.): EVENTS carries
|
||||
// every other seat event, and the view's durable on the kept stream is the one the grants part composes.
|
||||
const runnerSeat = "mesh-pipeline-runner"
|
||||
var seatSubjects []string
|
||||
for _, seat := range []string{"mesh-catalog", "mesh-delivery", "mesh-conditions", "mesh-broker", "node-engine", "mesh-wants", "mesh-grants", "mesh-module-assigner"} {
|
||||
seatSubjects = append(seatSubjects, "mesh.seat."+seat+".event.>")
|
||||
}
|
||||
for _, e := range []string{pseat.EventPipelineStarted, pseat.EventPipelineEnded, pseat.EventRePinned} {
|
||||
seatSubjects = append(seatSubjects, "mesh.seat."+runnerSeat+".event."+e, "mesh.seat."+runnerSeat+".event."+e+".>")
|
||||
}
|
||||
seatEventSubjects = seatSubjects
|
||||
t.Cleanup(func() { seatEventSubjects = []string{"mesh.seat.*.event.>"} })
|
||||
keptSubjects := []string{"mesh.seat." + runnerSeat + ".event." + pseat.EventStepEnded, "mesh.seat." + runnerSeat + ".event." + pseat.EventStepEnded + ".>"}
|
||||
keptStream := seatdef.KeptStream(runnerSeat, seatdef.Message{Name: pseat.EventStepEnded})
|
||||
if _, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: keptStream, Subjects: keptSubjects}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := js.CreateOrUpdateConsumer(ctx, keptStream, process.Account{Node: "n", Module: testView}.SeatEventConsumerConfig(keptSubjects, false)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
kvs := map[string]jetstream.KeyValue{}
|
||||
for _, name := range []string{view.WantsBucket, view.HaveBucket, viewstate.BucketsOf(testView).Reach} {
|
||||
kv, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: name, History: 5})
|
||||
@@ -916,6 +941,30 @@ func TestProcessWholeSaysTheSourceRevisionIsDelivered(t *testing.T) {
|
||||
if err != nil || len(seen) < 2 || seen[len(seen)-1][0] != "release.10" {
|
||||
t.Fatalf("the pipelines followed = %v, %v; want release.10 after the runner's event", seen, err)
|
||||
}
|
||||
// A step-ended, a kept seat event on its own stream, refreshes the pipelines page too (design 47 H2b §836 1., H-A-467): the
|
||||
// view's one Start binds that stream, so the page is read again at the event and shows the pipeline the runner lists now.
|
||||
var after [][]string
|
||||
err = view.AskPipelines(env["MESH_DELIVERY_SOCKET"], "", 0, "", "", "", true, func(page view.PipelinesPage, _ *view.PipelineAnswer) bool {
|
||||
var keys []string
|
||||
for _, r := range page.Rows {
|
||||
keys = append(keys, r.Pipeline)
|
||||
}
|
||||
after = append(after, keys)
|
||||
if len(after) == 1 {
|
||||
pipelines.set(pseat.PipelineRow{Pipeline: "release.11", Source: rev + 2, Revision: 11, Outcome: "running", MoverCount: 1},
|
||||
pseat.PipelineRow{Pipeline: "release.10", Source: rev + 1, Revision: 10, Outcome: "running", MoverCount: 1},
|
||||
pseat.PipelineRow{Pipeline: "release.9", Source: rev, Revision: 9, Outcome: "passed", MoverCount: 1})
|
||||
body, _ := json.Marshal(pseat.StepEndedEvent{Pipeline: "release.10", Branch: catalogBranch, Module: "web"})
|
||||
if _, err := js.Publish(ctx, "mesh.seat."+runnerSeat+".event."+pseat.EventStepEnded+".web", body); err != nil {
|
||||
t.Error(err)
|
||||
return false
|
||||
}
|
||||
}
|
||||
return len(after) < 2 || !slices.Contains(keys, "release.11")
|
||||
})
|
||||
if err != nil || len(after) < 2 || after[len(after)-1][0] != "release.11" {
|
||||
t.Fatalf("the pipelines followed = %v, %v; want release.11 after the runner's step-ended", after, err)
|
||||
}
|
||||
snap, err := view.Ask(env["MESH_DELIVERY_SOCKET"])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -205,8 +205,10 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
return fmt.Errorf("the runner's events are not handled: %w", err)
|
||||
}
|
||||
go pipes.Run(ctx)
|
||||
if err := hub.StartUntilBound(ctx, js, cred, nil, nil); err != nil {
|
||||
logger.Printf("the consumer is not heard yet (tried again until it is): %v", err)
|
||||
// One Start binds every pattern's stream, the kept seat events' too, and binds again at the grants part's durables-composed
|
||||
// (design 47 H2b §836 1.).
|
||||
if err := hub.Start(ctx, js, cred); err != nil {
|
||||
logger.Printf("the consumer is not heard yet (bound when the bus makes it): %v", err)
|
||||
}
|
||||
go func() {
|
||||
select {
|
||||
|
||||
@@ -35,8 +35,10 @@ func waitPatterns() []string {
|
||||
}
|
||||
|
||||
// applyWait keeps one wait event: wait-held puts the wait under its key, wait-ended deletes it. The owner is the seat or module
|
||||
// of the subject unless the body names one.
|
||||
func applyWait(subject string, body []byte, put func(key string, value []byte) error, del func(key string) error) error {
|
||||
// of the subject unless the body names one. A wait-held whose wait is held as it says, and a wait-ended whose wait is not held,
|
||||
// write nothing, whether the event is a repeat under its id or comes under a new one (design 47 H §832 5., H-A-857): the owed events
|
||||
// of the assigner are said again, and a repeat is no new revision of the state. get reads the held value of a key, false when none.
|
||||
func applyWait(subject string, body []byte, get func(key string) ([]byte, bool, error), put func(key string, value []byte) error, del func(key string) error) error {
|
||||
parts := strings.Split(subject, ".")
|
||||
if len(parts) < 5 || parts[0] != "mesh" || (parts[1] != "seat" && parts[1] != "mod") || parts[3] != "event" {
|
||||
return fmt.Errorf("%s is no wait's subject", subject)
|
||||
@@ -51,8 +53,18 @@ func applyWait(subject string, body []byte, put func(key string, value []byte) e
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
held, ok, err := get(w.Key())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if ok && string(held) == string(raw) {
|
||||
return nil
|
||||
}
|
||||
return put(w.Key(), raw)
|
||||
case eventWaitEnded:
|
||||
if _, ok, err := get(w.Key()); err != nil || !ok {
|
||||
return err
|
||||
}
|
||||
return del(w.Key())
|
||||
}
|
||||
return fmt.Errorf("%s is no wait's subject", subject)
|
||||
@@ -62,6 +74,23 @@ func applyWait(subject string, body []byte, put func(key string, value []byte) e
|
||||
// one that could not be kept is not acknowledged, so the bus gives it again.
|
||||
func hearWaits(ctx context.Context, hub *process.EventHub, js jetstream.JetStream, bucket string, logf func(string, ...any)) error {
|
||||
kv := func() (jetstream.KeyValue, error) { return js.KeyValue(ctx, bucket) }
|
||||
get := func(key string) ([]byte, bool, error) {
|
||||
b, err := kv()
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
e, err := b.Get(ctx, key)
|
||||
if errors.Is(err, jetstream.ErrKeyNotFound) {
|
||||
return nil, false, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
if op := e.Operation(); op == jetstream.KeyValueDelete || op == jetstream.KeyValuePurge {
|
||||
return nil, false, nil
|
||||
}
|
||||
return e.Value(), true, nil
|
||||
}
|
||||
put := func(key string, value []byte) error {
|
||||
b, err := kv()
|
||||
if err != nil {
|
||||
@@ -82,7 +111,7 @@ func hearWaits(ctx context.Context, hub *process.EventHub, js jetstream.JetStrea
|
||||
}
|
||||
for _, pattern := range waitPatterns() {
|
||||
if err := hub.Handle(pattern, func(m jetstream.Msg) {
|
||||
if err := applyWait(m.Subject(), m.Data(), put, del); err != nil {
|
||||
if err := applyWait(m.Subject(), m.Data(), get, put, del); err != nil {
|
||||
logf("the wait event %s is not kept (the bus gives it again): %v", m.Subject(), err)
|
||||
_ = m.Nak()
|
||||
return
|
||||
|
||||
@@ -10,20 +10,36 @@ import (
|
||||
|
||||
func TestWaitEventsAreKeptUnderTheirKeyAndEnded(t *testing.T) {
|
||||
kept := map[string]string{}
|
||||
put := func(k string, v []byte) error { kept[k] = string(v); return nil }
|
||||
del := func(k string) error { delete(kept, k); return nil }
|
||||
writes := 0 // every put and delete is a new revision of the state
|
||||
get := func(k string) ([]byte, bool, error) { v, ok := kept[k]; return []byte(v), ok, nil }
|
||||
put := func(k string, v []byte) error { kept[k] = string(v); writes++; return nil }
|
||||
del := func(k string) error { delete(kept, k); writes++; return nil }
|
||||
held := `{"step":"delivery","module":"web","node":"ace","part":"db","machines":["g14"],"since":"2026-11-12T01:00:00Z","words":"waiting for delivery of db to g14"}`
|
||||
if err := applyWait("mesh.seat.mesh-wants.event.wait-held", []byte(held), put, del); err != nil || len(kept) != 1 ||
|
||||
if err := applyWait("mesh.seat.mesh-wants.event.wait-held", []byte(held), get, put, del); err != nil || len(kept) != 1 ||
|
||||
!strings.Contains(kept["mesh-wants.delivery.ace.web"], "waiting for delivery of db to g14") {
|
||||
t.Fatalf("kept %v, %v", kept, err)
|
||||
}
|
||||
if err := applyWait("mesh.mod.mesh-delivery-builder.event.wait-held.web.fp", []byte(`{"step":"building","module":"web","on":"toolchain:go@1","since":"2026-11-12T01:00:00Z"}`), put, del); err != nil || len(kept) != 2 {
|
||||
if err := applyWait("mesh.mod.mesh-delivery-builder.event.wait-held.web.fp", []byte(`{"step":"building","module":"web","on":"toolchain:go@1","since":"2026-11-12T01:00:00Z"}`), get, put, del); err != nil || len(kept) != 2 {
|
||||
t.Fatalf("a module's wait: %v, %v", kept, err)
|
||||
}
|
||||
if err := applyWait("mesh.seat.mesh-wants.event.wait-ended", []byte(`{"step":"delivery","module":"web","node":"ace","how":"ran","since":"2026-11-12T01:00:00Z"}`), put, del); err != nil || len(kept) != 1 {
|
||||
if err := applyWait("mesh.seat.mesh-wants.event.wait-ended", []byte(`{"step":"delivery","module":"web","node":"ace","how":"ran","since":"2026-11-12T01:00:00Z"}`), get, put, del); err != nil || len(kept) != 1 {
|
||||
t.Fatalf("ended: %v, %v", kept, err)
|
||||
}
|
||||
if err := applyWait("mesh.seat.mesh-wants.event.wait-held", []byte(`{"module":"web"}`), put, del); err == nil {
|
||||
// A repeated wait-held, under its id or a new one, and a repeated wait-ended write nothing new (AC-832m, H-A-857).
|
||||
before := writes
|
||||
for _, subject := range []string{"mesh.mod.mesh-delivery-builder.event.wait-held.web.fp", "mesh.mod.mesh-delivery-builder.event.wait-held.web.fp.2"} {
|
||||
if err := applyWait(subject, []byte(`{"step":"building","module":"web","on":"toolchain:go@1","since":"2026-11-12T01:00:00Z"}`), get, put, del); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
ended := []byte(`{"step":"delivery","module":"web","node":"ace","how":"ran","since":"2026-11-12T01:00:00Z"}`)
|
||||
if err := applyWait("mesh.seat.mesh-wants.event.wait-ended", ended, get, put, del); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if writes != before {
|
||||
t.Errorf("repeats wrote %d times, want none", writes-before)
|
||||
}
|
||||
if err := applyWait("mesh.seat.mesh-wants.event.wait-held", []byte(`{"module":"web"}`), get, put, del); err == nil {
|
||||
t.Error("a wait with no step was kept")
|
||||
}
|
||||
// None of the patterns overlaps another: the hub gives a message one taker.
|
||||
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"git.novox.be/novox/mesh-contracts/go/seats/meshbroker"
|
||||
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
@@ -99,6 +100,7 @@ func hearConsumed(ctx context.Context, js jetstream.JetStream, cred process.Acco
|
||||
w.NotHeard("EVENTS", "the seats' events cannot be handled", err)
|
||||
}
|
||||
}
|
||||
hub.OnUnheard(eventsUnheard(w, "what it carries is heard once the grants part has made the consumer "+cred.EventConsumerName()))
|
||||
var mu sync.Mutex
|
||||
opened := map[string]bool{}
|
||||
open := func(stream, name string) {
|
||||
@@ -110,11 +112,11 @@ func hearConsumed(ctx context.Context, js jetstream.JetStream, cred process.Acco
|
||||
// Not bound, the stream is the finding family-not-heard (ADR 0615 §5) until it is, at a later change of the
|
||||
// membership or a later start.
|
||||
if stream == "EVENTS" {
|
||||
// Start's nil says the hub started, never that EVENTS is heard: the hub's unheard list says it (H-A-877).
|
||||
if err := hub.Start(ctx, js, cred); err != nil {
|
||||
w.NotHeard(stream, "what it carries is heard once the grants part has made the consumer "+name, err)
|
||||
return
|
||||
}
|
||||
w.Heard(stream)
|
||||
opened[stream] = true
|
||||
return
|
||||
}
|
||||
@@ -265,3 +267,17 @@ func buildSeatSubject(w *watch.Watchman, subject string, body []byte) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// eventsUnheard is the hub's word of what it does not hear, as the watchman's finding family-not-heard of EVENTS: heard when the
|
||||
// list names no EVENTS entry, else not heard with the hub's reason (design 47 H2b H-A-877).
|
||||
func eventsUnheard(w *watch.Watchman, consequence string) func([]process.Unheard) {
|
||||
return func(list []process.Unheard) {
|
||||
for _, u := range list {
|
||||
if u.Stream == "EVENTS" {
|
||||
w.NotHeard("EVENTS", consequence, errors.New(u.Why))
|
||||
return
|
||||
}
|
||||
}
|
||||
w.Heard("EVENTS")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,25 @@ func TestRunNeedsItsCredential(t *testing.T) { // 1135/AC6
|
||||
}
|
||||
}
|
||||
})
|
||||
t.Run("H-A-877: EVENTS is heard from the hub's unheard list, never from Start's nil", func(t *testing.T) {
|
||||
out := &findingsOut{findings: map[string]bool{}}
|
||||
hubSays := eventsUnheard(watch.New(watchmanModule, out, time.Now), "x is not heard")
|
||||
for _, row := range []struct {
|
||||
name string
|
||||
list []process.Unheard
|
||||
want int
|
||||
}{
|
||||
{"EVENTS unbound", []process.Unheard{{Pattern: "mesh.seat.a.event.>", Stream: "EVENTS", Why: "consumer not found"}}, 1},
|
||||
{"a kept stream only", []process.Unheard{{Pattern: "mesh.seat.b.event.c", Stream: "SEAT_b_c", Why: "refused"}}, 0},
|
||||
{"EVENTS unbound again", []process.Unheard{{Pattern: "p", Stream: "EVENTS", Why: "w"}}, 1},
|
||||
{"all heard", nil, 0},
|
||||
} {
|
||||
hubSays(row.list)
|
||||
if len(out.findings) != row.want {
|
||||
t.Errorf("%s: findings %v, want %d", row.name, out.findings, row.want)
|
||||
}
|
||||
}
|
||||
})
|
||||
t.Run("DLV-W1: the consumed events reach the watchman by their subjects", func(t *testing.T) {
|
||||
out := &findingsOut{findings: map[string]bool{}}
|
||||
w := watch.New(watchmanModule, out, time.Now)
|
||||
|
||||
@@ -78,12 +78,22 @@ func (w *Watchman) putStands(id string, a meshwants.Wait, bound time.Duration, f
|
||||
", so the node's want is not at the build that was put.",
|
||||
Needs: "the put to go on, or released by hand (assigner_release)"}
|
||||
left := bound - w.now().Sub(from)
|
||||
w.unsignal(actingRow, id)
|
||||
w.unfind(f.Key())
|
||||
if left > 0 {
|
||||
w.signal(actingRow, id, left, signalDue{Do: dueFind, Finding: f})
|
||||
// A wait held again as it stands, its pulse standing for the same finding and none raised, changes nothing (design 47 H
|
||||
// §832 5., H-A-856): the assigner says an owed event again, and a repeat is no new pulse.
|
||||
due := signalDue{Do: dueFind, Finding: f}
|
||||
if held, ok := w.signals[signalKey(actingRow, id)]; ok && sameDue(held, due) {
|
||||
if _, raised := w.findings[f.Key()]; !raised {
|
||||
return
|
||||
}
|
||||
}
|
||||
w.unsignal(actingRow, id)
|
||||
w.unfind(f.Key())
|
||||
w.signal(actingRow, id, left, due)
|
||||
return
|
||||
}
|
||||
// Past its bound: the finding is written when it differs from the one the bucket holds, so a repeat clears and raises nothing.
|
||||
w.unsignal(actingRow, id)
|
||||
w.find(f)
|
||||
}
|
||||
|
||||
@@ -151,3 +161,10 @@ func (w *Watchman) EngineWaitEnded(node, module string) {
|
||||
w.unsignal(engineRow, id)
|
||||
w.unfind(FindingKey(ScopeDelivery, id, KindKeptBuildWaits))
|
||||
}
|
||||
|
||||
// sameDue says whether two signals' expiries do the same thing for the same finding.
|
||||
func sameDue(a, b signalDue) bool {
|
||||
x, err := json.Marshal(a)
|
||||
y, err2 := json.Marshal(b)
|
||||
return err == nil && err2 == nil && string(x) == string(y)
|
||||
}
|
||||
|
||||
@@ -26,18 +26,37 @@ func TestAPutWithoutHoldThatStandsIsPutStands(t *testing.T) {
|
||||
if len(o.findings) != 0 || len(o.pulses) != 0 {
|
||||
t.Fatalf("an acting part's wait is timed: findings %v, pulses %v", o.findings, o.pulses)
|
||||
}
|
||||
w.WaitHeld("mesh-wants", put(c.t))
|
||||
held := put(c.t)
|
||||
w.WaitHeld("mesh-wants", held)
|
||||
if len(o.findings) != 0 {
|
||||
t.Fatalf("within the bound: %v", o.findings)
|
||||
}
|
||||
// A repeated wait-held, under its id or a new one, changes nothing (design 47 H §832 5., H-A-856, AC-832n): its pulse stands
|
||||
// as it was written, never deleted and written again.
|
||||
deletes := len(o.pulseDeletes)
|
||||
w.WaitHeld("mesh-wants", held)
|
||||
if len(o.pulseDeletes) != deletes {
|
||||
t.Fatalf("a repeated wait-held deleted its pulse again: %v", o.pulseDeletes)
|
||||
}
|
||||
expire(w, c, signalKey(actingRow, id), 30*time.Minute)
|
||||
if _, ok := o.findings[FindingKey(ScopeDelivery, id, KindPutStands)]; !ok || len(o.findings) != 1 {
|
||||
t.Fatalf("past its bound: %v", o.findings)
|
||||
}
|
||||
w.WaitEnded("mesh-wants", put(c.t))
|
||||
// Past its bound, a repeat neither clears nor raises put-stands again.
|
||||
writes := o.findingWrites
|
||||
w.WaitHeld("mesh-wants", held)
|
||||
if o.findingWrites != writes || len(o.findings) != 1 {
|
||||
t.Fatalf("a repeated wait-held past its bound wrote the finding again: %d writes, was %d", o.findingWrites, writes)
|
||||
}
|
||||
w.WaitEnded("mesh-wants", held)
|
||||
if len(o.findings) != 0 {
|
||||
t.Fatalf("wait-ended left %v", o.findings)
|
||||
}
|
||||
deletes = len(o.pulseDeletes)
|
||||
w.WaitEnded("mesh-wants", held)
|
||||
if len(o.pulseDeletes) != deletes || len(o.findings) != 0 {
|
||||
t.Fatalf("a repeated wait-ended wrote again: %v", o.pulseDeletes)
|
||||
}
|
||||
}
|
||||
|
||||
// design 47 G §499, §541 (WM5): a node-engine's wait for a kept build standing 60 minutes is `kept-build-waits` naming the node,
|
||||
|
||||
@@ -18,4 +18,21 @@ func TestTheLoopOfOwnHearsLeavesTheStreamsADedicatedHearingOwns(t *testing.T) {
|
||||
if len(got) != 1 || got[0].Stream != "mod-c_feed" {
|
||||
t.Errorf("the streams opened are %+v, want mod-c_feed alone", got)
|
||||
}
|
||||
// H-A-877: the seat list is read when the hub says every pattern is heard, never when it is registered or started.
|
||||
t.Run("the seat list is read at the hub's all-heard, not before", func(t *testing.T) {
|
||||
hub := &fakeAllHeard{}
|
||||
lives := 0
|
||||
liveWhenAllHeard(hub, func() { lives++ })
|
||||
if lives != 0 || len(hub.fs) != 1 {
|
||||
t.Fatalf("live was called %d times with %d hooks registered, want none called and one registered", lives, len(hub.fs))
|
||||
}
|
||||
hub.fs[0]()
|
||||
if lives != 1 {
|
||||
t.Errorf("live was called %d times at the all-heard, want one", lives)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
type fakeAllHeard struct{ fs []func() }
|
||||
|
||||
func (h *fakeAllHeard) OnAllHeard(f func()) { h.fs = append(h.fs, f) }
|
||||
|
||||
@@ -245,6 +245,9 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
registered = true
|
||||
// An owner's views event goes to the follower of its state, which acknowledges it (firstviews.go).
|
||||
// The hub says when the bus made its consumer: a picture asked before then is asked again (views.Follower.ConsumerMade).
|
||||
// Start's nil says the hub started, never that its events are heard: the seat list is read now when it is unread
|
||||
// only once every pattern is heard (design 47 H2b §836 1.; H-A-877).
|
||||
liveWhenAllHeard(hub, gate.EventsLive)
|
||||
hub.OnBound(func(created time.Time) {
|
||||
for _, f := range byState {
|
||||
f.ConsumerMade(ctx, created)
|
||||
@@ -274,7 +277,6 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
if err := hub.Start(ctx, js, account); err != nil {
|
||||
return err
|
||||
}
|
||||
gate.EventsLive()
|
||||
hears, err := grants.OwnHears(ownStore{conn}, account.Node)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -371,6 +373,13 @@ func hearRunning(ctx context.Context, account process.Account, js jetstream.JetS
|
||||
return nil
|
||||
}
|
||||
|
||||
// allHeardHub is the event hub's hook that says every pattern is heard.
|
||||
type allHeardHub interface{ OnAllHeard(f func()) }
|
||||
|
||||
// liveWhenAllHeard has live called each time the hub comes to hear every pattern, never at registration (design 47 H2b §836 1.;
|
||||
// H-A-877).
|
||||
func liveWhenAllHeard(hub allHeardHub, live func()) { hub.OnAllHeard(live) }
|
||||
|
||||
// seatGate is the part's seat-list wiring (mesh-sdk seatlist.Part, ADR 0636 §1, §7) that also says the definitions the
|
||||
// list holds, which the part makes each kept event's stream from.
|
||||
type seatGate struct{ *seatlist.Part }
|
||||
|
||||
@@ -66,6 +66,8 @@ type fakeBus struct {
|
||||
events []string
|
||||
// seatEvents are the seat events said, as seat.event.
|
||||
seatEvents []string
|
||||
// seatBodies are the bodies of the seat events said, in the same order.
|
||||
seatBodies []any
|
||||
writes []string
|
||||
// Each membership's subject: the last membership said there, every notice, and whether it is refused.
|
||||
stream map[string][]byte
|
||||
@@ -485,13 +487,27 @@ func (b *fakeBus) Emit(event string, _ any) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *fakeBus) EmitSeat(seat, event string, _ any) error {
|
||||
func (b *fakeBus) EmitSeat(seat, event string, body any) error {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
b.seatEvents = append(b.seatEvents, seat+"."+event)
|
||||
b.seatBodies = append(b.seatBodies, body)
|
||||
return nil
|
||||
}
|
||||
|
||||
// composedSaid are the durables-composed events the part said, with their bodies.
|
||||
func composedSaid(b *fakeBus) []meshgrants.DurablesComposed {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
var out []meshgrants.DurablesComposed
|
||||
for i, e := range b.seatEvents {
|
||||
if strings.HasPrefix(e, "mesh-grants."+meshgrants.EventDurablesComposed+".") {
|
||||
out = append(out, b.seatBodies[i].(meshgrants.DurablesComposed))
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (b *fakeBus) count(key string) int {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
@@ -2437,7 +2453,14 @@ func TestGrants(t *testing.T) {
|
||||
len(res.Consumers.Matched) != 1 {
|
||||
t.Fatalf("filters added %v, now %v, said %+v", b.filterAdds, b.consumers["EVENTS"], res.Consumers)
|
||||
}
|
||||
// 1984/AC-836k: filters added to a held durable are a composed durable too, said once for its module.
|
||||
if got := composedSaid(b); len(got) != 1 || got[0].Module != "mod-c" || got[0].Durables[0].Name != "b_mod-c" {
|
||||
t.Errorf("durables-composed said %+v after filters were added", got)
|
||||
}
|
||||
p.Compose()
|
||||
if got := composedSaid(b); len(got) != 1 {
|
||||
t.Errorf("a pass that added no filter said durables-composed again: %+v", got)
|
||||
}
|
||||
if len(b.filterAdds) != 1 {
|
||||
t.Errorf("a consumer that holds every filter was added to again: %v", b.filterAdds)
|
||||
}
|
||||
@@ -4205,6 +4228,66 @@ func TestGrants(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
// H-A-870 (design 47 H2b §836 2.): a module with a program may ask the stream info of EVENTS and of each kept stream it
|
||||
// consumes, and hears the grants part's durables-composed for its own node and module alone; one with no program neither.
|
||||
t.Run("the event hub of a program: stream info and its wake", func(t *testing.T) {
|
||||
const stream = "SEAT_mesh-conditions_findings-asked"
|
||||
heard := []buscompose.Heard{{Stream: stream, Emitter: "mesh-conditions", Filters: []string{"mesh.seat.mesh-conditions.event.findings-asked"}}}
|
||||
users, err := buscompose.Users(buscompose.Records{Nodes: []string{"b"},
|
||||
Assigned: map[string][]buscompose.Declared{"b": {{Module: "mod-c", HasProgram: true, Hears: heard}, {Module: "mod-d", Hears: heard}}}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
woke := map[string]bool{}
|
||||
for _, u := range users {
|
||||
if u.Kind != buscompose.KindModule {
|
||||
continue
|
||||
}
|
||||
perms, err := buscompose.PermissionsFor(u)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
own := "mesh.seat.mesh-grants.event.durables-composed.b." + u.Module
|
||||
woke[u.Module] = buscompose.MaySubscribe(perms, own)
|
||||
want := u.Module == "mod-c"
|
||||
if got := buscompose.MayPublish(perms, "$JS.API.STREAM.INFO.EVENTS") && buscompose.MayPublish(perms, "$JS.API.STREAM.INFO."+stream); got != want {
|
||||
t.Errorf("%s: may ask the stream info of EVENTS and %s: %v, want %v", u.Module, stream, got, want)
|
||||
}
|
||||
if woke[u.Module] != want || buscompose.MaySubscribe(perms, "mesh.seat.mesh-grants.event.durables-composed.b.other") {
|
||||
t.Errorf("%s: hears its durables-composed: %v (and another module's: want neither of the second), want %v", u.Module, woke[u.Module], want)
|
||||
}
|
||||
}
|
||||
if len(woke) != 2 {
|
||||
t.Fatalf("composed accounts of %v, want mod-c and mod-d", woke)
|
||||
}
|
||||
// H-A-871: a process with a bus of its own that hears a kept stream has them too, and one that hears none has neither.
|
||||
procs, err := buscompose.Users(buscompose.Records{Nodes: []string{"b"},
|
||||
Kept: []buscompose.KeptEvent{{Seat: "mesh-conditions", Event: "findings-asked", Stream: stream, Filter: "mesh.seat.mesh-conditions.event.findings-asked"}},
|
||||
Assigned: map[string][]buscompose.Declared{"b": {{Module: "mod-e", Consumes: []string{"mesh-conditions.findings-asked"},
|
||||
Processes: []buscompose.ProcessPrincipal{{Process: "hearer", Consumes: []string{"mesh-conditions.findings-asked"}}, {Process: "mute"}}}}}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
seen := 0
|
||||
for _, u := range procs {
|
||||
if u.Kind != buscompose.KindProcess {
|
||||
continue
|
||||
}
|
||||
seen++
|
||||
perms, err := buscompose.PermissionsFor(u)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := u.Process == "hearer"
|
||||
if got := buscompose.MayPublish(perms, "$JS.API.STREAM.INFO.EVENTS") && buscompose.MaySubscribe(perms, "mesh.seat.mesh-grants.event.durables-composed.b.mod-e"); got != want {
|
||||
t.Errorf("process %s: the hub's grants %v, want %v", u.Process, got, want)
|
||||
}
|
||||
}
|
||||
if seen != 2 {
|
||||
t.Fatalf("composed %d process accounts, want 2", seen)
|
||||
}
|
||||
})
|
||||
|
||||
// 774/AC6 (novox/hq ADR 0561 §6), 1126/A1/AC1: the durable consumers an account needs, with the composed
|
||||
// configuration, are created where the bus lacks them with no lease key at all (the controller ended by its
|
||||
// unassignment, never by the lease write); one the bus holds is never changed.
|
||||
@@ -4230,10 +4313,33 @@ func TestGrants(t *testing.T) {
|
||||
if made == nil || made["max_deliver"] != 5 || !slices.Contains(made["filters"].([]string), "mesh.mod.mod-y.event.done") {
|
||||
t.Errorf("b_mod-c was made as %v, not as the controller makes it", made)
|
||||
}
|
||||
// 1984/AC-836k (design 47 H2b §836 2.): the pass that made the durable says durables-composed once, naming it.
|
||||
if got := composedSaid(b); len(got) != 1 || got[0].Node != "b" || got[0].Module != "mod-c" ||
|
||||
len(got[0].Durables) != 1 || got[0].Durables[0].Name != "b_mod-c" || got[0].Durables[0].Stream != "EVENTS" {
|
||||
t.Errorf("durables-composed said %+v, want one for b mod-c naming EVENTS b_mod-c", got)
|
||||
}
|
||||
res = p.Compose()
|
||||
if len(res.Consumers.Created) != 0 || len(res.Consumers.Missing) != 0 || len(b.consumerCreates) != 1 {
|
||||
t.Errorf("a consumer the bus holds was asked again: %+v, %v", res.Consumers, b.consumerCreates)
|
||||
}
|
||||
if got := composedSaid(b); len(got) != 1 {
|
||||
t.Errorf("a pass that composed no durable said durables-composed again: %+v", got)
|
||||
}
|
||||
// 1984/AC-838a (design 47 H2b §838): a module whose processes are all run-once or on a schedule has no program, so
|
||||
// no durable of its own is made for it; one with a long-running process without a bus has.
|
||||
for module, resources := range map[string]string{
|
||||
"mod-once": `,"resources":[{"id":"step","type":"process","run":["./step"],"run-once":true}]`,
|
||||
"mod-sched": `,"resources":[{"id":"step","type":"process","run":["./step"],"schedule":"daily"}]`,
|
||||
"mod-long": programResource,
|
||||
} {
|
||||
b.manifestOf(module, `{"module":"`+module+`","version":"1","own-secrets":{"broker":"/var/lib/c/broker"},"consumes":["mod-y.done"]`+resources+`}`)
|
||||
b.assign("b", module)
|
||||
}
|
||||
b.loaded = shadowOf(t, b)
|
||||
res = p.Compose()
|
||||
if !slices.Equal(res.Consumers.Created, []string{"EVENTS.b_mod-long"}) {
|
||||
t.Errorf("modules with a run-once, a scheduled and a long-running process: created %v, want b_mod-long alone", res.Consumers.Created)
|
||||
}
|
||||
// A held consumer that differs is never changed by a pass: it is raised as a condition naming it, and brought to
|
||||
// the composed configuration only by hand (grants_consumer_match), with no lease key too.
|
||||
var said, behind, orphaned []oc.Condition
|
||||
|
||||
@@ -1296,7 +1296,7 @@ func theBusModulesProcessKeepsBusState(t *testing.T) {
|
||||
}
|
||||
for _, s := range keeper.Subscribe {
|
||||
if !strings.HasPrefix(s, "_INBOX.a.nats.keeper.") && !strings.HasPrefix(s, "$JS.EVENT.ADVISORY.STREAM.CREATED.KV_nats_") &&
|
||||
!strings.HasPrefix(s, "mesh.seat.operator-channel.") {
|
||||
!strings.HasPrefix(s, "mesh.seat.operator-channel.") && s != "mesh.seat.mesh-grants.event.durables-composed.a.nats" /* H-A-871: its wake */ {
|
||||
t.Errorf("the bus module's process subscribes %s, beyond its inbox, its own state's creation and its conditions' answers", s)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,6 +229,11 @@ func ConsumersOf(users []Principal) []ModuleConsumer {
|
||||
if c, ok := keeperConsumer(p); ok {
|
||||
out = append(out, ModuleConsumer{Node: p.Node, Module: p.Module, Consumer: c})
|
||||
}
|
||||
for _, h := range p.Hears {
|
||||
if len(h.Filters) > 0 {
|
||||
out = append(out, ModuleConsumer{Node: p.Node, Module: p.Module, Consumer: heardConsumer(p, h)})
|
||||
}
|
||||
}
|
||||
}
|
||||
// Any other process hears what its bus consumes on consumers of its own: on EVENTS, and on each kept seat event's
|
||||
// stream (design 47 G A-340).
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/identity-and-access/go/seats/meshgrants"
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatdef"
|
||||
)
|
||||
@@ -52,3 +53,24 @@ func gatedEndedGrants(user string, marked, invokes, answers []string) (pub, sub
|
||||
func GatedEndedSubject(seat, caller string) string {
|
||||
return seatdef.EventSubject(seat, seatdef.GatedEndedEvent) + "." + caller
|
||||
}
|
||||
|
||||
// hubGrants are what the event hub of a module's program asks beside its durables (design 47 H2b §836 2., H-A-870): the stream
|
||||
// info of EVENTS and of each kept seat event's stream its module consumes (the hub binds a stream it finds), and its wake, the
|
||||
// grants part's durables-composed for its own node and module. A module with no program has none; a process that declares a
|
||||
// bus has them where it hears a kept stream or is the bus module's keeper, which waits on durables-composed (H-A-871).
|
||||
func hubGrants(p Principal) (pub, sub []string) {
|
||||
hubs := p.Kind == KindModule && p.HasProgram
|
||||
if p.Kind == KindProcess {
|
||||
hubs = p.KeepsBus || slices.ContainsFunc(p.Hears, func(h Heard) bool { return strings.HasPrefix(h.Stream, seatdef.KeptStreamPrefix) })
|
||||
}
|
||||
if !hubs || !safeSubject.MatchString(p.Node) || !safeSubject.MatchString(p.Module) {
|
||||
return nil, nil
|
||||
}
|
||||
pub = []string{"$JS.API.STREAM.INFO.EVENTS"}
|
||||
for _, h := range p.Hears {
|
||||
if safeSubject.MatchString(h.Stream) && strings.HasPrefix(h.Stream, seatdef.KeptStreamPrefix) {
|
||||
pub = append(pub, "$JS.API.STREAM.INFO."+h.Stream)
|
||||
}
|
||||
}
|
||||
return unique(pub), []string{seatdef.EventSubject(GrantsModule, meshgrants.EventDurablesComposed) + "." + p.Node + "." + p.Module}
|
||||
}
|
||||
|
||||
@@ -1147,6 +1147,11 @@ func permissionsFor(p Principal) (Permissions, error) {
|
||||
}
|
||||
pub = append(pub, heardGrants(p, p.Hears)...)
|
||||
|
||||
// 2a'. The event hub of its program (design 47 H2b §836 2., H-A-870): the stream info of EVENTS and of each kept
|
||||
// stream its module consumes, and its wake, the grants part's durables-composed for this node and module.
|
||||
hp, hs := hubGrants(p)
|
||||
pub, sub = append(pub, hp...), append(sub, hs...)
|
||||
|
||||
// 2b. Events of a role it watches, under the seat's own namespace. Subscribe only: watching a
|
||||
// role is hearing what it announced, not taking part in it.
|
||||
sub = append(sub, watchedEvents(p.Watches)...)
|
||||
|
||||
@@ -126,12 +126,18 @@ func processGrants(p Principal) (pub, sub []string, err error) {
|
||||
if c, ok := keeperConsumer(p); ok {
|
||||
pub = append(pub, keeperConsumerGrants(c)...)
|
||||
}
|
||||
pub = append(pub, heardGrants(p, p.Hears)...) // and its heard durable on each kept stream its module consumes (design 47 H2b §836 5.)
|
||||
pub = append(pub, ownStreamGrants(p.Module, p.Streams)...)
|
||||
pub = append(pub, p.SaysSeatEvents...)
|
||||
tp, ts := seatTrafficGrants(SeatTrafficOf(p.Module, nil, p.Uses, nil))
|
||||
pub, sub = append(pub, tp...), append(sub, ts...)
|
||||
}
|
||||
|
||||
// 7. The event hub of its process (design 47 H2b §836 2., H-A-871): the stream info of EVENTS and of each kept stream it hears,
|
||||
// and its module's own durables-composed.
|
||||
hp, hs := hubGrants(p)
|
||||
pub, sub = append(pub, hp...), append(sub, hs...)
|
||||
|
||||
return pub, sub, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -325,6 +325,9 @@ func Users(r Records) ([]Principal, error) {
|
||||
k.KeepsBus, k.KeepsBusState = true, BusStateNames(r.BusState, r.Bound)
|
||||
k.KeepsRestricted = restrictedStreamNames(r)
|
||||
k.Consumes, k.Streams = d.Consumes, d.Streams
|
||||
// A kept seat event its module consumes is heard on the event's own stream, as every other process hears one
|
||||
// (design 47 H2b §836 5.): its heard durable, named as its durable on EVENTS.
|
||||
_, k.Hears = SplitKept(r.Kept, d.Consumes)
|
||||
k.Watches = d.Watches
|
||||
k.SaysSeatEvents = brokerSeatEvents(d.Holds)
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ import (
|
||||
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/identity-and-access/go/seats/meshgrants"
|
||||
|
||||
occ "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/clients/operatorchannelclient"
|
||||
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
|
||||
"mesh-grants/internal/buscompose"
|
||||
@@ -231,8 +233,19 @@ func (p *Part) consumers(res *Result, recs buscompose.Records, match string) {
|
||||
defer func() { p.behindSeen = seen }()
|
||||
var orphans []string
|
||||
byStream := map[string][]buscompose.Consumer{}
|
||||
ownerOf := map[string]buscompose.ModuleConsumer{} // the module and node of each composed durable, by `<stream>.<name>`
|
||||
for _, mc := range wanted {
|
||||
byStream[mc.Consumer.Stream] = append(byStream[mc.Consumer.Stream], mc.Consumer)
|
||||
ownerOf[mc.Consumer.Stream+"."+mc.Consumer.Name] = mc
|
||||
}
|
||||
// composedOf are the durables this pass created or gave filters, per module and node: each module's are said once,
|
||||
// after the pass's last durable (design 47 H2b §836 2.).
|
||||
composedOf := map[string][]meshgrants.DurablesComposedDurablesItem{}
|
||||
composedAt := func(stream, name string) {
|
||||
if mc, ok := ownerOf[stream+"."+name]; ok {
|
||||
k := mc.Node + "\x00" + mc.Module
|
||||
composedOf[k] = append(composedOf[k], meshgrants.DurablesComposedDurablesItem{Name: name, Stream: stream})
|
||||
}
|
||||
}
|
||||
// The durables no pass composes, the tool runner's twins it makes itself from the membership's spec and the plain one of a
|
||||
// module whose program left, are still judged here, held on the streams each consuming module's heard entries name
|
||||
@@ -304,6 +317,7 @@ func (p *Part) consumers(res *Result, recs buscompose.Records, match string) {
|
||||
p.Logf("consumer %s gained the filters %s", key, strings.Join(add, ", "))
|
||||
}
|
||||
p.say(res, EventAsserted, map[string]any{"consumer": c.Name, "stream": stream, "filters-added": add})
|
||||
composedAt(stream, c.Name)
|
||||
h.Filters = append(slices.Clone(h.Filters), add...)
|
||||
}
|
||||
}
|
||||
@@ -335,6 +349,7 @@ func (p *Part) consumers(res *Result, recs buscompose.Records, match string) {
|
||||
p.Logf("consumer %s created", key)
|
||||
}
|
||||
p.say(res, EventAsserted, map[string]any{"consumer": c.Name, "stream": stream})
|
||||
composedAt(stream, c.Name)
|
||||
case errors.Is(err, ErrHeld):
|
||||
default:
|
||||
st.Missing = append(st.Missing, key)
|
||||
@@ -349,11 +364,28 @@ func (p *Part) consumers(res *Result, recs buscompose.Records, match string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
p.sayDurablesComposed(res, composedOf)
|
||||
p.sayDiffer(st)
|
||||
p.sayBehind(st)
|
||||
p.sayOrphaned(orphans)
|
||||
}
|
||||
|
||||
// sayDurablesComposed says the seat's event durables-composed once for each module and node whose durables the pass
|
||||
// created or gave filters, after the pass's last durable, so a module's event hub binds a stream it could not bind at its
|
||||
// start (design 47 H2b §836 2.). A pass that composed none of a module's says none, whether its membership changed or not.
|
||||
func (p *Part) sayDurablesComposed(res *Result, composedOf map[string][]meshgrants.DurablesComposedDurablesItem) {
|
||||
if p.Emit == nil {
|
||||
return
|
||||
}
|
||||
for _, k := range sortedKeys(composedOf) {
|
||||
node, module, _ := strings.Cut(k, "\x00")
|
||||
body := meshgrants.DurablesComposed{At: p.now(), Durables: composedOf[k], Module: module, Node: node}
|
||||
if err := p.Emit.EmitSeat(meshgrants.Seat, meshgrants.EventDurablesComposed+"."+node+"."+module, body); err != nil {
|
||||
res.Errors = append(res.Errors, fmt.Sprintf("the seat event %s of %s on %s could not be said: %v", meshgrants.EventDurablesComposed, module, node, err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sayDiffer raises the warning condition mesh-grants.consumer-differs while an account consumer the part owns (from the
|
||||
// controller's end) differs from its composed configuration, naming each with the fields that differ, and clears it when
|
||||
// they match. Said once per set of differences, again when it changes.
|
||||
|
||||
@@ -2,6 +2,7 @@ package grants
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -62,8 +63,12 @@ func TestAProcessBusHearsWhatItsModuleConsumes(t *testing.T) {
|
||||
}
|
||||
const stream, subject = "SEAT_mesh-conditions_findings-asked", "mesh.seat.mesh-conditions.event.findings-asked"
|
||||
users, err := buscompose.Users(buscompose.Records{Nodes: []string{"ace"},
|
||||
Kept: []buscompose.KeptEvent{{Seat: "mesh-conditions", Event: "findings-asked", Stream: stream, Filter: subject}},
|
||||
Assigned: map[string][]buscompose.Declared{"ace": {{Module: "zfs", Consumes: m.Consumes, Processes: processesOf(m)}}}})
|
||||
Kept: []buscompose.KeptEvent{{Seat: "mesh-conditions", Event: "findings-asked", Stream: stream, Filter: subject}},
|
||||
Assigned: map[string][]buscompose.Declared{"ace": {{Module: "zfs", Consumes: m.Consumes, Processes: processesOf(m)},
|
||||
// 1984/AC-836l (design 47 H2b §836 5.): the bus module's process hears what its module consumes of a kept seat event on
|
||||
// the event's stream too, on a durable named as its durable on EVENTS.
|
||||
{Module: "nats", SnapshotsTheBus: true, Consumes: []string{"mesh-conditions.findings-asked"},
|
||||
Processes: []buscompose.ProcessPrincipal{{Process: "bus-keeper", Keeps: true}}}}}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -86,6 +91,25 @@ func TestAProcessBusHearsWhatItsModuleConsumes(t *testing.T) {
|
||||
buscompose.MayPublish(perms["keeper"], s), buscompose.MayPublish(perms["mute"], s))
|
||||
}
|
||||
}
|
||||
for _, u := range users {
|
||||
if u.Kind == buscompose.KindProcess && u.Process == "bus-keeper" {
|
||||
pm, err := buscompose.PermissionsFor(u)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
const keeperDurable = "ace_nats_bus-keeper"
|
||||
if !buscompose.MayPublish(pm, "$JS.API.CONSUMER.MSG.NEXT."+stream+"."+keeperDurable) || !buscompose.MayPublish(pm, "$JS.ACK."+stream+"."+keeperDurable+".1") {
|
||||
t.Errorf("the bus module's process may not read its durable on %s", stream)
|
||||
}
|
||||
heard := false
|
||||
for _, c := range buscompose.AccountConsumers(users) {
|
||||
heard = heard || c.Module == "nats" && c.Consumer.Stream == stream && c.Consumer.Name == keeperDurable && slices.Equal(c.Consumer.Filters, []string{subject})
|
||||
}
|
||||
if !heard {
|
||||
t.Errorf("the bus module's process has no durable %s on %s", keeperDurable, stream)
|
||||
}
|
||||
}
|
||||
}
|
||||
var made []string
|
||||
for _, c := range buscompose.AccountConsumers(users) {
|
||||
if c.Module == "zfs" && strings.HasPrefix(c.Consumer.Name, "ace_zfs_") && !strings.HasSuffix(c.Consumer.Name, buscompose.ToolsSuffix) { // the processes' own, not the module's nor its runner's
|
||||
|
||||
@@ -652,12 +652,14 @@ func queueOwnersOf(m catalogue.Manifest) []buscompose.QueueOwner {
|
||||
return out
|
||||
}
|
||||
|
||||
// hasOwnProcess says the manifest names a process resource with no `bus` of its own: one that runs on the module's own
|
||||
// account and reads its consumer <node>_<module> (H-A-472 second addendum).
|
||||
// hasOwnProcess says the manifest names a process resource with no `bus` of its own that runs for the module's whole
|
||||
// life: one that runs on the module's own account and reads its consumer <node>_<module> (H-A-472 second addendum). A
|
||||
// process marked `run-once: true` or carrying a `schedule` runs to its end and never pulls a durable, so it counts for
|
||||
// nothing (design 47 H2b §838).
|
||||
func hasOwnProcess(m catalogue.Manifest) bool {
|
||||
buses := m.ProcessBuses()
|
||||
for _, r := range m.Resources {
|
||||
if fmt.Sprint(r["type"]) != "process" {
|
||||
if fmt.Sprint(r["type"]) != "process" || !catalogue.LongRunning(r) {
|
||||
continue
|
||||
}
|
||||
if _, bus := buses[fmt.Sprint(r["id"])]; !bus {
|
||||
|
||||
Reference in New Issue
Block a user