carlos / platform Public

ha: only group members with the switch on take generations locks

Option A (8a3d302 for Paul, 2026-11-19), after branch review round 2:
a box takes a storage-generations lock only when it is a member of the
region's group (CARLOS_BOX_REFERENCE=group) and its switch is on or
fast. hafresh.Proofs.GenerationsEligible gates it: DecideAcquire refuses
every generations lock (held, expired or a release marker) first, with
ReasonGenerationsIneligible, and lease.acquireHARestricted ignores
GenerationsOn without it, so an ineligible box never takes or writes
one. The activator computes eligibility once per wake and per adoption
from its environment (generationsEligible); the group's
generations_floor is not known on the box. Eligible boxes behave as
before, sticky mode included. The activation guard stays.

Tests: hafresh and lease ineligible tables, and activator tests for a
fixed box (switch on or fast) and a switch-off member refusing, a
switched-on member taking, a fixed box still taking ordinary locks, and
fixed-box adoption refusing. Existing tests now run as eligible boxes.

Also fixes TestKeptWakeReadsEitherMarkerFormat (CI): after the switch,
retirement's LIST of the host folder and the replicator's level listing
under g-N race the test. The request filter now drops generation level
listings, and the test checks the wake up to the switch and allows only
retirement's one listing after it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 748d53e19cbb749b20121c8e9ed9be44ee87c32d parent 8afd38d
23 files changed, +459 −126
  • internal/activator/haadopt.go +5 −2
  • internal/activator/hagenerations_test.go +193 −28
  • internal/activator/hapoint_test.go +1 −1
  • internal/activator/harelease_test.go +7 −0
  • internal/activator/hatakeover_test.go +7 −7
  • internal/activator/hawake.go +27 −9
  • internal/hafresh/acquire.go +19 −0
  • internal/hafresh/acquire_test.go +70 −26
  • internal/hafresh/generations_test.go +3 −3
  • internal/hafresh/pools_test.go +1 −1
  • internal/lease/generations_lock_test.go +70 −4
  • internal/lease/gentake_minio_test.go +1 −1
  • internal/lease/gentakeover_test.go +4 −4
  • internal/lease/ha.go +8 −1
  • internal/lease/ha_observe_test.go +4 −3
  • internal/lease/ha_test.go +15 −15
  • internal/lease/haduty_test.go +4 −4
  • internal/lease/pools_test.go +4 −4
  • internal/lease/release_test.go +2 −2
  • internal/lease/termination_proof_test.go +4 −4
  • internal/lease/unclean_marker_test.go +5 −5
  • internal/sim/regionha/actions_test.go +3 −1
  • internal/sim/regionha/duties_model_test.go +2 −1
