From bbbc613c3ed0ee15a832b8a11ef8d3adbe2d0c20 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 6 Dec 2026 02:54:47 -0800 Subject: [PATCH] seaweed-block: a rack outage test asserts the detach's settlement (review round 1) The plain detach answered during the outage settles as a stop-abort: with the filer answering, a guest write completes within 30 s (tried every 2 s) and HEAD, as "ops chunk show" reads it, is live with the holder, claim and epoch it had before the detach, its generation past the baseline's and its committed image unchanged. The header comment now states this claim. The repeated plain detach after recovery leaves HEAD detached with the same holder, claim and epoch, at a position no older than the newest LSN the holder reports written (HeadLSN in /status/durable) after the last outage-time guest write. The recovery steps are numbered in the order they run: 9 restart, 10 the snapshot resumed, 11 the plain detach repeated, 12 the restore repeated. Co-Authored-By: Claude Opus 5.5 --- .../e9_rack_outage_integration_test.go | 165 +++++++++++++----- 1 file changed, 123 insertions(+), 42 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/e9_rack_outage_integration_test.go b/seaweed-block/cmd/blockvolume/e9_rack_outage_integration_test.go index 06016701d6..c14c7b578b 100644 --- a/seaweed-block/cmd/blockvolume/e9_rack_outage_integration_test.go +++ b/seaweed-block/cmd/blockvolume/e9_rack_outage_integration_test.go @@ -41,9 +41,9 @@ import ( // outage; guest load; then, during the outage, a cut, a snapshot, a restore // of the pre-outage snapshot into a new volume, and a plain detach last. // Then recovery: rackC's server restarts, and each interrupted request is -// repeated as it was asked (the snapshot resumed by its request id before -// the plain detach, since a detached volume admits no snapshot; the -// restore last). +// repeated as it was asked: the snapshot resumed by its request id (before +// the plain detach, since a detached volume admits no snapshot), the plain +// detach, the restore. // // Asserted (the model's answers): during the outage the cut, the snapshot, // the restore and the plain detach each answer within the bound and none @@ -51,11 +51,16 @@ import ( // CLI resuming it answers no_progress, retryable; the restore answers // outcome_unknown, retryable, with its target listed as a dependent of the // source snapshot; the plain detach answers 503 cut_stalled, retryable, -// "I/O stays stopped", and a guest write after it does not complete; -// HEAD's committed image (current root and position) and the pre-outage -// snapshot's root are unchanged. After recovery the same requests -// complete: the snapshot succeeds and is listed, the plain detach answers -// 200, the restore succeeds. Recorded, one grep-able "E9-OUTAGE step N" +// "I/O stays stopped", and then settles as a stop-abort: with the filer +// answering, a guest write completes within 30 s and HEAD is live with the +// same holder, claim and epoch, its generation past the baseline's and its +// committed image unchanged; HEAD's committed image (current root and +// position) and the pre-outage snapshot's root are unchanged. After +// recovery the same requests complete: the snapshot succeeds and is +// listed; the plain detach answers 200 and HEAD is detached with the same +// holder, claim and epoch at a position no older than the newest LSN the +// holder reported written after the last outage-time guest write; the +// restore succeeds. Recorded, one grep-able "E9-OUTAGE step N" // line per step: guest write and flush latency before and during the // outage, each answer and the time to it, HEAD, the snapshot list and the // orphan count. @@ -168,7 +173,8 @@ func TestE9RackOutageOnAReleasedStore(t *testing.T) { cluster.stopProc(t, w4VolumeProc(len(racks)-1)) downAt := time.Now() during := e9GuestLoad(t, env, 60*time.Second, 'C') - t.Logf("E9-OUTAGE step 3 rackC down %s", during) + lsn3 := e9WrittenLSN(t, status) + t.Logf("E9-OUTAGE step 3 rackC down %s; holder written LSN %s", during, lsn3) // 4. A cut during the outage. snaps4 := snapList() @@ -222,6 +228,7 @@ func TestE9RackOutageOnAReleasedStore(t *testing.T) { } // 7. A plain detach during the outage, last. + hPre := head() snaps7 := snapList() detach := e9Handle(t, status, "/chunk/detach", map[string]any{"volumeID": "v1", "plain": true, "timeoutMs": e9Window.Milliseconds()}) t.Logf("E9-OUTAGE step 7 plain detach window=%s: HTTP %d code=%q retryable=%v after %s: %s; snapshots before=%s after=%s", @@ -234,12 +241,33 @@ func TestE9RackOutageOnAReleasedStore(t *testing.T) { case detach.status != http.StatusServiceUnavailable || detach.code != "cut_stalled" || !detach.retryable || !strings.Contains(detach.message, "I/O stays stopped"): t.Errorf("step 7: the plain detach answered HTTP %d %q retryable %v %q; want 503 cut_stalled, retryable, \"I/O stays stopped\"", detach.status, detach.code, detach.retryable, detach.message) } - // Guest I/O after the detach's answer: recorded, not asserted. I/O stays - // stopped only while the stop is unsettled; once the holder settles it as - // aborted (a stop-abort HEAD write, nothing published) serving resumes, so - // a write that completes here is the settled outcome, not a violation. - probeWrite := e9WriteProbe(env, 10*time.Second) - t.Logf("E9-OUTAGE step 7 guest write after the detach: %s", probeWrite) + // The detach settles as a stop-abort: I/O stays stopped only while the + // stop is unsettled; with the filer answering, the holder writes a + // stop-abort HEAD (nothing published) and serving resumes. A guest write + // is tried every 2 s until one completes or 30 s pass. + settleStart := time.Now() + var probes []string + completed := false + for !completed && time.Since(settleStart) < 30*time.Second { + bound := min(10*time.Second, 30*time.Second-time.Since(settleStart)) + r := e9WriteProbe(env, bound) + probes = append(probes, r) + if completed = r == "completed"; !completed { + time.Sleep(2 * time.Second) + } + } + lsn7 := e9WrittenLSN(t, status) + h7 := head() + t.Logf("E9-OUTAGE step 7 guest write after the detach: completed=%v after %s, %d tries %v; holder written LSN %s; HEAD gen=%d epoch=%d holder=%q claim=%q position=%d state=%q image=%s (before the detach gen=%d epoch=%d holder=%q claim=%q)", + completed, time.Since(settleStart).Round(time.Millisecond), len(probes), probes, lsn7, h7.Gen, h7.Epoch, h7.Holder, h7.ClaimID, h7.Position, h7.State, image(h7), + hPre.Gen, hPre.Epoch, hPre.Holder, hPre.ClaimID) + if !completed { + t.Errorf("step 7: no guest write completed within 30s of the detach's answer: %v", probes) + } + if h7.State != "" || h7.Holder != hPre.Holder || h7.ClaimID != hPre.ClaimID || h7.Epoch != hPre.Epoch || h7.Gen <= h1.Gen || image(h7) != image(h1) { + t.Errorf("step 7: HEAD after the detach is state %q holder %q claim %q epoch %d gen %d image %s; want the stop-abort settlement: live, holder %q claim %q epoch %d, gen past %d, image %s", + h7.State, h7.Holder, h7.ClaimID, h7.Epoch, h7.Gen, image(h7), hPre.Holder, hPre.ClaimID, hPre.Epoch, h1.Gen, image(h1)) + } // 8. HEAD's committed image is the baseline's and the pre-outage // snapshot names the same root; orphans recorded. @@ -264,55 +292,65 @@ func TestE9RackOutageOnAReleasedStore(t *testing.T) { t.Fatalf("step 9: no 020 placement writable within 3m of rackC's restart: %v", err) } - // 11 (before 10: a detached volume admits no snapshot, a resumed one - // included). The stalled snapshot resumed with its request id succeeds. + // 10. The stalled snapshot resumed with its request id succeeds (before + // the detach: a detached volume admits no snapshot, a resumed one + // included). // A client repeats a retryable answer: every 5 s for at most 5 min. - snaps11 := snapList() - start11 := time.Now() + snaps10 := snapList() + start10 := time.Now() var resumed e9CLIAnswer - var first11 string - tries11 := 0 + var first10 string + tries10 := 0 for { - tries11++ + tries10++ resumed = e9CLI(t, env, snapCLIArgs...) - if tries11 == 1 { - first11 = fmt.Sprintf("exit %d code=%q: %s", resumed.exit, resumed.code, firstLine(resumed.message)) + if tries10 == 1 { + first10 = fmt.Sprintf("exit %d code=%q: %s", resumed.exit, resumed.code, firstLine(resumed.message)) } - if resumed.exit == 0 || !resumed.retryable || time.Since(start11) > e9RepeatBound { + if resumed.exit == 0 || !resumed.retryable || time.Since(start10) > e9RepeatBound { break } time.Sleep(5 * time.Second) } listed := e9SnapshotListed(t, env, outageSnap) - t.Logf("E9-OUTAGE step 11 snapshot resumed with its request id: %d tries over %s, first %s; last exit %d code=%q: %s; %s listed=%v; snapshots before=%s after=%s", - tries11, time.Since(start11).Round(time.Millisecond), first11, resumed.exit, resumed.code, firstLine(resumed.message), outageSnap, listed, snaps11, snapList()) + t.Logf("E9-OUTAGE step 10 snapshot resumed with its request id: %d tries over %s, first %s; last exit %d code=%q: %s; %s listed=%v; snapshots before=%s after=%s", + tries10, time.Since(start10).Round(time.Millisecond), first10, resumed.exit, resumed.code, firstLine(resumed.message), outageSnap, listed, snaps10, snapList()) if resumed.exit != 0 || !listed { - t.Errorf("step 11: the resumed snapshot answered exit %d code %q, listed %v; want success and %s listed", resumed.exit, resumed.code, listed, outageSnap) + t.Errorf("step 10: the resumed snapshot answered exit %d code %q, listed %v; want success and %s listed", resumed.exit, resumed.code, listed, outageSnap) } - // 10. The same plain detach, repeated, completes. - snaps10 := snapList() - start10 := time.Now() + // 11. The same plain detach, repeated, completes: HEAD is detached with + // the holder, claim and epoch it had, at a position no older than the + // newest LSN written after the last outage-time guest write. + snaps11 := snapList() + start11 := time.Now() var detached e9Answer - var first10 string - tries10 := 0 + var first11 string + tries11 := 0 for { - tries10++ + tries11++ detached = e9Handle(t, status, "/chunk/detach", map[string]any{"volumeID": "v1", "plain": true, "timeoutMs": e9Window.Milliseconds()}) - if tries10 == 1 { - first10 = fmt.Sprintf("HTTP %d code=%q", detached.status, detached.code) + if tries11 == 1 { + first11 = fmt.Sprintf("HTTP %d code=%q", detached.status, detached.code) } - if detached.status == http.StatusOK || !detached.retryable || time.Since(start10) > e9RepeatBound { + if detached.status == http.StatusOK || !detached.retryable || time.Since(start11) > e9RepeatBound { break } time.Sleep(5 * time.Second) } - h10 := head() - t.Logf("E9-OUTAGE step 10 plain detach repeated: %d tries over %s, first %s; last HTTP %d code=%q retryable=%v after %s: %s; HEAD gen=%d epoch=%d position=%d state=%q image=%s; snapshots before=%s after=%s", - tries10, time.Since(start10).Round(time.Millisecond), first10, detached.status, detached.code, detached.retryable, detached.at.Round(time.Millisecond), firstLine(detached.message), - h10.Gen, h10.Epoch, h10.Position, h10.State, image(h10), snaps10, snapList()) + h11 := head() + t.Logf("E9-OUTAGE step 11 plain detach repeated: %d tries over %s, first %s; last HTTP %d code=%q retryable=%v after %s: %s; HEAD gen=%d epoch=%d holder=%q claim=%q position=%d state=%q image=%s (written LSN after step 3 %s, after step 7 %s); snapshots before=%s after=%s", + tries11, time.Since(start11).Round(time.Millisecond), first11, detached.status, detached.code, detached.retryable, detached.at.Round(time.Millisecond), firstLine(detached.message), + h11.Gen, h11.Epoch, h11.Holder, h11.ClaimID, h11.Position, h11.State, image(h11), lsn3, lsn7, snaps11, snapList()) if detached.status != http.StatusOK { - t.Errorf("step 10: the repeated plain detach answered HTTP %d %q retryable %v; want 200", detached.status, detached.code, detached.retryable) + t.Errorf("step 11: the repeated plain detach answered HTTP %d %q retryable %v; want 200", detached.status, detached.code, detached.retryable) + } + if h11.State != "detached" || h11.Holder != hPre.Holder || h11.ClaimID != hPre.ClaimID || h11.Epoch != hPre.Epoch { + t.Errorf("step 11: HEAD after the detach is state %q holder %q claim %q epoch %d; want detached, holder %q claim %q epoch %d", + h11.State, h11.Holder, h11.ClaimID, h11.Epoch, hPre.Holder, hPre.ClaimID, hPre.Epoch) + } + if !lsn7.known || h11.Position < lsn7.head { + t.Errorf("step 11: HEAD position %d; want at least the holder's written LSN after the last outage-time guest write (%s)", h11.Position, lsn7) } // 12. The same restore, repeated, completes: v2 is store-ready. @@ -325,6 +363,49 @@ func TestE9RackOutageOnAReleasedStore(t *testing.T) { } } +// e9LSN is the holder's newest written LSN for v1 as /status/durable +// reports it (HeadLSN, valid when FrontierKnown). +type e9LSN struct { + head uint64 + known bool + operational bool +} + +func (l e9LSN) String() string { + return fmt.Sprintf("HeadLSN=%d frontierKnown=%v operational=%v", l.head, l.known, l.operational) +} + +// e9WrittenLSN reads v1's HeadLSN (the newest LSN written) from the +// holder's /status/durable. +func e9WrittenLSN(t *testing.T, addr string) e9LSN { + t.Helper() + client := &http.Client{Timeout: 30 * time.Second} + resp, err := client.Get("http://" + addr + "/status/durable?volume=v1") + if err != nil { + t.Fatalf("durable status: %v", err) + } + defer resp.Body.Close() + var st struct { + Volumes []struct { + VolumeID string + FrontierKnown bool + HeadLSN uint64 + Operational bool + } + } + b, err := io.ReadAll(io.LimitReader(resp.Body, 4<<20)) + if err != nil || resp.StatusCode != http.StatusOK || json.Unmarshal(b, &st) != nil { + t.Fatalf("durable status: HTTP %d %v: %.200q", resp.StatusCode, err, b) + } + for _, v := range st.Volumes { + if v.VolumeID == "v1" { + return e9LSN{head: v.HeadLSN, known: v.FrontierKnown, operational: v.Operational} + } + } + t.Fatalf("durable status lists no v1: %.200q", b) + return e9LSN{} +} + // e9SnapshotListed reports whether "ops chunk snapshots" lists v1's // snapshot name. func e9SnapshotListed(t *testing.T, env *handoffEnv, name string) bool {