The node-engine applies a want by the bus revision of its key; run is information (design 47 H2 §813 (1), H-A-504 third to fifth addendum) #253
@@ -90,8 +90,15 @@ func (h sessionHaves) Read(ctx context.Context, module string) (agent.Have, bool
|
||||
if !ok {
|
||||
return agent.Have{}, false
|
||||
}
|
||||
return haveOf(module, got), true
|
||||
}
|
||||
|
||||
// haveOf is a module's have value as the agent reads it: every read gives the run, the pipeline and the want revision it
|
||||
// was applied from, so a have written over it (held, failed, waiting) keeps them (H-A-504 fourth addendum).
|
||||
func haveOf(module string, got nodeengine.HaveByNodeModuleValue) agent.Have {
|
||||
return agent.Have{Module: module, FP: got.Fp, Composed: got.Composed, Phase: string(got.Phase), Detail: got.Detail,
|
||||
Sealed: got.SealedAt, Wait: got.Wait}, true
|
||||
Sealed: got.SealedAt, Wait: got.Wait, Run: got.Run, Pipeline: got.Pipeline,
|
||||
WantRevision: uint64(max(got.WantRevision, 0))}
|
||||
}
|
||||
|
||||
// ReadErr is Read telling a have absent from one the bus could not read (agent.HavesReadErr).
|
||||
@@ -114,9 +121,7 @@ func (h sessionHaves) ReadAt(ctx context.Context, module string) (agent.Have, ui
|
||||
if !ok || err != nil {
|
||||
return agent.Have{}, revision, false, err
|
||||
}
|
||||
return agent.Have{Module: module, FP: got.Fp, Composed: got.Composed, Phase: string(got.Phase), Detail: got.Detail,
|
||||
Sealed: got.SealedAt, Wait: got.Wait, Run: got.Run, Pipeline: got.Pipeline,
|
||||
WantRevision: uint64(max(got.WantRevision, 0))}, revision, true, nil
|
||||
return haveOf(module, got), revision, true, nil
|
||||
}
|
||||
|
||||
// WriteAt writes a module's have only while its key is at the revision read (agent.HavesAt, H-A-480).
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||
"github.com/nats-io/nats.go"
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
"github.com/novox/mesh-host/internal/agent"
|
||||
"github.com/novox/mesh-host/internal/buckets"
|
||||
"github.com/novox/mesh-host/internal/link"
|
||||
"github.com/novox/mesh-host/internal/nodegrant"
|
||||
@@ -134,6 +135,17 @@ func TestNatsTheRecoveryStepAsksHearsBoundsAndCatchesUpOverTheBus(t *testing.T)
|
||||
|
||||
say("old", meshrecovery.RestoredEventOutcomeFailed) // said before anyone listens: the last message of the subject
|
||||
session := b.startSession()
|
||||
// H-A-504 fourth addendum: a have written through the agent's haves and read back gives the run, the pipeline and the
|
||||
// want revision it was applied from, by every read, so a have written over it keeps them.
|
||||
hv := sessionHaves{session: session}
|
||||
hv.Write(ctx, agent.Have{Module: "web", FP: "src2:" + strings.Repeat("a", 64), Composed: "sha256:" + strings.Repeat("b", 64),
|
||||
Phase: "running", Run: "12", Pipeline: "main.12", WantRevision: 301924})
|
||||
within(t, 5*time.Second, "the have read back through the agent's haves lacks its run, pipeline or want revision", func() bool {
|
||||
got, ok := hv.Read(ctx, "web")
|
||||
at, _, okAt, err := hv.ReadAt(ctx, "web")
|
||||
return ok && okAt && err == nil && got.Run == "12" && got.Pipeline == "main.12" && got.WantRevision == 301924 &&
|
||||
at.Run == got.Run && at.Pipeline == got.Pipeline && at.WantRevision == got.WantRevision
|
||||
})
|
||||
r := recoveryEnv(session, nil)
|
||||
// Design 47 H2 §775, H-A-364: over the same session, an ask of the seat is taken once in the state taken: the first time,
|
||||
// and never again within its bound.
|
||||
|
||||
@@ -447,6 +447,28 @@ func testAWantAndItsCompositionApplyTheModuleAndTheHaveNamesBoth(t *testing.T) {
|
||||
t.Errorf("%s: the have names want revision %d and run %q, want %d and %q", row.name, h.WantRevision, h.Run, next, row.run)
|
||||
}
|
||||
}
|
||||
// H-A-504 fourth addendum: the want revision is written with every have, so a failed apply after one keeps the revision
|
||||
// the module was applied from, and the next want is still ordered against it.
|
||||
hf := b.haves.last("web")
|
||||
hf.WantRevision = wantsRev() // the older row's earlier life ends: what was applied is at the latest write
|
||||
b.haves.Write(context.Background(), hf)
|
||||
applied := hf.WantRevision
|
||||
b.mu.Lock()
|
||||
b.failWith = "systemctl start web.service: exit status 1"
|
||||
b.mu.Unlock()
|
||||
fpf := fpOf("c")
|
||||
ckf, crawf, digf := composition(t, "web", fpf, false, archive("a", d1))
|
||||
b.comps.put(ckf, crawf)
|
||||
wkf, _ := wantFor(t, "web", fpf, digf, "")
|
||||
rawf, _ := bucketstest.Want(meshwants.WantsByWantNodeModuleValue{Fp: fpf, Run: "11"})
|
||||
b.wants.put(wkf, rawf)
|
||||
b.idle()
|
||||
if h := b.haves.last("web"); h.Phase != string(nodeengineclient.PhaseFailed) || h.WantRevision != applied || h.Run != "3" {
|
||||
t.Errorf("the failed have after an apply: phase %s, want revision %d, run %q; want failed, %d and \"3\"", h.Phase, h.WantRevision, h.Run, applied)
|
||||
}
|
||||
b.mu.Lock()
|
||||
b.failWith = ""
|
||||
b.mu.Unlock()
|
||||
b.mu.Lock()
|
||||
said := strings.Join(b.said, "\n")
|
||||
b.mu.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user