From 28c61803c85ead2cf8c82f05065d39ab6402e620 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 01:34:22 -0800 Subject: [PATCH] fix: inherit migration checkpoint births without changing unknown coverage --- .../frontend/chunkstore/retention_test.go | 22 +++++++++++++++---- .../storage/chunk_birth_migration_test.go | 12 +++++----- .../core/storage/chunk_fake_remote_test.go | 2 +- seaweed-block/core/storage/migrate_v3.go | 4 +++- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/seaweed-block/core/frontend/chunkstore/retention_test.go b/seaweed-block/core/frontend/chunkstore/retention_test.go index 765aee8490..10109d3916 100644 --- a/seaweed-block/core/frontend/chunkstore/retention_test.go +++ b/seaweed-block/core/frontend/chunkstore/retention_test.go @@ -362,6 +362,19 @@ func TestCatalog_UsageFromManifests(t *testing.T) { f, b, c, h := catalogFixture(t) // HEAD: chunks 0 and 3 ctx := context.Background() full := uint64(catGeo.ChunkBlocks) * uint64(catGeo.BlockSize) + r, _ := NewChunkRemote(f, b, path.Join(catBase, "v1")) + manifestBytes := func(head storage.ChunkHead) uint64 { + var total uint64 + for _, ref := range head.Segments { + body, err := r.Get(ctx, ref.Key) + if err != nil { + t.Fatal(err) + } + total += uint64(len(body)) + } + return total + } + expectedManifestBytes := manifestBytes(h) if _, err := c.CreateSnapshot(ctx, "v1", SnapshotRequest{Name: "s1", RequestID: "r1"}, h); err != nil { t.Fatal(err) } @@ -372,12 +385,13 @@ func TestCatalog_UsageFromManifests(t *testing.T) { if u.LiveChunks != 2 || u.LiveBytes != 2*full || len(u.Snapshots) != 1 || u.Snapshots[0].ExclusiveBytes != 0 { t.Fatalf("shared chunks: %+v", u) } - if u.StoredBindings != 2+u.ManifestBindings || u.ManifestBindings != 1 || u.StoredBytes != 2*full+u.ManifestBytes || u.StoredUpperBound { + if u.StoredBindings != 3 || u.ManifestBindings != 1 || expectedManifestBytes == 0 || u.ManifestBytes != expectedManifestBytes || u.StoredBytes != 2*full+expectedManifestBytes || u.StoredUpperBound { t.Fatalf("stored: %+v; want 2 bindings, exact", u) } // HEAD moves on: chunk 0 is rewritten, so s1 alone holds the old one. - publishTagged(t, f, b, "v1", "e2", map[uint64][]byte{0: chunkBytes(0x20), 3: chunkBytes(0x13)}) + newHead := publishTagged(t, f, b, "v1", "e2", map[uint64][]byte{0: chunkBytes(0x20), 3: chunkBytes(0x13)}) + expectedManifestBytes += manifestBytes(newHead) u, err = c.Usage(ctx, "v1") if err != nil { t.Fatal(err) @@ -386,7 +400,7 @@ func TestCatalog_UsageFromManifests(t *testing.T) { // both of s1's chunks are now exclusive: the new HEAD uses e2 keys t.Fatalf("after HEAD moved: s1 exclusive %d, want %d", u.Snapshots[0].ExclusiveBytes, 2*full) } - if u.StoredBindings != 4+u.ManifestBindings || u.ManifestBindings != 2 || u.StoredBytes != 4*full+u.ManifestBytes || u.StoredUpperBound { + if u.StoredBindings != 6 || u.ManifestBindings != 2 || u.ManifestBytes != expectedManifestBytes || u.StoredBytes != 4*full+expectedManifestBytes || u.StoredUpperBound { t.Fatalf("stored after HEAD moved: %+v; want 4 bindings, exact", u) } @@ -399,7 +413,7 @@ func TestCatalog_UsageFromManifests(t *testing.T) { if err != nil { t.Fatal(err) } - if len(u.Snapshots) != 0 || u.StoredBindings != 4+u.ManifestBindings || !u.StoredUpperBound { + if len(u.Snapshots) != 0 || u.StoredBindings != 6 || !u.StoredUpperBound { t.Fatalf("after delete: %+v; want no snapshots, 4 bindings, upper bound", u) } } diff --git a/seaweed-block/core/storage/chunk_birth_migration_test.go b/seaweed-block/core/storage/chunk_birth_migration_test.go index 7888f79fcb..987c7bab07 100644 --- a/seaweed-block/core/storage/chunk_birth_migration_test.go +++ b/seaweed-block/core/storage/chunk_birth_migration_test.go @@ -73,16 +73,18 @@ func TestChunkBirthMigrationCarriesImageFrontier(t *testing.T) { } } -func TestChunkBirthSeededFrontierAnchorsDirectImage(t *testing.T) { +func TestChunkBirthSeededFrontierPreservesInheritedImage(t *testing.T) { s, _ := newChunkTestStore(t) if err := s.SeedChunkFrontier(7); err != nil { t.Fatal(err) } - if err := s.WriteExtentDirect(5, makeBlock(ctBlockSize, 0x57)); err != nil { - t.Fatal(err) - } f := newFakeChunkRemote() - l := mustAttach(t, s, f, ctConfig(1)) + image := make([]byte, ctNumBlocks*ctBlockSize) + copy(image[ctChunkBlocks*ctBlockSize:], makeBlock(ctBlockSize, 0x57)) + f.seedHead(t, image, 7, 1) + cfg := ctConfig(2) + cfg.FreshFromHead = true + l := mustAttach(t, s, f, cfg) newest, err := s.Write(0, makeBlock(ctBlockSize, 0x41)) if err != nil { t.Fatal(err) diff --git a/seaweed-block/core/storage/chunk_fake_remote_test.go b/seaweed-block/core/storage/chunk_fake_remote_test.go index f3eef79172..ea6d6da91f 100644 --- a/seaweed-block/core/storage/chunk_fake_remote_test.go +++ b/seaweed-block/core/storage/chunk_fake_remote_test.go @@ -386,7 +386,7 @@ func (f *fakeChunkRemote) seedHead(t *testing.T, image []byte, remoteLSN, epoch key := fmt.Sprintf("seed/%d", idx) f.objs[key] = append([]byte(nil), c...) f.everStored[key] = true - head.Chunks[uint64(idx)] = chunkRef{Key: key, SHA256: sha256.Sum256(c)} + head.Chunks[uint64(idx)] = chunkRef{Key: key, SHA256: sha256.Sum256(c), Encoding: "full", BirthLSN: remoteLSN} } f.installLocked(head) } diff --git a/seaweed-block/core/storage/migrate_v3.go b/seaweed-block/core/storage/migrate_v3.go index 16ebb3964d..89c12c0e6b 100644 --- a/seaweed-block/core/storage/migrate_v3.go +++ b/seaweed-block/core/storage/migrate_v3.go @@ -107,7 +107,8 @@ func ValidateMigrationV3(src MigrationSourceV3) error { // PrepareMigrationV3 runs DESIGN 10.1 step 3 and builds the slot images of // steps 4 to 6. It (re)creates the initial map sidecar at mapPath durably: -// generation 1, every chunk UNKNOWN with maxWriteLSN 0, coveredCheckpoint = +// generation 1, every chunk UNKNOWN with its inherited checkpoint frontier, +// coveredCheckpoint = // the v2 checkpoint (a fully flushed WAL is not remote-clean). The slots // carry a fresh random nonce and the map fields of that root. It writes // nothing to the store file. @@ -141,6 +142,7 @@ func PrepareMigrationV3(mapPath string, src MigrationSourceV3) (MigrationPlanV3, entries := make([]chunkLSNEntryV3, int(shape.chunks)) for i := range entries { entries[i].Unknown = true + entries[i].LSN = src.CheckpointLSN } c, err := m.Prepare(1, src.CheckpointLSN, entries, nil) if err = errors.Join(err, m.Close()); err != nil {