H-A-480 a: the composer's mark is a compare-and-set on the have's revision
Under load, a rank wait settle wrote between the composer's read of a have and its mark was overwritten by the mark and never written again. The mark and its clear now write over the revision they read (a lost race reads again and keeps the other cause), a module waiting for its rank is never marked, and a mark on a module that never ran is cleared at the next pass that composes it. Builds: design 47 H2 H-A-480 (and its addendum), H §771, H-A-59
This commit is contained in:
@@ -104,12 +104,23 @@ func (h sessionHaves) ReadErr(ctx context.Context, module string) (agent.Have, b
|
||||
}
|
||||
return agent.Have{Module: module, Composed: got.Composed, Sealed: got.SealedAt}, true, nil
|
||||
}
|
||||
got, ok, err := h.session.ReadHaveErr(ctx, module)
|
||||
got, _, ok, err := h.ReadAt(ctx, module)
|
||||
return got, ok, err
|
||||
}
|
||||
|
||||
// ReadAt is ReadErr with the revision of the module's key (agent.HavesAt).
|
||||
func (h sessionHaves) ReadAt(ctx context.Context, module string) (agent.Have, uint64, bool, error) {
|
||||
got, revision, ok, err := h.session.ReadHaveAt(ctx, module)
|
||||
if !ok || err != nil {
|
||||
return agent.Have{}, false, err
|
||||
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}, true, nil
|
||||
Sealed: got.SealedAt, Wait: got.Wait, Run: got.Run, Pipeline: got.Pipeline}, revision, true, nil
|
||||
}
|
||||
|
||||
// WriteAt writes a module's have only while its key is at the revision read (agent.HavesAt, H-A-480).
|
||||
func (h sessionHaves) WriteAt(ctx context.Context, x agent.Have, revision uint64) (bool, error) {
|
||||
return h.session.NoteModuleAt(ctx, moduleFact(x), revision)
|
||||
}
|
||||
|
||||
func (h sessionHaves) Write(ctx context.Context, x agent.Have) {
|
||||
@@ -120,13 +131,18 @@ func (h sessionHaves) Write(ctx context.Context, x agent.Have) {
|
||||
}
|
||||
return
|
||||
}
|
||||
h.session.NoteModule(ctx, moduleFact(x))
|
||||
}
|
||||
|
||||
// moduleFact is a module's have as the session writes it.
|
||||
func moduleFact(x agent.Have) link.ModuleFact {
|
||||
phase := x.Phase
|
||||
if phase == string(nodeengineclient.PhaseRunning) {
|
||||
phase = ""
|
||||
}
|
||||
h.session.NoteModule(ctx, link.ModuleFact{Module: x.Module, FP: x.FP, Composed: x.Composed, Phase: phase,
|
||||
return link.ModuleFact{Module: x.Module, FP: x.FP, Composed: x.Composed, Phase: phase,
|
||||
Failed: phase == string(nodeengineclient.PhaseFailed), Detail: shorten(x.Detail), Judgement: x.Judgement, Waits: x.Waits,
|
||||
BuildAlone: x.BuildAlone, Kept: x.Kept, Sealed: x.Sealed, PullWait: x.PullWait, Wait: x.Wait, Run: x.Run, Pipeline: x.Pipeline})
|
||||
BuildAlone: x.BuildAlone, Kept: x.Kept, Sealed: x.Sealed, PullWait: x.PullWait, Wait: x.Wait, Run: x.Run, Pipeline: x.Pipeline}
|
||||
}
|
||||
|
||||
func (h sessionHaves) Removed(ctx context.Context, module string) {
|
||||
|
||||
+148
-32
@@ -581,6 +581,42 @@ type HavesReadErr interface {
|
||||
ReadErr(ctx context.Context, module string) (Have, bool, error)
|
||||
}
|
||||
|
||||
// HavesAt is what a Haves may answer besides Write: a module's have with the revision of its key (zero when the bucket
|
||||
// holds none), and a write of it that lands only while the key is still at that revision, false when it moved (design 47
|
||||
// H2 H-A-480: the composer's mark is a compare-and-set on the have's revision).
|
||||
type HavesAt interface {
|
||||
ReadAt(ctx context.Context, module string) (Have, uint64, bool, error)
|
||||
WriteAt(ctx context.Context, h Have, revision uint64) (bool, error)
|
||||
}
|
||||
|
||||
// readHaveAt is readHave with the revision of the have's key, for a write over it (writeHaveAt). A Haves that keeps no
|
||||
// revisions answers zero, and its writes land whatever moved.
|
||||
func (a *Agent) readHaveAt(ctx context.Context, module string) (h Have, revision uint64, found, unread bool) {
|
||||
at, tells := a.env.Haves.(HavesAt)
|
||||
if !tells {
|
||||
h, found, unread = a.readHave(ctx, module)
|
||||
return h, 0, found, unread
|
||||
}
|
||||
for try := 0; ; try++ {
|
||||
h, revision, found, err := at.ReadAt(ctx, module)
|
||||
if err == nil {
|
||||
return h, revision, found, false
|
||||
}
|
||||
if try == 2 || ctx.Err() != nil {
|
||||
return Have{}, 0, false, true
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return Have{}, 0, false, true
|
||||
case <-time.After(time.Duration(1<<try) * readAgain):
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// markTries is how many times a mark or its clear is written over a have that moved since it was read, each after
|
||||
// reading it again (writeHaveAt).
|
||||
const markTries = 3
|
||||
|
||||
// readHave reads a module's have: found, absent, or unread. A read that fails is tried again after a short wait while
|
||||
// the bus does not answer (a reload pauses it for a few seconds, issue 1126), and is unread when it still fails. A
|
||||
// Haves that cannot tell an absent key from a failed read says absent.
|
||||
@@ -672,21 +708,18 @@ func (a *Agent) NotComposedEach(ctx context.Context, why string, held map[string
|
||||
back.Phase = string(r.Phase)
|
||||
}
|
||||
}
|
||||
if back.Composed == "" {
|
||||
continue // nothing said what ran: nothing to say back
|
||||
if back.Module == "" {
|
||||
// Nothing said what ran, and its have held no key before the mark: the apply the composing pass starts
|
||||
// replaces the mark in the same settle (H-A-480).
|
||||
continue
|
||||
}
|
||||
a.writeHave(ctx, back)
|
||||
a.clearMark(ctx, module, back)
|
||||
continue
|
||||
}
|
||||
if !marked {
|
||||
if ran {
|
||||
mark.prior = Have{Module: module, FP: r.Fp, Composed: r.Composed, Phase: string(r.Phase)}
|
||||
if mark.prior.Phase == "" {
|
||||
mark.prior.Phase = string(nodeengineclient.PhaseRunning)
|
||||
}
|
||||
} else if h, found, unread := a.readHave(ctx, module); found {
|
||||
mark.prior = h // what its last have said runs: this agent has run nothing of it since its start
|
||||
} else if unread {
|
||||
var revision uint64
|
||||
if !marked && !ran {
|
||||
h, rev, found, unread := a.readHaveAt(ctx, module)
|
||||
if unread {
|
||||
if ctx.Err() != nil {
|
||||
return
|
||||
}
|
||||
@@ -697,24 +730,29 @@ func (a *Agent) NotComposedEach(ctx context.Context, why string, held map[string
|
||||
a.mu.Unlock()
|
||||
continue
|
||||
}
|
||||
if found {
|
||||
mark.prior = h // what its last have said runs: this agent has run nothing of it since its start
|
||||
}
|
||||
revision = rev
|
||||
} else {
|
||||
if !marked {
|
||||
mark.prior = Have{Module: module, FP: r.Fp, Composed: r.Composed, Phase: string(r.Phase)}
|
||||
if mark.prior.Phase == "" {
|
||||
mark.prior.Phase = string(nodeengineclient.PhaseRunning)
|
||||
}
|
||||
}
|
||||
_, rev, _, unread := a.readHaveAt(ctx, module)
|
||||
if unread {
|
||||
if ctx.Err() != nil {
|
||||
return
|
||||
}
|
||||
a.mu.Lock()
|
||||
a.sayOnce("unmarked:"+module, fmt.Sprintf("%s's have cannot be read, so it is not marked: the node cannot compose it: %s", module, why))
|
||||
a.mu.Unlock()
|
||||
continue
|
||||
}
|
||||
revision = rev
|
||||
}
|
||||
// A have that already says another cause (an apply that failed, a backup held, an apply under way) keeps it: a
|
||||
// composer's mark over it would hide that cause, and baseline would take the mark for what runs (review of the
|
||||
// switch, round 1).
|
||||
if p := mark.prior.Phase; !marked && p != "" && p != string(nodeengineclient.PhaseRunning) && !composerMark(mark.prior) {
|
||||
a.mu.Lock()
|
||||
a.sayOnce("unmarked-cause:"+module, fmt.Sprintf("%s is not marked: its have says %s (%s), and the node cannot compose it: %s",
|
||||
module, p, mark.prior.Detail, why))
|
||||
a.mu.Unlock()
|
||||
continue
|
||||
}
|
||||
if ctx.Err() != nil {
|
||||
return
|
||||
}
|
||||
mark.why = why
|
||||
a.mu.Lock()
|
||||
a.notComposed[module] = mark
|
||||
a.mu.Unlock()
|
||||
phase, detail := string(nodeengineclient.PhaseFailed), NotComposedDetail+why
|
||||
var wait *nodeengine.Wait
|
||||
if heldForEntry(why) {
|
||||
@@ -724,8 +762,63 @@ func (a *Agent) NotComposedEach(ctx context.Context, why string, held map[string
|
||||
// The hold says what it waits on, as every hold but a failed backup does (design 47 G A-453, section 541).
|
||||
wait = a.composeWait(strings.TrimSuffix(heldReason(why), ":"), why)
|
||||
}
|
||||
a.writeHave(ctx, Have{Module: module, FP: mark.prior.FP, Composed: mark.prior.Composed, Sealed: mark.prior.Sealed,
|
||||
Phase: phase, Detail: detail, Wait: wait})
|
||||
written := false
|
||||
for try := 0; try < markTries && !written; try++ {
|
||||
if ctx.Err() != nil {
|
||||
return
|
||||
}
|
||||
// A module waiting for its rank is never marked: its have says that wait (design 47 H §771, H-A-480).
|
||||
a.mu.Lock()
|
||||
_, placing := a.placing[module]
|
||||
a.mu.Unlock()
|
||||
if placing {
|
||||
break
|
||||
}
|
||||
// A have that already says another cause (an apply that failed, a backup held, an apply under way, a wait
|
||||
// for its rank) keeps it: a composer's mark over it would hide that cause, and baseline would take the mark
|
||||
// for what runs (review of the switch, round 1).
|
||||
if p := mark.prior.Phase; !marked && p != "" && p != string(nodeengineclient.PhaseRunning) && !composerMark(mark.prior) {
|
||||
a.mu.Lock()
|
||||
a.sayOnce("unmarked-cause:"+module, fmt.Sprintf("%s is not marked: its have says %s (%s), and the node cannot compose it: %s",
|
||||
module, p, mark.prior.Detail, why))
|
||||
a.mu.Unlock()
|
||||
break
|
||||
}
|
||||
if written = a.writeHaveAt(ctx, Have{Module: module, FP: mark.prior.FP, Composed: mark.prior.Composed, Sealed: mark.prior.Sealed,
|
||||
Phase: phase, Detail: detail, Wait: wait}, revision); written {
|
||||
break
|
||||
}
|
||||
// The have moved since it was read: read it again, and judge the mark against what it says now.
|
||||
h, rev, found, unread := a.readHaveAt(ctx, module)
|
||||
if unread {
|
||||
break
|
||||
}
|
||||
revision = rev
|
||||
if found && !composerMark(h) {
|
||||
mark.prior, marked = h, false // what another write said since: judged again as a have before any mark
|
||||
}
|
||||
}
|
||||
if !written {
|
||||
continue
|
||||
}
|
||||
mark.why = why
|
||||
a.mu.Lock()
|
||||
a.notComposed[module] = mark
|
||||
a.mu.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
// clearMark gives a module's have back as it was before the composer marked it (back), by a compare-and-set while the
|
||||
// have still says the mark: a have another cause wrote since is kept (H-A-480).
|
||||
func (a *Agent) clearMark(ctx context.Context, module string, back Have) {
|
||||
for try := 0; try < markTries && ctx.Err() == nil; try++ {
|
||||
h, revision, found, unread := a.readHaveAt(ctx, module)
|
||||
if unread || !found || !composerMark(h) {
|
||||
return
|
||||
}
|
||||
if a.writeHaveAt(ctx, back, revision) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -744,6 +837,12 @@ func (a *Agent) composeWait(reason, words string) *nodeengine.Wait {
|
||||
// said runs, its fingerprint, digest and sealed values, rather than a have naming nothing: what runs is not lost, and
|
||||
// the boxes the composer reuses after a restart stay (review of L2, rounds 2 and 3).
|
||||
func (a *Agent) writeHave(ctx context.Context, h Have) {
|
||||
a.env.Haves.Write(ctx, a.filledHave(ctx, h))
|
||||
}
|
||||
|
||||
// filledHave is h as writeHave writes it: with what the composer keeps of it, and what its last have said where h names
|
||||
// none.
|
||||
func (a *Agent) filledHave(ctx context.Context, h Have) Have {
|
||||
if h.Module != NodeModule {
|
||||
a.mu.Lock()
|
||||
h.Kept = a.kept[h.Module]
|
||||
@@ -769,7 +868,24 @@ func (a *Agent) writeHave(ctx context.Context, h Have) {
|
||||
if a.env.SelfComposed && h.Sealed == nil && h.Composed != "" {
|
||||
h.Sealed = a.sealedOf(ctx, h.Module, h.FP, h.Composed)
|
||||
}
|
||||
a.env.Haves.Write(ctx, h)
|
||||
return h
|
||||
}
|
||||
|
||||
// writeHaveAt is writeHave as a compare-and-set on the revision of the have's key the caller read (readHaveAt): false when
|
||||
// the key moved since, written nothing. A Haves that keeps no revisions writes whatever moved.
|
||||
func (a *Agent) writeHaveAt(ctx context.Context, h Have, revision uint64) bool {
|
||||
at, tells := a.env.Haves.(HavesAt)
|
||||
if !tells {
|
||||
a.writeHave(ctx, h)
|
||||
return true
|
||||
}
|
||||
ok, err := at.WriteAt(ctx, a.filledHave(ctx, h), revision)
|
||||
if err != nil {
|
||||
a.mu.Lock()
|
||||
a.sayOnce("unwritten:"+h.Module, fmt.Sprintf("%s's have is not written: its key cannot be read: %v", h.Module, err))
|
||||
a.mu.Unlock()
|
||||
}
|
||||
return ok && err == nil
|
||||
}
|
||||
|
||||
// KeptNow takes in what the composer's last pass keeps of each module as it runs because its manifest does not yet say it
|
||||
|
||||
@@ -71,6 +71,46 @@ type haves struct {
|
||||
removed []string
|
||||
// unreadable is each module whose have the bus cannot read now (ReadErr).
|
||||
unreadable map[string]bool
|
||||
// revs is each key's revision, moved by every write (HavesAt); afterRead is, by module, what writes between the next read
|
||||
// of its have and the write after it, once (H-A-480).
|
||||
revs map[string]uint64
|
||||
afterRead map[string]func()
|
||||
}
|
||||
|
||||
// read is a module's have and its revision, then what afterRead writes after it, once.
|
||||
func (h *haves) read(module string) (Have, uint64, bool) {
|
||||
h.mu.Lock()
|
||||
x, ok := h.stored[module]
|
||||
rev := h.revs[module]
|
||||
then := h.afterRead[module]
|
||||
delete(h.afterRead, module)
|
||||
h.mu.Unlock()
|
||||
if then != nil {
|
||||
then()
|
||||
}
|
||||
return x, rev, ok
|
||||
}
|
||||
|
||||
func (h *haves) ReadAt(_ context.Context, module string) (Have, uint64, bool, error) {
|
||||
h.mu.Lock()
|
||||
bad := h.unreadable[module]
|
||||
h.mu.Unlock()
|
||||
if bad {
|
||||
return Have{}, 0, false, fmt.Errorf("nats: no responders available for request")
|
||||
}
|
||||
x, rev, ok := h.read(module)
|
||||
return x, rev, ok, nil
|
||||
}
|
||||
|
||||
func (h *haves) WriteAt(ctx context.Context, x Have, revision uint64) (bool, error) {
|
||||
h.mu.Lock()
|
||||
if h.revs[x.Module] != revision {
|
||||
h.mu.Unlock()
|
||||
return false, nil
|
||||
}
|
||||
h.mu.Unlock()
|
||||
h.Write(ctx, x)
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (h *haves) ReadErr(ctx context.Context, module string) (Have, bool, error) {
|
||||
@@ -85,9 +125,7 @@ func (h *haves) ReadErr(ctx context.Context, module string) (Have, bool, error)
|
||||
}
|
||||
|
||||
func (h *haves) Read(_ context.Context, module string) (Have, bool) {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
x, ok := h.stored[module]
|
||||
x, _, ok := h.read(module)
|
||||
return x, ok
|
||||
}
|
||||
func (h *haves) Write(_ context.Context, x Have) {
|
||||
@@ -96,6 +134,10 @@ func (h *haves) Write(_ context.Context, x Have) {
|
||||
if h.stored == nil {
|
||||
h.stored = map[string]Have{}
|
||||
}
|
||||
if h.revs == nil {
|
||||
h.revs = map[string]uint64{}
|
||||
}
|
||||
h.revs[x.Module]++
|
||||
h.stored[x.Module] = x
|
||||
h.log = append(h.log, x)
|
||||
}
|
||||
@@ -2293,4 +2335,54 @@ func TestAgent(t *testing.T) {
|
||||
t.Run("ACompositionWhoseResourcesWereRemovedIsAppliedAgain", testACompositionWhoseResourcesWereRemovedIsAppliedAgain)
|
||||
t.Run("WhatRunsBeforeTheAgentTakesAModuleNamesItsFilledPaths", testWhatRunsBeforeTheAgentTakesAModuleNamesItsFilledPaths)
|
||||
t.Run("TheNodesOwnCompositionIsAppliedWhenItDiffersAndARecordMoveWaitsForAYes", testTheNodesOwnCompositionIsAppliedWhenItDiffersAndARecordMoveWaitsForAYes)
|
||||
t.Run("AComposersMarkKeepsWhatWasWrittenSinceItsRead", testAComposersMarkKeepsWhatWasWrittenSinceItsRead)
|
||||
}
|
||||
|
||||
// The composer's mark is a compare-and-set on the have's revision (design 47 H2 H-A-480): a wait for its rank or another
|
||||
// cause written between its read of the have and its write is kept, and a mark on a module that never ran is cleared at the
|
||||
// next pass that composes it. Seen 2026-11-22 under load: second's wait of step placing (rev 3) overwritten by the mark of
|
||||
// the bootstrapped seat list (rev 4), never written again.
|
||||
func testAComposersMarkKeepsWhatWasWrittenSinceItsRead(t *testing.T) {
|
||||
const why = "the node holds only its bootstrapped seat list, and has not read the seat mesh-catalog"
|
||||
failed := Have{Module: "second", Phase: string(nodeengineclient.PhaseFailed), Detail: "the apply failed: no space left"}
|
||||
for _, row := range []struct {
|
||||
name string
|
||||
// between writes the module's have between the composer's read and its write.
|
||||
between func(ctx context.Context, b *bed)
|
||||
check func(h Have) bool
|
||||
}{
|
||||
{"a wait for its rank", func(ctx context.Context, b *bed) { b.ag.placingHave(ctx, "second", []string{"first"}) },
|
||||
func(h Have) bool {
|
||||
return h.Phase == string(nodeengineclient.PhaseHeld) && h.Wait != nil && h.Wait.Step == nodeengine.WaitStepPlacing && h.Wait.On == "first"
|
||||
}},
|
||||
{"another cause", func(ctx context.Context, b *bed) { b.haves.Write(ctx, failed) },
|
||||
func(h Have) bool { return h.Phase == failed.Phase && h.Detail == failed.Detail }},
|
||||
} {
|
||||
t.Run(row.name, func(t *testing.T) {
|
||||
b := newBed(t)
|
||||
b.ag = New(b.env)
|
||||
ctx := context.Background()
|
||||
b.ag.wants["second"] = wantNow{Want: meshwants.WantsByWantNodeModuleValue{Fp: fpOf("b"), Pipeline: "main.7", Rank: 2}, Present: true}
|
||||
b.haves.afterRead = map[string]func(){"second": func() { row.between(ctx, b) }}
|
||||
b.ag.NotComposedEach(ctx, "", map[string]string{"second": why})
|
||||
if h := b.haves.last("second"); !row.check(h) {
|
||||
t.Fatalf("what was written between the composer's read and its write was overwritten: %+v", h)
|
||||
}
|
||||
})
|
||||
}
|
||||
t.Run("a mark on a module that never ran is cleared", func(t *testing.T) {
|
||||
b := newBed(t)
|
||||
b.ag = New(b.env)
|
||||
ctx := context.Background()
|
||||
b.ag.wants["third"] = wantNow{Want: meshwants.WantsByWantNodeModuleValue{Fp: fpOf("c")}, Present: true}
|
||||
b.haves.Write(ctx, Have{Module: "third", FP: fpOf("c"), Phase: string(nodeengineclient.PhaseRunning)})
|
||||
b.ag.NotComposedEach(ctx, "", map[string]string{"third": why})
|
||||
if h := b.haves.last("third"); !composerMark(h) {
|
||||
t.Fatalf("third is not marked: %+v", h)
|
||||
}
|
||||
b.ag.NotComposedEach(ctx, "", nil)
|
||||
if h := b.haves.last("third"); composerMark(h) || h.Phase != string(nodeengineclient.PhaseRunning) || h.FP != fpOf("c") {
|
||||
t.Fatalf("the mark of a module that never ran stays once it composes: %+v", h)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
+87
-19
@@ -75,6 +75,9 @@ type haveState struct {
|
||||
// unjudged is each module whose composition moved (an apply began, or the fact names another build) and that no look
|
||||
// has judged since it stopped moving: its health is not yet judged, never the last look's of what ran before.
|
||||
unjudged map[string]bool
|
||||
// unwritten is each module whose fact was taken in and is not yet written in its key: a write over a revision
|
||||
// (NoteModuleAt) loses to it, as the key is about to move (design 47 H2 H-A-480).
|
||||
unwritten map[string]bool
|
||||
}
|
||||
|
||||
// inMotion says a module's phase is one of a change still under way: what a look finds of it then judges nothing of the
|
||||
@@ -442,6 +445,7 @@ func (q *Session) writeHaves(ctx context.Context, bus Bus) {
|
||||
s.written = map[string]string{}
|
||||
}
|
||||
s.written[module] = f.Build
|
||||
delete(s.unwritten, module)
|
||||
if say, _ := q.haveSaid(); say != nil {
|
||||
said = append(said, func() { say(module, h) })
|
||||
}
|
||||
@@ -714,17 +718,7 @@ func (q *Session) NoteModule(ctx context.Context, f ModuleFact) {
|
||||
q.init()
|
||||
s := &q.haves
|
||||
s.mu.Lock()
|
||||
if s.modules == nil {
|
||||
s.modules = map[string]ModuleFact{}
|
||||
}
|
||||
// A change under way, or a fact naming another composition than the one looked at, leaves the module's health not
|
||||
// yet judged until a look after it: the last look judged what ran before (2026-10-25, the canary of the controller on
|
||||
// novox held on a have saying applying and failed two seconds before its launch said healthy).
|
||||
s.moved(f)
|
||||
s.modules[f.Module] = f
|
||||
delete(s.removed, f.Module)
|
||||
// Out of motion and not judged: a look is owed now, not at the loop's next statement (review of fix 15, B1).
|
||||
owe := !inMotion(f.Phase) && s.unjudged[f.Module]
|
||||
owe := s.take(f)
|
||||
s.mu.Unlock()
|
||||
if owe {
|
||||
q.oweHealth()
|
||||
@@ -735,6 +729,72 @@ func (q *Session) NoteModule(ctx context.Context, f ModuleFact) {
|
||||
q.writeHaves(ctx, bus)
|
||||
}
|
||||
|
||||
// take takes in one module's fact to be written, and says whether a look is owed for it now. Under s.mu.
|
||||
func (s *haveState) take(f ModuleFact) bool {
|
||||
if s.modules == nil {
|
||||
s.modules = map[string]ModuleFact{}
|
||||
}
|
||||
if s.unwritten == nil {
|
||||
s.unwritten = map[string]bool{}
|
||||
}
|
||||
// A change under way, or a fact naming another composition than the one looked at, leaves the module's health not
|
||||
// yet judged until a look after it: the last look judged what ran before (2026-10-25, the canary of the controller on
|
||||
// novox held on a have saying applying and failed two seconds before its launch said healthy).
|
||||
s.moved(f)
|
||||
s.modules[f.Module] = f
|
||||
s.unwritten[f.Module] = true
|
||||
delete(s.removed, f.Module)
|
||||
// Out of motion and not judged: a look is owed now, not at the loop's next statement (review of fix 15, B1).
|
||||
return !inMotion(f.Phase) && s.unjudged[f.Module]
|
||||
}
|
||||
|
||||
// NoteModuleAt is NoteModule as a compare-and-set on the revision of the module's key the caller read (zero: no key):
|
||||
// the fact is taken in and written only while the key is still at that revision and no other fact of the module waits
|
||||
// to be written; otherwise nothing is taken in, and it answers false, for the caller to read again (design 47 H2
|
||||
// H-A-480: the composer's mark never hides a wait written after its read). An error is the key that could not be read.
|
||||
func (q *Session) NoteModuleAt(ctx context.Context, f ModuleFact, revision uint64) (bool, error) {
|
||||
q.init()
|
||||
q.mu.Lock()
|
||||
bus := q.bus
|
||||
q.mu.Unlock()
|
||||
hb, ok := bus.(HaveBus)
|
||||
if !ok || bus == nil {
|
||||
return false, ErrNotLinkedHaves
|
||||
}
|
||||
key, err := nodeengineclient.HaveKey(q.Membership.Node, f.Module)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
s := &q.haves
|
||||
s.mu.Lock()
|
||||
if s.unwritten[f.Module] {
|
||||
s.mu.Unlock()
|
||||
return false, nil
|
||||
}
|
||||
read, cancel := context.WithTimeout(ctx, q.timeout())
|
||||
defer cancel()
|
||||
bucket, err := hb.HaveBind(read)
|
||||
if err != nil {
|
||||
s.mu.Unlock()
|
||||
return false, err
|
||||
}
|
||||
_, now, err := bucket.Get(read, key)
|
||||
if errors.Is(err, ErrHaveAbsent) {
|
||||
now, err = 0, nil
|
||||
}
|
||||
if err != nil || now != revision {
|
||||
s.mu.Unlock()
|
||||
return false, err
|
||||
}
|
||||
owe := s.take(f)
|
||||
s.mu.Unlock()
|
||||
if owe {
|
||||
q.oweHealth()
|
||||
}
|
||||
q.writeHaves(ctx, bus)
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// NoteUserList takes what the bus node's engine wrote of the bus's user list, and writes it in the bus module's have
|
||||
// where it differs from the bucket's (novox/hq ADR 0547 §8). A module this engine has said no have of yet carries it
|
||||
// from its first have on.
|
||||
@@ -767,6 +827,7 @@ func (q *Session) NoteRemoved(ctx context.Context, module, build string) {
|
||||
}
|
||||
s.removed[module] = build
|
||||
delete(s.modules, module)
|
||||
delete(s.unwritten, module)
|
||||
delete(s.written, module)
|
||||
delete(s.unjudged, module)
|
||||
s.mu.Unlock()
|
||||
@@ -892,36 +953,43 @@ var ErrNotLinkedHaves = errors.New("no link to the bus that binds the have bucke
|
||||
// ReadHaveErr is ReadHave telling a key absent (false, nil) from one that could not be read (false, the error): a bus
|
||||
// that does not answer for a moment is not a module that never ran (issue 1126).
|
||||
func (q *Session) ReadHaveErr(ctx context.Context, module string) (nodeengine.HaveByNodeModuleValue, bool, error) {
|
||||
h, _, ok, err := q.ReadHaveAt(ctx, module)
|
||||
return h, ok, err
|
||||
}
|
||||
|
||||
// ReadHaveAt is ReadHaveErr with the revision of the key it read (zero when the bucket holds none), for a write over it
|
||||
// (NoteModuleAt).
|
||||
func (q *Session) ReadHaveAt(ctx context.Context, module string) (nodeengine.HaveByNodeModuleValue, uint64, bool, error) {
|
||||
q.init()
|
||||
q.mu.Lock()
|
||||
bus := q.bus
|
||||
q.mu.Unlock()
|
||||
hb, ok := bus.(HaveBus)
|
||||
if !ok || bus == nil {
|
||||
return nodeengine.HaveByNodeModuleValue{}, false, ErrNotLinkedHaves
|
||||
return nodeengine.HaveByNodeModuleValue{}, 0, false, ErrNotLinkedHaves
|
||||
}
|
||||
key, err := nodeengineclient.HaveKey(q.Membership.Node, module)
|
||||
if err != nil {
|
||||
return nodeengine.HaveByNodeModuleValue{}, false, err
|
||||
return nodeengine.HaveByNodeModuleValue{}, 0, false, err
|
||||
}
|
||||
read, cancel := context.WithTimeout(ctx, q.timeout())
|
||||
defer cancel()
|
||||
bucket, err := hb.HaveBind(read)
|
||||
if err != nil {
|
||||
return nodeengine.HaveByNodeModuleValue{}, false, err
|
||||
return nodeengine.HaveByNodeModuleValue{}, 0, false, err
|
||||
}
|
||||
value, _, err := bucket.Get(read, key)
|
||||
value, revision, err := bucket.Get(read, key)
|
||||
if errors.Is(err, ErrHaveAbsent) {
|
||||
return nodeengine.HaveByNodeModuleValue{}, false, nil
|
||||
return nodeengine.HaveByNodeModuleValue{}, 0, false, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nodeengine.HaveByNodeModuleValue{}, false, err
|
||||
return nodeengine.HaveByNodeModuleValue{}, 0, false, err
|
||||
}
|
||||
h, err := nodeengineclient.DecodeHave(value)
|
||||
if err != nil {
|
||||
return nodeengine.HaveByNodeModuleValue{}, false, nil // a have no engine can read names nothing it runs
|
||||
return nodeengine.HaveByNodeModuleValue{}, revision, false, nil // a have no engine can read names nothing it runs
|
||||
}
|
||||
return h, true, nil
|
||||
return h, revision, true, nil
|
||||
}
|
||||
|
||||
// nothingJudged is the health of a module a look judged no resource of: ok when it was looked at and the module applied
|
||||
|
||||
@@ -1082,4 +1082,41 @@ func TestHave(t *testing.T) {
|
||||
t.Run("AHealthIsNotCarriedOverToAnotherComposition", testAHealthIsNotCarriedOverToAnotherComposition)
|
||||
t.Run("ADeclarationReportMovesAHealthAndARemovalForgetsIt", testADeclarationReportMovesAHealthAndARemovalForgetsIt)
|
||||
t.Run("AUserListReachesTheHaveOfAModuleNoApplyHereSays", testAUserListReachesTheHaveOfAModuleNoApplyHereSays)
|
||||
t.Run("AWriteOverARevisionLosesToAKeyThatMovedOrAFactNotYetWritten", testAWriteOverARevisionLosesToAKeyThatMovedOrAFactNotYetWritten)
|
||||
}
|
||||
|
||||
// H-A-480: the composer's mark is written over the revision of the have it read; a key that moved since, or a fact of the
|
||||
// module taken in and not yet written, wins, and nothing of the mark is taken in.
|
||||
func testAWriteOverARevisionLosesToAKeyThatMovedOrAFactNotYetWritten(t *testing.T) {
|
||||
l := newHaveLink()
|
||||
q, _ := aHaveQueue(l)
|
||||
ctx := context.Background()
|
||||
mark := ModuleFact{Module: "a", Phase: nodeengineclient.PhaseFailed, Failed: true, Detail: "the node cannot compose it"}
|
||||
if ok, err := q.NoteModuleAt(ctx, mark, 0); !ok || err != nil || l.have(t, "n1.a").Detail != mark.Detail {
|
||||
t.Fatalf("a mark over no key: %v %v, %+v", ok, err, l.have(t, "n1.a"))
|
||||
}
|
||||
wait := ModuleFact{Module: "a", Phase: nodeengineclient.PhaseHeld, Detail: "a waits for b of its pipeline"}
|
||||
q.NoteModule(ctx, wait)
|
||||
_, rev, _, err := q.ReadHaveAt(ctx, "a")
|
||||
if err != nil || rev != 2 {
|
||||
t.Fatalf("the revision read: %d %v", rev, err)
|
||||
}
|
||||
if ok, err := q.NoteModuleAt(ctx, mark, 1); ok || err != nil || l.have(t, "n1.a").Detail != wait.Detail {
|
||||
t.Fatalf("a mark over a revision the key moved from: %v %v, %+v", ok, err, l.have(t, "n1.a"))
|
||||
}
|
||||
// A fact taken in whose write failed is still to be written: a mark over the revision read loses to it.
|
||||
l.hmu.Lock()
|
||||
l.bindFails = true
|
||||
l.hmu.Unlock()
|
||||
q.NoteModule(ctx, ModuleFact{Module: "a", Phase: nodeengineclient.PhaseHeld, Detail: "a waits for c of its pipeline"})
|
||||
l.hmu.Lock()
|
||||
l.bindFails = false
|
||||
l.hmu.Unlock()
|
||||
if ok, err := q.NoteModuleAt(ctx, mark, 2); ok || err != nil {
|
||||
t.Fatalf("a mark over a fact not yet written: %v %v", ok, err)
|
||||
}
|
||||
q.NoteModule(ctx, ModuleFact{Module: "a", Phase: nodeengineclient.PhaseHeld, Detail: "a waits for c of its pipeline"})
|
||||
if got := l.have(t, "n1.a").Detail; got != "a waits for c of its pipeline" {
|
||||
t.Fatalf("the fact the mark lost to was not written: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user