Merge pull request 'Node-engine: judge a move's data forms from the entry kept of the running build; no endless handing again' (#231) from fix/47-G-engine-own-manifest into main
This commit was merged in pull request #231.
This commit is contained in:
@@ -239,9 +239,9 @@ func (a *Agent) keptStep(ctx context.Context, module string, w wantNow, comp com
|
||||
since := r.now()
|
||||
a.writeHave(ctx, Have{Module: module, FP: prev.Fp, Composed: prev.Composed, Phase: string(nodeengineclient.PhaseHeld), Detail: words,
|
||||
Wait: &nodeengine.Wait{Owner: nodeengine.Seat, Step: nodeengine.WaitStepCompose, Reason: "entry-missing", Since: since, Words: words}})
|
||||
if a.env.Waiting != nil {
|
||||
a.env.Waiting(module, fp)
|
||||
}
|
||||
// The composition of the want is held: the wait is for an entry, not for a composition, so the composer is not told it
|
||||
// is waited for (that handed the same composition again every pass, and the move failed the same way again); it
|
||||
// hands the composition again when the entry answers (Composer.entryChanged).
|
||||
return true, nil
|
||||
}
|
||||
take, restore := keptMoves(changes, prev.Fp, fp)
|
||||
|
||||
@@ -30,6 +30,7 @@ type recoveryFake struct {
|
||||
catchUp []meshrecovery.CatchUp
|
||||
expired chan struct{}
|
||||
unknown error // FormChanges answers it
|
||||
waited int // times the agent told the composer it waits for a composition
|
||||
}
|
||||
|
||||
type fakeAnswer struct {
|
||||
@@ -110,6 +111,7 @@ func moveDB(t *testing.T, f *recoveryFake, ranFrom, to string, settle func(b *be
|
||||
}
|
||||
f.events, f.expired = make(chan Ending, 16), make(chan struct{})
|
||||
b.env.Recovery = f.env()
|
||||
b.env.Waiting = func(string, string) { f.mu.Lock(); f.waited++; f.mu.Unlock() }
|
||||
b.env.Stop = func(context.Context, string) Result {
|
||||
f.mu.Lock()
|
||||
f.calls = append(f.calls, "stop")
|
||||
@@ -289,6 +291,11 @@ func testAMoveAcrossAFormChange(t *testing.T) {
|
||||
t.Run("a form change not known moves nothing and waits for the entries (A-113)", func(t *testing.T) {
|
||||
f := &recoveryFake{unknown: fmt.Errorf("the entry is asked")}
|
||||
b := moveDB(t, f, "a", "b", heldHave)
|
||||
f.mu.Lock()
|
||||
if f.waited != 0 {
|
||||
t.Errorf("the composer was told the agent waits for a composition %d times; it waits for an entry and holds the composition", f.waited)
|
||||
}
|
||||
f.mu.Unlock()
|
||||
if h := b.haves.last("db"); h.FP != fp("a") || !contains(h.Detail, "is not known") || h.Wait == nil || h.Wait.Reason != "entry-missing" {
|
||||
t.Fatalf("the have %+v", h)
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
|
||||
"github.com/novox/mesh-host/internal/agent"
|
||||
engcomp "github.com/novox/mesh-host/internal/compositions"
|
||||
)
|
||||
|
||||
// **The catalog half, read by fingerprint** (design 47 G §421, §683, §698; the lead's answers A-47 and A-50). The node-engine
|
||||
@@ -150,9 +151,42 @@ func (c *Composer) entryChanged(row meshcatalogclient.EntryRow) {
|
||||
c.keep(entryKey(row.Fingerprint), meshcatalog.EntryAnswer{Entry: *row.Entry})
|
||||
}
|
||||
c.tellNotFound(row.Fingerprint, row.State == meshcatalogclient.EntryNotFound)
|
||||
if row.State == meshcatalogclient.EntryAnswered {
|
||||
c.handAgainFor(row.Fingerprint)
|
||||
}
|
||||
c.askRehand()
|
||||
}
|
||||
|
||||
// handAgainFor forgets what was handed of each module of this node whose want or running build is fp, so the next pass hands it
|
||||
// again and the node agent, which waits for this entry to judge a move (agent.keptStep), settles it again.
|
||||
func (c *Composer) handAgainFor(fp string) {
|
||||
var running []engcomp.Composed
|
||||
if c.env.Running != nil {
|
||||
running = c.env.Running()
|
||||
}
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
for module, w := range c.wants {
|
||||
if module == agent.NodeModule || w.Fp == "" {
|
||||
continue
|
||||
}
|
||||
// Only a move is judged by the entries (agent.keptStep): a module that runs the build its want names has none to wait on.
|
||||
moves, runs := false, false
|
||||
for _, r := range running {
|
||||
if r.Module == module {
|
||||
moves = moves || r.FP != w.Fp
|
||||
runs = runs || r.FP == fp
|
||||
}
|
||||
}
|
||||
if !moves || (w.Fp != fp && !runs) {
|
||||
continue
|
||||
}
|
||||
if key, err := engcomp.Key(c.env.Node, module, w.Fp); err == nil {
|
||||
delete(c.handed, key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// tellNotFound tells the finding entry-not-found once when fp's entry is not found, and once when it no longer is (design 47 G §614, A-117).
|
||||
func (c *Composer) tellNotFound(fp string, notFound bool) {
|
||||
c.mu.Lock()
|
||||
@@ -222,6 +256,11 @@ func (c *Composer) entryOf(fp string) (meshcatalog.CatalogEntry, meshcatalogclie
|
||||
// wantedBuilds is each fingerprint a want of this node or a running heard names, of the new form, with whether a want names it.
|
||||
func (c *Composer) wantedBuilds() map[string]bool {
|
||||
out := map[string]bool{}
|
||||
// Read before the lock: what the node runs is the agent's, and a read of it may wait.
|
||||
var running []engcomp.Composed
|
||||
if c.env.Running != nil {
|
||||
running = c.env.Running()
|
||||
}
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
for module, w := range c.wants {
|
||||
@@ -244,6 +283,15 @@ func (c *Composer) wantedBuilds() map[string]bool {
|
||||
}
|
||||
}
|
||||
}
|
||||
// The build each module runs here, as the node's own record of it says: its entry, kept in the composition state, stays held
|
||||
// for the judgement of a move's data forms though the catalog half dropped it and no event of the stream names it.
|
||||
for _, r := range running {
|
||||
if r.Module != agent.NodeModule && strings.HasPrefix(r.FP, meshcatalogclient.SourcePrefix2) {
|
||||
if _, named := out[r.FP]; !named {
|
||||
out[r.FP] = false
|
||||
}
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
|
||||
@@ -311,3 +311,34 @@ func runningModuleWithoutEntryStandsAsTheNewestBuild(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// The node judges a move's data forms from the entry it kept of the build it runs, though the catalog half dropped that entry and no
|
||||
// running event names it; and an answered entry has the composition handed again, which the agent waits on (novox, mesh-hand-acts).
|
||||
func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) {
|
||||
old := meshcatalogclient.SourcePrefix2 + strings.Repeat("1", 64)
|
||||
next := meshcatalogclient.SourcePrefix2 + strings.Repeat("2", 64)
|
||||
env := newFakeBus().env()
|
||||
env.Node = "n1"
|
||||
env.Running = func() []compositions.Composed {
|
||||
return []compositions.Composed{{Node: "n1", Module: "hand", FP: old}}
|
||||
}
|
||||
c := New(env)
|
||||
c.mu.Lock()
|
||||
c.wants["hand"] = meshwants.WantsByWantNodeModuleValue{Fp: next}
|
||||
c.mu.Unlock()
|
||||
if named, ok := c.wantedBuilds()[old]; !ok || named {
|
||||
t.Errorf("the running build %s is asked of no want yet kept: %v, %v", old, named, ok)
|
||||
}
|
||||
key, _ := compositions.Key("n1", "hand", next)
|
||||
c.mu.Lock()
|
||||
c.handed[key] = "d"
|
||||
c.mu.Unlock()
|
||||
c.entryChanged(meshcatalogclient.EntryRow{Fingerprint: old, State: meshcatalogclient.EntryAnswered,
|
||||
Entry: &meshcatalog.CatalogEntry{Module: "hand", Fp: old}})
|
||||
c.mu.Lock()
|
||||
_, still := c.handed[key]
|
||||
c.mu.Unlock()
|
||||
if still {
|
||||
t.Error("an entry of the running build was answered, and the composition was not handed again")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user