H-A-771 unchanged-no-backup: back up a data module before its apply only when its move changed (issue 1984)

On ace at 03:40:55 the node-engine backed up lidarr (5.6 GB) for a move whose one difference was
env.MESH_FINGERPRINT, judged unchanged; the backup ran past its 10 minutes, lidarr was held, the operator
was asked, and the agent's loop stood still for 10 minutes. A move judged unchanged changes nothing of
the module, so it needs no backup.

- The apply backs a data module up only when the judge finds the move changed (any judgement but
  unchanged), or when the want carries the operator's answer again.
- The judgement compares the composition to what the machine applied (this engine's last apply, else
  the applied store's composition read at the start), never to a have, which in issue 1585's shape
  names a held composition not yet applied; with neither, the move is changed.
- A module held for a failed backup of a move judged unchanged has its hold ended at the engine's
  start, said in the journal, and is applied with no backup; the assigner takes its ask back as stale
  once the have runs.

Builds: design 47 H2 H-A-771, H-A-772 (1), (2)
This commit is contained in:
2026-11-26 04:10:26 +01:00
parent b4a9052669
commit 50dffe299f
2 changed files with 162 additions and 37 deletions
+41 -3
View File
@@ -274,6 +274,10 @@ type Agent struct {
// composition, read once at the start (loadHad): what runs of a module the agent has not taken yet, ahead of the kept
// declaration (issue 924).
had map[string]compNow
// appliedKept is, for each module, the composition the engine's applied store kept at the start (loadApplied), as the
// store has it, never replaced by a have: with applied, what the machine applied, which the judgement of a move before
// its backup compares to (design 47 H2 H-A-771, H-A-772 (1)).
appliedKept map[string]compNow
// keptData is, for each module of the kept declaration whose manifest could be read, whether it declares data
// (Env.HoldsData): the Data of what runs of it from the kept declaration.
keptData map[string]bool
@@ -362,7 +366,7 @@ func New(env Env) *Agent {
if env.Say == nil {
env.Say = func(string) {}
}
return &Agent{env: env, wants: map[string]wantNow{}, comps: map[string]compNow{}, running: map[string]nodeengine.HaveByNodeModuleValue{}, applied: map[string]compNow{}, had: map[string]compNow{}, keptData: map[string]bool{},
return &Agent{env: env, wants: map[string]wantNow{}, comps: map[string]compNow{}, running: map[string]nodeengine.HaveByNodeModuleValue{}, applied: map[string]compNow{}, had: map[string]compNow{}, appliedKept: map[string]compNow{}, keptData: map[string]bool{},
attempt: map[string]attempt{}, checked: map[string]bool{}, prior: map[string]bool{}, said: map[string]string{}, waited: map[string]string{}, notComposed: map[string]notComposedMark{},
pulls: map[string]*pullWait{}, settledAt: map[string]time.Time{}, settledSeq: map[string]int{},
retry: make(chan []string, 8), reconcile: make(chan []string, 64), failedAgain: make(chan string, 8), tries: map[string]int{}, again: make(chan againAsk, 64),
@@ -1338,6 +1342,7 @@ func (a *Agent) loadApplied(ctx context.Context) {
}
a.mu.Lock()
a.had[m] = compNow{Raw: kept[m], C: c, Dig: dig}
a.appliedKept[m] = a.had[m]
a.mu.Unlock()
switch {
case unread:
@@ -1828,6 +1833,17 @@ func (a *Agent) baseline(ctx context.Context, module string, w wantNow, comp com
h.Wait = nil
a.writeHave(ctx, h)
}
if h.Phase == string(nodeengineclient.PhaseHeld) && !judgedAgain(h) && recoveryCause(h) == recoveryNone &&
!a.moveChanged(module, comp) {
// Held for a failed backup of a move the judge finds unchanged (lidarr on ace, 2026-11-26 03:50): a backup
// H-A-771 no longer asks, so it is applied with no backup and its hold ends, said here; its ask is the
// assigner's to take back, as a stale ask is, once its have runs (design 47 H2 H-A-772 (2)).
a.mu.Lock()
a.sayOnce("unheld:"+module+":"+comp.Dig, fmt.Sprintf("%s's hold for a failed backup (%s) ends at this start: its "+
"move to %s is judged unchanged, so it is applied with no backup", module, h.Detail, short(comp.Dig)))
a.mu.Unlock()
return false
}
if h.Phase == string(nodeengineclient.PhaseHeld) && !judgedAgain(h) {
// Held for a failed backup, and the operator's answer is still to come: the hold is kept, nothing is
// backed up again or applied, and the next revision of the want is the answer (ADR 0568 §4). Said, so
@@ -1927,8 +1943,12 @@ func (a *Agent) apply(ctx context.Context, module string, w wantNow, comp compNo
}
// A data module is backed up before a new composition of it moves (ADR 0429 §14), unless the want says to go on
// without one (ADR 0539 §16).
if comp.C.Data && ranBefore && a.env.Backup != nil && w.Want.Backup != meshwants.WantsByWantNodeModuleValueBackupSkip {
// without one (ADR 0539 §16), and only when the judge finds the move from what the machine applied changed: a move
// judged unchanged (its one difference env.MESH_FINGERPRINT) changes nothing of the module, so it applies with no
// backup, no hold and no ask (design 47 H2 H-A-771). The operator's answer again backs it up whatever the judgement
// says (H-A-772 (1)).
if comp.C.Data && ranBefore && a.env.Backup != nil && w.Want.Backup != meshwants.WantsByWantNodeModuleValueBackupSkip &&
(w.Want.Backup == meshwants.WantsByWantNodeModuleValueBackupAgain || a.moveChanged(module, comp)) {
// What runs, read before the have says backing-up: a module known only from its have (a.prior) has no running
// entry, and its held have kept naming nothing (postgres on novox, 2026-10-31), as the not-composed mark keeps it.
a.mu.Lock()
@@ -2093,6 +2113,7 @@ func (a *Agent) remove(ctx context.Context, module string, w wantNow) {
delete(a.attempt, module)
delete(a.pulls, module)
delete(a.had, module)
delete(a.appliedKept, module)
a.running[module] = nodeengine.HaveByNodeModuleValue{Phase: nodeengineclient.PhaseRemoved}
a.mu.Unlock()
if a.env.Applied != nil {
@@ -2225,6 +2246,23 @@ func (a *Agent) waitsForYes(ctx context.Context, module string, w wantNow, comp
return true
}
// moveChanged says the judge finds moving module from what the machine applied to comp changed: any judgement but
// unchanged (design 47 H2 H-A-771). What the machine applied is the composition this engine last applied it from, else the
// one its applied store kept at the start, never a have, which may name a held composition not yet applied (H-A-772 (1),
// issue 1585's shape); a module with neither cannot be judged, and is changed. Called without a.mu held.
func (a *Agent) moveChanged(module string, comp compNow) bool {
a.mu.Lock()
from, known := a.applied[module]
if !known || from.Err != nil {
from, known = a.appliedKept[module]
}
a.mu.Unlock()
if !known {
return true
}
return judge.JudgeMove(&from.C, comp.C).Judgement != judge.JudgedUnchanged
}
// buildAlone says a move of module from what runs to the build want changes the build alone (ADR 0601 §1): another build than
// the one it runs, and the build it runs composed with today's settings and secrets is the composition it runs. Anything it
// cannot tell is no: the move is then asked of a person.
+121 -34
View File
@@ -1032,26 +1032,53 @@ func testADataModuleIsBackedUpFirstAndHeldWhenItFails(t *testing.T) {
}
// The live shape (nats on novox, 2026-11-04, issue 1585, the second failure): a module the node composes itself, of
// policy record, its want Self with the yes for its composition, and its held have naming that very composition (what
// runs is what the want names). The operator's answer acted on at the start, and in a revision of the want that
// arrives while the module is held; the engine's read tool says the want's answer and the hold.
// policy record, its want Self with the yes for its composition, and its held have naming that very composition, while
// the machine applied an older one (its applied store keeps it). The operator's answer acted on at the start, and in a
// revision of the want that arrives while the module is held; the engine's read tool says the want's answer and the
// hold. Design 47 H2 H-A-772: the judgement before the backup is of what the machine applied, never of the have, so
// those rows keep their backup and their hold; a hold for a failed backup of a move judged unchanged (lidarr on ace,
// 2026-11-26: its held have naming what it applied, the want's composition differing in env.MESH_FINGERPRINT alone)
// ends at the start with no backup, and again on such a move backs up once.
nbox := func(env map[string]string) json.RawMessage {
c := map[string]any{"id": "nats.server", "type": "container", "module": "nats", "name": "nats",
"image": "nats@sha256:" + strings.Repeat("5", 64)}
if env != nil {
c["env"] = env
}
raw, _ := json.Marshal(c)
return raw
}
for _, row := range []struct {
name string
atStart string // the answer the want carries when the engine starts
later string // the answer a later revision carries; "" writes none
backups int
holdsTill bool // it is held, and said held, before the later revision
unchanged bool // what the machine applied differs from the want's composition in env.MESH_FINGERPRINT alone
}{
{"answered before the start", meshwants.WantsByWantNodeModuleValueBackupAgain, "", 1, false},
{"answered while held", "", meshwants.WantsByWantNodeModuleValueBackupAgain, 1, true},
{"skipped while held", "", meshwants.WantsByWantNodeModuleValueBackupSkip, 0, true},
{"answered before the start", meshwants.WantsByWantNodeModuleValueBackupAgain, "", 1, false, false},
{"answered while held", "", meshwants.WantsByWantNodeModuleValueBackupAgain, 1, true, false},
{"skipped while held", "", meshwants.WantsByWantNodeModuleValueBackupSkip, 0, true, false},
{"held, its move unchanged", "", "", 0, false, true},
{"again on an unchanged move", meshwants.WantsByWantNodeModuleValueBackupAgain, "", 1, false, true},
} {
t.Run(row.name, func(t *testing.T) {
r := newBed(t)
r.env.SelfComposed, r.kept = true, nil
r.env.Policy = func(context.Context, string) string { return catalogue.PolicyRecord }
ck, craw, dig := composition(t, "nats", fp2, true, file("nats", "x", "2"))
ran, wanted := file("nats", "x", "1"), file("nats", "x", "2")
if row.unchanged {
ran, wanted = nbox(map[string]string{"MESH_FINGERPRINT": fp1}), nbox(nil)
}
ck, craw, dig := composition(t, "nats", fp2, true, wanted)
r.comps.before(ck, craw)
ack, araw, adig := composition(t, "nats", fp1, true, ran)
r.comps.before(ack, araw)
r.env.Applied = &memApplied{kept: map[string][]byte{"nats": araw}}
heldFP, heldDig := fp2, dig // issue 1585: the held have names the want's composition, not applied
if row.unchanged {
heldFP, heldDig = fp1, adig // as the engine writes a hold since A-453: what the machine applied
}
wk := meshwants.WantsByWantNodeModuleKey(node, "nats")
selfWant := func(backup string) []byte {
raw, err := bucketstest.Want(meshwants.WantsByWantNodeModuleValue{Fp: fp2, Self: true, Yes: dig, Backup: backup})
@@ -1061,7 +1088,7 @@ func testADataModuleIsBackedUpFirstAndHeldWhenItFails(t *testing.T) {
return raw
}
r.wants.before(wk, selfWant(row.atStart))
r.haves.stored = map[string]Have{"nats": {Module: "nats", FP: fp2, Composed: dig, Phase: string(nodeengineclient.PhaseHeld),
r.haves.stored = map[string]Have{"nats": {Module: "nats", FP: heldFP, Composed: heldDig, Phase: string(nodeengineclient.PhaseHeld),
Detail: "the backup failed: sh: exit status 1"}}
stopR := r.run()
defer stopR()
@@ -1107,6 +1134,13 @@ func testADataModuleIsBackedUpFirstAndHeldWhenItFails(t *testing.T) {
if n != row.backups {
t.Errorf("%d backups for the answer, want %d", n, row.backups)
}
if row.unchanged && row.atStart == "" {
r.mu.Lock()
defer r.mu.Unlock()
if !slices.ContainsFunc(r.said, func(s string) bool { return strings.Contains(s, "nats's hold for a failed backup") }) {
t.Errorf("the hold's end is not said: %q", r.said)
}
}
})
}
}
@@ -1129,35 +1163,88 @@ func cutAsAHaveIs(s string) string {
return s[:100] + " … " + s[len(s)-(300-100-len(" … ")):]
}
// A data module with a good backup is applied after it; one that never ran has nothing to back up.
// A data module with a good backup is applied after it; one that never ran has nothing to back up. Design 47 H2 H-A-771: a
// data module that ran before is backed up first only when the judge finds its move changed (any judgement but
// unchanged); a move whose one difference is env.MESH_FINGERPRINT is judged unchanged and applied with no backup ask.
func testABackupDoneIsFollowedByTheApplyAndANewModuleIsNotBackedUp(t *testing.T) {
t.Run("a move across a kept data's form change is taken as a restore point and restored at a revert", testAMoveAcrossAFormChange)
b := newBed(t)
stop := b.run()
defer stop()
fp := fpOf("c")
ck, craw, dig := composition(t, "db", fp, true, file("db", "x", "1"))
wk, wraw := wantFor(t, "db", fp, dig, "")
b.comps.put(ck, craw)
b.wants.put(wk, wraw)
eventually(t, "not applied", func() bool { return len(b.appliedList()) == 1 })
b.mu.Lock()
n := len(b.backups)
b.mu.Unlock()
if n != 0 {
t.Fatalf("a module that never ran was backed up (%d)", n)
fp, fp2 := fpOf("c"), fpOf("d")
box := func(image string, env map[string]string) json.RawMessage {
c := map[string]any{"id": "db.server", "type": "container", "module": "db", "name": "db",
"image": "db@sha256:" + strings.Repeat(image, 64), "volumes": []string{"/var/lib/db/data:/data"}}
if env != nil {
c["env"] = env
}
raw, _ := json.Marshal(c)
return raw
}
fp2 := fpOf("d")
ck2, craw2, dig2 := composition(t, "db", fp2, true, file("db", "x", "2"))
wk2, wraw2 := wantFor(t, "db", fp2, dig2, "")
b.comps.put(ck2, craw2)
b.wants.put(wk2, wraw2)
eventually(t, "second not applied", func() bool { return len(b.appliedList()) == 2 })
b.mu.Lock()
n = len(b.backups)
b.mu.Unlock()
if n != 1 {
t.Fatalf("a module that ran before was backed up %d times, want once", n)
dir := func(path string) json.RawMessage {
raw, _ := json.Marshal(map[string]any{"id": "db.data", "type": "directory", "module": "db", "path": path})
return raw
}
data := dir("/var/lib/db/data")
for _, row := range []struct {
name string
from, to []json.RawMessage
judged judge.Judgement
backedUp bool
}{
{"a file of it changes", []json.RawMessage{file("db", "x", "1")}, []json.RawMessage{file("db", "x", "2")},
judge.JudgedNeither, true},
{"its container recreates", []json.RawMessage{box("1", nil), data}, []json.RawMessage{box("2", nil), data},
judge.JudgedRecreates, true},
{"its data moves", []json.RawMessage{box("1", nil), data}, []json.RawMessage{box("1", nil), dir("/srv/db/data")},
judge.JudgedMovesData, true},
// H-A-771's live case (lidarr on ace, 2026-11-26 03:40): its container composed by an earlier node-engine with
// MESH_FINGERPRINT, the new composition with none (H-A-710 (1)).
{"only env.MESH_FINGERPRINT is taken out", []json.RawMessage{box("1", map[string]string{"MESH_FINGERPRINT": fp}), data},
[]json.RawMessage{box("1", nil), data}, judge.JudgedUnchanged, false},
{"only the value of env.MESH_FINGERPRINT differs", []json.RawMessage{box("1", map[string]string{"MESH_FINGERPRINT": fp}), data},
[]json.RawMessage{box("1", map[string]string{"MESH_FINGERPRINT": fp2}), data}, judge.JudgedUnchanged, false},
} {
t.Run(row.name, func(t *testing.T) {
if j := judge.JudgeMove(&compositions.Composed{Node: node, Module: "db", FP: fp, Data: true, Resources: row.from},
compositions.Composed{Node: node, Module: "db", FP: fp2, Data: true, Resources: row.to}); j.Judgement != row.judged {
t.Fatalf("the move is judged %s (%s), want %s", j.Judgement, j.Words, row.judged)
}
b := newBed(t)
stop := b.run()
defer stop()
ck, craw, dig := composition(t, "db", fp, true, row.from...)
wk, wraw := wantFor(t, "db", fp, dig, "")
b.comps.put(ck, craw)
b.wants.put(wk, wraw)
eventually(t, "not applied", func() bool { return len(b.appliedList()) == 1 })
b.mu.Lock()
n := len(b.backups)
b.mu.Unlock()
if n != 0 {
t.Fatalf("a module that never ran was backed up (%d)", n)
}
ck2, craw2, dig2 := composition(t, "db", fp2, true, row.to...)
wk2, wraw2 := wantFor(t, "db", fp2, dig2, "")
b.comps.put(ck2, craw2)
b.wants.put(wk2, wraw2)
eventually(t, "second not applied", func() bool {
h := b.haves.last("db")
return len(b.appliedList()) == 2 && h.Phase == string(nodeengineclient.PhaseRunning) && h.FP == fp2 && h.Composed == dig2
})
b.mu.Lock()
n = len(b.backups)
b.mu.Unlock()
if want := map[bool]int{true: 1, false: 0}[row.backedUp]; n != want {
t.Fatalf("a module that ran before, its move judged %s, was backed up %d times, want %d", row.judged, n, want)
}
if !row.backedUp {
b.haves.mu.Lock()
defer b.haves.mu.Unlock()
for _, h := range b.haves.log {
if h.Module == "db" && (h.Phase == string(nodeengineclient.PhaseBackingUp) || h.Phase == string(nodeengineclient.PhaseHeld)) {
t.Errorf("an unchanged move's have says %s: %+v", h.Phase, h)
}
}
}
})
}
}