From 18e5be507dbbc567c6e2948620ec60da487c9d70 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 25 Nov 2026 18:51:59 +0100 Subject: [PATCH] A1 tier-write-refused: a refused write of the tier progress is said and the pass goes on; AC-A3c's row, a held mover ends its tier late A refused write (a full bucket) no longer reads the same progress again for ever; the lost race alone does. The tier test gains the row of a provider whose want is held awaiting its reads. Builds: design 47 H2 H-A-627 (2), H-A-682 (4) --- .../cmd/mesh-delivery-assigner/tiers.go | 24 ++++--- .../cmd/mesh-delivery-assigner/tiers_test.go | 67 ++++++++++++++++++- 2 files changed, 80 insertions(+), 11 deletions(-) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tiers.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tiers.go index 18d32f708..d66bd317b 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tiers.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tiers.go @@ -219,18 +219,26 @@ func (p *passer) tiers(n assign.Nodes, placedOn func(module, branch string) []st if now.Before(t.Since) { t.PausedFrom = t.Since // never earlier than the progress's own start } - if p.writeTier(key, t, rev, "paused-from") { + err := p.writeTier(key, t, rev, "paused-from") + if err == nil { p.logf("pipeline %s: tier %d's count of tier-bound stands still: %s", pipeline, t.Tier, pauseNamed(standing, t, notRunning)) } - continue + if err == nil || errors.Is(err, errSwapped) { + continue // written, or a lost race: read the progress again + } + break // refused (said): reading it again would spin the pass } if !paused && !t.PausedFrom.IsZero() { held := now.Sub(t.PausedFrom) t.ClockFrom, t.PausedFrom = clock.Add(held), time.Time{} - if p.writeTier(key, t, rev, "clock-from") { + err := p.writeTier(key, t, rev, "clock-from") + if err == nil { p.logf("pipeline %s: tier %d's count of tier-bound stood still for %s and goes on; the tier is late at %s", pipeline, t.Tier, held.Round(time.Second), t.ClockFrom.Add(bound).Format(time.RFC3339)) } - continue + if err == nil || errors.Is(err, errSwapped) { + continue + } + break } if !t.PausedFrom.IsZero() { break // paused: no lateness, and no timer armed @@ -417,9 +425,9 @@ func tierBoundSetting(getenv func(string) string) (time.Duration, error) { // without a test waiting minutes. var tierBoundUnit = time.Minute -// writeTier swaps the tier progress at key by compare-and-set at rev; false when it was not written (the caller reads it again), -// the failure said but a lost race (what field the write was for names it). -func (p *passer) writeTier(key string, t tierProgress, rev uint64, field string) bool { +// writeTier swaps the tier progress at key by compare-and-set at rev; its error when it was not written: errSwapped for a lost race +// (the caller reads the progress again), any other said (what field the write was for names it) and the caller goes on. +func (p *passer) writeTier(key string, t tierProgress, rev uint64, field string) error { value, err := json.Marshal(t) if err == nil { err = p.ends.st.swap(key, value, rev) @@ -427,7 +435,7 @@ func (p *passer) writeTier(key string, t tierProgress, rev uint64, field string) if err != nil && !errors.Is(err, errSwapped) { p.logf("the tier progress %s is not written (%s): %v", key, field, err) } - return err == nil + return err } // pausingAsks are the keys of asks (the assigner's state asks, G ยง717) that pause the count of tier t of its pipeline: a key of diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tiers_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tiers_test.go index b1963be50..9946af620 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tiers_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tiers_test.go @@ -3,6 +3,7 @@ package main import ( "context" "encoding/json" + "errors" "maps" "slices" "strings" @@ -36,8 +37,9 @@ func TestAPipelinesWantsAreWrittenTierByTier(t *testing.T) { runs bool pipeline string paused bool // H-A-627: the provider's record ask stands in asks from minute 5 to minute 45, and the count stands still - }{{true, trunkBranch + ".5", false}, {false, trunkBranch + ".5", false}, {true, trunkBranch + ".5.again.2", false}, {false, trunkBranch + ".5.again.2", false}, - {true, trunkBranch + ".5", true}, {false, trunkBranch + ".5", true}} { + held bool // H-A-682 (2), (4): the provider's entry needs a capability g14's node-engine does not state, so its want there is held + }{{true, trunkBranch + ".5", false, false}, {false, trunkBranch + ".5", false, false}, {true, trunkBranch + ".5.again.2", false, false}, {false, trunkBranch + ".5.again.2", false, false}, + {true, trunkBranch + ".5", true, false}, {false, trunkBranch + ".5", true, false}, {false, trunkBranch + ".5", false, true}} { runs, pipeline := c.runs, c.pipeline start := time.Date(2026, 11, 20, 4, 0, 0, 0, time.UTC) now := start @@ -63,13 +65,26 @@ func TestAPipelinesWantsAreWrittenTierByTier(t *testing.T) { } for i, m := range []struct{ name, fp string }{{"db", db}, {"web", 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}) + value := meshcatalog.ModulesByModuleValue{Fp2: m.fp, Manifest: digest, Repository: "novox/" + m.name, Commit: strings.Repeat("1", 40), Path: meshcatalogclient.RootPath} + if c.held && m.name == "db" { + value.Needs = []string{"directory-contents-owner"} + } + mod, _ := meshcatalogclient.EncodeModule(value) 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") placeOn(t, p.w, "ace", "db", "web") p.w.heardPresence("ace", true, start) // away: not waited for + if c.held { // both engines state want:version; neither states the capability db needs + p.reads = &engineReadsKept{} + for _, node := range []string{"g14", "ace"} { + raw, _ := json.Marshal(engineWords{Words: []string{nodeengine.ManifestReadWordWantVersion}, At: start}) + if err := p.reads.take(node, raw, false); err != nil { + t.Fatal(err) + } + } + } p.w.mu.Lock() p.w.runningHeard = true p.w.mu.Unlock() @@ -94,6 +109,12 @@ func TestAPipelinesWantsAreWrittenTierByTier(t *testing.T) { if !wanted("g14", "db") || !wanted("ace", "db") || wanted("g14", "web") || wanted("ace", "web") { t.Fatalf("%s runs %v: tier 1 alone is not what is wanted first: %v", pipeline, runs, wantsKV.values) } + if c.held { + key, _ := mwc.WantKey("g14", "db") + if w, err := mwc.DecodeWant(wantsKV.values[key]); err != nil || !w.Hold || w.Words != mwc.HoldAwaitsReadsPrefix+"directory-contents-owner" { + t.Fatalf("%s: db's want on g14 is not held awaiting its reads: %+v (%v)", pipeline, w, err) + } + } runAt, lateBefore, lateAt := time.Minute, 29*time.Minute, 30*time.Minute if c.paused { runAt, lateBefore, lateAt = 50*time.Minute, 69*time.Minute, 70*time.Minute @@ -249,3 +270,43 @@ func TestALateMoverHoldsItsTier(t *testing.T) { }) } } + +// H-A-627 (2): a write of the tier progress that is refused (a full bucket), not lost to another writer, is said and not read +// again within the pass: the pass would spin on the same progress for ever. +func TestARefusedTierWriteDoesNotSpinThePass(t *testing.T) { + start := time.Date(2026, 11, 20, 4, 0, 0, 0, time.UTC) + for _, field := range []string{"paused-from", "clock-from"} { + st := &refusingEnds{memEnds: newMemEnds(), t: t} + p := newPasser(kvSet{buckets.Asks(): &memKV{values: map[string][]byte{}}}, start.Add(5*time.Minute)) + p.ends = newPipelineEnds(st, func() {}, func(string, ...any) {}) + prog := tierProgress{Tier: 1, Since: start, ClockFrom: start, Movers: []tierMover{{Module: "db", Fp: "fp", Tier: 1, NoVersion: true}}} + if field == "clock-from" { + prog.PausedFrom = start.Add(time.Minute) // the ask is gone: the pause ends + } else if akey, err := asks.RecordAskKey("g14", "db", "sha256:"+strings.Repeat("a", 64)); err != nil { + t.Fatal(err) + } else { + p.w.put(buckets.Asks(), akey, []byte(`{}`)) + } + raw, _ := json.Marshal(prog) + st.vals[tierKey(trunkBranch+".5")], st.revs[tierKey(trunkBranch+".5")] = raw, 1 + p.tiers(assign.Nodes{Online: map[string]bool{}}, func(string, string) []string { return []string{"g14"} }) + if st.swaps != 1 { + t.Errorf("%s: the refused write was made %d times in one pass", field, st.swaps) + } + } +} + +// refusingEnds is memEnds whose every swap is refused for a cause other than a lost race; it fails the test on the third. +type refusingEnds struct { + *memEnds + t *testing.T + swaps int +} + +func (r *refusingEnds) swap(string, []byte, uint64) error { + r.swaps++ + if r.swaps > 2 { + r.t.Fatal("the pass reads the refused progress again and writes it again") + } + return errors.New("the bucket is full") +}