rootfs: an interrupted release recovers as a binary attempt does; the release-phase intent is removed
Group R, R2 fix round 2 (controller ruling after Astra R2 round 2). An agent crash during a rootfs adoption's or first wake's release recovers exactly as a binary execution does today: the outstanding intent is the build's failure on restart, the build is retried explicitly, and the retry runs its release again (the row's committed good build is still the old one). Removes 03313767's P1-2 machinery: Intent.Phase, FailureBook.Advance, Interrupted, Attempt.BeforeWeb and WakePlan.BeforeWeb with every caller (webPhase, errWebPhaseUnrecorded), and their tests. Keeps P1-1 (committedGood) and everything R3 added. Adds TestACrashedReleaseRecoversAsABinaryAttemptDoes (the real scheduler and a reopened book, rootfs and binary) and TestRetryAfterACrashRunsTheReleaseAgain.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8 files changed,
+161
−624
internal/activator/rootfs_swap_release_test.go+22 −152internal/activator/swap.go+2 −48internal/activator/wakeplan.go+0 −16internal/rollout/failures.go+4 −73internal/rollout/rootfs_release_crash_test.go+133 −0internal/rollout/rootfs_release_phase_test.go+0 −313internal/rollout/scheduler.go+0 −11internal/rollout/wakeplan.go+0 −11
diff --git a/internal/activator/rootfs_swap_release_test.go b/internal/activator/rootfs_swap_release_test.go| index 1334ccaa1..57ba67812 100644 |
| --- a/internal/activator/rootfs_swap_release_test.go |
| +++ b/internal/activator/rootfs_swap_release_test.go |
| @@ -1223,158 +1223,28 @@ func TestReleaseRefusedWhenTheRowIsNotTheInstance(t *testing.T) { |
| } |
| } |
| -// Astra R2 round 1, P1 2: the release phase ends (Attempt.BeforeWeb) after |
| -// the release is proven and before the web's exec, never on a release that |
| -// failed or is unproven; a phase that cannot be recorded starts no web. |
| -func TestReleasePhaseEndsRightBeforeTheWeb(t *testing.T) { |
| - withPhase := func(f *relSwapFixture, err error) (Attempt, *atomic.Int32) { |
| - var calls atomic.Int32 |
| - at := f.attempt(ModeOverlap) |
| - at.BeforeWeb = func() error { |
| - calls.Add(1) |
| - f.b.record("release-phase-ended") |
| - return err |
| - } |
| - return at, &calls |
| +// Controller ruling (R2 fix round 2), the activator's half: after an agent |
| +// crash mid-release, B's failure is recorded on restart and B is retried |
| +// explicitly. The retry, on the new agent's Service with the registry's row |
| +// still good on A, runs B's release once more, before B's web. |
| +// (TestACrashedReleaseRecoversAsABinaryAttemptDoes pins the scheduler's half.) |
| +func TestRetryAfterACrashRunsTheReleaseAgain(t *testing.T) { |
| + f := newRelSwapFixture(t, true) |
| + f.committedRow(t) |
| + at := f.attempt(ModeOverlap) |
| + at.Cause = CauseRetry |
| + ch := f.swapAsync(at) |
| + f.nextUnit(t).done("1", "0", "success") |
| + res := waitSwap(t, ch) |
| + if res.Outcome != SwapDone || res.Gen.Build != "v2" { |
| + t.Fatalf("the retry = %+v", res) |
| } |
| - t.Run("a passed release", func(t *testing.T) { |
| - f := newRelSwapFixture(t, true) |
| - at, calls := withPhase(f, nil) |
| - ch := f.swapAsync(at) |
| - f.nextUnit(t).done("1", "0", "success") |
| - if res := waitSwap(t, ch); res.Outcome != SwapDone { |
| - t.Fatalf("Swap = %+v", res) |
| - } |
| - ev := f.b.events() |
| - order := []int{indexPrefix(ev, "release:proven:v2"), indexPrefix(ev, "raise"), indexPrefix(ev, "release-phase-ended"), indexPrefix(ev, "startGen:")} |
| - for i := range order { |
| - if order[i] < 0 || (i > 0 && order[i] < order[i-1]) { |
| - t.Fatalf("events %v (indexes %v): want the release proven, the admission, the phase's end, then the web", ev, order) |
| - } |
| - } |
| - if calls.Load() != 1 { |
| - t.Errorf("BeforeWeb asked %d times", calls.Load()) |
| - } |
| - }) |
| - for _, tc := range []struct { |
| - name string |
| - stuck bool |
| - code string |
| - }{{"a failed release", false, "1"}, {"an unproven release", true, "0"}} { |
| - t.Run(tc.name, func(t *testing.T) { |
| - f := newRelSwapFixture(t, true) |
| - f.rb.setStuck(tc.stuck) |
| - at, calls := withPhase(f, nil) |
| - ch := f.swapAsync(at) |
| - f.nextUnit(t).done("1", tc.code, "") |
| - res := waitSwap(t, ch) |
| - if res.Outcome == SwapDone || calls.Load() != 0 { |
| - t.Fatalf("Swap = %+v, BeforeWeb asked %d times; want the phase never ended", res, calls.Load()) |
| - } |
| - if tc.stuck { |
| - f.proveRecord(t) |
| - } |
| - }) |
| + if got := f.rb.startList(); !slices.Equal(got, []string{"v2"}) { |
| + t.Fatalf("releases started %v; want B's once", got) |
| + } |
| + ev := f.b.events() |
| + rs, rp, sg := indexPrefix(ev, "release:start:v2"), indexPrefix(ev, "release:proven:v2"), indexPrefix(ev, "startGen:"+f.staged) |
| + if rs < 0 || rp < rs || sg < rp { |
| + t.Fatalf("events %v: want B's release started and proven before its web", ev) |
| } |
| - t.Run("the phase cannot be recorded", func(t *testing.T) { |
| - f := newRelSwapFixture(t, true) |
| - incumbent := f.b.lastProc() |
| - at, _ := withPhase(f, errors.New("the failure book cannot be written")) |
| - ch := f.swapAsync(at) |
| - f.nextUnit(t).done("1", "0", "success") |
| - res := waitSwap(t, ch) |
| - if res.Outcome != SwapAbandoned || !res.Executed || !strings.Contains(res.Reason, errWebPhaseUnrecorded.Error()) { |
| - t.Fatalf("Swap = %+v; want abandoned, executed (its release ran)", res) |
| - } |
| - if gens, raises, restores := f.b.calls(); gens != 0 || raises != restores { |
| - t.Errorf("StartStaged %d, raises %d, restores %d", gens, raises, restores) |
| - } |
| - f.incumbentServing(t, incumbent, "after the phase could not be recorded") |
| - }) |
| - t.Run("a hold ends it before the stop", func(t *testing.T) { |
| - f := newRelSwapFixture(t, true) |
| - incumbent := f.b.lastProc() |
| - at, calls := withPhase(f, errors.New("the failure book cannot be written")) |
| - at.Mode = ModeHold |
| - res := f.swapNoRelease(t, at) |
| - if res.Outcome != SwapAbandoned || res.Executed || calls.Load() != 1 || incumbent.isStopped() { |
| - t.Fatalf("hold = %+v, BeforeWeb %d, incumbent stopped %v", res, calls.Load(), incumbent.isStopped()) |
| - } |
| - }) |
| -} |
| - |
| -// Astra R3 round 1, finding 3 (the activator's half): a planned first wake |
| -// ends its release phase (WakePlan.BeforeWeb) after B's release is proven |
| -// and before B's web, never on a release that failed (the fallback boots |
| -// the good build with the phase still open) or is unproven; a phase that |
| -// cannot be recorded starts no web and is no failure of B. |
| -func TestFirstWakeReleasePhaseEndsRightBeforeTheWeb(t *testing.T) { |
| - withPhase := func(r *wakeRelRig, err error) *atomic.Int32 { |
| - var calls atomic.Int32 |
| - p := r.plan |
| - p.BeforeWeb = func() error { |
| - calls.Add(1) |
| - r.b.record("release-phase-ended") |
| - return err |
| - } |
| - r.setPlan(p) |
| - return &calls |
| - } |
| - t.Run("a passed release", func(t *testing.T) { |
| - r := newWakeRelRig(t) |
| - calls := withPhase(r, nil) |
| - ch := r.wake(r.a) |
| - r.nextUnit(t).done("exited", "0", "success") |
| - if err := waitErr(t, ch); err != nil { |
| - t.Fatal(err) |
| - } |
| - rp, ph, st := r.index("release:proven:v2"), r.index("release-phase-ended"), r.index("start:v2") |
| - if rp < 0 || ph < rp || st < ph || calls.Load() != 1 { |
| - t.Fatalf("order %v (BeforeWeb %d): want release proven, the phase's end, then web", r.b.events(), calls.Load()) |
| - } |
| - }) |
| - t.Run("a failed release falls back with the phase open", func(t *testing.T) { |
| - r := newWakeRelRig(t) |
| - calls := withPhase(r, nil) |
| - ch := r.wake(r.a) |
| - r.nextUnit(t).done("exited", "1", "exit-code") |
| - if err := waitErr(t, ch); err != nil { |
| - t.Fatal(err) |
| - } |
| - r.evs.wait(t, GenFellBack) |
| - if calls.Load() != 0 { |
| - t.Fatalf("BeforeWeb asked %d times for a failed release", calls.Load()) |
| - } |
| - }) |
| - t.Run("an unproven release", func(t *testing.T) { |
| - r := newWakeRelRig(t) |
| - calls := withPhase(r, nil) |
| - r.b.setStuck(true) |
| - ch := r.wake(r.a) |
| - r.nextUnit(t).done("exited", "0", "success") |
| - if err := waitErr(t, ch); err == nil { |
| - t.Fatal("the wake served over an unproven release") |
| - } |
| - if calls.Load() != 0 || r.webStarts() != 0 { |
| - t.Fatalf("BeforeWeb %d, web starts %d", calls.Load(), r.webStarts()) |
| - } |
| - }) |
| - t.Run("the phase cannot be recorded", func(t *testing.T) { |
| - r := newWakeRelRig(t) |
| - withPhase(r, errors.New("the failure book cannot be written")) |
| - ch := r.wake(r.a) |
| - r.nextUnit(t).done("exited", "0", "success") |
| - err := waitErr(t, ch) |
| - if !errors.Is(err, errWebPhaseUnrecorded) || verdictOf(err) != gateNoOwnership { |
| - t.Fatalf("wake = %v; want the unrecorded phase, a refusal", err) |
| - } |
| - if n := r.webStarts(); n != 0 { |
| - t.Fatalf("%d web starts", n) |
| - } |
| - ev := r.evs.wait(t, GenCancelled) |
| - noBuildFailure(t, r.evs) |
| - if !ev.Executed { |
| - t.Errorf("GenCancelled %+v: the release ran, so the wake executed", ev) |
| - } |
| - }) |
| } |
diff --git a/internal/activator/swap.go b/internal/activator/swap.go| index 9ad4da01b..7bd05aec5 100644 |
| --- a/internal/activator/swap.go |
| +++ b/internal/activator/swap.go |
| @@ -51,17 +51,6 @@ type Attempt struct { |
| RestartID string |
| SchedRev uint64 // scheduler revision; the newest-attempt check compares it |
| Canary bool // observe the 10 s settle |
| - // BeforeWeb, when set, ends the attempt's release phase durably before |
| - // anything of the build but its release runs (rootfs apps Plan 3, |
| - // Group R; Astra R2 round 1, P1 2). The scheduler sets it on a rootfs |
| - // overlap adoption, whose write-ahead intent starts in the release |
| - // phase: an agent that dies while the release runs, or after it passed |
| - // and before the web starts, reopens its failure book with no failure |
| - // for the build, and the attempt runs again. Swap asks it right before |
| - // the successor's spawn (an overlap) or before the incumbent's stop (a |
| - // hold, whose release runs after the stop); an error abandons the |
| - // attempt with nothing of its web run. Nil on every other attempt. |
| - BeforeWeb func() error |
| } |
| // SwapOutcome is how an attempt ended. |
| @@ -237,8 +226,7 @@ const ( |
| // too: an open release record of the host (errReleaseOpen, INV-R4), an |
| // overlap whose build needs a release without this attempt's proven pass |
| // (errReleaseNotPassed, INV-R5), and a release refused for a route its |
| -// plan turned off (errReleaseTurnedOff), and a release phase that could |
| -// not be recorded as ended (errWebPhaseUnrecorded). Each refuses before anything of |
| +// plan turned off (errReleaseTurnedOff). Each refuses before anything of |
| // the build runs, at the admission or at the exec, so a refusal that |
| // surfaces from inside the spawn is abandonment, never the build's failure. |
| // |
| @@ -267,8 +255,7 @@ func verdictOf(err error) gateVerdict { |
| errors.Is(err, instancectl.ErrStagedImage), errors.Is(err, errRootfsRefused), |
| errors.Is(err, errRootfsBinaryLaunch), errors.Is(err, errNoRootfsControl), |
| errors.Is(err, errBuildStateUnwritten), errors.Is(err, errOwnershipRefused), |
| - errors.Is(err, errReleaseOpen), errors.Is(err, errReleaseNotPassed), errors.Is(err, errReleaseTurnedOff), |
| - errors.Is(err, errWebPhaseUnrecorded): |
| + errors.Is(err, errReleaseOpen), errors.Is(err, errReleaseNotPassed), errors.Is(err, errReleaseTurnedOff): |
| return gateNoOwnership |
| } |
| return gateProceed |
| @@ -345,11 +332,6 @@ func (a *Service) Swap(ctx context.Context, at Attempt, newest func(host string) |
| // (spec §2.9, rev 17). Its result reads as a hold's, SwapDown |
| // when the new build fails, and Mode tells the scheduler so: a |
| // hold build that ran is held down (spec §6.4, §8.3). |
| - if err := webPhase(at); err != nil { |
| - res := abandon(err) |
| - res.Mode = ModeHold |
| - return res |
| - } |
| res := a.swapHold(ctx, at, newest) |
| res.Mode = ModeHold |
| return res |
| @@ -367,11 +349,6 @@ func (a *Service) Swap(ctx context.Context, at Attempt, newest func(host string) |
| res.Mode = ModeOverlap |
| return res |
| case ModeHold: |
| - if err := webPhase(at); err != nil { |
| - res := abandon(err) |
| - res.Mode = ModeHold |
| - return res |
| - } |
| res := a.swapHold(ctx, at, newest) |
| res.Mode = ModeHold |
| return res |
| @@ -379,21 +356,6 @@ func (a *Service) Swap(ctx context.Context, at Attempt, newest func(host string) |
| return abandon(errSwapMode) |
| } |
| -// errWebPhaseUnrecorded: the attempt's release phase could not be ended |
| -// durably (Attempt.BeforeWeb), so nothing of its web runs. |
| -var errWebPhaseUnrecorded = errors.New("swap: the attempt's release phase could not be recorded as ended") |
| - |
| -// webPhase ends at's release phase (Attempt.BeforeWeb), when it has one. |
| -func webPhase(at Attempt) error { |
| - if at.BeforeWeb == nil { |
| - return nil |
| - } |
| - if err := at.BeforeWeb(); err != nil { |
| - return fmt.Errorf("%w: %v", errWebPhaseUnrecorded, err) |
| - } |
| - return nil |
| -} |
| - |
| // EffectiveMode is the mode Swap runs an attempt of mode m on host in: an |
| // overlap on a foreign-layout row runs as a hold (foreignRow, spec §2.9), |
| // anything else as given. The scheduler writes it into the attempt's |
| @@ -655,14 +617,6 @@ func (a *Service) swapOverlap(ctx context.Context, gb SwapBackend, at Attempt, n |
| return abandon(err) |
| } |
| - // The release phase ends, durably, before the web's exec: from here an |
| - // agent crash is the build's possible failure, as a binary attempt's |
| - // always is (Attempt.BeforeWeb). |
| - if err := webPhase(at); err != nil { |
| - a.dropMember(e, m) // restores the raised parent (leaveSet) |
| - return abandon(err) |
| - } |
| - |
| // Step 3: exec the attempt's staged build by path. The backend reports |
| // what it ran, and anything but the attempt's choice is refused. |
| g, proc, spawnErr := a.spawnSuccessor(mctx, gb, e, rt, work, m.gen, gate) |
diff --git a/internal/activator/wakeplan.go b/internal/activator/wakeplan.go| index 0fc9fb8b8..b54878d3c 100644 |
| --- a/internal/activator/wakeplan.go |
| +++ b/internal/activator/wakeplan.go |
| @@ -60,13 +60,6 @@ type WakePlan struct { |
| // the instance's env file at the spawn), so it carries this one, |
| // unchanged, into every GenEvent of the wake, beside Token. |
| ConfigRev string |
| - // BeforeWeb, when set, ends a first wake's release phase durably, as |
| - // Attempt.BeforeWeb does for an overlap (Group R; Astra R2 round 1, |
| - // P1 2, and R3 round 1, finding 3). The planner sets it on a rootfs |
| - // row's first wake, whose write-ahead intent starts in the release |
| - // phase. spawnPlanned asks it after Boot's release and before Boot's |
| - // web; an error starts no web and is no failure of Boot. |
| - BeforeWeb func() error |
| } |
| func (p WakePlan) planned() bool { return p.Boot.StagedPath != "" } |
| @@ -391,15 +384,6 @@ func (a *Service) spawnPlanned(ctx context.Context, e *actEntry, rt registry.Rou |
| } |
| released = executed |
| } |
| - // The release phase ends, durably, before Boot's web: from here an |
| - // agent crash is Boot's possible failure, as a binary first wake's |
| - // always is (WakePlan.BeforeWeb). |
| - if plan.BeforeWeb != nil { |
| - if err := plan.BeforeWeb(); err != nil { |
| - w.bootRan = released |
| - return nil, "", Gen{}, fmt.Errorf("%w: %v", errWebPhaseUnrecorded, err) |
| - } |
| - } |
| gate := a.planGate(ctx, e, lease, plan, boot.Version) |
| var healthBy time.Time |
| var left time.Duration |
diff --git a/internal/rollout/failures.go b/internal/rollout/failures.go| index 1434de7aa..04b50f5d7 100644 |
| --- a/internal/rollout/failures.go |
| +++ b/internal/rollout/failures.go |
| @@ -184,24 +184,8 @@ type Intent struct { |
| // time): a reconciled hold intent's marker carries it as its At (ruling |
| // 205). Zero when not known; reconciliation then uses the open time. |
| Start time.Time `json:"start"` |
| - // Phase is IntentPhaseRelease while a rootfs overlap adoption's or a |
| - // rootfs first wake's release may be running and nothing else of its |
| - // build has (rootfs |
| - // apps Plan 3, Group R; Astra R2 round 1, P1 2); Advance clears it |
| - // before the web starts. "" on every other intent, and once advanced. |
| - // An agent before it ignores the key and reconciles the intent as a |
| - // failure, the safe direction. |
| - Phase string `json:"phase,omitempty"` |
| } |
| -// IntentPhaseRelease is an intent in its release phase (a rootfs overlap |
| -// adoption or a rootfs first wake): the build's release command may be |
| -// running (or has passed) and its web has not started. An interruption |
| -// here is not the build's failure: reconciliation drops the intent with no |
| -// record (a hold keeps its hold-ran marker), and the attempt or the next |
| -// wake runs the build again, release first (D3, INV-R3). |
| -const IntentPhaseRelease = "release" |
| - |
| // wakeIntent reports whether id is a planned wake's intent: "w" leads a |
| // wake's identity, in this agent's form and an earlier one's alike. |
| func wakeIntent(id string) bool { return strings.HasPrefix(id, "w") } |
| @@ -400,10 +384,9 @@ type FailureBook struct { |
| held map[string]HoldRan |
| // intents are the executions in flight by host (Intent), saved with the |
| // records. reconciled is how many intents OpenFailureBook turned into |
| - // records, interrupted how many it dropped in their release phase. |
| - intents map[string]Intent |
| - reconciled int |
| - interrupted int |
| + // records. |
| + intents map[string]Intent |
| + reconciled int |
| // dirty is set whenever memory differs from the last save that landed |
| // (rule 2): a save failed, or the open changed something (a rotated |
| // identity, reconciled intents, epochs given to older entries). Memory is |
| @@ -633,24 +616,8 @@ func (b *FailureBook) reconcileLocked() { |
| hosts = append(hosts, host) |
| } |
| slices.Sort(hosts) // one order for every open of the same file |
| - recorded := 0 |
| for _, host := range hosts { |
| in := b.intents[host] |
| - if in.Phase == IntentPhaseRelease { |
| - // An execution interrupted in its release phase: only the |
| - // release may have run, and its result is unknown. No failure |
| - // and no hold-down: the attempt or the wake runs again, release |
| - // first. A hold's release ran against the database the good |
| - // build would boot on, so a hold keeps the hold-ran marker, as |
| - // a hold that ran and did not pass does: the next wake boots the |
| - // marked build (its release again), never the good build. |
| - b.interrupted++ |
| - if in.Mode == string(activator.ModeHold) { |
| - b.markLocked(host, HoldRan{Account: in.Account, App: in.App, Build: in.Build, Exec: in.ID, At: in.Start}) |
| - } |
| - continue |
| - } |
| - recorded++ |
| r := FailureRecord{Account: in.Account, App: in.App, Build: in.Build, Host: host, |
| Cause: string(activator.CauseRelease), Mode: in.Mode, Reason: reconciledReason, PromotedAt: now, At: now} |
| if in.Mode == string(activator.ModeHold) { |
| @@ -660,7 +627,7 @@ func (b *FailureBook) reconcileLocked() { |
| } |
| b.recordLocked(r) |
| } |
| - b.reconciled = recorded |
| + b.reconciled = len(hosts) |
| b.intents = nil |
| b.dirty = true |
| } |
| @@ -674,42 +641,6 @@ func (b *FailureBook) Reconciled() int { |
| return b.reconciled |
| } |
| -// Interrupted is how many intents OpenFailureBook dropped with no record: |
| -// executions an earlier agent left in their release phase |
| -// (IntentPhaseRelease), which run again. |
| -func (b *FailureBook) Interrupted() int { |
| - b.mu.Lock() |
| - defer b.mu.Unlock() |
| - return b.interrupted |
| -} |
| - |
| -// Advance ends the release phase of host's intent for execution id |
| -// (IntentPhaseRelease) and saves, before anything of the build but its |
| -// release runs (activator Attempt.BeforeWeb). From then on the intent |
| -// reconciles as any execution's. On a save error the phase is put back |
| -// and the error returned: the caller must not start the web, since a |
| -// restart would then read a failure as an interruption. An intent of |
| -// another execution, or none, is refused the same way. |
| -func (b *FailureBook) Advance(host, id string) error { |
| - b.mu.Lock() |
| - defer b.mu.Unlock() |
| - in, ok := b.intents[host] |
| - if !ok || id == "" || in.ID != id { |
| - return fmt.Errorf("%s: no intent of execution %q stands to advance", host, id) |
| - } |
| - if in.Phase == "" { |
| - return nil |
| - } |
| - prev := in |
| - in.Phase = "" |
| - b.intents[host] = in |
| - if err := b.saveLocked(); err != nil { |
| - b.intents[host] = prev |
| - return err |
| - } |
| - return nil |
| -} |
| - |
| // Flush saves the book now: after reconciliation, so the records it made |
| // and the intents it removed reach the disk before anything runs. |
| func (b *FailureBook) Flush() error { |
diff --git a/internal/rollout/rootfs_release_crash_test.go b/internal/rollout/rootfs_release_crash_test.go| new file mode 100644 |
| index 000000000..c209bf612 |
| --- /dev/null |
| +++ b/internal/rollout/rootfs_release_crash_test.go |
| @@ -0,0 +1,133 @@ |
| +package rollout |
| + |
| +// Rootfs apps Plan 3, Group R (controller ruling, R2 fix round 2): an agent |
| +// that dies while a rootfs build's release runs recovers exactly as a binary |
| +// attempt does. The adoption's write-ahead intent becomes B's failure when |
| +// the next agent opens the book; B stays off the host until it is retried |
| +// explicitly; and the retry runs B's release again before B's web, because |
| +// the row's committed good build is still A (the activator's releaseDue, |
| +// read through committedGood: TestRestartAfterAnOverlapRunsNoRelease and |
| +// TestRetryAfterACrashRunsTheReleaseAgain pin that half). |
| + |
| +import ( |
| + "context" |
| + "slices" |
| + "sync" |
| + "sync/atomic" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/activator" |
| + "github.com/carlosframework/platform/internal/registry" |
| +) |
| + |
| +func TestACrashedReleaseRecoversAsABinaryAttemptDoes(t *testing.T) { |
| + for _, rootfs := range []bool{true, false} { |
| + t.Run(map[bool]string{true: "rootfs", false: "binary (unchanged)"}[rootfs], func(t *testing.T) { |
| + h := newHarness(t, "a") |
| + if rootfs { |
| + r := h.rows.get("a") |
| + r.Runtime = registry.RuntimeRootfsV1 |
| + h.rows.put(r) |
| + } |
| + dir := h.onDisk() |
| + h.stage("v2") |
| + // The fake activator's Swap, modelled on the real one's order: |
| + // for a rootfs row, B's release runs first when B is not the |
| + // row's committed good build (releaseDue on committedGood), |
| + // then B's web. The first agent's attempt dies in the release. |
| + var ( |
| + mu sync.Mutex |
| + order []string |
| + causes []activator.Cause |
| + runs atomic.Int32 |
| + ) |
| + note := func(s string) { |
| + mu.Lock() |
| + order = append(order, s) |
| + mu.Unlock() |
| + } |
| + reached, park := make(chan struct{}), make(chan struct{}) |
| + h.act.outcome = func(a activator.Attempt) activator.SwapOutcome { |
| + if a.Build != "v2" { |
| + return activator.SwapDone |
| + } |
| + mu.Lock() |
| + causes = append(causes, a.Cause) |
| + mu.Unlock() |
| + if row := h.rows.get(a.Host); row.Rootfs() && row.GoodVersion != a.Build { |
| + note("release:" + a.Build) |
| + } |
| + if runs.Add(1) == 1 { |
| + close(reached) |
| + <-park // the agent dies here |
| + return activator.SwapAbandoned |
| + } |
| + note("web:" + a.Build) |
| + return activator.SwapDone |
| + } |
| + first := h.m |
| + t.Cleanup(func() { |
| + close(park) |
| + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) |
| + defer cancel() |
| + first.Close(ctx) |
| + h.m.Close(ctx) |
| + }) |
| + h.install("v2", "a") |
| + h.pass() |
| + select { |
| + case <-reached: |
| + case <-time.After(10 * time.Second): |
| + t.Fatal("the adoption never reached the activator") |
| + } |
| + if in, ok := fileOf(t, dir).Intents["a"]; !ok || in.Build != "v2" || in.Mode != "overlap" { |
| + t.Fatalf("the intent on disk at the crash: %+v, %v", in, ok) |
| + } |
| + |
| + // The next agent opens the book: the intent is B's failure, as |
| + // for any execution that did not record its outcome. |
| + b, err := OpenFailureBook(dir) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if b.Reconciled() != 1 || !b.Blocks("bab", "blog", "v2", "a", false) { |
| + t.Fatalf("reopened: reconciled %d, v2 blocked %v; want B's failure", b.Reconciled(), b.Blocks("bab", "blog", "v2", "a", false)) |
| + } |
| + if err := b.Flush(); err != nil { |
| + t.Fatal(err) |
| + } |
| + h.restartOn(b) |
| + h.pass() |
| + time.Sleep(200 * time.Millisecond) |
| + if n := runs.Load(); n != 1 { |
| + t.Fatalf("v2 ran %d times before a retry: its failure must keep it off the host", n) |
| + } |
| + |
| + // The explicit retry: B runs again, its release first (the row's |
| + // good build is still v1), then its web. |
| + if got := h.rows.get("a").GoodVersion; got != "v1" { |
| + t.Fatalf("the row's good build is %q before the retry; want v1", got) |
| + } |
| + if !h.retry("a", "v2") { |
| + t.Fatal("the retry of v2 cleared nothing") |
| + } |
| + h.pass() |
| + waitFor(t, "a on v2 after the retry", func() bool { return h.servingAll("v2", "a") }) |
| + mu.Lock() |
| + gotOrder, gotCauses := slices.Clone(order), slices.Clone(causes) |
| + mu.Unlock() |
| + want := []string{"web:v2"} |
| + if rootfs { |
| + want = []string{"release:v2", "release:v2", "web:v2"} |
| + } |
| + if !slices.Equal(gotOrder, want) { |
| + t.Fatalf("the activator saw %v; want %v (one release before the crash, one for the retry, then web)", gotOrder, want) |
| + } |
| + if len(gotCauses) != 2 || gotCauses[1] != activator.CauseRetry { |
| + t.Fatalf("attempt causes %v; want the retry second", gotCauses) |
| + } |
| + waitFor(t, "v2 recorded good", func() bool { return h.rows.get("a").GoodVersion == "v2" }) |
| + }) |
| + } |
| +} |
diff --git a/internal/rollout/rootfs_release_phase_test.go b/internal/rollout/rootfs_release_phase_test.go| deleted file mode 100644 |
| index 44a39299d..000000000 |
| --- a/internal/rollout/rootfs_release_phase_test.go |
| +++ /dev/null |
| @@ -1,313 +0,0 @@ |
| -package rollout |
| - |
| -// Rootfs apps Plan 3, Group R (Astra R2 round 1, P1 2): a rootfs overlap |
| -// adoption's write-ahead intent starts in its release phase, and the |
| -// activator ends the phase (Attempt.BeforeWeb, FailureBook.Advance) right |
| -// before the web starts. An agent that dies while the release runs, or |
| -// after it passed and before the web started, reopens its failure book with |
| -// no failure for the build, and the next agent runs the attempt again |
| -// (release first). Once the web has started, a crash is the build's possible |
| -// failure, as a binary attempt's always was. |
| - |
| -import ( |
| - "context" |
| - "sync/atomic" |
| - "testing" |
| - "time" |
| - |
| - "github.com/carlosframework/platform/internal/activator" |
| - "github.com/carlosframework/platform/internal/registry" |
| -) |
| - |
| -func TestAnInterruptedReleasePhaseReopensWithNoFailure(t *testing.T) { |
| - for _, tc := range []struct { |
| - name string |
| - rootfs bool |
| - webRan bool // the activator ended the release phase before the crash |
| - failure bool // the reopened book records the build's failure |
| - }{ |
| - {"rootfs, mid-release", true, false, false}, |
| - {"rootfs, after the release passed, before the web", true, false, false}, |
| - {"rootfs, after the web started", true, true, true}, |
| - {"binary, mid-swap (unchanged)", false, false, true}, |
| - } { |
| - t.Run(tc.name, func(t *testing.T) { |
| - h := newHarness(t, "a") |
| - if tc.rootfs { |
| - r := h.rows.get("a") |
| - r.Runtime = registry.RuntimeRootfsV1 |
| - h.rows.put(r) |
| - } |
| - dir := h.onDisk() |
| - h.stage("v2") |
| - var ( |
| - runs atomic.Int32 |
| - hadHook atomic.Bool |
| - advanceErr atomic.Value |
| - ) |
| - reached, park := make(chan struct{}), make(chan struct{}) |
| - // The fake activator's Swap, as the real one orders it: the |
| - // release (here, the crash points around it), then BeforeWeb |
| - // right before the web. Only the first agent's attempt parks. |
| - h.act.outcome = func(a activator.Attempt) activator.SwapOutcome { |
| - if a.Build != "v2" || runs.Add(1) > 1 { |
| - if a.BeforeWeb != nil { |
| - if err := a.BeforeWeb(); err != nil { |
| - return activator.SwapAbandoned |
| - } |
| - } |
| - return activator.SwapDone |
| - } |
| - hadHook.Store(a.BeforeWeb != nil) |
| - if tc.webRan { |
| - if err := a.BeforeWeb(); err != nil { |
| - advanceErr.Store(err) |
| - } |
| - } |
| - close(reached) |
| - <-park |
| - return activator.SwapDone |
| - } |
| - first := h.m |
| - t.Cleanup(func() { |
| - close(park) |
| - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) |
| - defer cancel() |
| - first.Close(ctx) |
| - h.m.Close(ctx) |
| - }) |
| - h.install("v2", "a") |
| - h.pass() |
| - select { |
| - case <-reached: |
| - case <-time.After(10 * time.Second): |
| - t.Fatal("the adoption never reached the activator") |
| - } |
| - if err, _ := advanceErr.Load().(error); err != nil { |
| - t.Fatalf("Advance: %v", err) |
| - } |
| - if hadHook.Load() != tc.rootfs { |
| - t.Fatalf("Attempt.BeforeWeb set %v on a rootfs row %v", hadHook.Load(), tc.rootfs) |
| - } |
| - in, ok := fileOf(t, dir).Intents["a"] |
| - wantPhase := "" |
| - if tc.rootfs && !tc.webRan { |
| - wantPhase = IntentPhaseRelease |
| - } |
| - if !ok || in.Build != "v2" || in.Mode != "overlap" || in.Phase != wantPhase { |
| - t.Fatalf("intent on disk at the crash: %+v, %v; want v2, overlap, phase %q", in, ok, wantPhase) |
| - } |
| - |
| - // The agent dies here; the next one opens the book. |
| - b, err := OpenFailureBook(dir) |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| - recorded := false |
| - for _, r := range b.List() { |
| - recorded = recorded || (r.Build == "v2" && r.Host == "a") |
| - } |
| - if recorded != tc.failure { |
| - t.Fatalf("reopened: v2 recorded failed %v, want %v (reconciled %d, interrupted %d)", recorded, tc.failure, b.Reconciled(), b.Interrupted()) |
| - } |
| - wantInterrupted := 0 |
| - if !tc.failure { |
| - wantInterrupted = 1 |
| - } |
| - if b.Interrupted() != wantInterrupted || b.Reconciled() != 1-wantInterrupted { |
| - t.Fatalf("reconciled %d, interrupted %d", b.Reconciled(), b.Interrupted()) |
| - } |
| - if err := b.Flush(); err != nil { |
| - t.Fatal(err) |
| - } |
| - if f := fileOf(t, dir); len(f.Intents) != 0 { |
| - t.Fatalf("intents left after the reopen: %+v", f.Intents) |
| - } |
| - |
| - // The new agent's scheduler. An interrupted release phase runs |
| - // the attempt again (release first) and B serves; a failure |
| - // keeps B off the host. |
| - h.restartOn(b) |
| - h.pass() |
| - if !tc.failure { |
| - waitFor(t, "the attempt to run again", func() bool { return runs.Load() >= 2 && h.servingAll("v2", "a") }) |
| - waitFor(t, "the rerun's intent to end", func() bool { return len(fileOf(t, dir).Intents) == 0 }) |
| - for _, r := range fileOf(t, dir).Records { |
| - if r.Build == "v2" { |
| - t.Fatalf("a failure of v2 after the rerun: %+v", r) |
| - } |
| - } |
| - return |
| - } |
| - time.Sleep(200 * time.Millisecond) |
| - h.pass() |
| - time.Sleep(200 * time.Millisecond) |
| - if n := runs.Load(); n != 1 { |
| - t.Fatalf("v2 ran %d times after its reconciled failure", n) |
| - } |
| - }) |
| - } |
| -} |
| - |
| -// Advance ends only its own execution's release phase, and a save it cannot |
| -// make leaves the phase in place: the web must not start then. |
| -func TestAdvanceEndsOnlyItsOwnReleasePhase(t *testing.T) { |
| - dir := t.TempDir() |
| - b, err := OpenFailureBook(dir) |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| - in := Intent{Account: "bab", App: "blog", Build: "v2", Mode: "overlap", ID: "a1-1", Phase: IntentPhaseRelease} |
| - if err := b.Begin("a", in); err != nil { |
| - t.Fatal(err) |
| - } |
| - if err := b.Advance("a", "a1-2"); err == nil { |
| - t.Fatal("Advance of another execution's intent succeeded") |
| - } |
| - if err := b.Advance("b", "a1-1"); err == nil { |
| - t.Fatal("Advance of a host with no intent succeeded") |
| - } |
| - if got := fileOf(t, dir).Intents["a"].Phase; got != IntentPhaseRelease { |
| - t.Fatalf("phase %q after refused advances", got) |
| - } |
| - readOnly(t, dir) |
| - if err := b.Advance("a", "a1-1"); err == nil { |
| - t.Fatal("Advance succeeded with the book unwritable") |
| - } |
| - writable(t, dir) |
| - if err := b.SaveIfDirty(); err != nil { |
| - t.Fatal(err) |
| - } |
| - if got := fileOf(t, dir).Intents["a"].Phase; got != IntentPhaseRelease { |
| - t.Fatalf("phase %q after a failed advance", got) |
| - } |
| - if err := b.Advance("a", "a1-1"); err != nil { |
| - t.Fatal(err) |
| - } |
| - if got := fileOf(t, dir).Intents["a"].Phase; got != "" { |
| - t.Fatalf("phase %q after the advance", got) |
| - } |
| - // A hold interrupted in its release phase: no failure, no hold-down, |
| - // and the hold-ran marker (its release ran against the database). |
| - if err := b.End("a", "a1-1"); err != nil { |
| - t.Fatal(err) |
| - } |
| - if err := b.Begin("a", Intent{Account: "bab", App: "blog", Build: "v2", Mode: "hold", ID: "a1-3", Phase: IntentPhaseRelease}); err != nil { |
| - t.Fatal(err) |
| - } |
| - r, err := OpenFailureBook(dir) |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| - mark, marked := r.HoldRanOn("a") |
| - if r.Interrupted() != 1 || r.Reconciled() != 0 || r.HeldDown("bab", "blog", "v2", "a") || len(r.List()) != 0 || |
| - !marked || mark.Build != "v2" || mark.Exec != "a1-3" { |
| - t.Fatalf("a hold intent in a release phase: reconciled %d, interrupted %d, records %v, marker %+v %v", |
| - r.Reconciled(), r.Interrupted(), r.List(), mark, marked) |
| - } |
| -} |
| - |
| -// Astra R3 round 1, finding 3: a rootfs first wake's intent starts in its |
| -// release phase too. An agent that dies during B's release (before the |
| -// activator ends the phase, WakePlan.BeforeWeb) reopens with no failure of |
| -// B and no hold-down, and the next agent's planner boots B again, release |
| -// first: an overlap row is not moved onto the good build, a hold row is not |
| -// left down (it keeps the hold-ran marker, so the good build never boots on |
| -// a database B's release ran against). Once the phase has ended, a crash is |
| -// B's possible failure, as a binary first wake's always is. |
| -func TestAnInterruptedFirstWakeReleaseReopensWithNoFailure(t *testing.T) { |
| - for _, tc := range []struct { |
| - name string |
| - rootfs bool |
| - hold bool |
| - webRan bool |
| - }{ |
| - {"rootfs overlap, during the release", true, false, false}, |
| - {"rootfs hold, during the release", true, true, false}, |
| - {"rootfs overlap, after the web started", true, false, true}, |
| - {"rootfs hold, after the web started", true, true, true}, |
| - {"binary overlap (unchanged)", false, false, false}, |
| - {"binary hold (unchanged)", false, true, false}, |
| - } { |
| - t.Run(tc.name, func(t *testing.T) { |
| - h := newHarness(t, "a") |
| - if tc.rootfs { |
| - r := h.rows.get("a") |
| - r.Runtime = registry.RuntimeRootfsV1 |
| - h.rows.put(r) |
| - } |
| - if tc.hold { |
| - h.mu.Lock() |
| - h.demands["v2"] = "hold" |
| - h.mu.Unlock() |
| - } |
| - dir := h.onDisk() |
| - h.stage("v2") |
| - h.install("v2", "a") |
| - h.wakeHost("a") |
| - p := h.m.Plan(context.Background(), h.rows.get("a")) |
| - wantMode := activator.ModeOverlap |
| - if tc.hold { |
| - wantMode = activator.ModeHold |
| - } |
| - if !p.FirstWake || p.Boot.Version != "v2" || p.Mode != wantMode || (p.BeforeWeb != nil) != tc.rootfs { |
| - t.Fatalf("plan %+v (BeforeWeb set %v): want a first wake of v2 in %s, BeforeWeb on a rootfs row only", p, p.BeforeWeb != nil, wantMode) |
| - } |
| - if tc.webRan { |
| - if err := p.BeforeWeb(); err != nil { |
| - t.Fatalf("BeforeWeb: %v", err) |
| - } |
| - } |
| - wantPhase := "" |
| - if tc.rootfs && !tc.webRan { |
| - wantPhase = IntentPhaseRelease |
| - } |
| - if in, ok := fileOf(t, dir).Intents["a"]; !ok || in.Build != "v2" || in.Mode != string(wantMode) || in.Phase != wantPhase { |
| - t.Fatalf("the wake's intent on disk at the crash: %+v, %v; want phase %q", in, ok, wantPhase) |
| - } |
| - |
| - // The agent dies during the wake; the next one opens the book. |
| - b, err := OpenFailureBook(dir) |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| - failed := false |
| - for _, r := range b.List() { |
| - failed = failed || (r.Build == "v2" && r.Host == "a") |
| - } |
| - interrupted := tc.rootfs && !tc.webRan |
| - if failed == interrupted || (b.Interrupted() == 1) != interrupted { |
| - t.Fatalf("reopened: v2 failed %v, interrupted %d; want an interruption %v", failed, b.Interrupted(), interrupted) |
| - } |
| - heldDown := b.HeldDown("bab", "blog", "v2", "a") |
| - if heldDown != (tc.hold && !interrupted) { |
| - t.Fatalf("reopened: held down %v", heldDown) |
| - } |
| - if mark, ok := b.HoldRanOn("a"); ok != tc.hold || (ok && mark.Build != "v2") { |
| - t.Fatalf("reopened: hold-ran marker %+v, %v; want one on a hold", mark, ok) |
| - } |
| - if err := b.Flush(); err != nil { |
| - t.Fatal(err) |
| - } |
| - |
| - // The next agent's planner. |
| - h.restartOn(b) |
| - h.wakeHost("a") |
| - next := h.m.Plan(context.Background(), h.rows.get("a")) |
| - switch { |
| - case interrupted: |
| - if !next.FirstWake || next.Boot.Version != "v2" || next.Mode != wantMode || next.Refuse != "" || next.BeforeWeb == nil { |
| - t.Fatalf("after an interrupted release: plan %+v; want v2's first wake again, its release first", next) |
| - } |
| - case tc.hold: |
| - if next.Refuse == "" { |
| - t.Fatalf("after a hold's possible failure: plan %+v; want it refused (held down)", next) |
| - } |
| - default: |
| - if next.FirstWake || next.Boot.Version != "v1" { |
| - t.Fatalf("after a possible failure: plan %+v; want the good build v1", next) |
| - } |
| - } |
| - }) |
| - } |
| -} |
diff --git a/internal/rollout/scheduler.go b/internal/rollout/scheduler.go| index 26b6bbfcf..409650d3c 100644 |
| --- a/internal/rollout/scheduler.go |
| +++ b/internal/rollout/scheduler.go |
| @@ -194,17 +194,6 @@ func (s *scheduler) execute(ctx context.Context, d dispatch) { |
| mode = m.d.Act.EffectiveMode(rt.Host, a.Mode) |
| } |
| in := Intent{Account: s.key.acct, App: s.key.app, Build: d.ID.Build, Mode: string(mode), ID: d.ExecID, Start: d.Started} |
| - // A rootfs overlap begins in its release phase (Group R; Astra R2 |
| - // round 1, P1 2): its release runs beside the serving incumbent |
| - // before anything else of the build, and an agent that dies there |
| - // has not seen the build fail. The activator ends the phase through |
| - // BeforeWeb, before the web starts. A binary row's intent, and a |
| - // hold's, are as they were. |
| - if !rt.IsSidecar() && rt.Rootfs() && mode == activator.ModeOverlap { |
| - in.Phase = IntentPhaseRelease |
| - host, exec := d.ID.Host, d.ExecID |
| - a.BeforeWeb = func() error { return m.d.Book.Advance(host, exec) } |
| - } |
| if err := m.d.Book.Begin(d.ID.Host, in); err != nil { // rolloutsim:M10 |
| m.d.Logf("rollout: %s: write the intent of its %s attempt onto %s: %v; not running it", d.ID.Host, d.ID.Cause, d.ID.Build, err) |
| reason := "failure records could not be written" |
diff --git a/internal/rollout/wakeplan.go b/internal/rollout/wakeplan.go| index 67ce2b934..bf4544ea1 100644 |
| --- a/internal/rollout/wakeplan.go |
| +++ b/internal/rollout/wakeplan.go |
| @@ -309,17 +309,6 @@ func (m *Manager) beginWake(rt registry.Route, plan activator.WakePlan, tok uint |
| } |
| in := Intent{Account: release.RouteAccount(rt), App: rt.App, Build: plan.Boot.Version, Mode: string(plan.Mode), |
| ID: m.wakeExecID(tok), Start: planAt} |
| - // A rootfs first wake begins in its release phase (Group R; Astra R2 |
| - // round 1, P1 2, R3 round 1, finding 3): the build's release runs |
| - // under the wake's lease before anything else of it, and an agent that |
| - // dies there has not seen the build fail. The activator ends the phase |
| - // through BeforeWeb, before the build's web starts. A binary row's |
| - // intent is as it was. |
| - if rt.Rootfs() && !rt.IsSidecar() { |
| - in.Phase = IntentPhaseRelease |
| - host, exec := rt.Host, in.ID |
| - plan.BeforeWeb = func() error { return m.d.Book.Advance(host, exec) } |
| - } |
| err := m.d.Book.Begin(rt.Host, in) |
| if err == nil { |
| // The intent is on disk: Close now waits for the terminal event |