H-find: the node-engine raises what only it knows of itself as its own findings
The have's failed phase (apply-failing), unhealthy health (module-unhealthy) and kept words (kept-as-it-runs), and each part of its health report (machine-network, network-rewritten, network-unreachable, machine-units, relogin-needed, directory-used-as-found, node-account-fallback), raised and cleared by the held writer where the engine knows the fact. Builds: design 47 G A-197 (ADR 0596, A-192, A-149) Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
@@ -440,6 +440,9 @@ func (q *Session) writeHaves(ctx context.Context, bus Bus) {
|
||||
s.written = map[string]string{}
|
||||
}
|
||||
s.written[module] = f.Build
|
||||
if say, _ := q.haveSaid(); say != nil {
|
||||
said = append(said, func() { say(module, h) })
|
||||
}
|
||||
if ev, ok := s.runningToSay(module, h, q.manifestOf()); ok {
|
||||
said = append(said, func() { q.sayRunning(ev) })
|
||||
}
|
||||
@@ -555,6 +558,9 @@ func (q *Session) writeRemoved(ctx context.Context, b HaveBucket, node string, s
|
||||
switch {
|
||||
case errors.Is(err, ErrHaveAbsent):
|
||||
delete(s.removed, module) // nothing to say: the key is not there
|
||||
if _, gone := q.haveSaid(); gone != nil {
|
||||
*said = append(*said, func() { gone(module) })
|
||||
}
|
||||
continue
|
||||
case err != nil:
|
||||
q.sayHave(fmt.Sprintf("could not read %s in the have bucket, and wrote nothing more there: %v", key, err))
|
||||
@@ -563,6 +569,9 @@ func (q *Session) writeRemoved(ctx context.Context, b HaveBucket, node string, s
|
||||
}
|
||||
if c, err := nodeengineclient.DecodeHave(current); err == nil && c.Phase == nodeengineclient.PhaseRemoved {
|
||||
delete(s.removed, module)
|
||||
if _, gone := q.haveSaid(); gone != nil {
|
||||
*said = append(*said, func() { gone(module) })
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err := b.Set(ctx, key, raw, revision); err != nil {
|
||||
@@ -571,6 +580,9 @@ func (q *Session) writeRemoved(ctx context.Context, b HaveBucket, node string, s
|
||||
return false
|
||||
}
|
||||
delete(s.removed, module)
|
||||
if _, gone := q.haveSaid(); gone != nil {
|
||||
*said = append(*said, func() { gone(module) })
|
||||
}
|
||||
// The module no longer runs here: running says stopped, with no fingerprint, on its own subject (design 47 G §365, §404).
|
||||
delete(s.runningSaid, module)
|
||||
*said = append(*said, func() { q.sayRunning(stoppedRunning(node, module)) })
|
||||
@@ -983,6 +995,20 @@ func (q *Session) sayRunning(ev nodeengine.Running) {
|
||||
q.sayEngineOn(nodeengine.SubjectRunning(ev.Node, ev.Module), "running", ev)
|
||||
}
|
||||
|
||||
// SetHaveSaid gives the session what it tells of each module's have as it writes it (said), and of a module whose have says
|
||||
// it is gone (gone): the node-engine's findings of itself are made of them (design 47 G A-197). Either may be nil.
|
||||
func (q *Session) SetHaveSaid(said func(module string, h nodeengine.HaveByNodeModuleValue), gone func(module string)) {
|
||||
q.haveSay.Lock()
|
||||
q.haveSaidFn, q.haveGoneFn = said, gone
|
||||
q.haveSay.Unlock()
|
||||
}
|
||||
|
||||
func (q *Session) haveSaid() (func(string, nodeengine.HaveByNodeModuleValue), func(string)) {
|
||||
q.haveSay.Lock()
|
||||
defer q.haveSay.Unlock()
|
||||
return q.haveSaidFn, q.haveGoneFn
|
||||
}
|
||||
|
||||
// SetManifestOf gives the session what names the manifest of the build a module runs (the composer's picture of the
|
||||
// catalog half): its digest, or "" when the node does not know it.
|
||||
func (q *Session) SetManifestOf(f func(module, fp string) string) {
|
||||
|
||||
@@ -230,7 +230,13 @@ func aHaveQueue(l *haveLink) (*Session, *[]string) {
|
||||
func TestAnAppliedModuleIsWrittenRunningAndAFailedOneFailed(t *testing.T) {
|
||||
l := newHaveLink()
|
||||
q, _ := aHaveQueue(l)
|
||||
// Design 47 G A-197: each have as written is told to the node-engine's findings of itself, the failed one with its detail.
|
||||
told := map[string]nodeengine.HaveByNodeModuleValue{}
|
||||
q.SetHaveSaid(func(m string, h nodeengine.HaveByNodeModuleValue) { told[m] = h }, nil)
|
||||
q.SayFacts(context.Background(), appliedModules())
|
||||
if told["b"].Phase != nodeengineclient.PhaseFailed || !strings.Contains(told["b"].Detail, "no space") || told["a"].Phase != nodeengineclient.PhaseRunning {
|
||||
t.Errorf("the haves told were %+v", told)
|
||||
}
|
||||
a, b := l.have(t, "n1.a"), l.have(t, "n1.b")
|
||||
if a.Phase != nodeengineclient.PhaseRunning || a.Build != "b-1" || a.Health != nodeengineclient.HealthOK {
|
||||
t.Errorf("a: %+v", a)
|
||||
@@ -563,9 +569,14 @@ func onlyA() Report {
|
||||
func TestAModuleLeavingTheDeclarationIsWrittenRemoved(t *testing.T) {
|
||||
l := newHaveLink()
|
||||
q, _ := aHaveQueue(l)
|
||||
var gone []string
|
||||
q.SetHaveSaid(nil, func(m string) { gone = append(gone, m) })
|
||||
q.SayFacts(context.Background(), appliedModules())
|
||||
revA, revB := l.kv["n1.a"].rev, l.kv["n1.b"].rev
|
||||
q.SayFacts(context.Background(), onlyA())
|
||||
if len(gone) != 1 || gone[0] != "b" { // design 47 G A-197: a module that left ends its findings
|
||||
t.Errorf("the modules told gone were %v, want b", gone)
|
||||
}
|
||||
b := l.have(t, "n1.b")
|
||||
if b.Phase != nodeengineclient.PhaseRemoved || b.Build != "b-2" {
|
||||
t.Errorf("b: %+v", b)
|
||||
|
||||
@@ -29,6 +29,10 @@ type Session struct {
|
||||
// Own is the module that is this node-engine (§527, §634): its discovery, finding writer and vault login names read it.
|
||||
// Nil names none, as a test's session does.
|
||||
Own *OwnName
|
||||
// haveSay guards haveSaidFn and haveGoneFn (SetHaveSaid).
|
||||
haveSay sync.Mutex
|
||||
haveSaidFn func(module string, h nodeengine.HaveByNodeModuleValue)
|
||||
haveGoneFn func(module string)
|
||||
// Fallback is the engine's fall back to its old login its health report carries now (Rotator.Fallback); nil says none.
|
||||
Fallback func() *nodeengine.LoginFallback
|
||||
// linkedUser is the bus user the link open now authenticated as, guarded by mu (WhenLinkedAs).
|
||||
|
||||
Reference in New Issue
Block a user