From 1b5f06291a6affae63ed89cf59ec0a3d8752e031 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 01:13:47 -0800 Subject: [PATCH] test: publish segmented data in catalog and fork controls --- .../frontend/chunkstore/catalog_settle_test.go | 12 ++++++++++-- .../core/frontend/chunkstore/catalog_test.go | 15 +++++++++------ .../core/frontend/chunkstore/gc_copy_test.go | 2 +- .../core/frontend/chunkstore/retention_test.go | 9 +++++++++ 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/seaweed-block/core/frontend/chunkstore/catalog_settle_test.go b/seaweed-block/core/frontend/chunkstore/catalog_settle_test.go index 7d7290c26f..44b67dffaa 100644 --- a/seaweed-block/core/frontend/chunkstore/catalog_settle_test.go +++ b/seaweed-block/core/frontend/chunkstore/catalog_settle_test.go @@ -28,8 +28,7 @@ func intentsOf(t *testing.T, f *fakeFiler, vol string) []storage.ChunkIntent { func sortedKeysOf(h storage.ChunkHead, qualify string) []string { var out []string - for _, ref := range h.Chunks { - k := ref.Key + for _, k := range headKeys(h) { if qualify != "" && !strings.HasPrefix(k, "@") { k = "@" + qualify + "/" + k } @@ -196,11 +195,20 @@ func TestFork_IncompleteRetryBoundToOriginalImage(t *testing.T) { next.Chunks[k] = v } next.Chunks[5] = storage.ChunkRef{Key: "chunks/e1/c5/new", SHA256: sha256Of(chunkBytes(0x55))} + next, ids, err := r1.PrepareManifest(ctx, h, next, h.ChunkBytes) + if err != nil { + t.Fatal(err) + } gen, err := r1.CASHead(ctx, storage.ChunkHeadVersion{Gen: h.Gen, Epoch: 1}, next) if err != nil { t.Fatal(err) } next.Gen = gen + for _, id := range ids { + if err := r1.DeleteIntent(ctx, id); err != nil { + t.Fatal(err) + } + } if _, err := c.CreateSnapshot(ctx, "v1", SnapshotRequest{Name: "s1", RequestID: "r-new"}, next); err != nil { t.Fatal(err) } diff --git a/seaweed-block/core/frontend/chunkstore/catalog_test.go b/seaweed-block/core/frontend/chunkstore/catalog_test.go index 6bdff5c17e..a81b2a262f 100644 --- a/seaweed-block/core/frontend/chunkstore/catalog_test.go +++ b/seaweed-block/core/frontend/chunkstore/catalog_test.go @@ -89,7 +89,10 @@ func chunkBytes(fill byte) []byte { func catalogFixture(t *testing.T) (*fakeFiler, *fakeBlobs, *Catalog, storage.ChunkHead) { t.Helper() f, b := newFakeFiler(), newFakeBlobs() - c := newCat(t, f) + c, err := NewCatalog(manifestFilerBlobs{f, gcBlobs{b}}, catBase) + if err != nil { + t.Fatal(err) + } if _, err := c.EnsureVolume(context.Background(), "v1", catGeo); err != nil { t.Fatal(err) } @@ -242,7 +245,7 @@ func TestCatalog_DeleteMarksThenIdempotent(t *testing.T) { } func TestFork_HeadIsEpochZeroWithQualifiedKeys(t *testing.T) { - f, _, c, h := catalogFixture(t) + f, b, c, h := catalogFixture(t) ctx := context.Background() if _, err := c.CreateSnapshot(ctx, "v1", SnapshotRequest{Name: "s1", RequestID: "r"}, h); err != nil { t.Fatal(err) @@ -268,7 +271,7 @@ func TestFork_HeadIsEpochZeroWithQualifiedKeys(t *testing.T) { if got, _ := f.ListEntries(ctx, catBase+"/v2/intents", "", "", 0); len(got) != 0 { t.Fatalf("fork left %d intents", len(got)) } - r2, _ := NewChunkRemote(f, newFakeBlobs(), catBase+"/v2") + r2, _ := NewChunkRemote(f, b, catBase+"/v2") head, err := r2.GetHead(ctx) if err != nil { t.Fatal(err) @@ -278,7 +281,7 @@ func TestFork_HeadIsEpochZeroWithQualifiedKeys(t *testing.T) { } for idx, ref := range head.Chunks { src := h.Chunks[idx] - if ref.Key != "@v1/"+src.Key || ref.SHA256 != src.SHA256 { + if ref.Key != qualifyManifestKey("v1", src.Key) || ref.SHA256 != src.SHA256 { t.Fatalf("chunk %d ref %+v, want @v1/%s with the same hash", idx, ref, src.Key) } } @@ -319,7 +322,7 @@ func TestFork_ForkOfForkKeepsOriginalOwner(t *testing.T) { r3, _ := NewChunkRemote(f, b, catBase+"/v3") h3, _ := r3.GetHead(ctx) for idx, ref := range h3.Chunks { - if ref.Key != "@v1/"+h.Chunks[idx].Key { + if ref.Key != qualifyManifestKey("v1", h.Chunks[idx].Key) { t.Fatalf("second-level fork chunk %d names %q, want the original owner @v1/%s", idx, ref.Key, h.Chunks[idx].Key) } if got, err := r3.Get(ctx, ref.Key); err != nil || sha256.Sum256(got) != ref.SHA256 { @@ -657,7 +660,7 @@ func TestCatalog_EnsureVolumeCreatesTheInitialHead(t *testing.T) { if _, err := c.EnsureVolume(ctx, "v2", catGeo); err != nil { t.Fatal(err) } - if kept, _, _ := c.ReadHead(ctx, "v2"); kept.Gen != pub.Gen || len(kept.Chunks) != 1 { + if kept, _, _ := c.ReadHead(ctx, "v2"); kept.Gen != pub.Gen || manifestCount(kept) != 1 || kept.Segments[0] != pub.Segments[0] { t.Fatalf("an existing HEAD was replaced by the initial one: %+v, published %+v", kept, pub) } diff --git a/seaweed-block/core/frontend/chunkstore/gc_copy_test.go b/seaweed-block/core/frontend/chunkstore/gc_copy_test.go index 3a296d2d37..00789d6bf4 100644 --- a/seaweed-block/core/frontend/chunkstore/gc_copy_test.go +++ b/seaweed-block/core/frontend/chunkstore/gc_copy_test.go @@ -164,7 +164,7 @@ func TestGC_PublishedUnnamedAttemptRootsUntilDeletingGrace(t *testing.T) { t.Fatalf("first unrooted mark: %+v %v", result, e) } *now = now.Add(time.Hour) - if result, e := g.Run(ctx); e != nil || result.Reclaimed != 1 { + if result, e := g.Run(ctx); e != nil || result.Reclaimed != 2 { t.Fatalf("deleted attempt retained chunks forever: %+v %v", result, e) } if _, e := f.LookupEntry(ctx, path.Dir(oldPath), path.Base(oldPath)); e != nil { diff --git a/seaweed-block/core/frontend/chunkstore/retention_test.go b/seaweed-block/core/frontend/chunkstore/retention_test.go index 79e8eed28b..17c5991523 100644 --- a/seaweed-block/core/frontend/chunkstore/retention_test.go +++ b/seaweed-block/core/frontend/chunkstore/retention_test.go @@ -338,11 +338,20 @@ func publishTagged(t *testing.T, f *fakeFiler, b *fakeBlobs, vol, tag string, ch if err != nil { t.Fatal(err) } + h, ids, err := r.PrepareManifest(ctx, cur, h, uint64(catGeo.BlockSize)*uint64(catGeo.ChunkBlocks)) + if err != nil { + t.Fatal(err) + } gen, err := r.CASHead(ctx, storage.ChunkHeadVersion{Gen: cur.Gen, Epoch: cur.Epoch}, h) if err != nil { t.Fatal(err) } h.Gen = gen + for _, id := range ids { + if err := r.DeleteIntent(ctx, id); err != nil { + t.Fatal(err) + } + } return h }