E2: take a compose-candidate ask once by its id
The holder of mesh-wants asks each node-engine compose-candidate as a kept call, so the same ask may come again on a transport fault. The engine reads the ask id from the request header, keeps it in its own state taken for compose-ask-bound (process.StateOver over the link it serves its seat on), and a repeat while the ask's run goes joins that run and gets the answer composed once; a repeat after the run ended is composed again, since the verb is a read and no answer is kept. The manifest declares taken with its 8 MiB cap. Builds: design 47 H2 §775, §820; H-A-351, H-A-364, H-A-383
This commit is contained in:
@@ -3,6 +3,7 @@ package selfcompose
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
@@ -84,12 +85,21 @@ func TestTheNodeComposesACandidateOnAsk(t *testing.T) {
|
||||
}
|
||||
return json.Marshal(meshcatalog.EntryAnswer{Entry: entry})
|
||||
})
|
||||
// Design 47 H2 §775, H-A-364: an ask with an id is taken once in the state taken, for compose-ask-bound.
|
||||
var takes []string
|
||||
taken := map[string]bool{}
|
||||
env.Taken = func(seat, ask string, bound time.Duration) (bool, error) {
|
||||
takes = append(takes, seat+"."+ask+" "+bound.String())
|
||||
first := !taken[ask]
|
||||
taken[ask] = true
|
||||
return first, nil
|
||||
}
|
||||
var handed atomic.Int64
|
||||
s := NewShadow(env, func(context.Context, map[string]nodeengine.CandidateAnswer) { handed.Add(1) })
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
go func() { _ = s.Run(ctx) }()
|
||||
if a := s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: accepted}); a.Verdict != nec.Unready || a.Refused == "" {
|
||||
if a := s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: accepted}, ""); a.Verdict != nec.Unready || a.Refused == "" {
|
||||
t.Errorf("a shadow not ready answered %+v", a)
|
||||
}
|
||||
place := assignedValues(t, meshmoduleassigner.Assignments{Node: "n1", Decided: meshmoduleassigner.NodeDecided{Hub: true, Address: "10.77.0.1"},
|
||||
@@ -111,7 +121,7 @@ func TestTheNodeComposesACandidateOnAsk(t *testing.T) {
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
}
|
||||
|
||||
a := s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: accepted})
|
||||
a := s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: accepted}, "")
|
||||
if _, err := nec.EncodeAnswer(a); err != nil {
|
||||
t.Fatalf("the answer does not fit the seat's shape: %v (%+v)", err, a)
|
||||
}
|
||||
@@ -120,9 +130,20 @@ func TestTheNodeComposesACandidateOnAsk(t *testing.T) {
|
||||
a.Own.Module != nec.NodeWord || a.Took > nec.AnswerBound.Milliseconds() {
|
||||
t.Errorf("an accepted candidate answered %+v", a)
|
||||
}
|
||||
// Design 47 H2 §775, H-A-364 (b): an ask with an id is taken once; given again after its run ended it is composed again,
|
||||
// to the same answer, and nothing of the answer is kept.
|
||||
for range 2 {
|
||||
if a := s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: accepted}, "ask-1"); a.Verdict != nec.Composed ||
|
||||
len(a.Modules) != 1 || a.Modules[0].Fp != fpNew {
|
||||
t.Errorf("an ask with an id answered %+v", a)
|
||||
}
|
||||
}
|
||||
if strings.Join(takes, ",") != "node-engine.ask-1 10s,node-engine.ask-1 10s" {
|
||||
t.Errorf("the asks with an id were taken as %v; want node-engine.ask-1 for compose-ask-bound, each time", takes)
|
||||
}
|
||||
// Issue 774: the input it sends the sandbox says how it composed the node (the builds), so the sandbox composes it
|
||||
// through the same path.
|
||||
sent := s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: accepted, Input: true})
|
||||
sent := s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: accepted, Input: true}, "")
|
||||
var in compose.Input
|
||||
raw, _ := json.Marshal(sent.Input)
|
||||
if err := json.Unmarshal(raw, &in); err != nil || in.ComposedHow == nil || in.ComposedHow.Node != "n1" ||
|
||||
@@ -132,43 +153,83 @@ func TestTheNodeComposesACandidateOnAsk(t *testing.T) {
|
||||
// A-226b: a branch pipeline's revision composes as the candidate, each module at the revision's build; one the catalog does
|
||||
// not hold, and a run on request's key, are refused in words.
|
||||
revKey, _ := nec.RevisionKey("main", 362)
|
||||
rv := s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: revKey})
|
||||
rv := s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: revKey}, "")
|
||||
if rv.Verdict != nec.Composed || len(rv.Modules) != 1 || rv.Modules[0].Fp != fpNew || !rv.Modules[0].Changed {
|
||||
t.Errorf("a catalog revision answered %+v", rv)
|
||||
}
|
||||
noRev, _ := nec.RevisionKey("main", 999)
|
||||
if m := s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: noRev}); m.Verdict != nec.Refused || !strings.Contains(m.Refused, "holds no revision 999") {
|
||||
if m := s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: noRev}, ""); m.Verdict != nec.Refused || !strings.Contains(m.Refused, "holds no revision 999") {
|
||||
t.Errorf("a revision the catalog does not hold answered %+v", m)
|
||||
}
|
||||
// A-226c: a run's key reads the indexer's candidates.run-<id> by its group, with no heads compared; one it holds none of is refused.
|
||||
candidateOf("run-r1", digest2)
|
||||
runKey, _ := nec.RunKey("r1")
|
||||
if m := s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: runKey}); m.Verdict != nec.Composed || len(m.Modules) != 1 || m.Modules[0].Fp != fpNew || !m.Modules[0].Changed {
|
||||
if m := s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: runKey}, ""); m.Verdict != nec.Composed || len(m.Modules) != 1 || m.Modules[0].Fp != fpNew || !m.Modules[0].Changed {
|
||||
t.Errorf("a run's key answered %+v", m)
|
||||
}
|
||||
noRun, _ := nec.RunKey("r2")
|
||||
if m := s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: noRun}); m.Verdict != nec.Refused || !strings.Contains(m.Refused, "holds no candidate") {
|
||||
if m := s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: noRun}, ""); m.Verdict != nec.Refused || !strings.Contains(m.Refused, "holds no candidate") {
|
||||
t.Errorf("a run the indexer holds none of answered %+v", m)
|
||||
}
|
||||
missing, _ := nec.CompositionKey("novox/x#8", "0123456789ab")
|
||||
if m := s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: missing}); !strings.Contains(m.Refused, "holds no candidate") {
|
||||
if m := s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: missing}, ""); !strings.Contains(m.Refused, "holds no candidate") {
|
||||
t.Errorf("a candidate the indexer does not hold answered %+v", m)
|
||||
}
|
||||
// The group's candidate moved to other heads since the ask: the node composes not the one asked, and answers
|
||||
// unready (no answer), naming the heads it holds.
|
||||
moved, _ := nec.CompositionKey("fix/940-no-retire-on-partial-read", "0123456789ab")
|
||||
if m := s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: moved}); m.Verdict != nec.Unready ||
|
||||
if m := s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: moved}, ""); m.Verdict != nec.Unready ||
|
||||
!strings.Contains(m.Refused, "heads") {
|
||||
t.Errorf("a candidate at other heads answered %+v", m)
|
||||
}
|
||||
ended, end := context.WithCancel(ctx)
|
||||
end()
|
||||
if e := s.ComposeCandidate(ended, nodeengine.ComposeCandidateInput{Candidate: accepted}); e.Verdict != nec.Unready {
|
||||
if e := s.ComposeCandidate(ended, nodeengine.ComposeCandidateInput{Candidate: accepted}, ""); e.Verdict != nec.Unready {
|
||||
t.Errorf("an ended bound answered %+v", e)
|
||||
}
|
||||
if len(state.written()) != 0 || applied.Load() != 0 || handed.Load() != 0 {
|
||||
t.Errorf("composing candidates wrote %v, marked %d have(s), handed %d answer(s); want nothing", state.written(), applied.Load(), handed.Load())
|
||||
}
|
||||
// H-A-364 (b): a repeat of an ask while its run goes joins that run and gets the answer it composes once; one whose
|
||||
// bound ends first answers unready; a repeat after the run ended composes again.
|
||||
t.Run("a repeat of an ask joins the run it started", func(t *testing.T) {
|
||||
var runs askRuns
|
||||
var composed atomic.Int64
|
||||
release, started := make(chan struct{}), make(chan struct{})
|
||||
compose := func() nodeengine.ComposeCandidateAnswer {
|
||||
if composed.Add(1) == 1 {
|
||||
close(started)
|
||||
<-release
|
||||
}
|
||||
return nodeengine.ComposeCandidateAnswer{Verdict: nec.Composed}
|
||||
}
|
||||
ended := func() nodeengine.ComposeCandidateAnswer { return nodeengine.ComposeCandidateAnswer{Verdict: nec.Unready} }
|
||||
first := make(chan bool, 1)
|
||||
go func() { _, joined := runs.once(ctx, "a", compose, ended); first <- joined }()
|
||||
<-started
|
||||
gone, cut := context.WithCancel(ctx)
|
||||
cut()
|
||||
if a, joined := runs.once(gone, "a", compose, ended); !joined || a.Verdict != nec.Unready {
|
||||
t.Errorf("a repeat whose bound ended answered %+v (joined %v)", a, joined)
|
||||
}
|
||||
again := make(chan nodeengine.ComposeCandidateAnswer, 1)
|
||||
go func() { a, _ := runs.once(ctx, "a", compose, ended); again <- a }()
|
||||
for joined := 0; joined < 2; runtime.Gosched() { // the cut repeat, then this one
|
||||
runs.mu.Lock()
|
||||
joined = runs.runs["a"].joined
|
||||
runs.mu.Unlock()
|
||||
}
|
||||
close(release)
|
||||
if joined := <-first; joined {
|
||||
t.Error("the first ask joined a run")
|
||||
}
|
||||
if a := <-again; a.Verdict != nec.Composed || composed.Load() != 1 {
|
||||
t.Errorf("a repeat while the run went answered %+v after %d composition(s); want the one", a, composed.Load())
|
||||
}
|
||||
if _, joined := runs.once(ctx, "a", compose, ended); joined || composed.Load() != 2 {
|
||||
t.Errorf("a repeat after the run ended joined %v, %d composition(s); want composed again", joined, composed.Load())
|
||||
}
|
||||
})
|
||||
// Issue 1126, 2026-11-03: off the control-node an ask of compose-candidate was not answered within a minute, and said
|
||||
// nothing of why. Each of its two compositions read every manifest in the mesh one by one, on copies of the shadow
|
||||
// that kept nothing, so every ask read them all twice again. Each manifest is now read once, before either
|
||||
@@ -269,7 +330,7 @@ func TestTheNodeComposesACandidateOnAsk(t *testing.T) {
|
||||
}
|
||||
var a nodeengine.ComposeCandidateAnswer
|
||||
for range tc.asks {
|
||||
a = s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: key})
|
||||
a = s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: key}, "")
|
||||
}
|
||||
if a.Verdict != tc.verdict || !strings.Contains(a.Refused, tc.words) {
|
||||
t.Errorf("answered %s %q; want %s with %q", a.Verdict, a.Refused, tc.verdict, tc.words)
|
||||
|
||||
Reference in New Issue
Block a user