carlos / platform Public

grouproll: under DR-4, refuse to roll a member a lock names

Dev W2 2026-11-10 restarted a lease-holding member with no drain: the
roll printed DR-4's lock-free rule and went on (8a3d302 P1).

A DR-4 roll now runs the lock sweep immediately before the first group
write and closes floor-refused (lock_held, floor_config, or the sweep's
own refusal) with no group write. It sweeps again immediately before
apply; a lock or a failed sweep journals lock-refused and returns the
member unchanged through the failed drain's return, which revokes the
permit, restores the shape and closes lock-refused.

The roll fake models the data bucket's locks, and the harness config
names data_bucket and data_prefix. Two ported tests move with it: the
shared outage starts at apply, and a lock read is one call of two
requests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 95514fb96fae05d804ab1db48945f3e4bbc49df1 parent 3a8eabd
6 files changed, +460 −22
  • internal/grouproll/dr4.go +120 −0
  • internal/grouproll/dr4_test.go +258 −0
  • internal/grouproll/fake_test.go +31 −8
  • internal/grouproll/roll.go +37 −11
  • internal/grouproll/roll_test.go +13 −3
  • region_ha_boundary_test.go +1 −0

Intent

Human

<task-notification> <task-id>b1rvxx12e</task-id> <tool-use-id>toolu_01MzVyv5NubvuLS9djLPAHEc</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/669506ff-23ec-45f1-9035-1d29593f2c37/tasks/b1rvxx12e.output</output-file> <status>completed</status> <summary>Background command "Send dennis ha_take issue to owner" completed (exit code 0)</summary> </task-notification>

