region-ha p1b-1: the simulation terminates boxes
The region HA model learns termination: a terminated box loses its agent, every unit and its disk, never restarts, and EC2 shows it 1 to 12 steps later. Survivors ask a confirmer (10 % errors while faults are on) through the real DecideAcquire's OwnerTerminated proof. A dying process's replica or manifest upload in flight lands up to TTL - 1 steps after its last renewal, under the dead pid. The finalization advances past visibility and expiry and gives each survivor one confirmation and one fault-free wake; I5 then reads world truth. Three rules, each caught alone by the 3000-seed sweep and its witness: takeover-unconfirmed (I1), takeover-before-expiry (I1, the late upload), no-takeover (I5).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 files changed,
+358
−16
internal/sim/regionha/actions_test.go+149 −7internal/sim/regionha/invariants_test.go+13 −0internal/sim/regionha/rules_test.go+5 −0internal/sim/regionha/sim_test.go+1 −0internal/sim/regionha/witness_test.go+46 −0internal/sim/regionha/world_test.go+144 −9
diff --git a/internal/sim/regionha/actions_test.go b/internal/sim/regionha/actions_test.go| index 6864c7eb0..81b2ab04a 100644 |
| --- a/internal/sim/regionha/actions_test.go |
| +++ b/internal/sim/regionha/actions_test.go |
| @@ -29,13 +29,23 @@ func (w *world) sliceEmpty(b *box, h string) bool { |
| return true |
| } |
| -// decideAcquire is hafresh.DecideAcquire with this box's proofs. |
| +// decideAcquire is hafresh.DecideAcquire with this box's proofs: the |
| +// same-box emptiness proof and the confirmer. |
| func (w *world) decideAcquire(b *box, h string, v hafresh.View) hafresh.Decision { |
| proof := func() (bool, error) { return w.sameBoxEmpty(b, h), nil } |
| if !on("same-box-no-proof") { |
| proof = func() (bool, error) { return true, nil } |
| } |
| - d := hafresh.DecideAcquire(v, b.Self, w.now(), hafresh.Proofs{SameBoxEmpty: proof}) |
| + if !on("takeover-before-expiry") && !v.Absent && v.Lock.Release == nil && !w.now().After(v.Lock.ExpiresAt) { |
| + // A caller that asks EC2 first and treats a confirmed termination |
| + // as the lease's end: it hands the table an expiry in the past. |
| + if o, ok := hafresh.ParseOwner(v.Lock.Owner); ok && o.IID != "" && o.IID != b.Self.IID { |
| + if gone, err := w.ownerTerminated(o.IID); err == nil && gone { |
| + v.Lock.ExpiresAt = w.now().Add(-tick) |
| + } |
| + } |
| + } |
| + d := hafresh.DecideAcquire(v, b.Self, w.now(), hafresh.Proofs{SameBoxEmpty: proof, OwnerTerminated: w.ownerTerminated}) |
| if !on("expiry-authorizes") && d.Action == hafresh.ActRefuse && d.Reason == hafresh.ReasonOtherExpired { |
| d = hafresh.Decision{Action: hafresh.ActTake, Reason: "expired"} |
| } |
| @@ -171,7 +181,7 @@ func (w *world) wake(b *box, h string, o wakeOpts, pre *pending) string { |
| switch { |
| case strings.HasPrefix(why, "held"): |
| w.event("refused-held") |
| - case why == hafresh.ReasonOtherExpired: |
| + case strings.HasPrefix(why, hafresh.ReasonOtherExpired): |
| w.event("refused-other-expired") |
| case strings.HasPrefix(why, hafresh.ReasonSameBoxUnsure): |
| w.event("refused-same-box") |
| @@ -185,7 +195,11 @@ func (w *world) wake(b *box, h string, o wakeOpts, pre *pending) string { |
| } |
| b.AcquiredHere[h] = true |
| if !e.View.Absent && e.View.Lock.Release == nil { |
| - w.event("same-box-retake") |
| + if o, _ := hafresh.ParseOwner(e.View.Lock.Owner); o.IID == b.Self.IID { |
| + w.event("same-box-retake") |
| + } else { |
| + w.event("takeover") |
| + } |
| } |
| w.logf("box%d: %s: acquired over %s", b.ID, h, viewWord(e.View)) |
| if o.CrashBeforeRestore { |
| @@ -716,6 +730,16 @@ func (w *world) retryObligation(b *box, ob *obligation, fails bool) bool { |
| // crash kills b's agent: its memory goes (entries, pending acquires, owed |
| // markers not on disk, publishers); the host units outlive it as orphans. |
| func (w *world) crash(b *box) { |
| + w.die(b) |
| + w.event("crash") |
| + w.logf("box%d: the agent crashes", b.ID) |
| +} |
| + |
| +// die is every death of b's agent process: the uploads it had in flight |
| +// are left to land (inFlight), and its memory goes. |
| +func (w *world) die(b *box) { |
| + w.inFlight(b) |
| + w.landLate() |
| b.Agent = agentDown |
| for _, h := range w.hosts { |
| for _, u := range b.Units[h] { |
| @@ -730,8 +754,115 @@ func (w *world) crash(b *box) { |
| b.Strays = nil |
| b.AcquiredHere = map[string]bool{} |
| b.Swept = false |
| - w.event("crash") |
| - w.logf("box%d: the agent crashes", b.ID) |
| +} |
| + |
| +// terminate is the instance's termination: everything crash does, and |
| +// every unit's processes go with it (stragglers and orphans included), the |
| +// disk goes (local copies, release records, obligations on disk), and the |
| +// box never restarts. w.terminated is the truth; EC2 shows it 1 to 12 |
| +// steps later (one in a scripted world; a witness may move it). |
| +func (w *world) terminate(b *box) { |
| + w.die(b) |
| + b.Units = map[string][]*unit{} |
| + b.Local = map[string]*localCopy{} |
| + b.Disk = map[string]*obligation{} |
| + d := 1 |
| + if !w.scripted { |
| + d = 1 + w.rng.Intn(12) |
| + } |
| + w.terminated[b.Self.IID] = w.step |
| + w.visibleAt[b.Self.IID] = w.step + d |
| + w.event("terminate") |
| + w.logf("box%d: the instance %s is terminated; EC2 shows it from step %d", b.ID, b.Self.IID, w.step+d) |
| +} |
| + |
| +// lateWrite is an upload a dead agent process sent before it died: a |
| +// replica upload (TXID, Ver), or a files manifest commit (Pub, Files). It |
| +// lands at step At, under the dead process's pid. |
| +type lateWrite struct { |
| + Box *box |
| + PID int |
| + Host string |
| + At int |
| + TXID uint64 |
| + Ver int |
| + Pub *publisher |
| + Files files |
| +} |
| + |
| +// inFlight is what b's dying agent process had sent and not seen settle: |
| +// for each host it holds, a seeded coin each for a replica upload and for |
| +// the commit of an in-flight files snapshot. The replica upload is of the |
| +// position not yet uploaded; with none, of the tenant's last transaction, |
| +// committed just before the death (not once the release has stopped the |
| +// unit). A scripted world draws nothing; its witness calls lateUpload. |
| +func (w *world) inFlight(b *box) { |
| + if w.scripted { |
| + return |
| + } |
| + for _, h := range w.hosts { |
| + e, l := b.Entries[h], b.Local[h] |
| + if e == nil { |
| + continue |
| + } |
| + if l != nil && (l.TXID > e.Uploaded || e.Releasing == nil) && w.pct(50) { |
| + if l.TXID == e.Uploaded { |
| + w.tenantWrite(b, h, false) |
| + } |
| + w.lateUpload(b, h, true, w.landing(e)) |
| + } |
| + if pub := e.Pub; pub != nil && pub.Inflight != nil && !pub.Broken && w.pct(50) { |
| + w.lateUpload(b, h, false, w.landing(e)) |
| + } |
| + } |
| +} |
| + |
| +// landing is a seeded step from 0 up to TTL - 1 steps after the lease's |
| +// last renewal. |
| +func (w *world) landing(e *entry) int { |
| + return stepOf(e.Expires) - ttlTicks + w.rng.Intn(ttlTicks) |
| +} |
| + |
| +// lateUpload is an upload b's agent process sent for h before it died, a |
| +// replica upload of its local position (replica) or the commit of its |
| +// in-flight files snapshot, landing at step at (at once if that has |
| +// passed) through replicaWrite or manifestWrite with the dead pid. It |
| +// models P1a's and the legacy path's assumption: an upload already sent |
| +// settles within the lease. The writer oracle (checkHolder) fails I1 if it |
| +// lands after another process took the lock. |
| +func (w *world) lateUpload(b *box, h string, replica bool, at int) { |
| + lw := &lateWrite{Box: b, PID: b.PID, Host: h, At: at} |
| + what := "manifest commit" |
| + if replica { |
| + l := b.Local[h] |
| + lw.TXID, lw.Ver = l.TXID, l.Ver |
| + what = fmt.Sprintf("replica upload txid %d", l.TXID) |
| + } else { |
| + pub := b.Entries[h].Pub |
| + lw.Pub, lw.Files = pub, pub.Inflight.Files |
| + pub.Inflight = nil |
| + } |
| + w.late = append(w.late, lw) |
| + w.event("late-upload") |
| + w.logf("box%d: %s: pid %d dies with a %s in flight; it lands at step %d", b.ID, h, b.PID, what, at) |
| +} |
| + |
| +// landLate lands every late upload whose step has come. |
| +func (w *world) landLate() { |
| + var keep []*lateWrite |
| + for _, lw := range w.late { |
| + if lw.At > w.step { |
| + keep = append(keep, lw) |
| + continue |
| + } |
| + w.logf("box%d: %s: an upload sent by the dead pid %d lands", lw.Box.ID, lw.Host, lw.PID) |
| + if lw.Pub != nil { |
| + w.manifestWrite(lw.Box, lw.Pub, lw.Files) |
| + } else { |
| + w.replicaWrite(lw.Box, lw.PID, lw.Host, lw.TXID, lw.Ver) |
| + } |
| + } |
| + w.late = keep |
| } |
| // restart starts a new agent process: its startup sweep (which, when it |
| @@ -914,10 +1045,21 @@ func init() { |
| w.crash(b) |
| return true |
| }}, |
| + // The instance is terminated, at the rate of a crash. At most one a |
| + // world: a terminated box never comes back, so more would leave |
| + // most worlds with one box for most of the walk. |
| + action{"terminate", 2, func(w *world) bool { |
| + b := w.randomBox() |
| + if w.calm() || len(w.terminated) > 0 { |
| + return false |
| + } |
| + w.terminate(b) |
| + return true |
| + }}, |
| action{"agent-restart", 6, func(w *world) bool { |
| b := w.randomBox() |
| sweepOK := !w.fault(30) |
| - if b.Agent != agentDown { |
| + if b.Agent != agentDown || w.isTerminated(b) { |
| return false |
| } |
| w.restart(b, sweepOK) |
diff --git a/internal/sim/regionha/invariants_test.go b/internal/sim/regionha/invariants_test.go| index 12cc94853..12891dadc 100644 |
| --- a/internal/sim/regionha/invariants_test.go |
| +++ b/internal/sim/regionha/invariants_test.go |
| @@ -27,6 +27,10 @@ import ( |
| // host whose agent crashed waits behind its own expired lease for its |
| // box's recovery (§9.6), and leftover objects under an absent lock |
| // refuse the first wake (the leftover action's, not a lease's). |
| +// After a termination (P1b-1, r1.4, r2.2): a host behind the lease of a |
| +// box terminated in truth is held by a live box of its pool once the |
| +// finalization has given each one a confirmation and a fault-free wake |
| +// (finalTakeovers). With no live box, I5 does not apply to that host. |
| // |
| // MODEL is the model's own consistency: a lock that does not decode. |
| @@ -114,6 +118,15 @@ func (w *world) checkLiveness() { |
| continue |
| } |
| v := w.view(h) |
| + if o, dead := w.terminatedOwner(v); dead { |
| + // The lease's box is gone with its obligations; the takeover is |
| + // the release. Read from world truth, never the confirmer. |
| + if len(w.survivors()) > 0 { |
| + w.fail("I5", "%s is stranded behind the lease of %s, terminated at step %d, while a live box of its pool could take it (lock %s)", |
| + h, o.IID, w.terminated[o.IID], w.lockString(h)) |
| + } |
| + continue |
| + } |
| if v.Lock.Release == nil && w.owed[h][p.ETag] { |
| w.fail("I5", "%s is stranded: the release marker owed for %s was never written (lock %s)", h, p.ETag, w.lockString(h)) |
| } |
diff --git a/internal/sim/regionha/rules_test.go b/internal/sim/regionha/rules_test.go| index 2fdd8336e..8086851b3 100644 |
| --- a/internal/sim/regionha/rules_test.go |
| +++ b/internal/sim/regionha/rules_test.go |
| @@ -58,4 +58,9 @@ var allRules = []string{ |
| "recover-without-sweep", // sameBoxEmpty needs this agent's startup sweep to have proven every unit stopped (r3.2) |
| "marker-before-slice-empty", // releaseHAClean holds the release until the host's slice reads empty (r3.2) |
| "failed-wake-before-slice-empty", // cleanupFailedWake and the reaper hold an HA release until the host's slice reads empty (haHostEmpty, final review F1) |
| + |
| + // takeover of a terminated box's hosts (P1b-1, N-HA9) |
| + "takeover-unconfirmed", // Proofs.OwnerTerminated: true only once EC2 shows the owner terminated, never for a box alive or hung |
| + "takeover-before-expiry", // the takeover row needs the lock expired too: an upload the dead process sent lands within its lease (N-HA9) |
| + "no-takeover", // a survivor of the pool takes a terminated owner's expired lock: the host comes back |
| } |
diff --git a/internal/sim/regionha/sim_test.go b/internal/sim/regionha/sim_test.go| index 8828d4af9..524412621 100644 |
| --- a/internal/sim/regionha/sim_test.go |
| +++ b/internal/sim/regionha/sim_test.go |
| @@ -214,6 +214,7 @@ func TestEveryActionFires(t *testing.T) { |
| "reclassified", "late-ack", "failed-restore", "failed-after-replication", "crash-before-restore", |
| "marker-clean", "marker-unclean", "marker-owed", "obligation-discharged", |
| "release-held", "failed-wake-held", "ha-lock-on-legacy-path", "hang-resumed", "manifest-committed", |
| + "terminate", "takeover", "late-upload", "confirm-error", |
| } { |
| if events[e] == 0 { |
| t.Errorf("no %s over 200 seeds", e) |
diff --git a/internal/sim/regionha/witness_test.go b/internal/sim/regionha/witness_test.go| index 795de155a..650c595e8 100644 |
| --- a/internal/sim/regionha/witness_test.go |
| +++ b/internal/sim/regionha/witness_test.go |
| @@ -62,6 +62,12 @@ var witnesses = []witness{ |
| "r3.2: a unit of the host outlives the stop; the release waits for the slice, and a marker before it lets another box run beside the straggler", wStragglerHoldsRelease}, |
| {"failed-wake-before-slice-empty", "failed-wake-before-slice-empty", "I1", |
| "final review F1: a wake fails after replication and a replacement invocation outlives its stop; the release waits for the slice, and an unclean marker before it lets another box run beside the replacement", wFailedWakeStragglerHoldsRelease}, |
| + {"takeover-unconfirmed", "takeover-unconfirmed", "I1", |
| + "A hangs past the TTL, alive; EC2 shows it running, so B refuses its expired lease; a confirmer that answers terminated lets B run beside the hung box's unit", wTakeoverUnconfirmed}, |
| + {"takeover-before-expiry", "takeover-before-expiry", "I1", |
| + "A is terminated with a replica upload in flight that lands at TTL - 2; B's wake right after visibility is held; a take before expiry lets A's upload land under B's lease", wTakeoverBeforeExpiry}, |
| + {"no-takeover", "no-takeover", "I5", |
| + "r2.2: A is terminated while it holds the host, and no request comes until the finalization; a survivor that never takes over leaves the host down", wNoTakeover}, |
| } |
| // TestWitnesses is the deterministic half of the mutation evidence. |
| @@ -497,6 +503,46 @@ func wFailedWakeStragglerHoldsRelease(t *testing.T, w *world) { |
| w.checkLiveness() |
| } |
| +func wTakeoverUnconfirmed(t *testing.T, w *world) { |
| + A, B, _ := w.abc() |
| + w.serve(t, A) |
| + w.write(A, false) |
| + w.syncNow(A, false) |
| + w.hang(A, ttlTicks+3) |
| + w.advance(ttlTicks + 1) |
| + r := w.req(B, wakeOpts{}) |
| + expect(t, "takeover-unconfirmed", r == "refused: "+hafresh.ReasonOtherExpired, "B's wake over the hung A's expired lease: %s", r) |
| + w.advance(3) // A resumes and renews |
| +} |
| + |
| +func wTakeoverBeforeExpiry(t *testing.T, w *world) { |
| + A, B, _ := w.abc() |
| + w.serve(t, A) // the lease's last renewal: this step |
| + w.write(A, false) |
| + w.lateUpload(A, sh, true, w.step+ttlTicks-2) |
| + w.terminate(A) |
| + w.check() |
| + w.advance(w.visibleAt[A.Self.IID] - w.step) |
| + r := w.req(B, wakeOpts{}) |
| + expect(t, "takeover-before-expiry", strings.HasPrefix(r, "refused: held"), "B's wake right after visibility, before expiry: %s", r) |
| + w.advance(ttlTicks + 1 - w.step) // A's upload lands; the lease expires |
| + if on("takeover-before-expiry") { |
| + r = w.req(B, wakeOpts{}) |
| + expect(t, "takeover-before-expiry", r == "served" && w.events["takeover"] == 1, "B's wake after expiry: %s", r) |
| + } |
| +} |
| + |
| +func wNoTakeover(t *testing.T, w *world) { |
| + A, _, _ := w.abc() |
| + w.serve(t, A) |
| + w.write(A, false) |
| + w.syncNow(A, false) |
| + w.terminate(A) |
| + w.check() |
| + w.final() |
| + expect(t, "no-takeover", w.events["takeover"] == 1, "no survivor took the terminated A's host: %s", w.lockString(sh)) |
| +} |
| + |
| // TestKnownGapReusedHostnameLegacyWake documents a known gap, not a rule: |
| // with hostnames reused (#199's never-reuse rule not in force), a box whose |
| // lifetime index still holds a negative entry from the name's earlier |
diff --git a/internal/sim/regionha/world_test.go b/internal/sim/regionha/world_test.go| index 2a08e6e0f..e7423591e 100644 |
| --- a/internal/sim/regionha/world_test.go |
| +++ b/internal/sim/regionha/world_test.go |
| @@ -2,6 +2,7 @@ package regionha |
| import ( |
| "encoding/json" |
| + "errors" |
| "fmt" |
| "math/rand" |
| "sort" |
| @@ -226,6 +227,21 @@ type world struct { |
| // that ETag at the end, the marker was never written (I5). |
| owed map[string]map[string]bool |
| + // terminated is world truth: the instances terminated, by instance id, |
| + // at the step of their termination. visibleAt is the step from which |
| + // EC2's DescribeInstances shows each one terminated. The oracles and the |
| + // finalization read these; a box learns of a termination only through |
| + // the confirmer (ownerTerminated), which the rules change. |
| + terminated map[string]int |
| + visibleAt map[string]int |
| + |
| + // late are the uploads dead agent processes had in flight, each landing |
| + // at its step (lateUpload). |
| + late []*lateWrite |
| + |
| + // faultsOff is set by the finalization: no fault from then on. |
| + faultsOff bool |
| + |
| clock, nextETag, nextPID, nextInode, nextVer int64 |
| // scripted is a witness's world: the timers run (expiry, hang ends, |
| @@ -284,6 +300,9 @@ func newWorldN(seed int64, rng *rand.Rand, n int, hosts []string) *world { |
| events: map[string]int{}, |
| owed: map[string]map[string]bool{}, |
| nextPID: 100, |
| + |
| + terminated: map[string]int{}, |
| + visibleAt: map[string]int{}, |
| } |
| for _, h := range hosts { |
| w.s3[h] = &prefix{} |
| @@ -342,8 +361,8 @@ func (w *world) pct(p int) bool { |
| return w.rng.Intn(100) < p |
| } |
| -// fault is pct, and false once the world is calm. |
| -func (w *world) fault(p int) bool { return !w.calm() && w.pct(p) } |
| +// fault is pct, and false once the world is calm or the faults are off. |
| +func (w *world) fault(p int) bool { return !w.calm() && !w.faultsOff && w.pct(p) } |
| func (w *world) logf(format string, args ...any) { |
| w.trace = append(w.trace, fmt.Sprintf("[%d] ", w.step)+fmt.Sprintf(format, args...)) |
| @@ -414,14 +433,82 @@ func (w *world) lockString(h string) string { |
| return fmt.Sprintf("lease{%s gen %d expires %s %s}", v.Lock.Owner, v.Lock.Generation, v.Lock.ExpiresAt.Sub(epoch), v.ETag) |
| } |
| +// ---- EC2 ---- |
| + |
| +// ownerTerminated is the confirmer (termfence.Confirmer.Terminated, P1b-1 |
| +// Task 2) as a box's acquire sees it: true only once DescribeInstances |
| +// shows the instance terminated, 1 to 12 steps after the termination. |
| +// While faults are on, a seeded 10 % of its calls fail. Only the rules |
| +// change it; the oracles read w.terminated and w.visibleAt instead. |
| +func (w *world) ownerTerminated(iid string) (bool, error) { |
| + if !w.scripted && w.fault(10) { |
| + w.event("confirm-error") |
| + return false, errors.New("DescribeInstances failed") |
| + } |
| + if !on("takeover-unconfirmed") { |
| + return true, nil // whatever the instance's state |
| + } |
| + if !on("no-takeover") { |
| + return false, nil |
| + } |
| + _, dead := w.terminated[iid] |
| + return dead && w.step >= w.visibleAt[iid], nil |
| +} |
| + |
| +// isTerminated is world truth: b's instance is terminated. |
| +func (w *world) isTerminated(b *box) bool { |
| + _, dead := w.terminated[b.Self.IID] |
| + return dead |
| +} |
| + |
| +// terminatedOwner is world truth about a lock: a lease (no marker) whose |
| +// owner's instance is terminated. |
| +func (w *world) terminatedOwner(v hafresh.View) (hafresh.Owner, bool) { |
| + if v.Absent || v.Lock.Release != nil { |
| + return hafresh.Owner{}, false |
| + } |
| + o, ok := hafresh.ParseOwner(v.Lock.Owner) |
| + if !ok { |
| + return hafresh.Owner{}, false |
| + } |
| + _, dead := w.terminated[o.IID] |
| + return o, dead |
| +} |
| + |
| +// survivors are the live boxes of a host's pool. Every box of the model |
| +// serves every host, so the pool is every box not terminated. |
| +func (w *world) survivors() []*box { |
| + var out []*box |
| + for _, b := range w.boxes { |
| + if !w.isTerminated(b) { |
| + out = append(out, b) |
| + } |
| + } |
| + return out |
| +} |
| + |
| +// holds reports whether some box holds h: it is awake there, or its |
| +// release is held there. |
| +func (w *world) holds(h string) bool { |
| + for _, b := range w.boxes { |
| + if b.Entries[h] != nil { |
| + return true |
| + } |
| + } |
| + return false |
| +} |
| + |
| +func stepOf(t time.Time) int { return int(t.Sub(epoch) / tick) } |
| + |
| // ---- timers and background work ---- |
| -// tick advances the background of one step: an agent's hang ends; |
| -// stragglers exit; orphans restart by systemd; and every running agent's |
| -// held releases retry, its publishers and replicators run, its leases |
| -// renew and its owed markers retry. A scripted world runs only the timers |
| +// tick advances the background of one step: uploads dead processes sent |
| +// land; an agent's hang ends; stragglers exit; orphans restart by systemd; |
| +// and every running agent's held releases retry, its publishers and |
| +// replicators run, its leases renew and its owed markers retry. A scripted world runs only the timers |
| // and what follows from them. |
| func (w *world) tick() { |
| + w.landLate() |
| for _, b := range w.boxes { |
| if b.Agent == agentHung && w.step >= b.HungTill { |
| b.Agent = agentUp |
| @@ -531,11 +618,16 @@ func (w *world) pick() *action { |
| } |
| // final clears every fault and lets the world settle: hung agents resume, |
| -// dead agents restart (their startup sweep succeeds), stragglers exit, |
| -// held releases finish and owed markers are retried. Then the liveness |
| -// oracle (I5). |
| +// dead agents restart (their startup sweep succeeds) unless their instance |
| +// is terminated, stragglers exit, held releases finish and owed markers |
| +// are retried. Then the takeovers after a termination (finalTakeovers) |
| +// and the liveness oracle (I5). |
| func (w *world) final() { |
| + w.faultsOff = true |
| for _, b := range w.boxes { |
| + if w.isTerminated(b) { |
| + continue |
| + } |
| switch b.Agent { |
| case agentHung: |
| b.Agent = agentUp |
| @@ -552,10 +644,53 @@ func (w *world) final() { |
| } |
| } |
| } |
| + w.finalTakeovers() |
| w.checkLiveness() |
| w.logf("final: %d steps, %d violations", w.step, len(w.violations)) |
| } |
| +// finalTakeovers is the finalization after a termination (r1.4, r2.2). For |
| +// every host no box holds whose lock is a lease of a box terminated in |
| +// truth, while a live box of its pool exists: the world advances past |
| +// EC2's visibility of the termination and past the lease's expiry, then |
| +// each live box in turn gets one confirmation attempt and one fault-free |
| +// wake, until one holds the host. The schedule reads world truth, never |
| +// the confirmer, so a mutated confirmer cannot skip it; checkLiveness then |
| +// fails I5 if no box holds the host. With no live box, I5 does not apply. |
| +func (w *world) finalTakeovers() { |
| + var hs []string |
| + until := w.step |
| + for _, h := range w.hosts { |
| + v := w.view(h) |
| + o, dead := w.terminatedOwner(v) |
| + if !dead || w.holds(h) || len(w.survivors()) == 0 { |
| + continue |
| + } |
| + hs = append(hs, h) |
| + until = max(until, w.visibleAt[o.IID], stepOf(v.Lock.ExpiresAt)+1) |
| + } |
| + if len(hs) == 0 { |
| + return |
| + } |
| + w.logf("final: %v behind a terminated box's lease; advancing to step %d", hs, until) |
| + w.advance(until - w.step) |
| + for _, h := range hs { |
| + o, dead := w.terminatedOwner(w.view(h)) |
| + if !dead { |
| + continue |
| + } |
| + for _, b := range w.survivors() { |
| + if w.holds(h) { |
| + break |
| + } |
| + gone, err := w.ownerTerminated(o.IID) |
| + w.logf("final: box%d asks EC2 about %s: terminated %v, error %v", b.ID, o.IID, gone, err) |
| + w.logf("final: box%d: %s: wake: %s", b.ID, h, w.wake(b, h, wakeOpts{}, nil)) |
| + w.check() |
| + } |
| + } |
| +} |
| + |
| func runSeed(seed int64, verbose bool) *world { |
| w := newWorld(seed, verbose) |
| for i := 0; i < chaosSteps+calmSteps; i++ { |