diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionreads.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionreads.go index 08be1b15c..19cf7f6d4 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionreads.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionreads.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "slices" "strings" "sync" "time" @@ -280,20 +281,33 @@ func (r *compositionRun) waiting(id string, d int) { } } -// clearRead clears the finding of a read's seat verb when this process raised it; answered says the verb answered. +// clearRead clears the finding of a read's seat verb: at the verb's answer (answered), or once no read waits on it. The finding is +// read from the findings bucket's keys, never from what this process raised, so one written before a restart is cleared as well +// (design 47 H2 H-A-708 (4), H-A-722). func (r *compositionRun) clearRead(id string, answered bool) { r.readMu.Lock() - raised := r.raised[id] - if raised && (answered || r.inflight[id] <= 0) { + was := r.raised[id] + clear := answered || r.inflight[id] <= 0 + if clear { delete(r.raised, id) - } else { - raised = false } r.readMu.Unlock() - if !raised || r.findings.Delete == nil { + if !clear || r.findings.Delete == nil { return } - if err := r.findings.Delete(readFindingKey(id)); err != nil { - r.logf("the finding %s is not cleared: %v", readFindingKey(id), err) + key := readFindingKey(id) + if r.findings.Keys != nil { + ks, err := r.findings.Keys() + if err != nil { + r.logf("the finding %s is not cleared, the findings are not read: %v", key, err) + return + } + was = slices.Contains(ks, key) + } + if !was { + return + } + if err := r.findings.Delete(key); err != nil { + r.logf("the finding %s is not cleared: %v", key, err) } } diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go index 729aa48b4..a8fcf2674 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go @@ -787,25 +787,33 @@ func TestARunsReadsShareOneDeadline(t *testing.T) { // Design 47 H2 H-A-708 (4), H-A-731, AC-A7: a read that waited five minutes writes the finding call-unanswered, id `.`, // naming its holder and machine, the last fault and since when; the verb's answer clears it, and so does the end of the last read -// waiting on it past its bound. +// waiting on it past its bound; a finding written before a restart, which no process of this run raised, is cleared the same way +// (H-A-722: the clear reads the findings bucket's keys). func TestAReadUnansweredForFiveMinutesIsTheFindingCallUnanswered(t *testing.T) { step := meshwants.StepRun{Module: "m", Branch: "main", Revision: 7, Step: meshwants.StepRunStepComposition} - for _, answered := range []bool{true, false} { + for _, c := range []struct{ answered, restarted bool }{{true, false}, {false, false}, {true, true}, {false, true}} { + answered, restarted := c.answered, c.restarted s := newRunStand(t, "src2:e1", "src2:e1", "d1") inner := s.r.call findings := map[string]mcseat.Finding{} s.r.findings = assign.Findings{Put: func(f mcseat.Finding) error { findings[views.FindingKey(f.Scope, f.ID, f.Kind)] = f; return nil }, + Keys: func() ([]string, error) { return slices.Collect(maps.Keys(findings)), nil }, Delete: func(key string) error { delete(findings, key); return nil }} s.r.holder = func(string) (string, []string) { return "mesh-delivery-indexer", []string{"novox"} } since := time.Unix(500, 0) key := mccond.Key(mccond.ScopeCall, "mesh-catalog.revision", mccond.KindCallUnanswered) + if restarted { // written before a restart: this process raised nothing + findings[key] = mcseat.Finding{} + } s.r.call = func(ask process.KeptAsk, k string, body any) (json.RawMessage, error) { if k != mcc.RevisionVerb { return inner(ask, k, body) } - ask.Hook(busretry.Waited{Seat: "mesh-catalog", Verb: "revision", Since: since, Last: "away: the trunk's revision 512 not read yet"}) - if f, ok := findings[key]; !ok || !strings.Contains(f.Summary, "mesh-delivery-indexer on novox") || !strings.Contains(f.Summary, "the trunk's revision 512") || - !strings.Contains(f.Summary, since.UTC().Format(time.RFC3339)) { + if !restarted { + ask.Hook(busretry.Waited{Seat: "mesh-catalog", Verb: "revision", Since: since, Last: "away: the trunk's revision 512 not read yet"}) + } + if f, ok := findings[key]; !restarted && (!ok || !strings.Contains(f.Summary, "mesh-delivery-indexer on novox") || !strings.Contains(f.Summary, "the trunk's revision 512") || + !strings.Contains(f.Summary, since.UTC().Format(time.RFC3339))) { t.Errorf("at five minutes the findings are %+v", findings) } if answered { 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 9946af620..2bad78bdc 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 @@ -76,7 +76,7 @@ func TestAPipelinesWantsAreWrittenTierByTier(t *testing.T) { 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 + 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})