carlos / platform Public

grouproll: generations floor at admission and on resume

Astra R1 fixes for the enforced generations floor. While
generations_floor is set:

- a returning member (before ExitStandby) and a replacement (before it is
  admitted) must publish replica-generations-1 on the fresh edges file
  readiness read; otherwise the generations-floor stop refuses with
  floor_generations and journals floor-error, and the transaction stays
  open (rollback still returns a capable old binary);
- resume re-reads every edges file when the transaction already has a
  floor row, before any further step; a missing capability or an
  unreadable listing or file refuses with floor_generations;
- prepare checks generations_floor before min_release, so a release below
  both gets the generations refusal and its floor-error row.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 2d1aad3e9531bfb34abf40ae156d37ac87113307 parent c5ddae7
4 files changed, +280 −8
  • internal/grouproll/depart.go +7 −1
  • internal/grouproll/floor.go +70 −0
  • internal/grouproll/floor_test.go +189 −0
  • internal/grouproll/roll.go +14 −7
diff --git a/internal/grouproll/depart.go b/internal/grouproll/depart.go
index 9536191cf..e0cec7669 100644
--- a/internal/grouproll/depart.go
+++ b/internal/grouproll/depart.go
@@ -1077,6 +1077,8 @@ func (e *Engine) departWatch(ctx context.Context) error {
switch {
case err == nil:
replacement = fresh[0]
+ case isStop(err, "generations-floor"):
+ return err
case refusalOrUncertain(err):
ready = false
default:
@@ -1157,7 +1159,8 @@ func (e *Engine) restoreAnswered(op string, n int) bool {
}
// admitReplacement: the replacement is online, ready, and at the floor
-// too (§25.9: it publishes ha_take 1).
+// too (§25.9: it publishes ha_take 1), and, while generations_floor is
+// set, publishes replica-generations-1 (generationsAdmitted).
func (e *Engine) admitReplacement(ctx context.Context, iid string, start int64) error {
on, err := e.online(ctx, iid)
if err != nil {
@@ -1173,6 +1176,9 @@ func (e *Engine) admitReplacement(ctx context.Context, iid string, start int64)
if take, ok := r.Edges["ha_take"].(int64); !ok || take != 1 {
return refuse("admission")
}
+ if err := e.generationsAdmitted(r); err != nil {
+ return err
+ }
_, err = e.event("replacement-admitted", map[string]any{"iid": iid, "seconds": seconds(ms(e.clock()) - start)})
return err
}
diff --git a/internal/grouproll/floor.go b/internal/grouproll/floor.go
index 4fc822663..4b7da59a2 100644
--- a/internal/grouproll/floor.go
+++ b/internal/grouproll/floor.go
@@ -277,6 +277,76 @@ func (e *Engine) generationsRefusal(errs, reasons []any) error {
return refuse("floor_generations")
}
+// generationsStop is generationsRefusal as the generations-floor stop,
+// which the return and watch loops return at once instead of waiting it
+// out as a dropped readiness. A journal failure is returned as itself.
+func (e *Engine) generationsStop(errs []any) error {
+ err := e.generationsRefusal(errs, []any{})
+ var r Refusal
+ if errors.As(err, &r) {
+ return stop{kind: "generations-floor", r: r}
+ }
+ return err
+}
+
+// generationsAdmitted is the admission half of the generations floor
+// (ruling A): while generations_floor is set, a member is accepted into
+// service (a rolled or returning member before ExitStandby, a replacement
+// before it is admitted) only when its fresh admission evidence, the
+// edges file readiness read, publishes replica-generations-1. Otherwise
+// it is the generations-floor stop naming the box: the member stays out
+// of the transaction's return and the transaction stays open.
+func (e *Engine) generationsAdmitted(r readiness) error {
+ if e.c.GenerationsFloor == nil || e.probe || hasCapability(r.Edges, capReplicaGenerations1) {
+ return nil
+ }
+ box, _ := r.Status["box_ref"].(string)
+ return e.generationsStop([]any{Text("floor_generations_box", "box", box)})
+}
+
+// generationsOnResume re-reads the generations floor's population on
+// resume (ruling A): a floor row proves the population as it was, not as
+// it is. While generations_floor is set and the transaction has a floor
+// row and is not done, every present edges file must still publish
+// replica-generations-1, before any further step, whatever phase the
+// member is in. A missing capability or a listing or file that cannot be
+// read refuses with floor_generations and journals floor-error. Without
+// a floor row the floor itself runs next and reads everything.
+func (e *Engine) generationsOnResume(ctx context.Context) error {
+ if e.c.GenerationsFloor == nil || e.probe || !e.has("floor", nil) || e.has("done", nil) {
+ return nil
+ }
+ errs, gens := []any{}, []any{}
+ keys, err := e.edgesList(ctx)
+ if err != nil {
+ if !refusalOrUncertain(err) {
+ return err
+ }
+ errs = append(errs, reasonOf(err))
+ }
+ for _, key := range keys {
+ m := EdgesKey.FindStringSubmatch(key)
+ if m == nil {
+ continue
+ }
+ v, err := e.edgesKey(ctx, key)
+ if err != nil {
+ if !refusalOrUncertain(err) {
+ return err
+ }
+ errs = append(errs, Text("floor_unreadable", "key", key))
+ continue
+ }
+ if edges, _ := v.(map[string]any); !hasCapability(edges, capReplicaGenerations1) {
+ gens = append(gens, Text("floor_generations_box", "box", m[1]))
+ }
+ }
+ if len(errs) == 0 && len(gens) == 0 {
+ return nil
+ }
+ return e.generationsRefusal(append(errs, gens...), []any{})
+}
+
// rollRelease is the roll --to-sha256 mapping (§9): the release the
// signed router pointers name for sha, which must be the release the
// member's prepare reported. A different one is the release_mismatch
diff --git a/internal/grouproll/floor_test.go b/internal/grouproll/floor_test.go
index c4916d502..a2655926b 100644
--- a/internal/grouproll/floor_test.go
+++ b/internal/grouproll/floor_test.go
@@ -938,3 +938,192 @@ func TestFloorGenerationsFloorUnset(t *testing.T) {
t.Fatal("a DR-4 floor row names generations_floor")
}
}
+
+// Fix round 1 (Astra R1): the generations floor at admission, on resume,
+// and before min_release.
+
+// newGenerationsHeldHarness is newHeldHarness with generations_floor at
+// the held release, every box publishing replica-generations-1 unless
+// lacks says otherwise for its box ref.
+func newGenerationsHeldHarness(t *testing.T, lacks func(box string) bool) *harness {
+ t.Helper()
+ h := newHeldHarness(t, 2, func(c *Config) {
+ floor := "v0.35.0"
+ c.GenerationsFloor = &floor
+ })
+ h.capabilities(func(box string) []any {
+ if lacks != nil && lacks(box) {
+ return []any{"lifetimes-1"}
+ }
+ return []any{"lifetimes-1", generationsCap}
+ })
+ return h
+}
+
+// mustGenerationsRow: transaction tx's journal has a floor-error row
+// naming generations_floor with reason among its errors.
+func (h *harness) mustGenerationsRow(t *testing.T, tx, reason string) {
+ t.Helper()
+ row, _ := h.txJournal(tx).Last("floor-error", nil)
+ if row == nil || !containsValue(row["errors"], reason) || row["generations_floor"] == nil {
+ t.Fatalf("floor-error row = %v, want %q", row, reason)
+ }
+ if !strings.Contains(h.out.String(), Text("line", "phase", "floor", "detail", reason)) {
+ t.Fatalf("output %q lacks %q", h.out.String(), reason)
+ }
+}
+
+// A rolled member whose new binary's fresh edges file lacks the
+// capability is refused before ExitStandby; rollback still returns it.
+func TestRollRefusesRolledMemberWithoutGenerationsCapability(t *testing.T) {
+ var h *harness
+ h = newGenerationsHeldHarness(t, func(box string) bool {
+ return box == ref(fakeIID) && h.f.boxes[fakeIID]["binary_sha256"] == newSHA
+ })
+ if err := h.heldRoll(); refusalKey(err) != "floor_generations" {
+ t.Fatalf("roll = %v\n%s", err, h.out.String())
+ }
+ if countOf(h.f.writes, "apply") != 1 || countOf(h.f.writes, "exit") != 0 {
+ t.Fatalf("writes %v", h.f.writes)
+ }
+ if h.f.states[fakeIID] != "Standby" || h.activeTx() != "t6-roll" {
+ t.Fatalf("state %s active %q", h.f.states[fakeIID], h.activeTx())
+ }
+ h.mustGenerationsRow(t, "t6-roll", Text("floor_generations_box", "box", ref(fakeIID)))
+ if _, ok := h.txJournal("t6-roll").Last("exit-intent", nil); ok {
+ t.Fatal("an exit intent was journaled")
+ }
+ // resume refuses again; rollback restores the capable old binary.
+ if err := h.resume(); refusalKey(err) != "floor_generations" || countOf(h.f.writes, "exit") != 0 {
+ t.Fatalf("resume = %v, writes %v", err, h.f.writes)
+ }
+ if err := h.rollbackMember(); err != nil {
+ t.Fatalf("rollback: %v\n%s", err, h.out.String())
+ }
+ if h.f.states[fakeIID] != "InService" || h.f.boxes[fakeIID]["binary_sha256"] != oldSHA || h.activeTx() != "" {
+ t.Fatalf("state %s binary %v active %q", h.f.states[fakeIID], h.f.boxes[fakeIID]["binary_sha256"], h.activeTx())
+ }
+}
+
+// A replacement whose fresh edges file lacks the capability is never
+// admitted; the transaction stays open.
+func TestDepartRefusesReplacementWithoutGenerationsCapability(t *testing.T) {
+ h := newGenerationsHeldHarness(t, func(box string) bool { return box == ref(replacementIID) })
+ if err := h.depart("replace", heldTx); refusalKey(err) != "floor_generations" {
+ t.Fatalf("depart = %v\n%s", err, h.out.String())
+ }
+ if _, ok := h.txJournal(heldTx).Last("replacement-admitted", nil); ok {
+ t.Fatal("the replacement was admitted")
+ }
+ if h.activeTx() != heldTx {
+ t.Fatalf("active %q", h.activeTx())
+ }
+ h.mustGenerationsRow(t, heldTx, Text("floor_generations_box", "box", ref(replacementIID)))
+ if err := h.resume(); refusalKey(err) != "floor_generations" {
+ t.Fatalf("resume = %v", err)
+ }
+}
+
+// Unset, a replacement and a rolled member without the capability are
+// admitted as today.
+func TestGenerationsFloorUnsetAdmitsWithoutCapability(t *testing.T) {
+ h := newHeldHarness(t, 2, nil)
+ if err := h.heldRoll(); err != nil {
+ t.Fatalf("roll: %v", err)
+ }
+ h = newHeldHarness(t, 2, nil)
+ if err := h.depart("replace", heldTx); err != nil {
+ t.Fatalf("replace: %v", err)
+ }
+}
+
+// Resume re-reads the population after a floor row: a fixed forwarder
+// that stopped publishing the capability, or an edges file that cannot be
+// read, refuses before any further write, from Standby too.
+func TestResumeRechecksGenerationsFloor(t *testing.T) {
+ type cut struct {
+ name string
+ run func(h *harness) error
+ at int // the write the process dies after
+ }
+ cuts := []cut{
+ {"roll after enter", func(h *harness) error { return h.heldRoll() }, 3},
+ {"roll after minimum", func(h *harness) error { return h.heldRoll() }, 2},
+ {"replace after enter", func(h *harness) error { return h.depart("replace", heldTx) }, 2},
+ }
+ for _, c := range cuts {
+ for _, change := range []string{"capability", "unreadable", "listing"} {
+ t.Run(c.name+"/"+change, func(t *testing.T) {
+ lost := false
+ h := newGenerationsHeldHarness(t, func(box string) bool { return lost && box == "adi" })
+ h.f.fault, h.f.faultAt = "death", c.at
+ if !expectDeath(t, func() { c.run(h) }) {
+ t.Fatal("no death")
+ }
+ tx := h.activeTx()
+ if _, ok := h.txJournal(tx).Last("floor", nil); !ok {
+ t.Fatal("no floor row before the cut")
+ }
+ writes := append([]string(nil), h.f.writes...)
+ state := h.f.states[fakeIID]
+ reason := Text("floor_generations_box", "box", "adi")
+ switch change {
+ case "capability":
+ lost = true
+ case "unreadable", "listing":
+ caps := h.f.wrap
+ h.f.wrap = func(op string, args map[string]any, r any, err error) (any, error) {
+ if change == "unreadable" && op == "edges" && args["box_ref"] == "adi" {
+ return nil, Uncertain{Key: "api"}
+ }
+ return caps(op, args, r, err)
+ }
+ h.f.before = func(op string, args map[string]any) error {
+ if change == "listing" && op == "edges_list" {
+ return Uncertain{Key: "api"}
+ }
+ return nil
+ }
+ reason = Text("floor_unreadable", "key", "control/edges/adi.json")
+ if change == "listing" {
+ reason = Text("api")
+ }
+ }
+ if err := h.resume(); refusalKey(err) != "floor_generations" {
+ t.Fatalf("resume = %v\n%s", err, h.out.String())
+ }
+ if !reflect.DeepEqual(h.f.writes, writes) || h.f.states[fakeIID] != state || h.activeTx() != tx {
+ t.Fatalf("writes %v (were %v) state %s (was %s)", h.f.writes, writes, h.f.states[fakeIID], state)
+ }
+ h.mustGenerationsRow(t, tx, reason)
+ })
+ }
+ }
+ // With the population capable again, resume finishes the roll.
+ lost := false
+ h := newGenerationsHeldHarness(t, func(box string) bool { return lost && box == "adi" })
+ h.f.fault, h.f.faultAt = "death", 3
+ if !expectDeath(t, func() { h.heldRoll() }) {
+ t.Fatal("no death")
+ }
+ if err := h.resume(); err != nil || h.activeTx() != "" || h.f.states[fakeIID] != "InService" {
+ t.Fatalf("resume = %v active %q state %s", err, h.activeTx(), h.f.states[fakeIID])
+ }
+}
+
+// A candidate below both generations_floor and min_release is the
+// generations refusal, with its floor-error row.
+func TestRollBelowGenerationsFloorAndMinRelease(t *testing.T) {
+ h := newHarnessWith(t, stateRoot(t), 2, func(c *Config) {
+ floor := "v0.39.0"
+ c.GenerationsFloor = &floor
+ })
+ h.f.version = "v0.33.0" // below min_release v0.34.0 too
+ if err := h.runRoll(); refusalKey(err) != "floor_generations" {
+ t.Fatalf("roll = %v", err)
+ }
+ if !reflect.DeepEqual(h.f.writes, []string{"prepare"}) {
+ t.Fatalf("writes %v", h.f.writes)
+ }
+ h.mustGenerationsRow(t, h.onlyTx(), Text("floor_generations_version", "release", "v0.33.0"))
+}
diff --git a/internal/grouproll/roll.go b/internal/grouproll/roll.go
index 557275443..27fe7c95e 100644
--- a/internal/grouproll/roll.go
+++ b/internal/grouproll/roll.go
@@ -30,7 +30,7 @@ var departKinds = map[string]bool{"replace": true, "remove": true}
// stop is one of the script's Refusal subclasses: a refusal that also
// says how the transaction stopped. The operator sees the refusal's text.
type stop struct {
- kind string // failed-probe, divergence-held, drain-failed, drain-moving, lock-refused
+ kind string // failed-probe, divergence-held, drain-failed, drain-moving, lock-refused, generations-floor
r Refusal
}
@@ -168,6 +168,9 @@ func (e *Engine) Resume(ctx context.Context, tx string) error {
return err
}
defer e.close()
+ if err := e.generationsOnResume(ctx); err != nil {
+ return err
+ }
return e.resume(ctx)
}
@@ -940,15 +943,16 @@ func (e *Engine) prepare(ctx context.Context) error {
if !releaseVersion.MatchString(version) {
return refuse("release_version")
}
- if belowFloor(version, e.c.MinRelease) {
- return refuse("release_floor")
- }
- // The enforced generations floor refuses here, before any group
+ // The enforced generations floor refuses here, before min_release (a
+ // release below both is a generations refusal) and before any group
// write; the floor step checks the release the signed pointers map
// the artifact to again.
if g := e.c.GenerationsFloor; g != nil && belowFloor(version, *g) {
return e.generationsRefusal([]any{Text("floor_generations_version", "release", version)}, []any{})
}
+ if belowFloor(version, e.c.MinRelease) {
+ return refuse("release_floor")
+ }
_, err = e.event("prepared", map[string]any{"result": p})
return err
}
@@ -1260,7 +1264,7 @@ func (e *Engine) returnMember(ctx context.Context) error {
case "observe-ready":
r, err := e.returnReadiness(ctx, iid, group)
if err != nil {
- if isStop(err, "drain-moving") || !refusalOrUncertain(err) {
+ if isStop(err, "drain-moving") || isStop(err, "generations-floor") || !refusalOrUncertain(err) {
return err
}
o.readiness = "dropped"
@@ -1357,7 +1361,7 @@ func (e *Engine) returnMember(ctx context.Context) error {
case err == nil:
case errors.As(err, &done):
return done.err
- case isStop(err, "drain-moving"):
+ case isStop(err, "drain-moving"), isStop(err, "generations-floor"):
return err
case refusalOrUncertain(err):
opErr = err
@@ -1386,6 +1390,9 @@ func (e *Engine) returnReadiness(ctx context.Context, iid string, group *snapsho
if err != nil {
return nil, err
}
+ if err := e.generationsAdmitted(r); err != nil {
+ return nil, err
+ }
if intent, ok := e.last("exit-intent", nil); ok && (group == nil || group.View.Members[iid].Phase != Parked) {
edge, _ := r.Status["edge"].(map[string]any)
if !pyEqual(edge["identity"], intent["process"]) {