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:
+121
-34
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user