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 81291b45a..08be1b15c 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionreads.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionreads.go @@ -8,9 +8,12 @@ import ( "sync" "time" + mccond "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient" mcc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" "git.novox.be/novox/mesh-sdk/go/buscalls" + "git.novox.be/novox/mesh-sdk/go/busretry" "git.novox.be/novox/mesh-sdk/go/process" + "mesh-delivery-assigner/internal/assign" ) // The reads of a composition step (design 47 G §354, A-252, A-261): the entries of one catalog revision are read once and shared by @@ -100,7 +103,10 @@ func (r *compositionRun) callRead(ctx context.Context, key string, body any) (js return nil, "", fmt.Errorf("%s is not read: the run's reads passed their deadline of %s (the setting reads-bound) counted from its first read at %s%s", key, bound, first.UTC().Format(time.RFC3339), last) } - raw, err := r.call(process.KeptAsk{Bound: left}, key, body) + id := readFindingID(key) + r.waiting(id, +1) + raw, err := r.call(process.KeptAsk{Bound: left, Hook: r.readHook}, key, body) + r.waiting(id, -1) if err != nil { words := fmt.Errorf("%s%s: %w", key, r.holderWords(key), err) clock.mu.Lock() @@ -218,3 +224,76 @@ func unreadErr(what string, err error, said string) error { } return fmt.Errorf("%s: %s", what, said) } + +// readFindingID is the id of the finding call-unanswered of a read of key: `.`. +func readFindingID(key string) string { return strings.TrimPrefix(key, "seat:") } + +// readKey is the key of the finding call-unanswered of a read: one per seat verb. +func readFindingKey(id string) string { + return mccond.Key(mccond.ScopeCall, assign.KeyID(id), mccond.KindCallUnanswered) +} + +// readHook is the kept-call form's hook (design 47 H2 H-A-708 (4), H-A-731): told when a read has waited five minutes, it writes the +// finding call-unanswered of its seat verb naming its holder, its machine, the last fault and since when; told of the answer, it +// clears it. +func (r *compositionRun) readHook(w busretry.Waited) { + id := w.Seat + "." + w.Verb + if w.Answered { + r.clearRead(id, true) + return + } + if r.findings.Put == nil { + return + } + holder, nodes := "", []string(nil) + if r.holder != nil { + holder, nodes = r.holder(w.Seat) + } + f := assign.ReadUnanswered(w.Seat, w.Verb, holder, nodes, w.Last, w.Since).Finding(r.now()) + if err := r.findings.Put(f); err != nil { + r.logf("the finding %s is not written: %v", readFindingKey(id), err) + return + } + r.readMu.Lock() + if r.raised == nil { + r.raised = map[string]bool{} + } + r.raised[id] = true + r.readMu.Unlock() +} + +// waiting counts the reads of one seat verb now waiting for an answer; when the last one ends, the finding it raised is cleared: +// no run waits on it any more, and each run's could-not-run says it (design 47 H2 H-A-708 (4)). +func (r *compositionRun) waiting(id string, d int) { + r.readMu.Lock() + if r.inflight == nil { + r.inflight = map[string]int{} + } + r.inflight[id] += d + none := r.inflight[id] <= 0 + if none { + delete(r.inflight, id) + } + r.readMu.Unlock() + if d < 0 && none { + r.clearRead(id, false) + } +} + +// clearRead clears the finding of a read's seat verb when this process raised it; answered says the verb answered. +func (r *compositionRun) clearRead(id string, answered bool) { + r.readMu.Lock() + raised := r.raised[id] + if raised && (answered || r.inflight[id] <= 0) { + delete(r.raised, id) + } else { + raised = false + } + r.readMu.Unlock() + if !raised || 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) + } +} diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go index 05f9b20e9..4157c3b7f 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go @@ -64,6 +64,11 @@ type compositionRun struct { readsBound time.Duration // holder is the module holding a seat and the machines it runs on, for the words of a read that met a fault; nil: none named. holder func(seat string) (module string, nodes []string) + // readMu guards inflight, the reads now waiting by seat verb, and raised, the seat verbs whose finding call-unanswered this + // process wrote (H-A-708 (4)). + readMu sync.Mutex + inflight map[string]int + raised map[string]bool // callFile asks a seat verb held once for the mesh whose answer comes in chunks, as a kept call (process.Conn.CallFileKept), // answering the verb's answer with the bytes received as its member `file`, base64: the validate step's seat-list (H-A-443). callFile func(ask process.KeptAsk, key string, body any) (json.RawMessage, error) 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 cfd090f49..729aa48b4 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 @@ -18,6 +18,7 @@ import ( mmac "git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient" mma "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner" ne "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" + mccond "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" mcc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" builds "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds" @@ -26,6 +27,7 @@ import ( "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/composer" "git.novox.be/novox/mesh-sdk/go/keys" + "git.novox.be/novox/mesh-sdk/go/views" "mesh-delivery-assigner/internal/assign" ) @@ -783,6 +785,47 @@ 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. +func TestAReadUnansweredForFiveMinutesIsTheFindingCallUnanswered(t *testing.T) { + step := meshwants.StepRun{Module: "m", Branch: "main", Revision: 7, Step: meshwants.StepRunStepComposition} + for _, answered := range []bool{true, false} { + 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 }, + 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) + 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)) { + t.Errorf("at five minutes the findings are %+v", findings) + } + if answered { + ask.Hook(busretry.Waited{Seat: "mesh-catalog", Verb: "revision", Since: since, Answered: true}) + if _, ok := findings[key]; ok { + t.Error("the answer left the finding") + } + return inner(ask, k, body) + } + return nil, &busretry.Unanswered{Seat: "mesh-catalog", Verb: "revision", Bound: ask.Bound} + } + if out := s.r.run(context.Background(), "ask-step", step); answered == (out.Outcome == meshwants.StepEndedOutcomeCouldNotRun) { + t.Errorf("answered %v: the step came to %+v", answered, out) + } + if len(findings) != 0 { + t.Errorf("answered %v: the findings stand after the read: %+v", answered, findings) + } + } +} + // Design 47 G §718, §719, §720: three composition steps of one revision on two machines start two runs, one request and one run // ask per machine, and each step reads both verdicts; the run records its program with the node-engine fingerprint it was chosen // from and the digest of its kept request, which names no module of the asking pipeline; a step of another candidate starts its diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep.go index a35719078..3cca23537 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep.go @@ -480,8 +480,11 @@ func (r *compositionRun) seatList(ctx context.Context, ask string) ([]json.RawMe if _, err := rand.Read(bits[:]); err != nil { return nil, "", fmt.Errorf("%s: %w", what, err) } - raw, err := r.callFile(process.KeptAsk{ID: ask + "." + meshcatalog.VerbSeatList, Bound: left}, seatListKey, + id := readFindingID(seatListKey) + r.waiting(id, +1) + raw, err := r.callFile(process.KeptAsk{ID: ask + "." + meshcatalog.VerbSeatList, Bound: left, Hook: r.readHook}, seatListKey, meshcatalog.SeatListInput{Call: hex.EncodeToString(bits[:])}) + r.waiting(id, -1) if err != nil { return nil, "", fmt.Errorf("%s: %w", what, err) } diff --git a/modules/mesh-delivery-assigner/internal/assign/findings.go b/modules/mesh-delivery-assigner/internal/assign/findings.go index 260ba6ea8..a374727e9 100644 --- a/modules/mesh-delivery-assigner/internal/assign/findings.go +++ b/modules/mesh-delivery-assigner/internal/assign/findings.go @@ -75,6 +75,27 @@ func CallUnanswered(id, callee, machine, fault, source string, since time.Time) Source: source} } +// ReadUnanswered is the observation of a seat verb a run's read waited five minutes on (design 47 H2 H-A-708 (4), ADR 0668 §3): id +// `.`, the summary naming its holder, the machines it runs on, the last fault and since when; the id is one finding per +// seat verb. +func ReadUnanswered(seat, verb, holder string, machines []string, fault string, since time.Time) Observed { + who := "its holder is not read" + if holder != "" { + who = "its holder " + holder + if len(machines) > 0 { + who += " on " + strings.Join(machines, ", ") + } + } + callee := seat + "." + verb + return Observed{Scope: mcc.ScopeCall, ID: callee, Kind: mcc.KindCallUnanswered, Severity: mcseat.FindingSeverityWarning, + Summary: fmt.Sprintf("%s is unanswered since %s (%s); the last fault: %s", callee, since.UTC().Format(time.RFC3339), who, fault), + Said: fault, Headline: "A read of a run is not answered", + Explanation: fmt.Sprintf("A composition or validate run's read of %s is asked again at the kept-call pace and has not been answered since %s; %s. "+ + "The last fault: %s.", callee, since.UTC().Format(time.RFC3339), who, fault), + Needs: "the holder of the seat " + seat + " to answer", + Source: "assigner." + mcc.KindCallUnanswered} +} + // FindingOf is a said condition as a finding: from the condition's own key `mesh-delivery-assigner..` (the // subject's id when the key names none), its words unchanged but the resolved ones. raised is false for a clear, whose // finding names only its scope, id and kind.