From 12e9536674b2b1b2c9a19574225a522ee6e271ea Mon Sep 17 00:00:00 2001 From: pingqiu Date: Tue, 17 Nov 2026 18:06:42 -0800 Subject: [PATCH] test(durable): retain real batch caller and reopen completed local BASE --- .../durable/provider_format_v3_base_test.go | 27 +++++++++--- .../durable/provider_format_v3_test.go | 42 +++++++++++++++++++ seaweed-block/core/storage/base_install_v3.go | 2 +- 3 files changed, 65 insertions(+), 6 deletions(-) diff --git a/seaweed-block/core/frontend/durable/provider_format_v3_base_test.go b/seaweed-block/core/frontend/durable/provider_format_v3_base_test.go index 131aab9669..45667982ab 100644 --- a/seaweed-block/core/frontend/durable/provider_format_v3_base_test.go +++ b/seaweed-block/core/frontend/durable/provider_format_v3_base_test.go @@ -114,7 +114,8 @@ func TestDurableProviderV3_CompletedBASEDoesNotRestoreOlderHEAD(t *testing.T) { if e := source.Close(); e != nil { t.Fatal(e) } - target := mappedProviderV3(t, t.TempDir(), remote) + root := t.TempDir() + target := mappedProviderV3(t, root, remote) st, e := target.EnsureStorage("v1") if e != nil { t.Fatal(e) @@ -141,10 +142,26 @@ func TestDurableProviderV3_CompletedBASEDoesNotRestoreOlderHEAD(t *testing.T) { if _, e = target.RecoverVolume(ctx, "v1"); e != nil { t.Fatalf("completed local BASE was treated as empty remote restore: %v", e) } - for lba, expected := range map[int64][]byte{5: want, 9: make([]byte, 4096)} { - got := make([]byte, 4096) - if n, e := target.Backend("v1").Read(ctx, lba*4096, got); e != nil || n != 4096 || !bytes.Equal(got, expected) { - t.Fatalf("local BASE lba%d bytes lost: n%d err%v", lba, n, e) + check := func() { + t.Helper() + for lba, expected := range map[int64][]byte{5: want, 9: make([]byte, 4096)} { + got := make([]byte, 4096) + if n, e := target.Backend("v1").Read(ctx, lba*4096, got); e != nil || n != 4096 || !bytes.Equal(got, expected) { + t.Fatalf("local BASE lba%d bytes lost: n%d err%v", lba, n, e) + } } + } + check() + if e = target.Close(); e != nil { + t.Fatal(e) + } + target = mappedProviderV3(t, root, remote) + if _, e = target.EnsureStorage("v1"); e != nil { + t.Fatal(e) + } + if _, e = target.RecoverVolume(ctx, "v1"); e != nil { + t.Fatal(e) + } + check() } diff --git a/seaweed-block/core/frontend/durable/provider_format_v3_test.go b/seaweed-block/core/frontend/durable/provider_format_v3_test.go index 1f7574db1c..a71b789518 100644 --- a/seaweed-block/core/frontend/durable/provider_format_v3_test.go +++ b/seaweed-block/core/frontend/durable/provider_format_v3_test.go @@ -420,3 +420,45 @@ func TestDurableProviderV3_StatusTracksRecoverSyncAndCapture(t *testing.T) { t.Fatalf("after capture=%+v", v) } } + +func TestDurableProviderV3_ContiguousWriteSurvivesCheckpointAndReopen(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) + defer cancel() + root := t.TempDir() + remote := storage.NewMemChunkRemote() + p := mappedProviderV3(t, root, remote) + st, e := p.EnsureStorage("v1") + if e != nil { + t.Fatal(e) + } + if _, e = p.RecoverVolume(ctx, "v1"); e != nil { + t.Fatal(e) + } + want := append(bytes.Repeat([]byte{0x31}, 4096), bytes.Repeat([]byte{0x72}, 4096)...) + if n, e := p.Backend("v1").Write(ctx, 4*4096, want); e != nil || n != len(want) { + t.Fatalf("actual provider contiguous Write: n=%d err=%v", n, e) + } + if e = p.Backend("v1").Sync(ctx); e != nil { + t.Fatal(e) + } + if e = storage.FlushMappedWALStoreV3Test(st.(*storage.WALStore)); e != nil { + t.Fatal(e) + } + if _, e = p.CaptureVolume(ctx, "v1"); e != nil { + t.Fatal(e) + } + if e = p.Close(); e != nil { + t.Fatal(e) + } + q := mappedProviderV3(t, root, remote) + if _, e = q.EnsureStorage("v1"); e != nil { + t.Fatal(e) + } + if _, e = q.RecoverVolume(ctx, "v1"); e != nil { + t.Fatal(e) + } + got := make([]byte, len(want)) + if n, e := q.Backend("v1").Read(ctx, 4*4096, got); e != nil || n != len(want) || !bytes.Equal(got, want) { + t.Fatalf("reopen n=%d err=%v equal=%v", n, e, bytes.Equal(got, want)) + } +} diff --git a/seaweed-block/core/storage/base_install_v3.go b/seaweed-block/core/storage/base_install_v3.go index 8896b13e9a..1c30cbb86b 100644 --- a/seaweed-block/core/storage/base_install_v3.go +++ b/seaweed-block/core/storage/base_install_v3.go @@ -15,7 +15,7 @@ import ( // exclusive, which drains every already-admitted mutation of the old ID; a // handle mutation takes it shared and checks, under it, that the volume is // still installing under the handle's ID. Below it the order is the store's -// usual captureMu -> lifecycleMu -> syncMu -> s.mu -> descMu -> fileSyncMu, +// optional chunk capMu -> captureMu -> lifecycleMu -> syncMu -> s.mu -> descMu -> fileSyncMu, // and nothing below ever waits for installMu. var (