diff --git a/internal/activator/haadopt.go b/internal/activator/haadopt.go
index 50ff596b0..1f7439c45 100644
--- a/internal/activator/haadopt.go
+++ b/internal/activator/haadopt.go
@@ -313,8 +313,11 @@ func (a *Service) AdoptHost(ctx context.Context, rt registry.Route, req Adoption
return Deferred, err
}
ctx = context.WithValue(ctx, adoptionCauseKey{}, req.Ref)
- // No GenerationsFast: adoption keeps today's table under `fast` (safe, only slower).
- proofs := hafresh.Proofs{LocalEligible: func() bool { return b.poolEligible(rt) }, SameBoxEmpty: b.sameBoxEmpty(ctx, rt), OwnerTerminated: b.ownerTerminated(ctx, rt)}
+ // No GenerationsFast: adoption keeps today's table under `fast` (safe,
+ // only slower). A box that takes no generations lock (Option A:
+ // generationsEligible) refuses to adopt one.
+ eligible, _ := generationsEligible(haGetenv)
+ proofs := hafresh.Proofs{LocalEligible: func() bool { return b.poolEligible(rt) }, SameBoxEmpty: b.sameBoxEmpty(ctx, rt), OwnerTerminated: b.ownerTerminated(ctx, rt), GenerationsEligible: eligible}
if b.TerminationProofs != nil {
adapter := *b.TerminationProofs
adapter.Observe = func(iid string, gone bool, err error) { b.reportTakeover(ctx, rt, iid, gone, err) }
diff --git a/internal/activator/hagenerations_test.go b/internal/activator/hagenerations_test.go
index e67d00926..aa4a88dba 100644
--- a/internal/activator/hagenerations_test.go
+++ b/internal/activator/hagenerations_test.go
@@ -1,12 +1,14 @@
package activator
import (
+ "bytes"
"context"
"crypto/sha256"
"database/sql"
"encoding/hex"
"encoding/json"
"errors"
+ "fmt"
"os"
"path/filepath"
"slices"
@@ -137,15 +139,17 @@ func TestHADutyPeerGenerationsRelease(t *testing.T) {
}
}
-// Adoption of a generations host: the adopter's take keeps generations
-// mode (carlos_generation, the next generation's name) with the switch off,
-// its release writes the generations marker, and the adoption recognises
+// Adoption of a generations host on an eligible box (Option A: a group
+// member with the switch on): the adopter's take keeps generations mode
+// (carlos_generation, the next generation's name), its release writes the
+// generations marker, and the adoption recognises
// that marker as its own (selfMarker). Over an unclean or clean marker, and
// over an expired generations lock whose owner is terminated (a crash
// right after its take, before any head read).
func TestHAAdoptGenerationsLock(t *testing.T) {
for _, kind := range []string{"unclean", "clean", "expired"} {
t.Run(kind, func(t *testing.T) {
+ generationsBox(t, "on")
s, req := haAdoptionFixture(t)
ctx := context.Background()
switch kind {
@@ -267,13 +271,17 @@ func TestSuspectHolderObservesEitherFormat(t *testing.T) {
// Lease-loss recovery (haleaseloss.go) over this box's own release marker,
// the same record in either format: not foreign, so recovery takes it, and
-// the fresh take over the generations marker keeps generations mode.
+// the fresh take over the generations marker (on an eligible box, Option
+// A) keeps generations mode.
func TestHALostLeaseRecoversOverEitherMarkerFormat(t *testing.T) {
for _, gen := range []bool{false, true} {
t.Run(formatName(gen), func(t *testing.T) {
s, e, r := lostTestEntry(t)
finishLostTestEntry(t, s, e, r)
s.rewriteMarkerFormat(t, gen)
+ if gen {
+ generationsBox(t, "on") // Option A: an eligible box recovers it
+ }
taken := s.lockView(t).Lock.Generation + 1
n := recoverLostTestHost(t, s)
if n == e {
@@ -314,6 +322,11 @@ func TestKeptWakeReadsEitherMarkerFormat(t *testing.T) {
if !m.Clean || m.FilesGen == "" {
t.Fatalf("want a clean marker with a files generation: %+v", m)
}
+ if gen {
+ // Option A: only an eligible box (a group member with the
+ // switch on) takes a generations lock.
+ generationsBox(t, "on")
+ }
before := len(s.fx.Requests())
e, err := s.wakeForTest(context.Background())
if err != nil {
@@ -339,7 +352,24 @@ func TestKeptWakeReadsEitherMarkerFormat(t *testing.T) {
held := s.lockView(t).Lock
g := s.loc() + "/" + held.GenName + "/"
manifest := hostfiles.ManifestKey(s.b.filesPrefix(s.rt.Host))
- rest := reqs[3:]
+ // The wake ends at the switch (PUT head.json). After it,
+ // and racing the test, retirement lists the host's folders
+ // once (startRetirement, after the replicator starts); the
+ // replicator's own level listings are dropped by
+ // wakePathRequests. Nothing else may follow.
+ end := slices.Index(reqs, "PUT "+s.headKey())
+ if end < 0 {
+ t.Fatalf("the kept take made no switch: %v", reqs)
+ }
+ for _, r := range reqs[end+1:] {
+ if r != "LIST "+s.loc()+"/" {
+ t.Fatalf("after the switch the wake made %v", reqs[end+1:])
+ }
+ }
+ if countReqs(reqs[end+1:], "LIST "+s.loc()+"/") > 1 {
+ t.Fatalf("retirement listed more than once: %v", reqs[end+1:])
+ }
+ rest := reqs[3 : end+1]
if len(rest) < 4 || rest[0] != "LISTV "+s.loc()+"/" || rest[len(rest)-2] != "PUT "+manifest || rest[len(rest)-1] != "PUT "+s.headKey() {
t.Fatalf("the kept take made %v", reqs)
}
@@ -465,7 +495,7 @@ func countReqs(reqs []string, prefix string) int {
// the predecessor into g-N, restores its rows from there, switches head
// to g-N and replicates only under it; the manifest carries N.
func TestHAWakeTakesAGeneration(t *testing.T) {
- t.Setenv("CARLOS_HA_GENERATIONS", "on")
+ generationsBox(t, "on")
s, e := haServiceEntry(t, "shop.example.com")
if h, _ := s.head(t); h.Generation != replicagen.Name(1) || h.StartTXID != 0 || h.Predecessor != "" {
t.Fatalf("first wake's head %+v", h)
@@ -529,14 +559,14 @@ func TestHAWakeTakesAGeneration(t *testing.T) {
// first take starts g-N from the root, restores the root's rows, and
// head.json records the root as predecessor and history.
func TestHAWakeSwitchOnMigratesFromTheRoot(t *testing.T) {
- t.Setenv("CARLOS_HA_GENERATIONS", "")
+ generationsBox(t, "")
s, e := haServiceEntry(t, "shop.example.com")
s.insertRows(t, 0, 4)
s.stopForTest(e)
if _, ok := s.fx.Object(s.headKey()); ok {
t.Fatal("head.json with the switch off")
}
- t.Setenv("CARLOS_HA_GENERATIONS", "fast")
+ generationsBox(t, "fast")
s.loseLocalDB(t)
e, err := s.wakeForTest(context.Background())
if err != nil {
@@ -560,7 +590,7 @@ func TestHAWakeSwitchOnMigratesFromTheRoot(t *testing.T) {
// the wake is today's, plus one GET of head.json (none on a first wake,
// whose acquire proved the prefix empty), kept or restored from the root.
func TestHAWakeSwitchOffNoHeadUnchanged(t *testing.T) {
- t.Setenv("CARLOS_HA_GENERATIONS", "")
+ generationsBox(t, "")
s, e := haServiceEntry(t, "shop.example.com")
for _, r := range s.fx.Requests() {
if strings.Contains(r, "head.json") || strings.HasPrefix(r, "COPY ") || strings.HasPrefix(r, "LISTV ") || strings.Contains(r, "/g-") {
@@ -606,7 +636,7 @@ func TestHAWakeSwitchOffNoHeadUnchanged(t *testing.T) {
// that is not (switch off, an ordinary marker) refuses the wake, copies
// nothing, leaves head.json as it is, and pages once an hour.
func TestHAWakeNonGenerationsLockWithHeadRefuses(t *testing.T) {
- t.Setenv("CARLOS_HA_GENERATIONS", "")
+ generationsBox(t, "")
s, e := haServiceEntry(t, "shop.example.com")
s.stopForTest(e)
pages := recordPages(s.b)
@@ -642,7 +672,7 @@ func TestHAWakeNonGenerationsLockWithHeadRefuses(t *testing.T) {
// generation) holds LTX files but no L0. One page, no copy, head.json
// unchanged.
func TestHAWakeRefusalPages(t *testing.T) {
- t.Setenv("CARLOS_HA_GENERATIONS", "on")
+ generationsBox(t, "on")
s, e := haServiceEntry(t, "shop.example.com")
s.stopForTest(e)
pages := recordPages(s.b)
@@ -690,7 +720,7 @@ func TestHAWakeHeadMovedRetriesOnce(t *testing.T) {
{"fence conflict once", 1, true},
} {
t.Run(c.name, func(t *testing.T) {
- t.Setenv("CARLOS_HA_GENERATIONS", "on")
+ generationsBox(t, "on")
s, e := haServiceEntry(t, "shop.example.com")
s.insertRows(t, 0, 2)
s.stopForTest(e)
@@ -759,24 +789,34 @@ func TestGenerationsSwitchParse(t *testing.T) {
}
}
-// The wake hands the acquire table the switch's `fast` (slice 4) and the
-// take its `on`: unset or anything else is neither, "on" only the
-// generations take, "fast" both.
+// The wake hands the acquire table its eligibility (Option A) and the
+// switch's `fast` (slice 4), and the take its `on`: only a group member
+// with the switch on or fast is eligible, and only an eligible box's take
+// is on; a fixed box, or a member with the switch unset, is neither,
+// whatever the switch says.
func TestHAWakeProofsCarryTheFastSwitch(t *testing.T) {
for _, c := range []struct {
- env string
- on, fast bool
- }{{"", false, false}, {"on", true, false}, {"fast", true, true}} {
- t.Run("switch="+c.env, func(t *testing.T) {
- t.Setenv("CARLOS_HA_GENERATIONS", c.env)
+ member bool
+ env string
+ eligible, fast bool
+ }{
+ {true, "", false, false}, {true, "on", true, false}, {true, "fast", true, true},
+ {false, "", false, false}, {false, "on", false, false}, {false, "fast", false, false},
+ } {
+ t.Run(fmt.Sprintf("member=%v/switch=%s", c.member, c.env), func(t *testing.T) {
+ if c.member {
+ generationsBox(t, c.env)
+ } else {
+ fixedBox(t, c.env)
+ }
s := haService(t, "shop.example.com")
old := acquireHALease
t.Cleanup(func() { acquireHALease = old })
calls := 0
acquireHALease = func(ctx context.Context, bucket, prefix, region string, base hafresh.Marker, p hafresh.Proofs, opts lease.AcquireOptions) (*lease.Held, error) {
calls++
- if p.GenerationsFast != c.fast || opts.GenerationsOn != c.on {
- t.Errorf("acquire with GenerationsFast %v, GenerationsOn %v; want %v, %v", p.GenerationsFast, opts.GenerationsOn, c.fast, c.on)
+ if p.GenerationsEligible != c.eligible || p.GenerationsFast != c.fast || opts.GenerationsOn != c.eligible {
+ t.Errorf("acquire with GenerationsEligible %v, GenerationsFast %v, GenerationsOn %v; want %v, %v, %v", p.GenerationsEligible, p.GenerationsFast, opts.GenerationsOn, c.eligible, c.fast, c.eligible)
}
return old(ctx, bucket, prefix, region, base, p, opts)
}
@@ -792,6 +832,24 @@ func TestHAWakeProofsCarryTheFastSwitch(t *testing.T) {
}
}
+// generationsBox makes this test's box a member of a region's group
+// (host.env's CARLOS_BOX_REFERENCE=group) with the storage-generations
+// switch set to value: eligible for generations locks (Option A) when the
+// value is on or fast.
+func generationsBox(t *testing.T, value string) {
+ t.Helper()
+ t.Setenv("CARLOS_BOX_REFERENCE", "group")
+ t.Setenv("CARLOS_HA_GENERATIONS", value)
+}
+
+// fixedBox makes this test's box a fixed box (no group reference) with the
+// switch set to value: never eligible for generations locks (Option A).
+func fixedBox(t *testing.T, value string) {
+ t.Helper()
+ t.Setenv("CARLOS_BOX_REFERENCE", "")
+ t.Setenv("CARLOS_HA_GENERATIONS", value)
+}
+
// A truncated replica (Task 5 fix round 1): the clean marker records a
// TXID above the newest L0 the replica holds. Every wake refuses it
// (clean_marker_above_l0), the second as the first, also after the agent
@@ -801,7 +859,7 @@ func TestHAWakeProofsCarryTheFastSwitch(t *testing.T) {
func TestHAWakeTruncatedReplicaRefusesEveryWake(t *testing.T) {
setup := func(t *testing.T) (*haSvc, uint64) {
t.Helper()
- t.Setenv("CARLOS_HA_GENERATIONS", "on")
+ generationsBox(t, "on")
s, e := haServiceEntry(t, "shop.example.com")
s.insertRows(t, 0, 3)
s.stopForTest(e)
@@ -861,7 +919,7 @@ func TestHAWakeTruncatedReplicaRefusesEveryWake(t *testing.T) {
// history (ended eight days ago), so the root layout's LTX file goes; an
// abandoned g-0 written just now, lock.json and head.json stay.
func TestHAWakeRetiresAfterTheReplicatorStarts(t *testing.T) {
- t.Setenv("CARLOS_HA_GENERATIONS", "on")
+ generationsBox(t, "on")
s, e := haServiceEntry(t, "shop.example.com")
s.b.retiring.Wait()
s.insertRows(t, 0, 3)
@@ -946,7 +1004,7 @@ func (l listDirsFails) ListDirs(ctx context.Context, prefix string) ([]string, e
// A retirement that fails is logged as ha_generation_retire_failed and
// never fails the wake: the host serves, and the next take tries again.
func TestHAWakeRetirementFailureNeverFailsTheWake(t *testing.T) {
- t.Setenv("CARLOS_HA_GENERATIONS", "on")
+ generationsBox(t, "on")
lines := captureLogLines(t)
s := haService(t, "shop.example.com")
s.b.FilesStore = listDirsFails{Store: s.b.FilesStore, prefix: s.loc() + "/"}
@@ -989,7 +1047,7 @@ func (l *listDirsBlocks) ListDirs(ctx context.Context, prefix string) ([]string,
// the wake still completes and serves while it is held; retirement
// finishes once the listing is let go.
func TestHAWakeDoesNotWaitForRetirement(t *testing.T) {
- t.Setenv("CARLOS_HA_GENERATIONS", "on")
+ generationsBox(t, "on")
s := haService(t, "shop.example.com")
blk := &listDirsBlocks{Store: s.b.FilesStore, prefix: s.loc() + "/", entered: make(chan struct{}), unblock: make(chan struct{})}
s.b.FilesStore = blk
@@ -1044,7 +1102,7 @@ func TestHAWakeReplicationFailureStartsNoRetirement(t *testing.T) {
if os.Geteuid() == 0 {
t.Skip("root removes a file from a read-only directory")
}
- t.Setenv("CARLOS_HA_GENERATIONS", "on")
+ generationsBox(t, "on")
s, e := haServiceEntry(t, "shop.example.com")
s.b.retiring.Wait()
s.stopForTest(e)
@@ -1087,7 +1145,7 @@ type noStoreTime struct{ release.Store }
// ha_generation_retire_failed reason=no_store_time: it never judges ages
// by the box's clock instead.
func TestHAWakeRetirementWithoutStoreTime(t *testing.T) {
- t.Setenv("CARLOS_HA_GENERATIONS", "on")
+ generationsBox(t, "on")
lines := captureLogLines(t)
s := haService(t, "shop.example.com")
s.b.FilesStore = noStoreTime{s.b.FilesStore}
@@ -1135,3 +1193,110 @@ func TestKeptBaselineComparesAndRereadsWithoutAPublisher(t *testing.T) {
t.Fatalf("log %q", logs.String())
}
}
+
+// ---- Option A (8a3d302 for Paul, 2026-11-19): only a group member with
+// the switch on or fast takes a generations lock ----
+
+// requireIneligibleRefusal: the wake was refused as a generations lock on
+// a box that takes none, the lock is byte for byte as it was, and no
+// head.json appeared.
+func requireIneligibleRefusal(t *testing.T, s *haSvc, err error, lock []byte) {
+ t.Helper()
+ var re *errLeaseRefused
+ if !errors.As(err, &re) || !strings.Contains(re.reason, hafresh.ReasonGenerationsIneligible) {
+ t.Fatalf("wake: %v, want the ineligible refusal", err)
+ }
+ if got := s.fx.LockBody(s.loc()); !bytes.Equal(got, lock) {
+ t.Fatalf("the lock changed: %s", got)
+ }
+ if _, ok := s.fx.Object(s.headKey()); ok {
+ t.Fatal("a head.json was written")
+ }
+}
+
+// A generations release marker is refused by a fixed box with the switch
+// on or fast and by a group member with the switch off, and taken by a
+// group member with the switch on.
+func TestOptionAOnlyEligibleBoxesTakeGenerationsLocks(t *testing.T) {
+ for _, c := range []struct {
+ name string
+ box func(*testing.T, string)
+ value string
+ takes bool
+ }{
+ {"fixed box, switch on", fixedBox, "on", false},
+ {"fixed box, switch fast", fixedBox, "fast", false},
+ {"member, switch off", generationsBox, "", false},
+ {"member, switch 0", generationsBox, "0", false},
+ {"member, switch on", generationsBox, "on", true},
+ } {
+ t.Run(c.name, func(t *testing.T) {
+ s, e := haServiceEntry(t, "shop.example.com")
+ s.stopForTest(e)
+ s.rewriteMarkerFormat(t, true)
+ lock := s.fx.LockBody(s.loc())
+ c.box(t, c.value)
+ e, err := s.wakeForTest(context.Background())
+ if !c.takes {
+ requireIneligibleRefusal(t, s, err, lock)
+ return
+ }
+ if err != nil {
+ t.Fatal(err)
+ }
+ if v := s.lockView(t); v.Lock.GenName == "" || v.Lock.GenName != replicagen.Name(v.Lock.Generation) {
+ t.Fatalf("the member's take %+v, want a generations lock", v.Lock)
+ }
+ s.stopForTest(e)
+ })
+ }
+}
+
+// A fixed box with the switch on still serves ordinary HA hosts as
+// before: its wakes write ordinary locks and no head.json.
+func TestOptionAFixedBoxTakesOrdinaryLocks(t *testing.T) {
+ fixedBox(t, "on")
+ s, e := haServiceEntry(t, "shop.example.com")
+ if v := s.lockView(t); v.Generations() {
+ t.Fatalf("a fixed box's first wake wrote %+v", v.Lock)
+ }
+ s.stopForTest(e)
+ e, err := s.wakeForTest(context.Background())
+ if err != nil {
+ t.Fatal(err)
+ }
+ if v := s.lockView(t); v.Generations() || v.Lock.Generation < 2 {
+ t.Fatalf("a fixed box's second wake wrote %+v", v.Lock)
+ }
+ if _, ok := s.fx.Object(s.headKey()); ok {
+ t.Fatal("a fixed box wrote head.json")
+ }
+ s.stopForTest(e)
+}
+
+// Adoption on a fixed box, the switch on, refuses a generations lock and
+// writes nothing.
+func TestOptionAFixedBoxAdoptionRefusesGenerationsLock(t *testing.T) {
+ fixedBox(t, "on")
+ s, req := haAdoptionFixture(t)
+ ctx := context.Background()
+ putLockFor(t, s.b, s.rt, formatMarker(t, true, hafresh.Marker{V: 1, Box: "b", IID: "i-b", Lifetime: req.Lifetime, At: time.Now().UTC(), Clean: true, Settled: true}))
+ var err error
+ req.Observed, err = lease.ReadLock(ctx, s.b.Cfg.Bucket, s.b.Cfg.hibernatePrefix(s.rt.Host), s.b.Cfg.Region)
+ if err != nil || !req.Observed.Generations() {
+ t.Fatalf("observed %+v %v", req.Observed, err)
+ }
+ s.mu.Lock()
+ start := len(s.lockLog)
+ s.mu.Unlock()
+ got, err := s.a.AdoptHost(ctx, s.rt, req)
+ if err == nil || got == Adopted || !strings.Contains(err.Error(), hafresh.ReasonGenerationsIneligible) {
+ t.Fatalf("adopt %v %v, want the ineligible refusal", got, err)
+ }
+ s.mu.Lock()
+ writes := len(s.lockLog) - start
+ s.mu.Unlock()
+ if writes != 0 {
+ t.Fatalf("a refused adoption wrote the lock %d times", writes)
+ }
+}
diff --git a/internal/activator/hapoint_test.go b/internal/activator/hapoint_test.go
index e48d7e902..cd61ca26b 100644
--- a/internal/activator/hapoint_test.go
+++ b/internal/activator/hapoint_test.go
@@ -26,7 +26,7 @@ import (
// and box are its), and so does the take's TXID, so only the generation
// the take read tells them apart.
func TestHAWakeAfterAPointRestoresThePointedGeneration(t *testing.T) {
- t.Setenv("CARLOS_HA_GENERATIONS", "on")
+ generationsBox(t, "on")
s, e := haServiceEntry(t, "shop.example.com")
s.insertRows(t, 0, 5)
s.stopForTest(e)
diff --git a/internal/activator/harelease_test.go b/internal/activator/harelease_test.go
index 36e12fab4..142dd398d 100644
--- a/internal/activator/harelease_test.go
+++ b/internal/activator/harelease_test.go
@@ -906,6 +906,13 @@ func (s *haSvc) wakePathRequests(reqs []string) []string {
if level, ok := strings.CutPrefix(r, "LIST "+prefix); ok && isReplicaLevelDir(level) {
continue
}
+ // The same listing under a storage generation (g-N/NNNN/): the
+ // replicator of a generations wake writes there.
+ if rel, ok := strings.CutPrefix(r, "LIST "+prefix+"g-"); ok {
+ if _, level, ok := strings.Cut(rel, "/"); ok && isReplicaLevelDir(level) {
+ continue
+ }
+ }
out = append(out, r)
}
return out
diff --git a/internal/activator/hatakeover_test.go b/internal/activator/hatakeover_test.go
index 850a3ba46..48e77857c 100644
--- a/internal/activator/hatakeover_test.go
+++ b/internal/activator/hatakeover_test.go
@@ -305,7 +305,7 @@ func TestFastLiveHolderRaisesNoAlarm(t *testing.T) {
}
}
t.Run("other box, not terminated, live", func(t *testing.T) {
- t.Setenv("CARLOS_HA_GENERATIONS", "fast")
+ generationsBox(t, "fast")
logs := captureLog(t)
oracle := &terminatedOracle{}
b, rt := haBackend(t, "shop.example.com")
@@ -318,7 +318,7 @@ func TestFastLiveHolderRaisesNoAlarm(t *testing.T) {
}
})
t.Run("other box, not terminated, expired", func(t *testing.T) {
- t.Setenv("CARLOS_HA_GENERATIONS", "fast")
+ generationsBox(t, "fast")
logs := captureLog(t)
b, rt := haBackend(t, "shop.example.com")
b.OwnerTerminated = (&terminatedOracle{}).terminated
@@ -333,7 +333,7 @@ func TestFastLiveHolderRaisesNoAlarm(t *testing.T) {
}
})
t.Run("other box, terminated, live", func(t *testing.T) {
- t.Setenv("CARLOS_HA_GENERATIONS", "fast")
+ generationsBox(t, "fast")
logs := captureLog(t)
b, rt := haBackend(t, "shop.example.com")
b.OwnerTerminated = (&terminatedOracle{yes: map[string]bool{"i-b": true}}).terminated
@@ -348,7 +348,7 @@ func TestFastLiveHolderRaisesNoAlarm(t *testing.T) {
}
})
t.Run("other box, proof cache, running, live", func(t *testing.T) {
- t.Setenv("CARLOS_HA_GENERATIONS", "fast")
+ generationsBox(t, "fast")
logs := captureLog(t)
b, rt := haBackend(t, "shop.example.com")
me := hafresh.Self{Ref: "a", IID: "i-0123456789abcdef0", Account: "111122223333", Region: "eu-west-1"}
@@ -375,7 +375,7 @@ func TestFastLiveHolderRaisesNoAlarm(t *testing.T) {
}
})
t.Run("same box, unproven, live", func(t *testing.T) {
- t.Setenv("CARLOS_HA_GENERATIONS", "fast")
+ generationsBox(t, "fast")
logs := captureLog(t)
b, rt := haBackend(t, "shop.example.com") // no startup sweep: no emptiness proof
owner := hafresh.OwnerFor(hafresh.Self{Ref: "a", IID: "i-a"}, 7, true)
@@ -384,7 +384,7 @@ func TestFastLiveHolderRaisesNoAlarm(t *testing.T) {
requireHeldQuiet(t, b, rt, body, logs, owner)
})
t.Run("same box, unproven, expired", func(t *testing.T) {
- t.Setenv("CARLOS_HA_GENERATIONS", "fast")
+ generationsBox(t, "fast")
logs := captureLog(t)
b, rt := haBackend(t, "shop.example.com")
putLockFor(t, b, rt, genLeaseBody(t, hafresh.OwnerFor(hafresh.Self{Ref: "a", IID: "i-a"}, 7, true), expired()))
@@ -417,7 +417,7 @@ func TestFastSameBoxLiveLockOnlyFromAPreviousProcess(t *testing.T) {
{"held by this process's adoption", func(b *ExecBackend, host string) { b.sameBox.markAdoptionHeld(host) }, false},
} {
t.Run(c.name, func(t *testing.T) {
- t.Setenv("CARLOS_HA_GENERATIONS", "fast")
+ generationsBox(t, "fast")
logs := captureLog(t)
b, rt := haBackend(t, "shop.example.com")
sameBoxReady(b)
diff --git a/internal/activator/hawake.go b/internal/activator/hawake.go
index 5a4d2ae14..bcac2e80b 100644
--- a/internal/activator/hawake.go
+++ b/internal/activator/hawake.go
@@ -14,6 +14,7 @@ import (
"time"
"github.com/carlosframework/platform/internal/hafresh"
+ "github.com/carlosframework/platform/internal/hostenv"
"github.com/carlosframework/platform/internal/hostfiles"
"github.com/carlosframework/platform/internal/instancefs"
"github.com/carlosframework/platform/internal/layout/pubclass"
@@ -106,6 +107,21 @@ func generationsSwitch(getenv func(string) string) (on, fast bool) {
return false, false
}
+// generationsEligible is Option A (8a3d302 for Paul, 2026-11-19): only a
+// member of a region's group (host.env's CARLOS_BOX_REFERENCE=group, which
+// only a group member's boot writes) whose switch is on or fast takes a
+// storage-generations lock. A fixed box, or a member with the switch off,
+// refuses every one (hafresh.ReasonGenerationsIneligible), so the wake
+// fails there and a member serves the host. The group's generations_floor
+// lives only in the roll engine's group config, so it is not part of the
+// test here; the runbook requires it before the switch. Read once per wake
+// from getenv, never polled. fast is the switch's fast on an eligible box.
+func generationsEligible(getenv func(string) string) (eligible, fast bool) {
+ on, f := generationsSwitch(getenv)
+ member := strings.TrimSpace(getenv(hostenv.BoxReference)) == hostenv.GroupReference
+ return on && member, f && on && member
+}
+
// haLegacyRoute reports a route that is legacy before any record lookup
// (r3.4): an unstamped sidecar, a route the provision pass did not mint,
// or a kind other than an instance or native sidecar. It keeps today's acquire, and an HA-format
@@ -460,16 +476,18 @@ func (b *ExecBackend) acquireClassified(ctx context.Context, rt registry.Route)
}
ctx = lease.WithTerminationProof(ctx, &adapter)
}
- // The switch, read once for this wake: on, the take writes a
- // generations lock over any lock; off, only over a generations lock
- // (the mode is sticky). Either way the Restore takes a generation on a
- // generations lock. fast (slice 4) lets the acquire table take a
- // generations lock without the marker wait or the owner's expiry, on
- // the same proofs (hafresh.DecideAcquire); any other lock is decided
- // as without it.
- on, fast := generationsSwitch(haGetenv)
+ // The switch and the box's group membership, read once for this wake
+ // (generationsEligible, Option A). Eligible, the take writes a
+ // generations lock over any lock, and the Restore takes a generation
+ // on it. Not eligible (a fixed box, or the switch off), the acquire
+ // table refuses every generations lock and the take writes none. fast
+ // (slice 4) lets the table take a generations lock without the marker
+ // wait or the owner's expiry, on the same proofs
+ // (hafresh.DecideAcquire); any other lock is decided as without it.
+ eligible, fast := generationsEligible(haGetenv)
+ proofs.GenerationsEligible = eligible
proofs.GenerationsFast = fast
- opts := lease.AcquireOptions{GenerationsOn: on}
+ opts := lease.AcquireOptions{GenerationsOn: eligible}
var held *lease.Held
if duty, ok := ctx.Value(dutyContextKey{}).(dutyRestriction); ok {
held, err = lease.AcquireHAForDuty(ctx, b.Cfg.Bucket, prefix, b.Cfg.Region, hafresh.Marker{Lifetime: entry.ID}, proofs, duty.allow, opts)
diff --git a/internal/hafresh/acquire.go b/internal/hafresh/acquire.go
index 6b33dc956..3f1436400 100644
--- a/internal/hafresh/acquire.go
+++ b/internal/hafresh/acquire.go
@@ -49,6 +49,15 @@ type Proofs struct {
OwnerTerminated func(iid string) (bool, error)
// ObserveRefusal receives the classified view after an acquire round refuses.
ObserveRefusal func(View, Decision)
+ // GenerationsEligible is whether this box takes a storage-generations
+ // lock at all (Option A, 8a3d302 for Paul, 2026-11-19): only a group
+ // member whose switch is on or fast. False, the default, refuses every
+ // generations lock (View.Generations), held, expired or a release
+ // marker, before any other row, the way a slice-0 box refuses one: a
+ // fixed box or a box with the switch off never takes or writes one,
+ // so it never runs a generations host and an activation below the
+ // floor there cannot meet one.
+ GenerationsEligible bool
// GenerationsFast is the box switch's `fast` (CARLOS_HA_GENERATIONS,
// storage generations spec §5.3, slice 4). It changes the table only
// for a generations lock (View.Generations): see DecideAcquire.
@@ -89,11 +98,18 @@ const (
// ReasonUnknownField refuses a lock carrying a carlos_ field this
// binary does not know (View.Unknown): a later release wrote it.
ReasonUnknownField = "unknown lock field"
+ // ReasonGenerationsIneligible refuses a storage-generations lock on a
+ // box that does not take them (Proofs.GenerationsEligible false).
+ ReasonGenerationsIneligible = "generations lock on a box that takes none (a fixed box, or the switch off)"
)
// DecideAcquire is the HA acquire's one table (I1), for HA hosts only.
// term is the lease term (lease.LeaseTTL in production):
//
+// - a storage-generations lock (View.Generations) on a box that is not
+// eligible for them (Proofs.GenerationsEligible false: a fixed box,
+// or a group member with the switch off): refuse, whatever else the
+// lock says (Option A);
// - absent: create (the caller still proves the prefix empty);
// - present, carrying a carlos_ field this binary does not know
// (View.Unknown): refuse, whatever else the lock says. A later release
@@ -142,6 +158,9 @@ func DecideAcquire(v View, self Self, now time.Time, term time.Duration, p Proof
if len(v.Unknown) > 0 {
return Decision{Action: ActRefuse, Reason: ReasonUnknownField}
}
+ if v.Generations() && !p.GenerationsEligible {
+ return Decision{Action: ActRefuse, Reason: ReasonGenerationsIneligible}
+ }
if v.Absent {
return Decision{Action: ActCreate, Reason: ReasonAbsent}
}
diff --git a/internal/hafresh/acquire_test.go b/internal/hafresh/acquire_test.go
index 01ac1625d..1460c9e43 100644
--- a/internal/hafresh/acquire_test.go
+++ b/internal/hafresh/acquire_test.go
@@ -13,23 +13,23 @@ func TestDecideAcquireTable(t *testing.T) {
self := Self{Ref: "a", IID: "i-a"}
exp := now.Add(-time.Minute)
other, mine := OwnerFor(Self{Ref: "b", IID: "i-b"}, 9, true), OwnerFor(self, 9, true)
- yes := Proofs{LocalEligible: func() bool { return true }, SameBoxEmpty: func() (bool, error) { return true, nil }}
- no := Proofs{LocalEligible: func() bool { return true }, SameBoxEmpty: func() (bool, error) { return false, nil }}
- broken := Proofs{LocalEligible: func() bool { return true }, SameBoxEmpty: func() (bool, error) { return true, errors.New("cgroup unreadable") }}
- terminated := Proofs{LocalEligible: func() bool { return true }, OwnerTerminated: func(string) (bool, error) { return true, nil }}
- terminatedErr := Proofs{LocalEligible: func() bool { return true }, OwnerTerminated: func(string) (bool, error) { return true, errors.New("ec2 unreachable") }}
+ yes := Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }, SameBoxEmpty: func() (bool, error) { return true, nil }}
+ no := Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }, SameBoxEmpty: func() (bool, error) { return false, nil }}
+ broken := Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }, SameBoxEmpty: func() (bool, error) { return true, errors.New("cgroup unreadable") }}
+ terminated := Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }, OwnerTerminated: func(string) (bool, error) { return true, nil }}
+ terminatedErr := Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }, OwnerTerminated: func(string) (bool, error) { return true, errors.New("ec2 unreachable") }}
noIIDOther := OwnerFor(Self{Ref: "c"}, 9, true)
for i, c := range []struct {
v View
p Proofs
want Action
}{
- {View{Absent: true}, Proofs{LocalEligible: func() bool { return true }}, ActCreate},
- {View{Lock: Lock{ExpiresAt: exp, Owner: "ip-10-0-0-1:77"}}, Proofs{LocalEligible: func() bool { return true }}, ActRefuse},
- {View{Lock: Lock{Owner: "released/v1;ref=b;iid=i-b", Release: &Marker{Box: "b", Settled: true}}}, Proofs{LocalEligible: func() bool { return true }}, ActTake},
- {View{Lock: Lock{ExpiresAt: now.Add(time.Minute), Owner: other}}, Proofs{LocalEligible: func() bool { return true }}, ActHeld},
+ {View{Absent: true}, Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }}, ActCreate},
+ {View{Lock: Lock{ExpiresAt: exp, Owner: "ip-10-0-0-1:77"}}, Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }}, ActRefuse},
+ {View{Lock: Lock{Owner: "released/v1;ref=b;iid=i-b", Release: &Marker{Box: "b", Settled: true}}}, Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }}, ActTake},
+ {View{Lock: Lock{ExpiresAt: now.Add(time.Minute), Owner: other}}, Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }}, ActHeld},
{View{Lock: Lock{ExpiresAt: exp, Owner: other}}, yes, ActRefuse},
- {View{Lock: Lock{ExpiresAt: exp, Owner: mine}}, Proofs{LocalEligible: func() bool { return true }}, ActRefuse},
+ {View{Lock: Lock{ExpiresAt: exp, Owner: mine}}, Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }}, ActRefuse},
{View{Lock: Lock{ExpiresAt: exp, Owner: mine}}, yes, ActTake},
// Beyond the plan's table: a proof that says "not empty", or that
// fails, refuses; an unexpired lock of this very box is held; a
@@ -40,7 +40,7 @@ func TestDecideAcquireTable(t *testing.T) {
{View{Lock: Lock{ExpiresAt: now.Add(time.Minute), Owner: mine}}, yes, ActHeld},
{View{Lock: Lock{ExpiresAt: exp, Owner: OwnerFor(self, 9, false)}}, yes, ActRefuse},
{View{Lock: Lock{ExpiresAt: exp, Owner: "released/v1;ref=b"}}, yes, ActRefuse},
- {View{Lock: Lock{ExpiresAt: exp, Owner: other}}, Proofs{LocalEligible: func() bool { return true }}, ActRefuse},
+ {View{Lock: Lock{ExpiresAt: exp, Owner: other}}, Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }}, ActRefuse},
// Another box's lock, EC2 confirming it terminated: taken only
// once expired; a failed confirmation or an iid-less owner refuses.
{View{Lock: Lock{ExpiresAt: exp, Owner: other}}, terminated, ActTake},
@@ -58,10 +58,10 @@ func TestDecideAcquireTable(t *testing.T) {
p Proofs
want string
}{
- {View{Lock: Lock{ExpiresAt: exp, Owner: "ip-10-0-0-1:77"}}, Proofs{LocalEligible: func() bool { return true }}, ReasonLeftoverLock},
+ {View{Lock: Lock{ExpiresAt: exp, Owner: "ip-10-0-0-1:77"}}, Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }}, ReasonLeftoverLock},
{View{Lock: Lock{ExpiresAt: exp, Owner: other}}, yes, ReasonOtherExpired},
- {View{Lock: Lock{ExpiresAt: exp, Owner: mine}}, Proofs{LocalEligible: func() bool { return true }}, ReasonSameBoxUnsure},
- {View{Lock: Lock{ExpiresAt: now.Add(time.Minute), Owner: other}}, Proofs{LocalEligible: func() bool { return true }}, other},
+ {View{Lock: Lock{ExpiresAt: exp, Owner: mine}}, Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }}, ReasonSameBoxUnsure},
+ {View{Lock: Lock{ExpiresAt: now.Add(time.Minute), Owner: other}}, Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }}, other},
{View{Lock: Lock{ExpiresAt: exp, Owner: other}}, terminated, ReasonTerminated},
{View{Lock: Lock{ExpiresAt: exp, Owner: mine}}, yes, ReasonSameBox},
} {
@@ -84,11 +84,11 @@ func TestDecideAcquireReasons(t *testing.T) {
now := time.Unix(1_800_000_000, 0)
self := Self{Ref: "a", IID: "i-a"}
v := View{Lock: Lock{ExpiresAt: now.Add(-time.Minute), Owner: OwnerFor(Self{Ref: "b", IID: "i-b"}, 9, true)}}
- d := DecideAcquire(v, self, now, 15*time.Minute, Proofs{LocalEligible: func() bool { return true }, OwnerTerminated: func(string) (bool, error) { return true, nil }})
+ d := DecideAcquire(v, self, now, 15*time.Minute, Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }, OwnerTerminated: func(string) (bool, error) { return true, nil }})
if d.Action != ActTake || d.Reason != ReasonTerminated {
t.Fatalf("terminated take: %+v", d)
}
- d = DecideAcquire(v, self, now, 15*time.Minute, Proofs{LocalEligible: func() bool { return true }, OwnerTerminated: func(string) (bool, error) { return false, errors.New("throttled") }})
+ d = DecideAcquire(v, self, now, 15*time.Minute, Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }, OwnerTerminated: func(string) (bool, error) { return false, errors.New("throttled") }})
if d.Action != ActRefuse || d.Reason != ReasonOtherExpired+": throttled" {
t.Fatalf("proof error: %+v", d)
}
@@ -115,7 +115,7 @@ func TestDecideAcquireProofScope(t *testing.T) {
} {
var term []string
same := 0
- p := Proofs{LocalEligible: func() bool { return true },
+ p := Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true },
SameBoxEmpty: func() (bool, error) { same++; return true, nil },
OwnerTerminated: func(iid string) (bool, error) { term = append(term, iid); return true, nil },
}
@@ -131,7 +131,7 @@ func TestDecideAcquireProofScope(t *testing.T) {
func TestDecideAcquireStoppedOwnerIsNotTaken(t *testing.T) {
now := time.Unix(1_800_000_000, 0)
v := View{Lock: Lock{ExpiresAt: now.Add(-time.Minute), Owner: OwnerFor(Self{Ref: "b", IID: "i-b"}, 9, true)}}
- d := DecideAcquire(v, Self{Ref: "a", IID: "i-a"}, now, 15*time.Minute, Proofs{LocalEligible: func() bool { return true }, OwnerTerminated: func(string) (bool, error) { return false, nil }})
+ d := DecideAcquire(v, Self{Ref: "a", IID: "i-a"}, now, 15*time.Minute, Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }, OwnerTerminated: func(string) (bool, error) { return false, nil }})
if d.Action != ActRefuse || d.Reason != ReasonOtherExpired {
t.Fatalf("%+v", d)
}
@@ -202,7 +202,7 @@ func TestDecideAcquireUnsettledMarkerWaitsALeaseTerm(t *testing.T) {
now := time.Unix(1_800_000_000, 0)
const term = 15 * time.Minute
self := Self{Ref: "a", IID: "i-a"}
- p := Proofs{LocalEligible: func() bool { return true },
+ p := Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true },
SameBoxEmpty: func() (bool, error) { t.Error("emptiness proof asked for a marker"); return true, nil },
OwnerTerminated: func(string) (bool, error) { t.Error("termination proof asked for a marker"); return true, nil }}
view := func(m Marker) View {
@@ -284,7 +284,7 @@ func TestDecideAcquireRefusesUnknownField(t *testing.T) {
const term = 15 * time.Minute
self := Self{Ref: "a", IID: "i-a"}
asked := 0
- p := Proofs{LocalEligible: func() bool { return true },
+ p := Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true },
SameBoxEmpty: func() (bool, error) { asked++; return true, nil },
OwnerTerminated: func(string) (bool, error) { asked++; return true, nil }}
other, mine := OwnerFor(Self{Ref: "b", IID: "i-b"}, 9, true), OwnerFor(self, 9, true)
@@ -334,7 +334,7 @@ func TestDecideAcquireRefusesUnknownField(t *testing.T) {
}
// Pool eligibility still comes first.
v := View{Lock: Lock{ExpiresAt: now.Add(time.Minute), Owner: other}, Unknown: []string{"carlos_future"}}
- if d := DecideAcquire(v, self, now, term, Proofs{}); d.Reason != ReasonPoolIneligible {
+ if d := DecideAcquire(v, self, now, term, Proofs{GenerationsEligible: true}); d.Reason != ReasonPoolIneligible {
t.Fatalf("ineligible box: %+v", d)
}
}
@@ -358,7 +358,7 @@ func TestDecideAcquireFastRows(t *testing.T) {
other, mine := OwnerFor(Self{Ref: "b", IID: "i-b"}, 9, true), OwnerFor(self, 9, true)
noIIDOther := OwnerFor(Self{Ref: "c"}, 9, true)
proofs := func(term, empty func() (bool, error)) Proofs {
- p := Proofs{LocalEligible: func() bool { return true }}
+ p := Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }}
if term != nil {
p.OwnerTerminated = func(string) (bool, error) { return term() }
}
@@ -466,10 +466,10 @@ func TestDecideAcquireFastRows(t *testing.T) {
// carlos_ field this binary does not know.
v := held(other, live, gen)
v.Unknown = []string{"carlos_future"}
- if d := DecideAcquire(v, self, now, term, Proofs{GenerationsFast: true}); d.Reason != ReasonPoolIneligible {
+ if d := DecideAcquire(v, self, now, term, Proofs{GenerationsEligible: true, GenerationsFast: true}); d.Reason != ReasonPoolIneligible {
t.Fatalf("ineligible box: %+v", d)
}
- if d := DecideAcquire(v, self, now, term, Proofs{LocalEligible: func() bool { return true }, GenerationsFast: true, OwnerTerminated: func(string) (bool, error) { return true, nil }}); d.Reason != ReasonUnknownField {
+ if d := DecideAcquire(v, self, now, term, Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }, GenerationsFast: true, OwnerTerminated: func(string) (bool, error) { return true, nil }}); d.Reason != ReasonUnknownField {
t.Fatalf("unknown field: %+v", d)
}
}
@@ -497,7 +497,7 @@ func TestDecideAcquireFastProofScope(t *testing.T) {
} {
var term []string
same := 0
- p := Proofs{LocalEligible: func() bool { return true }, GenerationsFast: true,
+ p := Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }, GenerationsFast: true,
SameBoxEmpty: func() (bool, error) { same++; return true, nil },
OwnerTerminated: func(iid string) (bool, error) { term = append(term, iid); return true, nil },
}
@@ -540,7 +540,7 @@ func TestDecideAcquireFastAsksTheLiveProofs(t *testing.T) {
}
return false, errors.New("unproven")
}
- p := Proofs{LocalEligible: func() bool { return true }, GenerationsFast: true,
+ p := Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }, GenerationsFast: true,
OwnerTerminated: func(iid string) (bool, error) { return ask("term:" + iid) },
SameBoxEmpty: func() (bool, error) { return ask("same") },
LiveOwnerTerminated: func(iid string) (bool, error) { return ask("live-term:" + iid) },
@@ -552,3 +552,47 @@ func TestDecideAcquireFastAsksTheLiveProofs(t *testing.T) {
}
}
}
+
+// Option A (8a3d302 for Paul, 2026-11-19): without GenerationsEligible a
+// generations lock is refused in every state, before any other row, and
+// an ordinary lock or an absent one is decided as before.
+func TestDecideAcquireRefusesGenerationsWhenIneligible(t *testing.T) {
+ now := time.Date(2027, 1, 15, 8, 0, 0, 0, time.UTC)
+ self := Self{Ref: "a", IID: "i-a"}
+ mine := OwnerFor(self, 9, true)
+ other := OwnerFor(Self{Ref: "b", IID: "i-b"}, 9, true)
+ all := Proofs{
+ LocalEligible: func() bool { return true },
+ SameBoxEmpty: func() (bool, error) { return true, nil },
+ OwnerTerminated: func(string) (bool, error) { return true, nil },
+ GenerationsFast: true,
+ }
+ gen := "g-00000000000000000003"
+ for name, v := range map[string]View{
+ "generations marker, clean": {Lock: Lock{Generation: 3, Owner: "released/v1;ref=b;iid=i-b;gen=1", Release: &Marker{Box: "b", IID: "i-b", Clean: true, Gen: true}}},
+ "generations marker, settled": {Lock: Lock{Generation: 3, Owner: "released/v1;ref=b;iid=i-b;gen=1", Release: &Marker{Box: "b", IID: "i-b", Settled: true, Gen: true}}},
+ "held by another box": {Lock: Lock{Generation: 3, ExpiresAt: now.Add(time.Minute), Owner: other, GenName: gen}},
+ "expired, another box": {Lock: Lock{Generation: 3, ExpiresAt: now.Add(-time.Minute), Owner: other, GenName: gen}},
+ "expired, this box": {Lock: Lock{Generation: 3, ExpiresAt: now.Add(-time.Minute), Owner: mine, GenName: gen}},
+ "held by this box": {Lock: Lock{Generation: 3, ExpiresAt: now.Add(time.Minute), Owner: mine, GenName: gen}},
+ } {
+ if !v.Generations() {
+ t.Fatalf("%s: fixture is not a generations lock", name)
+ }
+ if d := DecideAcquire(v, self, now, 15*time.Minute, all); d.Action != ActRefuse || d.Reason != ReasonGenerationsIneligible {
+ t.Errorf("%s, ineligible: %+v", name, d)
+ }
+ eligible := all
+ eligible.GenerationsEligible = true
+ if d := DecideAcquire(v, self, now, 15*time.Minute, eligible); d.Reason == ReasonGenerationsIneligible {
+ t.Errorf("%s, eligible: %+v", name, d)
+ }
+ }
+ if d := DecideAcquire(View{Absent: true}, self, now, 15*time.Minute, all); d.Action != ActCreate {
+ t.Errorf("absent, ineligible: %+v", d)
+ }
+ ordinary := View{Lock: Lock{Generation: 3, Owner: "released/v1;ref=b;iid=i-b", Release: &Marker{Box: "b", IID: "i-b", Clean: true}}}
+ if d := DecideAcquire(ordinary, self, now, 15*time.Minute, all); d.Action != ActTake {
+ t.Errorf("ordinary marker, ineligible: %+v", d)
+ }
+}
diff --git a/internal/hafresh/generations_test.go b/internal/hafresh/generations_test.go
index b53973d2a..3d65d9de2 100644
--- a/internal/hafresh/generations_test.go
+++ b/internal/hafresh/generations_test.go
@@ -162,7 +162,7 @@ func TestOldBinaryRefusesGenMarker(t *testing.T) {
if !v.HAOn() {
t.Fatal("an old binary reads a generations marker as not HA-format: its legacy take would take it")
}
- p := Proofs{LocalEligible: func() bool { return true },
+ p := Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true },
SameBoxEmpty: func() (bool, error) { return true, nil },
OwnerTerminated: func(string) (bool, error) { return true, nil }}
for _, self := range []Self{{Ref: "a", IID: "i-a"}, {Ref: "b", IID: "i-b"}} {
@@ -179,7 +179,7 @@ func TestDecideAcquireReadsGenMarker(t *testing.T) {
now := time.Date(2026, 11, 17, 12, 0, 0, 0, time.UTC)
term := 15 * time.Minute
self := Self{Ref: "a", IID: "i-a"}
- p := Proofs{LocalEligible: func() bool { return true }}
+ p := Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }}
decode := func(m Marker) View {
t.Helper()
m.Gen = true
@@ -337,7 +337,7 @@ func TestHeldLockMinTXID(t *testing.T) {
}
// The old-binary fence: a field outside a binary's known set refuses
// the lock before any row of the table.
- if d := DecideAcquire(View{Lock: Lock{Owner: "box/v1;ref=b;iid=i-b;pid=1;ha=1"}, Unknown: []string{"carlos_min_txid"}}, Self{Ref: "a", IID: "i-a"}, time.Now(), time.Minute, Proofs{LocalEligible: func() bool { return true }}); d.Reason != ReasonUnknownField {
+ if d := DecideAcquire(View{Lock: Lock{Owner: "box/v1;ref=b;iid=i-b;pid=1;ha=1"}, Unknown: []string{"carlos_min_txid"}}, Self{Ref: "a", IID: "i-a"}, time.Now(), time.Minute, Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }}); d.Reason != ReasonUnknownField {
t.Fatalf("a binary that does not know the field: %+v", d)
}
}
diff --git a/internal/hafresh/pools_test.go b/internal/hafresh/pools_test.go
index 368fa0a0f..1f41090a7 100644
--- a/internal/hafresh/pools_test.go
+++ b/internal/hafresh/pools_test.go
@@ -18,7 +18,7 @@ func TestAcquireHAPoolEligibility(t *testing.T) {
"unexpired": {Lock: Lock{Owner: OwnerFor(me, 1, true), ExpiresAt: now.Add(time.Hour)}},
} {
t.Run(name, func(t *testing.T) {
- p := Proofs{SameBoxEmpty: func() (bool, error) { t.Error("emptiness proof called"); return true, nil }, OwnerTerminated: func(string) (bool, error) { t.Error("termination proof called"); return true, nil }}
+ p := Proofs{GenerationsEligible: true, SameBoxEmpty: func() (bool, error) { t.Error("emptiness proof called"); return true, nil }, OwnerTerminated: func(string) (bool, error) { t.Error("termination proof called"); return true, nil }}
for _, eligible := range []func() bool{nil, func() bool { return false }} {
p.LocalEligible = eligible
d := DecideAcquire(v, me, now, 15*time.Minute, p)
diff --git a/internal/lease/generations_lock_test.go b/internal/lease/generations_lock_test.go
index bf83e116f..bae283685 100644
--- a/internal/lease/generations_lock_test.go
+++ b/internal/lease/generations_lock_test.go
@@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"errors"
+ "fmt"
"net/http"
"slices"
"strings"
@@ -26,7 +27,7 @@ import (
var genOn = lease.AcquireOptions{GenerationsOn: true}
func eligibleProofs() hafresh.Proofs {
- return hafresh.Proofs{LocalEligible: func() bool { return true }, SameBoxEmpty: func() (bool, error) { return true, nil }}
+ return hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }, SameBoxEmpty: func() (bool, error) { return true, nil }}
}
func genHeld(t *testing.T, fx *leasetest.LockFixture, prefix string, ttl time.Duration, opts lease.AcquireOptions) *lease.Held {
@@ -137,9 +138,11 @@ func TestGenerationsOffWritesTodaysLock(t *testing.T) {
}
}
-// Generations mode is sticky: every take of a generations lock writes
-// carlos_generation, the switch off or on; the switch adds it over an
-// ordinary lock; off over an ordinary lock, nothing.
+// Generations mode is sticky on an eligible box (Option A: a group
+// member): every take of a generations lock writes carlos_generation, the
+// switch off or on; the switch adds it over an ordinary lock; off over an
+// ordinary lock, nothing. TestIneligibleBoxRefusesGenerationsLocks is the
+// other side.
func TestGenerationsStickyAcrossTakes(t *testing.T) {
now := time.Now()
mine := hafresh.OwnerFor(hafresh.Self{Ref: "a", IID: "i-a"}, 9, true)
@@ -334,3 +337,66 @@ func TestGenerationsObligationRetriesGenMarker(t *testing.T) {
}
requireGenMarker(t, fx, "instances/h", h.LockGeneration())
}
+
+// Option A (8a3d302 for Paul, 2026-11-19): a box that is not eligible for
+// generations (a fixed box, or a group member with the switch off) refuses
+// every generations lock, whatever its state, before writing anything, the
+// switch on or off; over an ordinary lock it takes today's lock, never a
+// generations one, even with the switch on.
+func TestIneligibleBoxRefusesGenerationsLocks(t *testing.T) {
+ now := time.Now()
+ mine := hafresh.OwnerFor(hafresh.Self{Ref: "a", IID: "i-a"}, 9, true)
+ other := hafresh.OwnerFor(hafresh.Self{Ref: "b", IID: "i-b"}, 9, true)
+ genMarker, _ := hafresh.MarkerBody(3, hafresh.Marker{V: 1, Box: "b", IID: "i-b", Clean: true, At: now, Gen: true})
+ expiredOwn, _ := json.Marshal(hafresh.Lock{Generation: 3, ExpiresAt: now.Add(-time.Minute), Owner: mine, GenName: replicagen.Name(3)})
+ expiredOther, _ := json.Marshal(hafresh.Lock{Generation: 3, ExpiresAt: now.Add(-time.Minute), Owner: other, GenName: replicagen.Name(3)})
+ held, _ := json.Marshal(hafresh.Lock{Generation: 3, ExpiresAt: now.Add(time.Minute), Owner: other, GenName: replicagen.Name(3)})
+ ineligible := hafresh.Proofs{
+ LocalEligible: func() bool { return true },
+ SameBoxEmpty: func() (bool, error) { return true, nil },
+ OwnerTerminated: func(string) (bool, error) { return true, nil },
+ GenerationsFast: true,
+ }
+ for _, c := range []struct {
+ name string
+ body []byte
+ }{
+ {"generations marker", genMarker},
+ {"this box's expired generations lock", expiredOwn},
+ {"another box's expired generations lock", expiredOther},
+ {"a held generations lock", held},
+ } {
+ for _, opts := range []lease.AcquireOptions{{}, genOn} {
+ t.Run(fmt.Sprintf("%s, switch on %v", c.name, opts.GenerationsOn), func(t *testing.T) {
+ haBox(t)
+ fx := leasetest.NewLockFixture(t)
+ fx.PutLock("instances/h", c.body)
+ _, err := lease.AcquireHAOptsForTest(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1, Box: "a", IID: "i-a", Lifetime: "L1"}, ineligible, lease.LeaseTTL, opts)
+ var re *lease.RefusedError
+ if !errors.As(err, &re) || re.Reason != hafresh.ReasonGenerationsIneligible {
+ t.Fatalf("acquire = %v, want the ineligible refusal", err)
+ }
+ if r := fx.Requests(); !slices.Equal(r, []string{"GET instances/h/lock.json"}) {
+ t.Fatalf("requests %v, want the one read", r)
+ }
+ if !bytes.Equal(fx.LockBody("instances/h"), c.body) {
+ t.Fatalf("the lock changed: %s", fx.LockBody("instances/h"))
+ }
+ })
+ }
+ }
+ t.Run("ordinary marker, switch on", func(t *testing.T) {
+ haBox(t)
+ fx := leasetest.NewLockFixture(t)
+ ordinary, _ := hafresh.MarkerBody(3, hafresh.Marker{V: 1, Box: "b", IID: "i-b", Clean: true, At: now})
+ fx.PutLock("instances/h", ordinary)
+ h, err := lease.AcquireHAOptsForTest(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1, Box: "a", IID: "i-a", Lifetime: "L1"}, ineligible, lease.LeaseTTL, genOn)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer h.Release(ctx)
+ if v := lockView(t, fx, "instances/h"); v.Lock.Generation != 4 || v.Generations() || h.GenName() != "" {
+ t.Fatalf("took %+v, want today's lock at generation 4", v.Lock)
+ }
+ })
+}
diff --git a/internal/lease/gentake_minio_test.go b/internal/lease/gentake_minio_test.go
index 50f634ae0..731971af7 100644
--- a/internal/lease/gentake_minio_test.go
+++ b/internal/lease/gentake_minio_test.go
@@ -271,7 +271,7 @@ func (m minioGen) take(t *testing.T) {
t.Fatal("A's first wake wrote no head.json")
}
terminated := func(iid string) (bool, error) { return iid == "i-a", nil }
- bHeld, err := acquireB(fx, ttl, hafresh.Proofs{LocalEligible: func() bool { return true }, OwnerTerminated: terminated, GenerationsFast: true})
+ bHeld, err := acquireB(fx, ttl, hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }, OwnerTerminated: terminated, GenerationsFast: true})
if err != nil {
t.Fatalf("B with fast, A terminated: %v", err)
}
diff --git a/internal/lease/gentakeover_test.go b/internal/lease/gentakeover_test.go
index 0f5f57206..75a706fae 100644
--- a/internal/lease/gentakeover_test.go
+++ b/internal/lease/gentakeover_test.go
@@ -374,14 +374,14 @@ func TestTerminatedHolderTakenOnProofAlone(t *testing.T) {
terminated := func(iid string) (bool, error) { asked = append(asked, iid); return iid == "i-a", nil }
running := func(string) (bool, error) { return false, nil }
eligible := func() bool { return true }
- requireHeldNothingWritten(t, fx, lw, ttl, hafresh.Proofs{LocalEligible: eligible, OwnerTerminated: terminated}, v.Lock.ExpiresAt, "B without fast")
+ requireHeldNothingWritten(t, fx, lw, ttl, hafresh.Proofs{GenerationsEligible: true, LocalEligible: eligible, OwnerTerminated: terminated}, v.Lock.ExpiresAt, "B without fast")
if len(asked) != 0 {
t.Fatalf("without fast the termination proof was asked about an unexpired lock: %v", asked)
}
- requireHeldNothingWritten(t, fx, lw, ttl, hafresh.Proofs{LocalEligible: eligible, OwnerTerminated: running, GenerationsFast: true}, v.Lock.ExpiresAt, "B with fast, A not terminated")
- requireHeldNothingWritten(t, fx, lw, ttl, hafresh.Proofs{LocalEligible: eligible, GenerationsFast: true}, v.Lock.ExpiresAt, "B with fast, no proof wired")
+ requireHeldNothingWritten(t, fx, lw, ttl, hafresh.Proofs{GenerationsEligible: true, LocalEligible: eligible, OwnerTerminated: running, GenerationsFast: true}, v.Lock.ExpiresAt, "B with fast, A not terminated")
+ requireHeldNothingWritten(t, fx, lw, ttl, hafresh.Proofs{GenerationsEligible: true, LocalEligible: eligible, GenerationsFast: true}, v.Lock.ExpiresAt, "B with fast, no proof wired")
- bHeld, err := acquireB(fx, ttl, hafresh.Proofs{LocalEligible: eligible, OwnerTerminated: terminated, GenerationsFast: true})
+ bHeld, err := acquireB(fx, ttl, hafresh.Proofs{GenerationsEligible: true, LocalEligible: eligible, OwnerTerminated: terminated, GenerationsFast: true})
if err != nil {
t.Fatalf("B with fast, A terminated: %v", err)
}
diff --git a/internal/lease/ha.go b/internal/lease/ha.go
index e8efdc565..9227f0dfd 100644
--- a/internal/lease/ha.go
+++ b/internal/lease/ha.go
@@ -70,7 +70,11 @@ func AcquireHA(ctx context.Context, bucket, prefix, region string, base hafresh.
// (CARLOS_HA_GENERATIONS on or fast): the take writes a generations lock
// (carlos_generation) over any lock. Off, the take still writes one over a
// generations lock: the mode is sticky (classifyAndTake), so off never
-// turns a generations host back.
+// turns a generations host back. Only a box whose proofs say it is
+// eligible (hafresh.Proofs.GenerationsEligible, Option A) takes a
+// generations lock at all: without that, DecideAcquire refuses every
+// one, and GenerationsOn is ignored, so an ineligible box never writes
+// one either.
type AcquireOptions struct {
GenerationsOn bool
}
@@ -91,6 +95,9 @@ func acquireHATTL(ctx context.Context, bucket, prefix, region string, base hafre
}
func acquireHARestricted(ctx context.Context, bucket, prefix, region string, base hafresh.Marker, p hafresh.Proofs, ttl time.Duration, allow func(hafresh.View) error, opts AcquireOptions) (*Held, error) {
+ if !p.GenerationsEligible {
+ opts.GenerationsOn = false // Option A: an ineligible box writes no generations lock
+ }
if p.LocalEligible == nil || !p.LocalEligible() {
return nil, &RefusedError{Reason: hafresh.ReasonPoolIneligible}
}
diff --git a/internal/lease/ha_observe_test.go b/internal/lease/ha_observe_test.go
index 3afb1eb03..1a640b2f1 100644
--- a/internal/lease/ha_observe_test.go
+++ b/internal/lease/ha_observe_test.go
@@ -50,9 +50,10 @@ func TestAcquireHAObserveRefusal(t *testing.T) {
return false, nil
}
p := hafresh.Proofs{
- LocalEligible: func() bool { return mode != "pool" },
- SameBoxEmpty: proof,
- OwnerTerminated: func(string) (bool, error) { return proof() },
+ GenerationsEligible: true,
+ LocalEligible: func() bool { return mode != "pool" },
+ SameBoxEmpty: proof,
+ OwnerTerminated: func(string) (bool, error) { return proof() },
ObserveRefusal: func(v hafresh.View, d hafresh.Decision) {
calls++
if d != want || !reflect.DeepEqual(v.Lock, expected.Lock) || v.ETag == "" || v.Absent {
diff --git a/internal/lease/ha_test.go b/internal/lease/ha_test.go
index 15bb220af..8a1143352 100644
--- a/internal/lease/ha_test.go
+++ b/internal/lease/ha_test.go
@@ -91,7 +91,7 @@ func TestAcquireHAMarkerCostsOneGetOnePut(t *testing.T) {
fx := leasetest.NewLockFixture(t)
body, _ := hafresh.MarkerBody(3, hafresh.Marker{V: 1, Box: "b", IID: "i-b", Clean: true})
fx.PutLock("instances/h", body)
- h, err := lease.AcquireHA(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1, Box: "a", IID: "i-a"}, hafresh.Proofs{LocalEligible: func() bool { return true }})
+ h, err := lease.AcquireHA(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1, Box: "a", IID: "i-a"}, hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }})
if err != nil || !h.HA() {
t.Fatal(err)
}
@@ -113,7 +113,7 @@ func TestAcquireHAMarkerCostsOneGetOnePut(t *testing.T) {
func TestAcquireHAFirstWakeCostsOneGetOneListOnePut(t *testing.T) {
haBox(t)
fx := leasetest.NewLockFixture(t)
- h, err := lease.AcquireHA(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1}, hafresh.Proofs{LocalEligible: func() bool { return true }})
+ h, err := lease.AcquireHA(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1}, hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }})
if err != nil {
t.Fatal(err)
}
@@ -139,7 +139,7 @@ func TestAcquireHAReclassifiesOnConflict(t *testing.T) {
fx.BeforeWrite(func(m, k string) {
fx.PutLock("instances/h", leaseBody(hafresh.OwnerFor(hafresh.Self{Ref: "c", IID: "i-c"}, 1, true), time.Now().Add(time.Hour)))
})
- _, err := lease.AcquireHA(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1}, hafresh.Proofs{LocalEligible: func() bool { return true }})
+ _, err := lease.AcquireHA(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1}, hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }})
var held *lease.HeldError
if !errors.As(err, &held) || !strings.Contains(held.Owner, "ref=c") {
t.Fatalf("did not reclassify: %v", err)
@@ -162,7 +162,7 @@ func TestAcquireHAGivesUpAfterThreeRounds(t *testing.T) {
}
fx.PutLock("instances/h", marker())
fx.BeforeWrite(func(m, k string) { fx.PutLock("instances/h", marker()) })
- if _, err := lease.AcquireHA(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1}, hafresh.Proofs{LocalEligible: func() bool { return true }}); err == nil {
+ if _, err := lease.AcquireHA(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1}, hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }}); err == nil {
t.Fatal("acquired a lock that never held still")
}
want := slices.Repeat([]string{"GET instances/h/lock.json", "PUT instances/h/lock.json"}, 3)
@@ -175,7 +175,7 @@ func TestAcquireHAFirstWakeRefusesLeftovers(t *testing.T) {
haBox(t)
fx := leasetest.NewLockFixture(t)
fx.PutObject("instances/h/files/0/manifest.json", []byte(`{}`))
- _, err := lease.AcquireHA(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1}, hafresh.Proofs{LocalEligible: func() bool { return true }})
+ _, err := lease.AcquireHA(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1}, hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }})
var r *lease.RefusedError
if !errors.As(err, &r) || r.Reason != lease.ReasonLeftoverData || slices.ContainsFunc(fx.Requests(), func(s string) bool { return strings.HasPrefix(s, "PUT") }) {
t.Fatal(err)
@@ -188,7 +188,7 @@ func TestAcquireHARefusesWithoutWriting(t *testing.T) {
other := hafresh.OwnerFor(hafresh.Self{Ref: "b", IID: "i-b"}, 9, true)
mine := hafresh.OwnerFor(hafresh.Self{Ref: "a", IID: "i-a", Account: "111122223333", Region: "eu-west-1"}, 9, true)
empty := func(ok bool) hafresh.Proofs {
- return hafresh.Proofs{LocalEligible: func() bool { return true }, SameBoxEmpty: func() (bool, error) { return ok, nil }}
+ return hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }, SameBoxEmpty: func() (bool, error) { return ok, nil }}
}
for _, c := range []struct {
name string
@@ -236,7 +236,7 @@ func TestAcquireHARefusesWithoutSelf(t *testing.T) {
t.Fatal(err)
}
fx := leasetest.NewLockFixture(t)
- if _, err := lease.AcquireHA(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1}, hafresh.Proofs{LocalEligible: func() bool { return true }}); !errors.Is(err, lease.ErrNoSelf) || len(fx.Requests()) != 0 {
+ if _, err := lease.AcquireHA(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1}, hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }}); !errors.Is(err, lease.ErrNoSelf) || len(fx.Requests()) != 0 {
t.Fatal(err)
}
}
@@ -256,7 +256,7 @@ func TestAcquireHARefusesWithoutInstanceID(t *testing.T) {
t.Fatal(err)
}
fx := leasetest.NewLockFixture(t)
- if _, err := lease.AcquireHA(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1}, hafresh.Proofs{LocalEligible: func() bool { return true }}); !errors.Is(err, lease.ErrNoSelf) || len(fx.Requests()) != 0 {
+ if _, err := lease.AcquireHA(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1}, hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }}); !errors.Is(err, lease.ErrNoSelf) || len(fx.Requests()) != 0 {
t.Fatalf("%+v: %v after %v", self, err, fx.Requests())
}
}
@@ -269,7 +269,7 @@ func TestAcquireHALateAckWritesUncleanMarker(t *testing.T) {
haBox(t)
fx := leasetest.NewLockFixture(t)
delayPutAck(t, fx, 4*time.Second)
- if _, err := lease.AcquireHATTL(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1, Box: "a", IID: "i-a"}, hafresh.Proofs{LocalEligible: func() bool { return true }}, 3*time.Second); err == nil {
+ if _, err := lease.AcquireHATTL(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1, Box: "a", IID: "i-a"}, hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }}, 3*time.Second); err == nil {
t.Fatal("late ack accepted")
}
v, _ := hafresh.DecodeLock(fx.LockBody("instances/h"), "")
@@ -380,7 +380,7 @@ func TestHAAcquireRefusedWithoutObligationStore(t *testing.T) {
t.Cleanup(lease.ResetForTest)
lease.SetSelf(hafresh.Self{Ref: "a", IID: "i-a", Account: "111122223333", Region: "eu-west-1"})
fx := leasetest.NewLockFixture(t)
- if _, err := lease.AcquireHA(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1}, hafresh.Proofs{LocalEligible: func() bool { return true }}); !errors.Is(err, lease.ErrNoObligationStore) || len(fx.Requests()) != 0 {
+ if _, err := lease.AcquireHA(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1}, hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }}); !errors.Is(err, lease.ErrNoObligationStore) || len(fx.Requests()) != 0 {
t.Fatal(err)
}
}
@@ -398,7 +398,7 @@ func TestAcquireCleanupObligationSurvivesRestart(t *testing.T) {
delayPutAck(t, fx, 4*time.Second) // the acquire's PUT
// The marker's PUT fails with an error the SDK does not retry.
fx.FailNextMatching(http.MethodPut, http.StatusForbidden, func(_ string, b []byte) bool { return bytes.Contains(b, []byte("carlos_release")) })
- _, err := lease.AcquireHATTL(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1, Box: "a", IID: "i-a"}, hafresh.Proofs{LocalEligible: func() bool { return true }}, 3*time.Second)
+ _, err := lease.AcquireHATTL(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1, Box: "a", IID: "i-a"}, hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }}, 3*time.Second)
var oe *lease.ObligationError
if !errors.As(err, &oe) || len(dirFiles(t, dir)) != 1 {
t.Fatalf("not persisted: %v", err)
@@ -408,7 +408,7 @@ func TestAcquireCleanupObligationSurvivesRestart(t *testing.T) {
if err := lease.SetObligationDir(dir); err != nil || len(lease.PendingObligations()) != 1 {
t.Fatalf("not loaded: %v", err)
}
- h, err := lease.AcquireHA(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1, Box: "a", IID: "i-a"}, hafresh.Proofs{LocalEligible: func() bool { return true }})
+ h, err := lease.AcquireHA(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1, Box: "a", IID: "i-a"}, hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }})
if err != nil {
t.Fatal(err)
}
@@ -431,12 +431,12 @@ func TestAcquireHAWithAFailingObligationReadsNothing(t *testing.T) {
fx := leasetest.NewLockFixture(t)
delayPutAck(t, fx, 2*time.Second)
fx.FailNextMatching(http.MethodPut, http.StatusForbidden, func(_ string, b []byte) bool { return bytes.Contains(b, []byte("carlos_release")) })
- if _, err := lease.AcquireHATTL(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1}, hafresh.Proofs{LocalEligible: func() bool { return true }}, time.Second); err == nil {
+ if _, err := lease.AcquireHATTL(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1}, hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }}, time.Second); err == nil {
t.Fatal("late ack accepted")
}
fx.FailNextMatching(http.MethodPut, http.StatusForbidden, func(_ string, b []byte) bool { return bytes.Contains(b, []byte("carlos_release")) })
before := len(fx.Requests())
- _, err := lease.AcquireHA(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1}, hafresh.Proofs{LocalEligible: func() bool { return true }})
+ _, err := lease.AcquireHA(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1}, hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }})
var oe *lease.ObligationError
if !errors.As(err, &oe) {
t.Fatal(err)
@@ -480,7 +480,7 @@ func TestAcquireHALogsTheWinningRule(t *testing.T) {
other := hafresh.OwnerFor(hafresh.Self{Ref: "b", IID: "i-b"}, 7, true)
clean, _ := hafresh.MarkerBody(3, hafresh.Marker{V: 1, Box: "b", IID: "i-b", Clean: true})
unclean, _ := hafresh.MarkerBody(3, hafresh.Marker{V: 1, Box: "b", IID: "i-b"})
- proofs := hafresh.Proofs{LocalEligible: func() bool { return true },
+ proofs := hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true },
SameBoxEmpty: func() (bool, error) { return true, nil },
OwnerTerminated: func(iid string) (bool, error) { return iid == "i-b", nil },
}
diff --git a/internal/lease/haduty_test.go b/internal/lease/haduty_test.go
index c1a382cfa..aada2ba91 100644
--- a/internal/lease/haduty_test.go
+++ b/internal/lease/haduty_test.go
@@ -31,11 +31,11 @@ func TestDutyAcquireRestrictionOnly(t *testing.T) {
}
denied := errors.New("duty-denied")
calls := 0
- _, err := lease.AcquireHAForDuty(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{}, hafresh.Proofs{LocalEligible: func() bool { return true }}, func(hafresh.View) error { calls++; return denied })
+ _, err := lease.AcquireHAForDuty(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{}, hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }}, func(hafresh.View) error { calls++; return denied })
if !errors.Is(err, denied) || calls != 1 || len(writes(fx)) != 0 {
t.Fatalf("err=%v calls=%d writes=%v", err, calls, writes(fx))
}
- h, err := lease.AcquireHAForDuty(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{}, hafresh.Proofs{LocalEligible: func() bool { return true }}, func(hafresh.View) error { return nil })
+ h, err := lease.AcquireHAForDuty(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{}, hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }}, func(hafresh.View) error { return nil })
if state == "absent" || state == "marker" {
if err != nil {
t.Fatal(err)
@@ -63,7 +63,7 @@ func TestDutyAcquireRestrictionOnly(t *testing.T) {
}
})
calls := 0
- _, err := lease.AcquireHAForDuty(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{}, hafresh.Proofs{LocalEligible: func() bool { return true }}, func(v hafresh.View) error {
+ _, err := lease.AcquireHAForDuty(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{}, hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }}, func(v hafresh.View) error {
calls++
if v.Lock.Generation != int64(calls+3) {
t.Errorf("stale view %+v", v)
@@ -90,7 +90,7 @@ func TestDutyAcquireRestrictionOnlyReclassifiedPeer(t *testing.T) {
})
denied := errors.New("peer duty refused")
calls, proofs := 0, 0
- h, err := lease.AcquireHAForDuty(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{}, hafresh.Proofs{LocalEligible: func() bool { return true }, OwnerTerminated: func(string) (bool, error) { proofs++; return true, nil }}, func(v hafresh.View) error {
+ h, err := lease.AcquireHAForDuty(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{}, hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }, OwnerTerminated: func(string) (bool, error) { proofs++; return true, nil }}, func(v hafresh.View) error {
calls++
if calls == 1 && v.Lock.Release != nil && v.Lock.Release.Box == "a" {
return nil
diff --git a/internal/lease/pools_test.go b/internal/lease/pools_test.go
index 98f42ae83..cf35a9246 100644
--- a/internal/lease/pools_test.go
+++ b/internal/lease/pools_test.go
@@ -31,7 +31,7 @@ func TestAcquireHAPoolEligibility(t *testing.T) {
fx.PutLock("instances/h", leaseBody(hafresh.OwnerFor(hafresh.Self{Ref: "b", IID: "i-b"}, 1, true), expires))
}
calls := 0
- p := hafresh.Proofs{SameBoxEmpty: func() (bool, error) { calls++; return true, nil }, OwnerTerminated: func(string) (bool, error) { calls++; return true, nil }}
+ p := hafresh.Proofs{GenerationsEligible: true, SameBoxEmpty: func() (bool, error) { calls++; return true, nil }, OwnerTerminated: func(string) (bool, error) { calls++; return true, nil }}
h, err := lease.AcquireHA(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{}, p)
if h != nil {
h.Release(ctx)
@@ -59,7 +59,7 @@ func TestPoolWithdrawalBetweenCASRounds(t *testing.T) {
eligible = false
}
})
- p := hafresh.Proofs{LocalEligible: func() bool { return eligible }}
+ p := hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return eligible }}
h, err := lease.AcquireHAForDuty(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{}, p, func(hafresh.View) error { allows++; return nil })
if h != nil {
h.Release(ctx)
@@ -75,7 +75,7 @@ func TestPoolRefusalLeavesOwedReleaseForRetry(t *testing.T) {
now := time.Now()
t.Cleanup(lease.SetOwedClockForTest(func() time.Time { return now }))
fx := locktest.NewLockFixture(t)
- h, err := lease.AcquireHA(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{}, hafresh.Proofs{LocalEligible: func() bool { return true }})
+ h, err := lease.AcquireHA(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{}, hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }})
if err != nil {
t.Fatal(err)
}
@@ -87,7 +87,7 @@ func TestPoolRefusalLeavesOwedReleaseForRetry(t *testing.T) {
t.Fatal("missing obligation")
}
before := len(fx.Requests())
- _, err = lease.AcquireHA(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{}, hafresh.Proofs{LocalEligible: func() bool { return false }})
+ _, err = lease.AcquireHA(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{}, hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return false }})
var refused *lease.RefusedError
if !errors.As(err, &refused) || refused.Reason != hafresh.ReasonPoolIneligible || len(fx.Requests()) != before || len(lease.PendingObligations()) != 1 {
t.Fatalf("err=%v requests=%v", err, fx.Requests()[before:])
diff --git a/internal/lease/release_test.go b/internal/lease/release_test.go
index 23d13351c..51d3daf30 100644
--- a/internal/lease/release_test.go
+++ b/internal/lease/release_test.go
@@ -35,7 +35,7 @@ func haHeld(t *testing.T, fx *leasetest.LockFixture, prefix string) *lease.Held
func haHeldTTL(t *testing.T, fx *leasetest.LockFixture, prefix string, ttl time.Duration) *lease.Held {
t.Helper()
- h, err := lease.AcquireHATTL(ctx, fx.Bucket, prefix, "", hafresh.Marker{V: 1, Box: "a", IID: "i-a", Lifetime: "L1"}, hafresh.Proofs{LocalEligible: func() bool { return true }}, ttl)
+ h, err := lease.AcquireHATTL(ctx, fx.Bucket, prefix, "", hafresh.Marker{V: 1, Box: "a", IID: "i-a", Lifetime: "L1"}, hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }}, ttl)
if err != nil {
t.Fatal(err)
}
@@ -413,7 +413,7 @@ func TestMarkerPutIsOneRequestPerAttempt(t *testing.T) {
now = t0.Add(time.Minute)
attempt("RetryPending", func() error { return lease.RetryPending(ctx) })
attempt("AcquireHA's settle", func() error {
- _, err := lease.AcquireHA(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1}, hafresh.Proofs{LocalEligible: func() bool { return true }})
+ _, err := lease.AcquireHA(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1}, hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }})
return err
})
}
diff --git a/internal/lease/termination_proof_test.go b/internal/lease/termination_proof_test.go
index 346ad9d84..37046bf77 100644
--- a/internal/lease/termination_proof_test.go
+++ b/internal/lease/termination_proof_test.go
@@ -146,7 +146,7 @@ func TestTerminationProofAcquireOnly(t *testing.T) {
body, _ := json.Marshal(hafresh.Lock{Generation: 1, Owner: owner, ExpiresAt: expiry})
fx.PutLock("instances/shop", body)
fallback := 0
- p := hafresh.Proofs{LocalEligible: func() bool { return true }, OwnerTerminated: func(iid string) (bool, error) { fallback++; return iid == "i-1123456789abcdef0", nil }}
+ p := hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }, OwnerTerminated: func(iid string) (bool, error) { fallback++; return iid == "i-1123456789abcdef0", nil }}
ctx := WithTerminationProof(context.Background(), adapter)
if mode == "equality" || mode == "unbound equality" {
v, err := readView(ctx, client, fx.Bucket, "instances/shop/lock.json")
@@ -244,7 +244,7 @@ func TestTerminationProofRequestBudget(t *testing.T) {
var wg sync.WaitGroup
for i := 0; i < 20; i++ {
wg.Go(func() {
- held, err := AcquireHA(ctx, fx.Bucket, fmt.Sprintf("instances/shop-%d", i), me.Region, hafresh.Marker{Lifetime: "life"}, hafresh.Proofs{LocalEligible: func() bool { return true }})
+ held, err := AcquireHA(ctx, fx.Bucket, fmt.Sprintf("instances/shop-%d", i), me.Region, hafresh.Marker{Lifetime: "life"}, hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }})
if held != nil {
_ = held.Release(context.Background())
}
@@ -281,7 +281,7 @@ func TestTerminationProofRequestBudget(t *testing.T) {
}
seconds.Store(10)
for i := 0; i < 20; i++ {
- held, err := AcquireHA(ctx, fx.Bucket, fmt.Sprintf("instances/shop-%d", i), me.Region, hafresh.Marker{Lifetime: "life"}, hafresh.Proofs{LocalEligible: func() bool { return true }})
+ held, err := AcquireHA(ctx, fx.Bucket, fmt.Sprintf("instances/shop-%d", i), me.Region, hafresh.Marker{Lifetime: "life"}, hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }})
if err != nil {
t.Fatal(err)
}
@@ -323,7 +323,7 @@ func TestRequestConfirmationEnqueuesFromAcquire(t *testing.T) {
t.Fatal(err)
}
view := hafresh.View{Lock: hafresh.Lock{Owner: hafresh.OwnerFor(hafresh.Self{Ref: "departed", IID: "i-1123456789abcdef0"}, 1, true), ExpiresAt: time.Now().Add(-time.Hour)}}
- p := bindTerminationProof(WithTerminationProof(t.Context(), adapter), client, fx.Bucket, "instances/shop", me.Region, hafresh.Marker{Lifetime: "life"}, me, view, hafresh.Proofs{LocalEligible: func() bool { return true }})
+ p := bindTerminationProof(WithTerminationProof(t.Context(), adapter), client, fx.Bucket, "instances/shop", me.Region, hafresh.Marker{Lifetime: "life"}, me, view, hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }})
if yes, err := p.OwnerTerminated("i-1123456789abcdef0"); yes || err == nil || notified != 1 {
t.Fatalf("journal failure yes=%v err=%v notifications=%d", yes, err, notified)
}
diff --git a/internal/lease/unclean_marker_test.go b/internal/lease/unclean_marker_test.go
index 4813306e5..a96d98805 100644
--- a/internal/lease/unclean_marker_test.go
+++ b/internal/lease/unclean_marker_test.go
@@ -31,7 +31,7 @@ func boxB() {
}
func acquireAsB(fx *locktest.LockFixture, prefix string, ttl time.Duration) (*lease.Held, error) {
- return lease.AcquireHATTL(ctx, fx.Bucket, prefix, "", hafresh.Marker{V: 1, Lifetime: "L1"}, hafresh.Proofs{LocalEligible: func() bool { return true }}, ttl)
+ return lease.AcquireHATTL(ctx, fx.Bucket, prefix, "", hafresh.Marker{V: 1, Lifetime: "L1"}, hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }}, ttl)
}
// The containment (2026-11-12) leaves the fast handovers alone: a clean
@@ -181,7 +181,7 @@ func TestUnsettledMarkerIsHeldForALeaseTerm(t *testing.T) {
boxB()
}
before := len(writes(fx))
- _, err := lease.AcquireHATTL(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1, Lifetime: "L1"}, hafresh.Proofs{LocalEligible: func() bool { return true }}, ttl)
+ _, err := lease.AcquireHATTL(ctx, fx.Bucket, "instances/h", "", hafresh.Marker{V: 1, Lifetime: "L1"}, hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }}, ttl)
var he *lease.HeldError
if !errors.As(err, &he) || he.Owner != v.Lock.Owner || !he.ExpiresAt.Equal(opens) {
t.Fatalf("%s before the term: %v (want held by %q until %v)", who, err, v.Lock.Owner, opens)
@@ -269,7 +269,7 @@ func TestUnsettledMarkerKeepsALateWriteOutOfTheSuccessorsHistory(t *testing.T) {
t.Setenv("AWS_CONFIG_FILE", filepath.Join(t.TempDir(), "absent"))
t.Setenv("AWS_SHARED_CREDENTIALS_FILE", filepath.Join(t.TempDir(), "absent"))
t.Setenv("CARLOS_S3_ENDPOINT", srv.URL)
- eligible := hafresh.Proofs{LocalEligible: func() bool { return true }, GenerationsFast: true}
+ eligible := hafresh.Proofs{GenerationsEligible: true, LocalEligible: func() bool { return true }, GenerationsFast: true}
acquire := func() (*lease.Held, error) {
return lease.AcquireHATTL(ctx, bucket, prefix, region, hafresh.Marker{V: 1, Lifetime: "L1"}, eligible, ttl)
}
@@ -410,9 +410,9 @@ func TestUnsettledGenMarkerTakenAtOnce(t *testing.T) {
boxB()
fx.setPhase("b-held")
eligible := func() bool { return true }
- requireHeldNothingWritten(t, fx, lw, ttl, hafresh.Proofs{LocalEligible: eligible}, m.At.Add(ttl), "B without fast")
+ requireHeldNothingWritten(t, fx, lw, ttl, hafresh.Proofs{GenerationsEligible: true, LocalEligible: eligible}, m.At.Add(ttl), "B without fast")
- bHeld, err := acquireB(fx, ttl, hafresh.Proofs{LocalEligible: eligible, GenerationsFast: true})
+ bHeld, err := acquireB(fx, ttl, hafresh.Proofs{GenerationsEligible: true, LocalEligible: eligible, GenerationsFast: true})
if err != nil {
t.Fatalf("B with fast: %v", err)
}
diff --git a/internal/sim/regionha/actions_test.go b/internal/sim/regionha/actions_test.go
index cb985575f..a6ecdde05 100644
--- a/internal/sim/regionha/actions_test.go
+++ b/internal/sim/regionha/actions_test.go
@@ -57,11 +57,13 @@ func (w *world) decideAcquire(b *box, h string, v hafresh.View) hafresh.Decision
}
}
}
+ // Every box is a group member eligible for generations locks (Option A:
+ // GenerationsEligible); a fixed box's refusal is hafresh's own test.
// GenerationsFast is every box's switch, `fast`: it changes the table
// only for a generations lock (View.Generations), which a host in
// generations mode writes (take). For any other lock the table is the
// one above it, whatever the flag says.
- d := hafresh.DecideAcquire(v, b.Self, w.now(), ttlTicks*tick, hafresh.Proofs{LocalEligible: func() bool { return true }, SameBoxEmpty: proof, OwnerTerminated: w.ownerTerminated, GenerationsFast: true})
+ d := hafresh.DecideAcquire(v, b.Self, w.now(), ttlTicks*tick, hafresh.Proofs{LocalEligible: func() bool { return true }, SameBoxEmpty: proof, OwnerTerminated: w.ownerTerminated, GenerationsEligible: true, GenerationsFast: true})
if !on("expiry-authorizes") && d.Action == hafresh.ActRefuse && d.Reason == hafresh.ReasonOtherExpired {
d = hafresh.Decision{Action: hafresh.ActTake, Reason: "expired"}
}
diff --git a/internal/sim/regionha/duties_model_test.go b/internal/sim/regionha/duties_model_test.go
index 8893ee149..52fe43ab5 100644
--- a/internal/sim/regionha/duties_model_test.go
+++ b/internal/sim/regionha/duties_model_test.go
@@ -324,7 +324,8 @@ func (d *dutyWorld) adopt(b *dutyBox, s *dutyScan, hi int) bool {
now = v.Lock.ExpiresAt.Add(time.Nanosecond)
}
// GenerationsFast: inert until the model writes generations locks (Task 11).
- p := hafresh.Proofs{LocalEligible: func() bool { return true }, GenerationsFast: true, OwnerTerminated: func(iid string) (bool, error) {
+ // GenerationsEligible: every adopter is a group member (Option A).
+ p := hafresh.Proofs{LocalEligible: func() bool { return true }, GenerationsEligible: true, GenerationsFast: true, OwnerTerminated: func(iid string) (bool, error) {
if !b.proofs[s.dead] {
d.proofReads++
if !d.storeDown && d.proofs[s.dead] {