From d49f308e92ffa61d91c2f9c767b0519ef2e4e0ba Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 01:02:04 -0800 Subject: [PATCH] test: align roundtrip and intent tracing with versioned segments --- .../core/frontend/chunkstore/chunk_remote_test.go | 3 +++ .../core/frontend/chunkstore/decode_fuzz_test.go | 2 +- seaweed-block/core/frontend/chunkstore/gc.go | 9 +++++++++ seaweed-block/core/frontend/chunkstore/manifest_test.go | 2 +- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/seaweed-block/core/frontend/chunkstore/chunk_remote_test.go b/seaweed-block/core/frontend/chunkstore/chunk_remote_test.go index 7bee5cbf5b..896b271c03 100644 --- a/seaweed-block/core/frontend/chunkstore/chunk_remote_test.go +++ b/seaweed-block/core/frontend/chunkstore/chunk_remote_test.go @@ -55,6 +55,9 @@ func TestChunkRemote_HeadRoundTripAndCAS(t *testing.T) { t.Fatal(err) } want := head(1, "a", 42, map[uint64]storage.ChunkRef{3: ref("chunks/e1/c3/n-1", d)}) + legacy := want.Chunks[3] + legacy.Encoding, legacy.BirthLSN = "full", want.RemoteLSN + want.Chunks[3] = legacy gen, err := r.CASHead(ctx, storage.ChunkHeadVersion{}, want) if err != nil || gen != 1 { t.Fatalf("first CAS = %d, %v; want gen 1", gen, err) diff --git a/seaweed-block/core/frontend/chunkstore/decode_fuzz_test.go b/seaweed-block/core/frontend/chunkstore/decode_fuzz_test.go index 5dce4f7ad3..86ec004bab 100644 --- a/seaweed-block/core/frontend/chunkstore/decode_fuzz_test.go +++ b/seaweed-block/core/frontend/chunkstore/decode_fuzz_test.go @@ -21,7 +21,7 @@ func fuzzHeadSeeds(tb testing.TB) [][]byte { {Gen: 3, Epoch: 4, Holder: "r2", RemoteLSN: 9, State: storage.ChunkHeadDetached, DetachedBy: &storage.ChunkDetachedBy{Holder: "r2", Epoch: 4, Gen: 3}, Chunks: map[uint64]storage.ChunkRef{}}, {Gen: 2, Epoch: 1, Holder: "r1", RemoteLSN: 3, ChunkBytes: 4 << 20, ManifestChunkCount: 2, - Segments: map[uint64]storage.ChunkSegment{0: {Key: "@v1/seg/00", SHA256: sum, Owner: "v1", Count: 2}}}, + Segments: map[uint64]storage.ChunkSegment{0: {Key: "@v1/seg/00", SHA256: sum, Owner: "v1", Count: 2, SegFormat: 2, MaxBirthLSN: 3}}}, } var out [][]byte for _, h := range heads { diff --git a/seaweed-block/core/frontend/chunkstore/gc.go b/seaweed-block/core/frontend/chunkstore/gc.go index 5d524d0c13..7e8bf522f5 100644 --- a/seaweed-block/core/frontend/chunkstore/gc.go +++ b/seaweed-block/core/frontend/chunkstore/gc.go @@ -230,6 +230,15 @@ func (g *Collector) run(ctx context.Context, apply bool) (result GCResult, err e } if in.Segments != nil { h := storage.ChunkHead{Segments: in.Segments, ChunkBytes: in.ChunkBytes} + // Intents protect keys without carrying a published frontier. + // Validate segment maxima against the reference maxima here. + for group, ref := range h.Segments { + if ref.SegFormat == 0 { + ref.SegFormat = 1 + h.Segments[group] = ref + } + h.RemoteLSN = max(h.RemoteLSN, ref.MaxBirthLSN) + } for _, ref := range in.Segments { h.ManifestChunkCount += ref.Count } diff --git a/seaweed-block/core/frontend/chunkstore/manifest_test.go b/seaweed-block/core/frontend/chunkstore/manifest_test.go index eb53976606..fa0309f434 100644 --- a/seaweed-block/core/frontend/chunkstore/manifest_test.go +++ b/seaweed-block/core/frontend/chunkstore/manifest_test.go @@ -54,7 +54,7 @@ func TestManifest_CapturePublishesSegmentRoot(t *testing.T) { if err = json.Unmarshal(e.Content, &doc); err != nil { t.Fatal(err) } - if doc.Format != 2 || len(doc.Chunks) != 0 || len(doc.Segments) != 1 { + if doc.Format != 3 || len(doc.Chunks) != 0 || len(doc.Segments) != 1 { t.Fatalf("cut did not publish a small segmented root: %s", e.Content) } h, err := r.GetHead(ctx)