diff --git a/internal/grouproll/dr4.go b/internal/grouproll/dr4.go
new file mode 100644
index 000000000..0e6db4aa1
--- /dev/null
+++ b/internal/grouproll/dr4.go
@@ -0,0 +1,120 @@
+package grouproll
+
+import (
+ "context"
+ "strings"
+)
+
+// The DR-4 lock rule for a roll (group roll verb spec V13). Under DR-4 a
+// roll restarts the member's edge with no drain, so only a member no lock
+// names may roll ("Replace only lock-free members"). The script printed
+// the rule and went on; the Go verb runs the departures' lock sweep
+// (locksNamingMember) twice:
+//
+// - up front, immediately before the first group write: a lock naming
+// the member, a config without data_bucket or data_prefix, or a sweep
+// that cannot read closes the transaction floor-refused with no group
+// write, as a preflight refusal closes;
+// - again immediately before the action, with the member in Standby and
+// the permit granted (the member may have taken a lease in between):
+// the same findings journal lock-refused and stop the mutation, and
+// the member returns unchanged through the failed drain's return (the
+// roll's return executor, chosen by Classify), which revokes the
+// permit, restores the shape and closes the transaction lock-refused.
+//
+// The drain rule is unchanged: H5 (preAction) covers it.
+
+// dr4Applies: this transaction is a roll under DR-4 (the probe and the
+// departures never reach here with a DR-4 rule to act on).
+func (e *Engine) dr4Applies() bool {
+ return !e.probe && e.kind() == "roll" && e.rule() == "dr4" && !e.seams.skipDR4Locks
+}
+
+// dr4Sweep is locksNamingMember, refusing floor_config when the config
+// cannot name the data bucket and prefix to sweep: never roll blind.
+func (e *Engine) dr4Sweep(ctx context.Context) ([]string, error) {
+ if e.c.DataBucket == nil || e.c.DataPrefix == nil {
+ return nil, refuse("floor_config")
+ }
+ return e.locksNamingMember(ctx)
+}
+
+// lockHeld is the lock_held refusal for the hosts (the first 20, as the
+// H5 check names them).
+func lockHeld(held []string) error {
+ if len(held) > 20 {
+ held = held[:20]
+ }
+ return refuse("lock_held", "hosts", strings.Join(held, ", "))
+}
+
+// dr4UpFront is the first sweep. It returns nil when the member is lock
+// free; otherwise it closes the transaction floor-refused, says the floor
+// refusal and returns the finding (lock_held, floor_config, or the
+// sweep's own refusal). A journal failure or an interrupt is returned as
+// itself and leaves the transaction open.
+func (e *Engine) dr4UpFront(ctx context.Context) error {
+ held, err := e.dr4Sweep(ctx)
+ if err != nil && !refusalOrUncertain(err) {
+ return err
+ }
+ if err == nil {
+ if len(held) == 0 {
+ return nil
+ }
+ err = lockHeld(held)
+ }
+ if _, jerr := e.event("done", map[string]any{"outcome": "floor-refused", "reason": reasonOf(err)}); jerr != nil {
+ return jerr
+ }
+ if ferr := e.s.Finish(); ferr != nil {
+ return ferr
+ }
+ e.say("floor", Text("floor_refused"))
+ return err
+}
+
+// dr4PreAction is the second sweep, immediately before the action. A
+// finding journals lock-refused (its reason, and the hosts when locks
+// named the member), says it, and stops lock-refused; the caller returns
+// the member unchanged.
+func (e *Engine) dr4PreAction(ctx context.Context) error {
+ held, err := e.dr4Sweep(ctx)
+ if err != nil && !refusalOrUncertain(err) {
+ return err
+ }
+ if err == nil && len(held) == 0 {
+ return nil
+ }
+ row := map[string]any{"hosts": nil}
+ if err == nil {
+ err = lockHeld(held)
+ hosts := make([]any, len(held))
+ for i, h := range held {
+ hosts[i] = h
+ }
+ row["hosts"] = hosts
+ }
+ row["reason"] = reasonOf(err)
+ if _, jerr := e.event("lock-refused", row); jerr != nil {
+ return jerr
+ }
+ e.say("ALERT", reasonOf(err))
+ return stopped("lock-refused", "floor_refused")
+}
+
+// lockRefusal is the refusal a lock-refused transaction closes with:
+// lock_held naming the hosts, or floor_refused when the sweep could not
+// read (its reason was said when it was journaled).
+func (e *Engine) lockRefusal() error {
+ row, _ := e.last("lock-refused", nil)
+ raw, _ := row["hosts"].([]any)
+ if len(raw) == 0 {
+ return refuse("floor_refused")
+ }
+ held := make([]string, len(raw))
+ for i, h := range raw {
+ held[i] = pyStrOf(h)
+ }
+ return lockHeld(held)
+}
diff --git a/internal/grouproll/dr4_test.go b/internal/grouproll/dr4_test.go
new file mode 100644
index 000000000..03433ba9f
--- /dev/null
+++ b/internal/grouproll/dr4_test.go
@@ -0,0 +1,258 @@
+//go:build linux || darwin
+
+package grouproll
+
+import (
+ "reflect"
+ "strings"
+ "testing"
+)
+
+// A roll under DR-4 (spec V13; dev W2 2026-11-10, agent manager 8a3d302
+// P1): the member's edge restarts with no drain, so the roll must refuse
+// a member a lock names. The sweep runs up front, before any group write,
+// and again immediately before the permit's action.
+
+// mustClosedWithoutGroupWrite: the only write was prepare, the
+// transaction is closed with outcome, and the output said floor_refused.
+func (h *harness) mustClosedWithoutGroupWrite(outcome string) {
+ h.t.Helper()
+ f := h.f
+ if !reflect.DeepEqual(f.writes, []string{"prepare"}) {
+ h.t.Fatalf("writes %v, want only prepare", f.writes)
+ }
+ if f.minimum != 2 || f.desired != 2 || f.maximum != 2 || f.states[fakeIID] != "InService" {
+ h.t.Fatalf("group %d %d %d, member %s", f.minimum, f.desired, f.maximum, f.states[fakeIID])
+ }
+ if f.boxes[fakeIID]["binary_sha256"] != oldSHA {
+ h.t.Fatalf("binary %v", f.boxes[fakeIID]["binary_sha256"])
+ }
+ if h.activeTx() != "" {
+ h.t.Fatalf("transaction %s still open", h.activeTx())
+ }
+ if done, _ := h.txJournal(h.onlyTx()).Last("done", nil); done["outcome"] != outcome {
+ h.t.Fatalf("done %v, want outcome %s", done, outcome)
+ }
+ if !strings.Contains(h.out.String(), Text("floor_refused")) {
+ h.t.Fatalf("output lacks the floor refusal: %s", h.out.String())
+ }
+ mustRetain(h.t, h)
+}
+
+func TestRollDR4RefusesLeaseHolder(t *testing.T) {
+ for name, owner := range map[string]map[string]any{
+ "ref and iid": heldLock(ref(fakeIID), fakeIID),
+ "another form": {"generation": int64(2), "expires_at": "2030-01-01T00:00:00Z",
+ "owner": "legacy:" + fakeIID},
+ } {
+ t.Run(name, func(t *testing.T) {
+ h := newHarness(t, 2)
+ h.f.locks["shop"] = owner
+ h.f.locks["idle"] = nil
+ err := h.runRoll()
+ refusedWith(t, err, "lock_held")
+ if !strings.Contains(err.Error(), "shop") || strings.Contains(err.Error(), "blog") {
+ t.Fatalf("refusal %q, want the member's host only", err)
+ }
+ h.mustClosedWithoutGroupWrite("floor-refused")
+ if floor, _ := h.txJournal(h.onlyTx()).Last("floor", nil); floor["rule"] != "dr4" {
+ t.Fatalf("floor %v", floor)
+ }
+ })
+ }
+}
+
+func TestRollDR4LockFreeProceeds(t *testing.T) {
+ h := newHarness(t, 2)
+ // A release marker naming the member and another box's lock both pass.
+ h.f.locks["shop"] = heldMarker(ref(fakeIID))
+ if err := scenarioStandbyRollOrder(h); err != nil {
+ t.Fatal(err)
+ }
+ if countOf(h.f.ops(), "lock_hosts") != 2 {
+ t.Fatalf("lock sweeps %d, want 2 (up front and before apply): %v", countOf(h.f.ops(), "lock_hosts"), h.f.ops())
+ }
+ for _, v := range []string{"drain", "edge-stop", "fence-clear"} {
+ if countOf(h.f.writes, v) != 0 {
+ t.Fatalf("%s under DR-4: %v", v, h.f.writes)
+ }
+ }
+ j := h.txJournal(h.onlyTx())
+ if floor, _ := j.Last("floor", nil); floor["rule"] != "dr4" {
+ t.Fatalf("floor %v", floor)
+ }
+ if done, _ := j.Last("done", nil); done["outcome"] != "returned" {
+ t.Fatalf("done %v", done)
+ }
+}
+
+func TestRollDR4MissingDataConfigRefuses(t *testing.T) {
+ for _, key := range []string{"data_bucket", "data_prefix"} {
+ t.Run(key, func(t *testing.T) {
+ h := newHarnessWith(t, stateRoot(t), 2, func(c *Config) {
+ if key == "data_bucket" {
+ c.DataBucket = nil
+ } else {
+ c.DataPrefix = nil
+ }
+ })
+ refusedWith(t, h.runRoll(), "floor_config")
+ if countOf(h.f.ops(), "lock_hosts") != 0 {
+ t.Fatalf("swept without the config: %v", h.f.ops())
+ }
+ h.mustClosedWithoutGroupWrite("floor-refused")
+ })
+ }
+}
+
+func TestRollDR4SweepErrorRefuses(t *testing.T) {
+ cases := map[string]struct {
+ op string
+ fail error
+ }{
+ "listing uncertain": {"lock_hosts", Uncertain{Key: "api"}},
+ "lock read refused": {"lock_get", Refusal{Key: "api"}},
+ }
+ for name, c := range cases {
+ t.Run(name, func(t *testing.T) {
+ h := newHarness(t, 2)
+ h.f.before = func(op string, _ map[string]any) error {
+ if op == c.op {
+ return c.fail
+ }
+ return nil
+ }
+ err := h.runRoll()
+ if !refusalOrUncertain(err) {
+ t.Fatalf("err = %v, want the sweep's refusal", err)
+ }
+ h.mustClosedWithoutGroupWrite("floor-refused")
+ })
+ }
+ t.Run("member names another data bucket", func(t *testing.T) {
+ h := newHarness(t, 2)
+ other := "other-bucket"
+ h.c.DataBucket = &other
+ h.f.c.DataBucket = &other
+ refusedWith(t, h.runRoll(), "data_bucket_mismatch")
+ h.mustClosedWithoutGroupWrite("floor-refused")
+ })
+}
+
+// A lease taken between the up-front sweep and the action: the second
+// sweep, after Standby and the permit, finds it. The member returns
+// unchanged (no apply), the permit is revoked, the shape is restored and
+// the transaction closes refusing with lock_held.
+func TestRollDR4LeaseAppearsBeforeApply(t *testing.T) {
+ h := newHarness(t, 2)
+ f := h.f
+ f.after = func(name string) {
+ if name == "enter" {
+ f.locks["shop"] = heldLock(ref(fakeIID), fakeIID)
+ }
+ }
+ err := h.runRoll()
+ refusedWith(t, err, "lock_held")
+ if !strings.Contains(err.Error(), "shop") {
+ t.Fatalf("refusal %q lacks the host", err)
+ }
+ want := []string{"prepare", "minimum", "enter", "permit", "exit", "minimum", "revoke"}
+ if !reflect.DeepEqual(f.writes, want) {
+ t.Fatalf("writes %v, want %v", f.writes, want)
+ }
+ if f.boxes[fakeIID]["binary_sha256"] != oldSHA || f.states[fakeIID] != "InService" {
+ t.Fatalf("member %v %s", f.boxes[fakeIID]["binary_sha256"], f.states[fakeIID])
+ }
+ if f.minimum != 2 || f.desired != 2 || f.maximum != 2 {
+ t.Fatalf("shape %d %d %d", f.minimum, f.desired, f.maximum)
+ }
+ if f.permit(fakeIID)["state"] != "absent" {
+ t.Fatalf("permit %v", f.permit(fakeIID))
+ }
+ if h.activeTx() != "" {
+ t.Fatalf("transaction %s still open", h.activeTx())
+ }
+ j := h.txJournal(h.onlyTx())
+ if done, _ := j.Last("done", nil); done["outcome"] != "lock-refused" {
+ t.Fatalf("done %v", done)
+ }
+ if _, ok := j.Last("lock-refused", nil); !ok {
+ t.Fatal("no lock-refused row")
+ }
+ if strings.Contains(h.out.String(), "cancel-drain") {
+ t.Fatalf("a DR-4 refusal printed the drain's instruction: %s", h.out.String())
+ }
+ mustRetain(t, h)
+ if _, ok := j.Last("drain-failed", nil); ok {
+ t.Fatal("a DR-4 lock refusal journaled a failed drain")
+ }
+}
+
+// A sweep that fails at the second check fails closed: no apply, the
+// member returns unchanged.
+func TestRollDR4SecondSweepErrorReturnsUnchanged(t *testing.T) {
+ h := newHarness(t, 2)
+ f := h.f
+ entered := false
+ f.after = func(name string) { entered = entered || name == "enter" }
+ f.before = func(op string, _ map[string]any) error {
+ if entered && op == "lock_hosts" {
+ return Uncertain{Key: "api"}
+ }
+ return nil
+ }
+ refusedWith(t, h.runRoll(), "floor_refused")
+ want := []string{"prepare", "minimum", "enter", "permit", "exit", "minimum", "revoke"}
+ if !reflect.DeepEqual(f.writes, want) {
+ t.Fatalf("writes %v, want %v", f.writes, want)
+ }
+ if f.boxes[fakeIID]["binary_sha256"] != oldSHA || h.activeTx() != "" {
+ t.Fatalf("binary %v, active %q", f.boxes[fakeIID]["binary_sha256"], h.activeTx())
+ }
+ if done, _ := h.txJournal(h.onlyTx()).Last("done", nil); done["outcome"] != "lock-refused" {
+ t.Fatalf("done %v", done)
+ }
+ mustRetain(t, h)
+}
+
+// A cut after the floor row and before the first group write: resume
+// sweeps before it lowers the minimum.
+func TestRollDR4ResumeSweepsBeforeFirstGroupWrite(t *testing.T) {
+ h := newHarness(t, 2)
+ f := h.f
+ f.before = func(op string, _ map[string]any) error {
+ if op == "lock_hosts" {
+ panic(fakeDeath{op})
+ }
+ return nil
+ }
+ if !expectDeath(t, func() { h.runRoll() }) {
+ t.Fatal("roll did not die at the sweep")
+ }
+ f.before = nil
+ f.locks["shop"] = heldLock(ref(fakeIID), fakeIID)
+ refusedWith(t, h.resume(), "lock_held")
+ h.mustClosedWithoutGroupWrite("floor-refused")
+}
+
+// A cut after the permit: resume sweeps again before the action.
+func TestRollDR4ResumeAfterPermitSweepsAgain(t *testing.T) {
+ h := newHarness(t, 2)
+ f := h.f
+ f.after = func(name string) {
+ if name == "enter" {
+ f.locks["shop"] = heldLock(ref(fakeIID), fakeIID)
+ }
+ if name == "permit" {
+ panic(fakeDeath{name})
+ }
+ }
+ if !expectDeath(t, func() { h.runRoll() }) {
+ t.Fatal("roll did not die at the permit")
+ }
+ f.after = nil
+ refusedWith(t, h.resume(), "lock_held")
+ if countOf(f.writes, "apply") != 0 {
+ t.Fatalf("applied: %v", f.writes)
+ }
+}
diff --git a/internal/grouproll/fake_test.go b/internal/grouproll/fake_test.go
index 2340b3b2c..8f5e8b423 100644
--- a/internal/grouproll/fake_test.go
+++ b/internal/grouproll/fake_test.go
@@ -135,6 +135,13 @@ type fake struct {
// held is the planned handovers' provider and agent (the held
// branch's HeldFake); nil keeps the roll fake as it was.
held *heldFake
+
+ // dataBucket and locks are the region's data bucket and its host
+ // locks (host: its lock.json body; nil is no lock), which a DR-4
+ // roll's lock sweep reads (spec V13). The held fake's own pair
+ // replaces them when it is set.
+ dataBucket string
+ locks map[string]any
}
// fixedEdges is a box outside the group: its ha_take (nil: none) and how
@@ -159,7 +166,9 @@ func newFake(t *testing.T, n int) *fake {
used: map[[2]string]bool{}, permitBodies: map[string]map[string]any{},
publicationLag: 2 * time.Second, published: map[string]time.Time{},
version: "v0.34.0", targetWarmup: 30 * time.Second, templateRelease: "v0.34.0",
- userID: "AIDAEXAMPLEOPERATOR",
+ userID: "AIDAEXAMPLEOPERATOR",
+ dataBucket: "example-bucket",
+ locks: map[string]any{"blog": heldLock(ref(fakePeer), fakePeer)},
}
f.order = []string{fakeIID, fakePeer}
for i := 2; i < n; i++ {
@@ -770,6 +779,14 @@ func (f *fake) session(iid, verb string, a BoxArgs) (any, error) {
func (f *fake) Bucket(name string) release.Store { return fakeStore{f: f, bucket: name} }
+// lockStore is the data bucket and its locks: the held fake's when set.
+func (f *fake) lockStore() (string, map[string]any) {
+ if f.held != nil {
+ return f.held.dataBucket, f.held.locks
+ }
+ return f.dataBucket, f.locks
+}
+
type fakeStore struct {
release.Store // nil: only Get is modelled
f *fake
@@ -781,7 +798,7 @@ type fakeStore struct {
// floor must skip.
func (s fakeStore) List(ctx context.Context, prefix string) ([]string, error) {
f := s.f
- if f.held != nil && s.bucket == f.held.dataBucket {
+ if bucket, _ := f.lockStore(); s.bucket == bucket {
return s.lockList(prefix)
}
r, err := f.request("edges_list", map[string]any{"prefix": prefix}, func() (any, error) {
@@ -809,7 +826,7 @@ func (s fakeStore) List(ctx context.Context, prefix string) ([]string, error) {
func (s fakeStore) Get(ctx context.Context, key string) ([]byte, string, error) {
f := s.f
- if f.held != nil && s.bucket == f.held.dataBucket {
+ if bucket, _ := f.lockStore(); s.bucket == bucket {
return s.lockGet(key)
}
if channel, ok := strings.CutPrefix(key, "control/system/router/"); ok {
@@ -965,6 +982,10 @@ func newHarnessAt(t *testing.T, root string, n int) *harness {
func newHarnessWith(t *testing.T, root string, n int, configure func(c *Config)) *harness {
t.Helper()
f := newFake(t, n)
+ // A deployment's data bucket and prefix, so a DR-4 roll can sweep the
+ // locks (V13); configure may take them away again.
+ prefix, bucket := "instances", f.dataBucket
+ f.c.DataPrefix, f.c.DataBucket = &prefix, &bucket
if configure != nil {
configure(&f.c)
}
@@ -1407,12 +1428,13 @@ func (f *fake) heldSession(iid, verb string, a BoxArgs) (r any, err error, ok bo
func (s fakeStore) ListDirs(ctx context.Context, prefix string) ([]string, error) {
f := s.f
r, err := f.request("lock_hosts", map[string]any{"bucket": s.bucket, "prefix": prefix}, func() (any, error) {
- if f.held == nil || s.bucket != f.held.dataBucket || prefix != "instances/" {
+ bucket, locks := f.lockStore()
+ if s.bucket != bucket || prefix != "instances/" {
f.violate("lock listing of %s/%s", s.bucket, prefix)
return nil, Uncertain{Key: "api"}
}
var out []string
- for _, host := range sortedKeys(f.held.locks) {
+ for _, host := range sortedKeys(locks) {
out = append(out, "instances/"+host+"/")
}
return out, nil
@@ -1439,7 +1461,7 @@ func (s fakeStore) lockList(prefix string) ([]string, error) {
f.violate("lock key listing of %s", prefix)
return nil, Uncertain{Key: "api"}
}
- if f.held.locks[host] == nil {
+ if _, locks := f.lockStore(); locks[host] == nil {
return []string{}, nil
}
return []string{prefix}, nil
@@ -1453,11 +1475,12 @@ func (s fakeStore) lockList(prefix string) ([]string, error) {
func (s fakeStore) lockGet(key string) ([]byte, string, error) {
f := s.f
r, err := f.request("lock_get", map[string]any{"key": key}, func() (any, error) {
+ _, locks := f.lockStore()
host, ok := lockHost(key)
- if !ok || f.held.locks[host] == nil {
+ if !ok || locks[host] == nil {
return nil, os.ErrNotExist
}
- return json.Marshal(f.held.locks[host])
+ return json.Marshal(locks[host])
})
if err != nil {
return nil, "", err
diff --git a/internal/grouproll/roll.go b/internal/grouproll/roll.go
index c38e5ab30..3d410d9ba 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
+ kind string // failed-probe, divergence-held, drain-failed, drain-moving, lock-refused
r Refusal
}
@@ -65,6 +65,7 @@ type seams struct {
unparkUnknownDrain bool // unknown drain status passes the return
restoreDesiredEarly bool // desired restored before the terminate check
acceptDrainResult bool // a drain whose result is not ok passes
+ skipDR4Locks bool // a DR-4 roll never sweeps the locks (V13)
// The probe's mutants (probe.go).
skipFreshness bool // ExitStandby on an observation of any age
@@ -389,9 +390,9 @@ func (e *Engine) beforeProcess() any {
return e.header["original_process"]
}
-// unchanged is a failed drain: the member returns as it was, with no
-// action run.
-func (e *Engine) unchanged() bool { return e.has("drain-failed", nil) }
+// unchanged is a failed drain, or a DR-4 roll's lock refusal before the
+// action (dr4.go): the member returns as it was, with no action run.
+func (e *Engine) unchanged() bool { return e.has("drain-failed", nil) || e.has("lock-refused", nil) }
// rule is the floor's rule for this transaction; dr4 until one is read.
func (e *Engine) rule() string {
@@ -664,7 +665,7 @@ func (e *Engine) decisionFacts(context string, group *snapshotView, timedOut boo
ActionVerified: e.has("box-action-verified", map[string]any{"action": e.action()}),
AlreadyRestored: e.has("rollback-requested", map[string]any{"already_restored": true}),
FloorChecked: e.kind() != "roll" || floorRead,
- DrainFailed: e.has("drain-failed", nil),
+ DrainFailed: e.unchanged(),
Observed: group != nil,
N: n,
TimedOut: timedOut,
@@ -726,6 +727,15 @@ func (e *Engine) resume(ctx context.Context) error {
return e.s.Finish()
case "return":
return e.returnMember(ctx)
+ case "lower-minimum":
+ // V13: under DR-4 only a lock-free member rolls. Swept
+ // immediately before the first group write, so a refusal
+ // closes the transaction with none.
+ if e.dr4Applies() && !facts.MinimumIntent {
+ if err := e.dr4UpFront(ctx); err != nil {
+ return err
+ }
+ }
}
err = func() error {
switch d.Action {
@@ -839,8 +849,9 @@ func (e *Engine) resume(ctx context.Context) error {
}()
switch {
case err == nil:
- case isStop(err, "drain-failed"):
- // Recorded as drain-failed; classify now chooses the return.
+ case isStop(err, "drain-failed"), isStop(err, "lock-refused"):
+ // Recorded as drain-failed or lock-refused; classify now
+ // chooses the return of the unchanged member.
group = nil
case refusalOrUncertain(err):
opErr = err
@@ -1044,6 +1055,12 @@ func (e *Engine) mutation(ctx context.Context) error {
return err
}
}
+ if action == "apply" && e.dr4Applies() {
+ // V13, immediately before the action: no lock names the member.
+ if err := e.dr4PreAction(ctx); err != nil {
+ return err
+ }
+ }
if _, err := e.event("phase", map[string]any{"phase": "mutation", "action": action}); err != nil {
return err
}
@@ -1109,7 +1126,7 @@ func (e *Engine) rollback(ctx context.Context, iid string) error {
if err := e.restoreHeader(); err != nil {
return err
}
- if e.kind() != "roll" || iid != e.hStr("iid") || e.has("exit-intent", nil) || e.has("drain-failed", nil) {
+ if e.kind() != "roll" || iid != e.hStr("iid") || e.has("exit-intent", nil) || e.unchanged() {
return refuse("rollback_refused")
}
end := e.clock().Add(standbyWait)
@@ -1399,7 +1416,8 @@ func (e *Engine) refuseWhileMoving(status map[string]any) error {
// earlier exit-intent: the gate in front of every ExitStandby (spec r2
// cut; the script skipped it once any exit-intent existed).
func (e *Engine) checkDrainBeforeExit(status map[string]any) error {
- if !e.unchanged() {
+ // A DR-4 lock refusal ran no drain, so no move can be running.
+ if !e.has("drain-failed", nil) {
return nil
}
d, ok := status["drain"].(map[string]any)
@@ -1422,7 +1440,8 @@ func (e *Engine) checkDrainBeforeExit(status map[string]any) error {
// finishReturn is the script's finish_return: lift the fence, revoke a
// remaining permit, record the outcome and close the transaction. A
// failed drain closes drain-failed and refuses with the cancel-drain
-// instruction.
+// instruction; a DR-4 lock refusal closes lock-refused and refuses with
+// what the second sweep found (V13).
func (e *Engine) finishReturn(ctx context.Context, ready *readiness) error {
if ready == nil {
return refuse("record")
@@ -1449,7 +1468,8 @@ func (e *Engine) finishReturn(ctx context.Context, ready *readiness) error {
return refuse("permit")
}
}
- failedDrain := e.unchanged()
+ failedDrain := e.has("drain-failed", nil)
+ lockRefused := e.has("lock-refused", nil)
if e.has("drained", nil) && !failedDrain {
if err := e.drainSummary(nil); err != nil {
return err
@@ -1459,6 +1479,8 @@ func (e *Engine) finishReturn(ctx context.Context, ready *readiness) error {
switch {
case failedDrain:
outcome = "drain-failed"
+ case lockRefused:
+ outcome = "lock-refused"
case e.has("failed-probe", nil):
outcome = "failed-probe-recovered"
}
@@ -1476,6 +1498,10 @@ func (e *Engine) finishReturn(ctx context.Context, ready *readiness) error {
e.say("ALERT", Text("drain_cancel", "config", e.ConfigPath, "iid", iid, "transaction", tx))
return refuse("drain_failed")
}
+ if lockRefused {
+ e.say("floor", Text("floor_refused"))
+ return e.lockRefusal()
+ }
e.say("done", Text("done"))
return nil
}
diff --git a/internal/grouproll/roll_test.go b/internal/grouproll/roll_test.go
index 64d4ef9b3..4200caf89 100644
--- a/internal/grouproll/roll_test.go
+++ b/internal/grouproll/roll_test.go
@@ -267,9 +267,14 @@ func TestRollStandbyResume(t *testing.T) {
// finishes once it clears.
func scenarioStandbySharedOutage(h *harness) error {
f := h.f
+ // The script started the outage at the permit. Under DR-4 the verb
+ // reads the member's edges file again right before apply (V13), and an
+ // unreadable sweep fails closed, so the outage starts at the apply it
+ // follows: the member drops its admission as the script's did.
f.after = func(name string) {
- if name == "permit" {
- f.outage = true
+ if name == "apply" {
+ f.outage, f.admitted = true, false
+ f.boxes[fakeIID]["health"] = map[string]any{"state": "unhealthy", "code": int64(503)}
}
}
start := f.now
@@ -1727,8 +1732,13 @@ func TestRollFsyncPrecedesProviderWrite(t *testing.T) {
h := newHarness(t, 2)
var trace []string
h.state.fsync = func(*os.File) error { trace = append(trace, "sync"); return nil }
+ previous := ""
h.f.before = func(op string, _ map[string]any) error {
- if op != "caller" && (len(trace) == 0 || trace[len(trace)-1] != "sync") {
+ // One journaled lock call is an exact-key listing, then its GET
+ // (the DR-4 sweep, V13).
+ within := op == "lock_get" && previous == "lock_list"
+ previous = op
+ if op != "caller" && !within && (len(trace) == 0 || trace[len(trace)-1] != "sync") {
t.Errorf("%s without a preceding fsync", op)
}
trace = append(trace, "api")
diff --git a/region_ha_boundary_test.go b/region_ha_boundary_test.go
index 79007ee94..4255ec850 100644
--- a/region_ha_boundary_test.go
+++ b/region_ha_boundary_test.go
@@ -57,6 +57,7 @@ var regionHACoreFiles = []string{
"internal/grouproll/floor.go",
"internal/grouproll/roll.go",
"internal/grouproll/depart.go",
+ "internal/grouproll/dr4.go",
"internal/grouproll/probe.go",
"internal/grouproll/testdata/remotecommand/main.go",
"internal/release/systemlookup.go",