From 51f9d95af677020e17b0c34332cd60c39a0dfd98 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 21 Nov 2026 14:57:57 -0800 Subject: [PATCH] test: preserve cut controls across HEAD claim at open --- .../core/frontend/durable/host_limit_test.go | 3 +- .../provider_chunk_authority_log_test.go | 2 +- .../durable/provider_chunk_control_test.go | 5 ++-- .../provider_chunk_detach_stop_test.go | 5 ++-- .../durable/provider_chunk_lifetime_test.go | 8 +++-- .../durable/provider_chunk_sched_test.go | 30 +++++++++++-------- .../durable/provider_maintenance_test.go | 3 +- .../host/volume/chunk_control_order_test.go | 11 +++++-- .../core/storage/chunk_precopy_detach_test.go | 3 +- 9 files changed, 44 insertions(+), 26 deletions(-) diff --git a/seaweed-block/core/frontend/durable/host_limit_test.go b/seaweed-block/core/frontend/durable/host_limit_test.go index e4b38a628b..084855ef8c 100644 --- a/seaweed-block/core/frontend/durable/host_limit_test.go +++ b/seaweed-block/core/frontend/durable/host_limit_test.go @@ -35,6 +35,7 @@ func TestHostCutLimitDoesNotGateGuestIO(t *testing.T) { } defer p.Close() s := openRecovered(t, p) + claimed := headHolder(t, r) if _, e = s.Write(0, block(0x72)); e != nil { t.Fatal(e) } @@ -54,7 +55,7 @@ func TestHostCutLimitDoesNotGateGuestIO(t *testing.T) { t.Fatal("limiter blocked read", e) } h, _ := r.GetHead(context.Background()) - if h.Gen != 0 { + if h.Gen != claimed.Gen { t.Fatal("refused cut published") } } diff --git a/seaweed-block/core/frontend/durable/provider_chunk_authority_log_test.go b/seaweed-block/core/frontend/durable/provider_chunk_authority_log_test.go index 9d3b9a2c4e..025ddf0fd0 100644 --- a/seaweed-block/core/frontend/durable/provider_chunk_authority_log_test.go +++ b/seaweed-block/core/frontend/durable/provider_chunk_authority_log_test.go @@ -90,7 +90,7 @@ func TestChunkAuthorityWaitLogsTheWaitTheClaimAndTheEnd(t *testing.T) { []string{"volume=v1: master authority after", `replica="r1" epoch=3 endpoint=1`, "first attach attempt"}, []string{`HEAD claim for volume=v1 starting: target epoch=3 holder="r1"`}, []string{`HEAD claim for volume=v1 observed HEAD gen=0 epoch=0 holder=""`, "; preparing"}, - []string{"HEAD claim for volume=v1 done in ", `gen=0 epoch=0 holder="", no HEAD to claim (new lineage)`}, + []string{"HEAD claim for volume=v1 done in ", `gen=1 epoch=3 holder="r1"`}, []string{"chunk authority wait for volume=v1 ended after", ": attached after 1 attempt(s)"}, ) if strings.Count(got, "first attach attempt") != 1 { diff --git a/seaweed-block/core/frontend/durable/provider_chunk_control_test.go b/seaweed-block/core/frontend/durable/provider_chunk_control_test.go index aef291bd2b..fb1496e089 100644 --- a/seaweed-block/core/frontend/durable/provider_chunk_control_test.go +++ b/seaweed-block/core/frontend/durable/provider_chunk_control_test.go @@ -19,17 +19,18 @@ func TestWALStoreChunk_CutVolumeReturnsInstalledHead(t *testing.T) { remote := storage.NewMemChunkRemote() p := chunkProvider(t, t.TempDir(), remote, v1View(), 0) s := openRecovered(t, p) + claimed := headHolder(t, remote) if _, err := s.Write(1, block(1)); err != nil { t.Fatal(err) } r, err := p.CutVolume(ctx, "v1", 0) head, _ := remote.GetHead(ctx) // (r.Stats is W3's: its fields read zero until then.) - if err != nil || r.Noop || head.Gen != 1 || r.Head.Gen != head.Gen || r.H != s.NextLSN()-1 || r.Head.RemoteLSN != r.H { + if err != nil || r.Noop || head.Gen != claimed.Gen+1 || r.Head.Gen != head.Gen || r.H != s.NextLSN()-1 || r.Head.RemoteLSN != r.H { t.Fatalf("cut: %+v %v; remote HEAD gen %d", r, err, head.Gen) } again, err := p.CutVolume(ctx, "v1", 0) - if err != nil || !again.Noop || again.Head.Gen != 1 || again.H != r.H { + if err != nil || !again.Noop || again.Head.Gen != r.Head.Gen || again.H != r.H { t.Fatalf("cut with nothing new: %+v %v", again, err) } if _, err := p.CutVolume(ctx, "v9", 0); !errors.Is(err, durable.ErrVolumeNotOpen) { diff --git a/seaweed-block/core/frontend/durable/provider_chunk_detach_stop_test.go b/seaweed-block/core/frontend/durable/provider_chunk_detach_stop_test.go index 0dda1b07f1..61f1fe7380 100644 --- a/seaweed-block/core/frontend/durable/provider_chunk_detach_stop_test.go +++ b/seaweed-block/core/frontend/durable/provider_chunk_detach_stop_test.go @@ -241,6 +241,7 @@ func TestWALStoreChunk_CutVolumeRefusesUnwrittenMinLSNBeforePublishing(t *testin remote := storage.NewMemChunkRemote() p := chunkProvider(t, t.TempDir(), remote, v1View(), 0) s := openRecovered(t, p) + claimed := headHolder(t, remote) if _, err := s.Write(1, block(1)); err != nil { t.Fatal(err) } @@ -248,11 +249,11 @@ func TestWALStoreChunk_CutVolumeRefusesUnwrittenMinLSNBeforePublishing(t *testin if _, err := p.CutVolume(ctx, "v1", last+1); err == nil { t.Fatal("a cut to an LSN never written succeeded") } - if head, _ := remote.GetHead(ctx); head.Gen != 0 || remote.Puts() != 0 { + if head, _ := remote.GetHead(ctx); head.Gen != claimed.Gen || remote.Puts() != 0 { t.Fatalf("a refused minLSN published: HEAD gen %d, %d chunks stored", head.Gen, remote.Puts()) } r, err := p.CutVolume(ctx, "v1", last) - if err != nil || r.H != last || r.Head.Gen != 1 { + if err != nil || r.H != last || r.Head.Gen != claimed.Gen+1 { t.Fatalf("cut to the last written LSN: %+v %v", r, err) } } diff --git a/seaweed-block/core/frontend/durable/provider_chunk_lifetime_test.go b/seaweed-block/core/frontend/durable/provider_chunk_lifetime_test.go index 21d1d73f72..ec5202d846 100644 --- a/seaweed-block/core/frontend/durable/provider_chunk_lifetime_test.go +++ b/seaweed-block/core/frontend/durable/provider_chunk_lifetime_test.go @@ -237,6 +237,7 @@ func TestWALStoreChunk_LineageDriftRefusesCapture(t *testing.T) { view := v1View() p := chunkProvider(t, t.TempDir(), remote, view, 0) s := openRecovered(t, p) + claimed := headHolder(t, remote) if _, err := s.Write(1, block(1)); err != nil { t.Fatal(err) } @@ -248,7 +249,7 @@ func TestWALStoreChunk_LineageDriftRefusesCapture(t *testing.T) { _, err := p.CaptureVolume(context.Background(), "v1") head, _ := remote.GetHead(context.Background()) if drift == nil { - if err != nil || head.Gen != 1 { + if err != nil || head.Gen != claimed.Gen+1 { t.Fatalf("capture under the attach lineage: %v (HEAD gen %d)", err, head.Gen) } return @@ -256,7 +257,7 @@ func TestWALStoreChunk_LineageDriftRefusesCapture(t *testing.T) { if !errors.Is(err, storage.ErrChunkCaptureRefused) { t.Fatalf("capture after %s drift: %v; want refused", name, err) } - if head.Gen != 0 || remote.Puts() != 0 { + if head.Gen != claimed.Gen || remote.Puts() != 0 { t.Fatalf("capture after %s drift published: HEAD gen %d, %d chunks stored", name, head.Gen, remote.Puts()) } }) @@ -273,6 +274,7 @@ func TestWALStoreChunk_LineageDriftDuringHeldUploadRefusesPublication(t *testing view := v1View() p := chunkProvider(t, t.TempDir(), g, view, 0) s := openRecovered(t, p) + claimed := headHolder(t, remote) if _, err := s.Write(1, block(1)); err != nil { t.Fatal(err) } @@ -286,7 +288,7 @@ func TestWALStoreChunk_LineageDriftDuringHeldUploadRefusesPublication(t *testing if err := recvErr(t, errc, "CaptureVolume"); !errors.Is(err, storage.ErrChunkCaptureRefused) { t.Fatalf("capture whose lineage moved during upload: %v; want refused", err) } - if head, _ := remote.GetHead(context.Background()); head.Gen != 0 { + if head, _ := remote.GetHead(context.Background()); head.Gen != claimed.Gen { t.Fatalf("stale lineage published HEAD gen %d", head.Gen) } } diff --git a/seaweed-block/core/frontend/durable/provider_chunk_sched_test.go b/seaweed-block/core/frontend/durable/provider_chunk_sched_test.go index 74526bc5b6..2ae68b0944 100644 --- a/seaweed-block/core/frontend/durable/provider_chunk_sched_test.go +++ b/seaweed-block/core/frontend/durable/provider_chunk_sched_test.go @@ -45,6 +45,7 @@ func TestWALStoreChunk_DirtyChunksNeverTriggerCut(t *testing.T) { remote := storage.NewMemChunkRemote() p := schedProvider(t, remote, 0) s := openRecovered(t, p) + claimed := headHolder(t, remote) for c := uint32(0); c < 4; c++ { // four dirty chunks if _, err := s.Write(c*pcChunkBlocks+1, block(byte(c+1))); err != nil { t.Fatal(err) @@ -52,7 +53,7 @@ func TestWALStoreChunk_DirtyChunksNeverTriggerCut(t *testing.T) { } // A negative invariant: checked repeatedly over several scheduler polls. for i := 0; i < 15; i++ { - if h := headGen(t, remote); h.Gen != 0 { + if h := headGen(t, remote); h.Gen != claimed.Gen { t.Fatalf("a cut was published with the timer off (HEAD gen %d, %d chunks)", h.Gen, len(h.Chunks)) } time.Sleep(100 * time.Millisecond) @@ -61,7 +62,7 @@ func TestWALStoreChunk_DirtyChunksNeverTriggerCut(t *testing.T) { if _, err := p.CaptureVolume(context.Background(), "v1"); err != nil { t.Fatal(err) } - if h := headGen(t, remote); h.Gen == 0 || len(h.Chunks) != 4 { + if h := headGen(t, remote); h.Gen != claimed.Gen+1 || len(h.Chunks) != 4 { t.Fatalf("explicit cut HEAD gen %d with %d chunks, want 4", h.Gen, len(h.Chunks)) } } @@ -73,6 +74,7 @@ func TestWALStoreChunk_ExplicitCutRestartsTheTimer(t *testing.T) { remote := storage.NewMemChunkRemote() p := schedProvider(t, remote, interval) s := openRecovered(t, p) + claimed := headHolder(t, remote) begin := time.Now() time.Sleep(2 * time.Second) @@ -83,8 +85,8 @@ func TestWALStoreChunk_ExplicitCutRestartsTheTimer(t *testing.T) { t.Fatal(err) } explicit := time.Now() - if h := headGen(t, remote); h.Gen != 1 { - t.Fatalf("explicit cut: HEAD gen %d, want 1", h.Gen) + if h := headGen(t, remote); h.Gen != claimed.Gen+1 { + t.Fatalf("explicit cut: HEAD gen %d, want open claim + 1", h.Gen) } if _, err := s.Write(pcChunkBlocks+1, block(0x02)); err != nil { t.Fatal(err) @@ -95,13 +97,13 @@ func TestWALStoreChunk_ExplicitCutRestartsTheTimer(t *testing.T) { if time.Now().After(explicit.Add(interval - 300*time.Millisecond)) { t.Skip("scheduling too slow to separate the two deadlines on this host") } - if h := headGen(t, remote); h.Gen != 1 { + if h := headGen(t, remote); h.Gen != claimed.Gen+1 { t.Fatalf("automatic cut %s after the explicit one (HEAD gen %d): the timer did not restart", time.Since(explicit), h.Gen) } // Progress, no timer (#227): the automatic cut follows; a loaded host only // delays it (the early-cut check above is the timing assertion, and it // skips when the host cannot separate the two deadlines). - for headGen(t, remote).Gen < 2 { + for headGen(t, remote).Gen < claimed.Gen+2 { time.Sleep(50 * time.Millisecond) } } @@ -186,6 +188,7 @@ func TestWALStoreChunk_PublishSettledHook(t *testing.T) { } t.Cleanup(func() { _ = p.Close() }) s := openRecovered(t, p) + claimed := headHolder(t, remote) for i, lba := range []uint32{1, 0, pcChunkBlocks + 1} { if lba != 0 { if _, err := s.Write(lba, block(byte(i+1))); err != nil { @@ -198,8 +201,10 @@ func TestWALStoreChunk_PublishSettledHook(t *testing.T) { } mu.Lock() defer mu.Unlock() - if len(got) != 2 || got[0] != "v1:0->1" || got[1] != "v1:1->2" { - t.Fatalf("reports %v; want [v1:0->1 v1:1->2] (the middle capture changed nothing)", got) + wantFirst := fmt.Sprintf("v1:%d->%d", claimed.Gen, claimed.Gen+1) + wantSecond := fmt.Sprintf("v1:%d->%d", claimed.Gen+1, claimed.Gen+2) + if len(got) != 2 || got[0] != wantFirst || got[1] != wantSecond { + t.Fatalf("reports %v; want [%s %s] (the middle capture changed nothing)", got, wantFirst, wantSecond) } } @@ -261,6 +266,7 @@ func TestWALStoreChunk_ExplicitCutOverlappingTheTimerRestartsIt(t *testing.T) { return loopEvent{} } s := openRecovered(t, p) + claimed := headHolder(t, remote.MemChunkRemote) begin := time.Now() // the loop started during open: its first deadline is at most begin + interval if _, err := s.Write(1, block(0x01)); err != nil { t.Fatal(err) @@ -307,8 +313,8 @@ func TestWALStoreChunk_ExplicitCutOverlappingTheTimerRestartsIt(t *testing.T) { t.Fatal("the explicit cut did not finish") } explicitAt := time.Now() - if h := headGen(t, remote); h.Gen != 1 { - t.Fatalf("explicit cut: HEAD gen %d, want 1", h.Gen) + if h := headGen(t, remote); h.Gen != claimed.Gen+1 { + t.Fatalf("explicit cut: HEAD gen %d, want open claim + 1", h.Gen) } if _, err := s.Write(pcChunkBlocks+1, block(0x02)); err != nil { t.Fatal(err) @@ -335,7 +341,7 @@ func TestWALStoreChunk_ExplicitCutOverlappingTheTimerRestartsIt(t *testing.T) { if cut2.event != "cut" || cut2.skipped { t.Fatalf("loop event %+v; want the next periodic cut taken", cut2) } - if h := headGen(t, remote); h.Gen != 2 { - t.Fatalf("after the next periodic cut: HEAD gen %d, want 2", h.Gen) + if h := headGen(t, remote); h.Gen != claimed.Gen+2 { + t.Fatalf("after the next periodic cut: HEAD gen %d, want open claim + 2", h.Gen) } } diff --git a/seaweed-block/core/frontend/durable/provider_maintenance_test.go b/seaweed-block/core/frontend/durable/provider_maintenance_test.go index 1f38b998b2..f19cc144e1 100644 --- a/seaweed-block/core/frontend/durable/provider_maintenance_test.go +++ b/seaweed-block/core/frontend/durable/provider_maintenance_test.go @@ -197,6 +197,7 @@ func TestCutDeadlineIncludesUploadWithBackgroundCaller(t *testing.T) { } t.Cleanup(func() { _ = p.Close() }) s := openRecovered(t, p) + claimed := headHolder(t, remote.MemChunkRemote) if _, err = s.Write(1, block(0x48)); err != nil { t.Fatal(err) } @@ -205,7 +206,7 @@ func TestCutDeadlineIncludesUploadWithBackgroundCaller(t *testing.T) { t.Fatalf("whole cut did not expire: %v", err) } h, err := remote.GetHead(context.Background()) - if err != nil || h.Gen != 0 { + if err != nil || h.Gen != claimed.Gen { t.Fatalf("expired upload published: %+v %v", h, err) } } diff --git a/seaweed-block/core/host/volume/chunk_control_order_test.go b/seaweed-block/core/host/volume/chunk_control_order_test.go index 71a16b3e89..63452f3718 100644 --- a/seaweed-block/core/host/volume/chunk_control_order_test.go +++ b/seaweed-block/core/host/volume/chunk_control_order_test.go @@ -7,6 +7,7 @@ package volume import ( "context" "errors" + "reflect" "testing" "github.com/seaweedfs/seaweed-block/core/frontend" @@ -68,6 +69,10 @@ func TestChunkControl_CutToUnwrittenMinLSNPublishesNothing(t *testing.T) { if _, err := dp.RecoverVolume(ctx, "v1"); err != nil { t.Fatal(err) } + claimed, err := remote.GetHead(ctx) + if err != nil { + t.Fatal(err) + } if _, err := s.Write(1, make([]byte, 4096)); err != nil { t.Fatal(err) } @@ -80,10 +85,10 @@ func TestChunkControl_CutToUnwrittenMinLSNPublishesNothing(t *testing.T) { if _, err := ctl.Cut(ctx, "v1", last+5); err == nil { t.Fatal("a cut to an LSN never written succeeded") } - if head, _ := remote.GetHead(ctx); head.Gen != 0 || remote.Puts() != 0 { - t.Fatalf("a refused minLSN published: HEAD gen %d, %d chunks stored", head.Gen, remote.Puts()) + if head, err := remote.GetHead(ctx); err != nil || !reflect.DeepEqual(head, claimed) || remote.Puts() != 0 { + t.Fatalf("a refused minLSN published beyond the open claim: HEAD %+v (claim %+v), %d chunks stored, err=%v", head, claimed, remote.Puts(), err) } - if r, err := ctl.Cut(ctx, "v1", last); err != nil || r.CutLSN != last || r.HeadGen != 1 { + if r, err := ctl.Cut(ctx, "v1", last); err != nil || r.CutLSN != last || r.HeadGen != claimed.Gen+1 { t.Fatalf("cut to the last written LSN: %+v %v", r, err) } } diff --git a/seaweed-block/core/storage/chunk_precopy_detach_test.go b/seaweed-block/core/storage/chunk_precopy_detach_test.go index d4f0059803..a309e22c97 100644 --- a/seaweed-block/core/storage/chunk_precopy_detach_test.go +++ b/seaweed-block/core/storage/chunk_precopy_detach_test.go @@ -191,7 +191,8 @@ func assertPrecopyMeasuredRefusal(t *testing.T, report PrecopyReport, err error) t.Helper() if !errors.Is(err, ErrPrecopyNotConverged) || report.Frozen || report.Estimate <= 1200*time.Millisecond || - (report.Reason != "tail_too_large" && report.Reason != "barrier_over_budget") { + (report.Reason != "tail_too_large" && report.Reason != "barrier_over_budget" && + !(report.Reason == "freeze_budget_exceeded" && report.Estimate > precopyFreezeLimit)) { t.Fatalf("not a valid measured over-budget refusal: report=%+v err=%v", report, err) } }