From 14254dd0bab1770acb0e68ca7e6db0c542947659 Mon Sep 17 00:00:00 2001 From: jochen Date: Sat, 21 Nov 2026 12:31:51 +0100 Subject: [PATCH] Assigner: no want before a revision is kept; the full-store verdict stays the pass's Review round 1: the start handed a removal-only keeping to the background while passes wrote wants with no revision kept, so their wanted was never said. A pass now writes no want until the first keeping keeps a revision (that keeping wakes the pass), the start's removal folds into the first pass's keeping, and the pass judges the store's fill itself, through a handle of its own, before it writes. The integration bed makes the revisions' object store, as the grants part does from the manifest. Builds: design 47 H H-A-259, H-A-261; ADR 0682 --- .../cmd/mesh-delivery-assigner/graphfill.go | 22 +++- .../mesh-delivery-assigner/graphfill_test.go | 13 +- .../cmd/mesh-delivery-assigner/graphkept.go | 60 +++++++--- .../mesh-delivery-assigner/graphkept_test.go | 113 ++++++++++++++---- .../integration_test.go | 6 + .../cmd/mesh-delivery-assigner/main.go | 5 +- .../cmd/mesh-delivery-assigner/pass.go | 5 +- 7 files changed, 170 insertions(+), 54 deletions(-) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphfill.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphfill.go index e2748a48..4809119e 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphfill.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphfill.go @@ -15,7 +15,21 @@ import ( // fillOf is the store's fill now: its bytes and cap, when the bucket says them and has a cap. func (g *graphKeeper) fillOf(ctx context.Context) (used, capacity int64, ok bool) { - f, is := g.objects.(assigngraph.Filler) + return fillIn(ctx, g.objects) +} + +// passObjects is the store as the pass reads its fill: a handle of its own where one is given, so the pass's read never shares one +// with a keeping that runs beside it (design 47 H-A-261). +func (g *graphKeeper) passObjects() assigngraph.Objects { + if g.reads != nil { + return g.reads + } + return g.objects +} + +// fillIn is the fill of the bucket o, when it says one and has a cap. +func fillIn(ctx context.Context, o assigngraph.Objects) (used, capacity int64, ok bool) { + f, is := o.(assigngraph.Filler) if !is { return 0, 0, false } @@ -35,7 +49,7 @@ func (p *passer) sayFill(event, about string, used, capacity int64, refused stri // its cap), so a fill reached while the process was down is said too. func (p *passer) fillAtStart(ctx context.Context) { g := p.graph - used, capacity, ok := g.fillOf(ctx) + used, capacity, ok := fillIn(ctx, g.passObjects()) if !ok { return } @@ -52,7 +66,7 @@ func (p *passer) fillAtStart(ctx context.Context) { // 80 % again. It answers true while the store is full. func (p *passer) fullBefore(ctx context.Context, c assigngraph.Computed) bool { g := p.graph - used, capacity, ok := g.fillOf(ctx) + used, capacity, ok := fillIn(ctx, g.passObjects()) if !ok { return false } @@ -60,7 +74,7 @@ func (p *passer) fullBefore(ctx context.Context, c assigngraph.Computed) bool { g.setFull(false) p.sayFill(meshwants.EventRoom, fmt.Sprint(used), used, capacity, "") } - if used+assigngraph.NewBytes(ctx, g.objects, c) <= capacity { + if used+assigngraph.NewBytes(ctx, g.passObjects(), c) <= capacity { g.setFull(false) return false } diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphfill_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphfill_test.go index 0b3fdee7..f4c43ced 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphfill_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphfill_test.go @@ -61,14 +61,14 @@ func TestTheAssignmentGraphStoreSaysFillingFullAndRoom(t *testing.T) { if len(events) != 0 { t.Fatalf("events %v", events) } - o.base = 700 + o.base, o.cap = 8500, 10000 // past 80 %, with room for the next revision, which the pass judges itself (H-A-261) p.graph.started = false - p.needKeeping(ctx, keepNeed{judge: true}) // a start again: its keeping judges the fill (H-A-259) + p.keepGraph(ctx) // a start again: its first pass judges the fill if len(events) != 1 || events[0] != meshwants.EventFilling { t.Fatalf("at the start past 80 %%: %v", events) } c := assigngraph.Computed{Revision: meshwants.AssignmentRevision{Entries: []meshwants.NodeEntryRef{}}} - o.base = 990 + o.base, o.cap = 990, 1000 if !p.fullBefore(ctx, c) || !p.graph.full || events[len(events)-1] != meshwants.EventFull { t.Fatalf("a revision that does not fit: events %v", events) } @@ -76,8 +76,15 @@ func TestTheAssignmentGraphStoreSaysFillingFullAndRoom(t *testing.T) { if n := len(events); n != 2 { t.Errorf("full is said once: %v", events) } + // H-A-261: the verdict is the pass's own: with the store full the pass writes no want, though a revision is kept. + if held := p.keepGraph(ctx); held != heldFull { + t.Errorf("a pass with the store full answers %q, want %q", held, heldFull) + } o.base = 100 if p.fullBefore(ctx, c) || p.graph.full || events[len(events)-1] != meshwants.EventRoom { t.Errorf("room: events %v", events) } + if held := p.keepGraph(ctx); held != "" { + t.Errorf("a pass with room and a revision kept answers %q, want the wants written", held) + } } diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphkept.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphkept.go index 19018a4a..b60771eb 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphkept.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphkept.go @@ -25,6 +25,8 @@ import ( // that follows are written from the revision it holds. type graphKeeper struct { objects assigngraph.Objects + // reads is the same store through a handle of the pass's own, for the pass's read of its fill (graphfill.go); nil reads objects. + reads assigngraph.Objects // halves is every followed branch's catalog graph revision held now. halves func() map[string]mcc.Half // mu guards what the keeping writes and the pass reads: the revision kept, full, and the need handed over (design 47 H-A-259). @@ -33,12 +35,14 @@ type graphKeeper struct { // until one is, and again when its keeping failed or found the store full, so the next pass hands it again. handedRev meshwants.AssignmentRevision handed bool + // handedOnce says a revision was handed: the first carries the start's removal (H-A-261). + handedOnce bool // kept is the revision the wants follow, and kept's source the trunk's source revision it carries; ok is false until one is kept. kept meshwants.AssignmentRevision source int64 ok bool said string - // full says the next revision did not fit the store, so no want is written (graphfill.go); started says the first keeping judged the fill. + // full says the next revision did not fit the store, so no want is written (graphfill.go); started says the first pass judged the fill. full, started bool // revisions removes a revision that ceased to be current (revisions.go, H-A-86); nil keeps every revision. revisions *revisionRemover @@ -78,13 +82,21 @@ func (g *graphKeeper) setFull(full bool) { g.mu.Unlock() } -// keepGraph computes the revision of this pass and hands it to the keeping when the pass's inputs differ from the last handed. The -// keeping and the removing of revisions run off the pass loop, one at a time, and the pass never waits on them: it judges and -// writes the wants from the graph it holds (design 47 H-A-259). -func (p *passer) keepGraph(ctx context.Context) { +// heldNoRevision is the pass's words while no assignment graph revision is kept: it writes no want (design 47 H-A-261). +const heldNoRevision = "held: no assignment graph revision is kept yet, so no want is written until the first keeping ends (H-A-261)" + +// heldFull is the pass's words while the next revision does not fit its store (design 47 G §181). +const heldFull = "the assignment graph store is full: no want is written (design 47 G §181)" + +// keepGraph computes the revision of this pass, judges the store's fill itself, and hands the revision to the keeping when the +// pass's inputs differ from the last handed. The keeping and the removing of revisions run off the pass loop, one at a time, and the +// pass never waits on them: it judges and writes the wants from the graph it holds (design 47 H-A-259). It answers why the pass +// writes no want, or "" when it writes them: none while the next revision does not fit the store (G §181), and none while no +// revision is kept (H-A-261), whose keeping wakes a pass when it ends. +func (p *passer) keepGraph(ctx context.Context) string { g := p.graph if g == nil || g.objects == nil || g.halves == nil { - return + return "" } c := assigngraph.Compute(p.graphInputs()) g.computed = c @@ -94,15 +106,32 @@ func (p *passer) keepGraph(ctx context.Context) { p.logf("the assignment graph leaves out %s", u) } } + if !g.started { // the first pass judges the fill once (graphfill.go) + g.started = true + p.fillAtStart(ctx) + } + if p.fullBefore(ctx, c) { + g.mu.Lock() + g.handed = false // handed once it fits + g.mu.Unlock() + return heldFull + } g.mu.Lock() same := g.handed && assigngraph.Same(g.handedRev, c.Revision) + first := !g.handedOnce if !same { - g.handedRev, g.handed = c.Revision, true + g.handedRev, g.handed, g.handedOnce = c.Revision, true, true } g.mu.Unlock() if !same { - p.needKeeping(ctx, keepNeed{c: &c}) + // The start's removal of the revisions not current folds into the first keeping: it keeps the first pass's revision, then + // removes (H-A-261). + p.needKeeping(ctx, keepNeed{c: &c, judge: first}) } + if _, _, ok := g.keptNow(); !ok { + return heldNoRevision + } + return "" } // needKeeping hands a need to the keeping: one keeping runs at a time, and a need that comes while one runs is folded into the one @@ -144,7 +173,7 @@ func (p *passer) needKeeping(ctx context.Context, n keepNeed) { run() } -// keepOne keeps one computed revision, judges the store's fill, says assignment-revision for a revision kept now and removes the +// keepOne keeps one computed revision, says assignment-revision for a revision kept now and removes the // revisions that ceased to be current; it says its duration in the journal, and wakes a pass when it changed what the pass reads. func (p *passer) keepOne(ctx context.Context, n keepNeed) { g := p.graph @@ -156,15 +185,12 @@ func (p *passer) keepOne(ctx context.Context, n keepNeed) { g.wake() } }() - if !g.started { // the first keeping, the start's, judges the fill once (graphfill.go) - g.started = true - p.fillAtStart(ctx) - } if n.c != nil { - full := g.isFull() + _, _, had := g.keptNow() fresh := p.keepRevision(ctx, *n.c) + _, _, has := g.keptNow() n.judge = n.judge || fresh - changed = fresh || full != g.isFull() + changed = fresh || had != has // the first revision kept: the pass writes the wants it held (H-A-261) } if n.judge && g.revisions != nil { g.revisions.judge() // the revision before ceased to be current @@ -180,10 +206,6 @@ func (p *passer) keepRevision(ctx context.Context, c assigngraph.Computed) bool g.mu.Unlock() } used, _, _ := g.fillOf(ctx) - if p.fullBefore(ctx, c) { - again() - return false - } rev, fresh, err := assigngraph.Keep(ctx, g.objects, c, meshwants.EventAssignmentRevision, p.clock()) if err != nil { p.logf("the assignment graph revision is not kept, so no want is said as wanted until it is: %v", err) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphkept_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphkept_test.go index 977f753b..5acdb424 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphkept_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphkept_test.go @@ -137,19 +137,55 @@ func TestTheWantsAreSaidWantedFromTheKeptAssignmentGraphRevision(t *testing.T) { } } -// blockedObjects is an object bucket whose every listing waits until free is closed: a keeping that does not end. +// blockedObjects is an object bucket whose listing waits while a gate stands: a keeping that does not end until it is opened. type blockedObjects struct { memObjects - free chan struct{} + mu sync.Mutex + gate chan struct{} } -func (b blockedObjects) Names(ctx context.Context) ([]string, error) { - <-b.free +func (b *blockedObjects) Names(ctx context.Context) ([]string, error) { + b.mu.Lock() + gate := b.gate + b.mu.Unlock() + if gate != nil { + <-gate + } + b.mu.Lock() + defer b.mu.Unlock() return b.memObjects.Names(ctx) } -// Design 47 H-A-256, H-A-259: the keeping of the assignment graph runs off the pass loop, so a pass writes the want of a passed -// pipeline while a keeping is blocked, and a pass after it hands nothing more while the same revision waits. +func (b *blockedObjects) Put(ctx context.Context, name string, data []byte) error { + b.mu.Lock() + defer b.mu.Unlock() + return b.memObjects.Put(ctx, name, data) +} + +func (b *blockedObjects) Get(ctx context.Context, name string) ([]byte, error) { + b.mu.Lock() + defer b.mu.Unlock() + return b.memObjects.Get(ctx, name) +} + +// block stands a gate, opened by the function it answers. +func (b *blockedObjects) block() func() { + gate := make(chan struct{}) + b.mu.Lock() + b.gate = gate + b.mu.Unlock() + return func() { + b.mu.Lock() + b.gate = nil + b.mu.Unlock() + close(gate) + } +} + +// Design 47 H-A-259, H-A-261: the keeping of the assignment graph runs off the pass loop. At the start, while the first keeping is +// blocked, a pass returns and writes no want; the keeping's end wakes a pass, which writes the passed pipeline's want. Later, while a +// keeping of new inputs is blocked, a pass writes the wants from the revision it holds, and a pass of the same inputs hands nothing +// more. Each pass and each keeping says its duration. func TestAPassWritesWantsWhileAKeepingIsBlocked(t *testing.T) { fp := mcc.SourcePrefix2 + strings.Repeat("a", 64) wantsKV := &memKV{values: map[string][]byte{}} @@ -170,21 +206,16 @@ func TestAPassWritesWantsWhileAKeepingIsBlocked(t *testing.T) { p.ends = newPipelineEnds(newMemEnds(), func() {}, t.Logf) p.ends.trunk = p.w.trunkName _, _ = p.ends.take(ended(trunkBranch, 5, mpr.PipelineEndedOutcomePassed, mover("web", fp, "0.1.2", 1, mpr.StepResultOutcomePassed))) - free := make(chan struct{}) + objects := &blockedObjects{memObjects: memObjects{}} var kept sync.WaitGroup - t.Cleanup(func() { // the keeping ends before the test does, and says its duration - close(free) - kept.Wait() - if !said("the keeping of the assignment graph took ") { - t.Error("the keeping does not say its duration") - } - }) + woke := make(chan struct{}, 8) half := mcc.Half{Revision: meshcatalog.CatalogRevision{Branch: trunkBranch, Kind: "trunk", Revision: 4, Source: 9, Entries: []meshcatalog.EntryRef{{Module: "web", Digest: "sha256:" + strings.Repeat("a", 64)}}}, Entries: map[string]meshcatalog.CatalogEntry{"web": {Module: "web", Fp: fp}}} - p.graph = &graphKeeper{objects: blockedObjects{memObjects{}, free}, halves: func() map[string]mcc.Half { return map[string]mcc.Half{trunkBranch: half} }, - background: func(f func()) { kept.Go(f) }} - for range 2 { + p.graph = &graphKeeper{objects: objects, halves: func() map[string]mcc.Half { return map[string]mcc.Half{trunkBranch: half} }, + background: func(f func()) { kept.Go(f) }, wake: func() { woke <- struct{}{} }} + pass := func() { + t.Helper() done := make(chan struct{}) go func() { p.pass(context.Background()); close(done) }() select { @@ -193,17 +224,53 @@ func TestAPassWritesWantsWhileAKeepingIsBlocked(t *testing.T) { t.Fatal("the pass waits on the keeping of the assignment graph") } } - if !said("the pass took ") { - t.Error("the pass does not say its duration") + wantOf := func(node string) (mwc.Want, error) { + key, _ := mwc.WantKey(node, "web") + return mwc.DecodeWant(wantsKV.values[key]) } - key, _ := mwc.WantKey("ace", "web") - if w, err := mwc.DecodeWant(wantsKV.values[key]); err != nil || w.Fp != fp || w.Version != "0.1.2" { - t.Errorf("the want of web on ace = %+v (%v), want the passed version", w, err) + open := objects.block() + t.Cleanup(func() { // the keeping ends before the test does, and says its duration + objects.mu.Lock() + standing := objects.gate != nil + objects.mu.Unlock() + if standing { + open() + } + kept.Wait() + if !said("the keeping of the assignment graph took ") { + t.Error("the keeping does not say its duration") + } + }) + + pass() // the start: the first keeping is blocked + if _, err := wantOf("ace"); err == nil { + t.Error("a pass at the start wrote a want before an assignment graph revision is kept") + } + open() + select { + case <-woke: + case <-time.After(10 * time.Second): + t.Fatal("the first keeping's end wakes no pass") + } + pass() + if w, err := wantOf("ace"); err != nil || w.Fp != fp || w.Version != "0.1.2" { + t.Errorf("the want of web on ace = %+v (%v), want the passed version once a revision is kept", w, err) + } + + open = objects.block() // a keeping of new inputs is blocked + placeOn(t, p.w, "g14", "web") + pass() + pass() // the same inputs again + if w, err := wantOf("g14"); err != nil || w.Fp != fp || w.Version != "0.1.2" { + t.Errorf("the want of web on g14 = %+v (%v), want the passed version while a keeping is blocked", w, err) } p.graph.mu.Lock() keeping, waiting := p.graph.keeping, p.graph.need p.graph.mu.Unlock() if !keeping || waiting != nil { - t.Errorf("keeping %v, need waiting %+v: the second pass, of the same inputs, handed its revision again", keeping, waiting) + t.Errorf("keeping %v, need waiting %+v: the pass of the same inputs handed its revision again", keeping, waiting) + } + if !said("the pass took ") { + t.Error("the pass does not say its duration") } } diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/integration_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/integration_test.go index 8a26a659..810880c6 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/integration_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/integration_test.go @@ -12,6 +12,7 @@ import ( "git.novox.be/novox/mesh-sdk/go/keys" "io" "maps" + "mesh-delivery-assigner/internal/assigngraph" "mesh-delivery-assigner/internal/assignment" "mesh-delivery-assigner/internal/buckets" "mesh-delivery-assigner/internal/puts" @@ -190,6 +191,11 @@ func startBed(t *testing.T, leaveOut string) *bed { if _, err := js.CreateObjectStore(ctx, jetstream.ObjectStoreConfig{Bucket: catalogue.BusName("mesh-delivery-assigner", catalogue.StateObjectsName(buckets.InputsState))}); err != nil { t.Fatal(err) } + // The assignment graph revisions' object store, which the grants part makes from the manifest's objects: no want is written + // before a revision is kept in it (design 47 H-A-261). + if _, err := js.CreateObjectStore(ctx, jetstream.ObjectStoreConfig{Bucket: catalogue.ObjectsBucket("mesh-delivery-assigner", assigngraph.RevisionsObjects)}); err != nil { + t.Fatal(err) + } // The builder's module log, as the runtime raises it (ADR 0297): the running commits are read from it (ADR 0571 clause 1). if _, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: buscompose.LogStreamName(builds.BuilderModule, builds.BuilderLog), Subjects: []string{buscompose.LogSubject(builds.BuilderModule, builds.BuilderLog) + ".>"}, AllowDirect: true}); err != nil { diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go index 2cf37108..61f65a13 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go @@ -615,7 +615,8 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber, objects := newBusObjects(js, process.Account{Node: thisNode, Module: assignment.Module()}, assigngraph.RevisionsObjects) // The keeping and removing of revisions runs off the pass loop, and a keeping that changed what the pass reads wakes // one (design 47 H-A-259). - p.graph = &graphKeeper{objects: objects, halves: iv.h.views, background: func(f func()) { go f() }, wake: wake} + p.graph = &graphKeeper{objects: objects, halves: iv.h.views, background: func(f func()) { go f() }, wake: wake, + reads: newBusObjects(js, process.Account{Node: thisNode, Module: assignment.Module()}, assigngraph.RevisionsObjects)} keep := func(ctx context.Context, ev meshcatalog.CatalogRevisionEvent) error { return p.keepCandidate(ctx, iv.call, ev) } @@ -630,7 +631,7 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber, // The revisions that are not current are removed when one ceases to be current and once now (revisions.go, // design 47 H §764, H-A-86). p.graph.revisions = &revisionRemover{ctx: ctx, objects: objects, inUse: inUseOf(w), logf: logger.Printf} - p.needKeeping(ctx, keepNeed{judge: true}) + // The start's removal of the revisions not current folds into the first pass's keeping (H-A-261). } } // The node-engine seat's manifest-reads-changed, for one node (design 47 H-A-104): its words are written into the state diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/pass.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/pass.go index cb7a6f97..56aec212 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/pass.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/pass.go @@ -144,12 +144,11 @@ func (p *passer) pass(ctx context.Context) { start := time.Now() defer func() { p.logf("the pass took %s", time.Since(start).Round(time.Millisecond)) }() // design 47 H-A-259 p.assignmentsSeat(ctx) - p.keepGraph(ctx) - if p.graph == nil || !p.graph.isFull() { // a full assignment graph store keeps the last revision and writes no new want (design 47 G §181) + if held := p.keepGraph(ctx); held == "" { p.wants(ctx) p.sayPass(ctx, "judged") } else { - p.sayPass(ctx, "the assignment graph store is full: no want is written (design 47 G §181)") + p.sayPass(ctx, held) // a full store keeps the last revision (design 47 G §181); none kept yet writes no want (H-A-261) } p.puts(ctx) p.nodeWants(ctx)