fix: inherit migration checkpoint births without changing unknown coverage

This commit is contained in:
pingqiu committed 2026-11-19 01:34:22 -08:00
1 parent 5c835e21af
commit 28c61803c8
4 files changed
+29 -11

No files matched your search

@@ -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)
}
}
@@ -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)
@@ -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)
}
+3 -1
View File
@@ -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 {