From 59a7633115332d2b38cc2de5851b37262d34b136 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 24 Nov 2026 18:23:47 -0800 Subject: [PATCH] command: read the compacted volume's version from its super block in tests Compaction can write a different needle version than the source volume, so parse the .cpd with the version it records instead of the current one. Co-Authored-By: Claude Opus 5.5 --- weed/command/compact_test.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/weed/command/compact_test.go b/weed/command/compact_test.go index 440f71265c..d1f66a065d 100644 --- a/weed/command/compact_test.go +++ b/weed/command/compact_test.go @@ -34,17 +34,21 @@ func compactedKeys(t *testing.T, base string) (indexed, intact []uint64) { } dat := backend.NewDiskFile(datFile) defer dat.Close() + sb, err := super_block.ReadSuperBlock(dat) + if err != nil { + t.Fatal(err) + } idxFile, err := os.Open(base + ".cpx") if err != nil { t.Fatal(err) } defer idxFile.Close() - listed := int64(super_block.SuperBlockSize) + listed := int64(sb.BlockSize()) if err := idx.WalkIndexFile(idxFile, 0, func(key types.NeedleId, offset types.Offset, size types.Size) error { indexed = append(indexed, uint64(key)) - listed += needle.GetActualSize(size, needle.GetCurrentVersion()) + listed += needle.GetActualSize(size, sb.Version) n := new(needle.Needle) - if n.ReadData(dat, offset.ToActualOffset(), size, needle.GetCurrentVersion()) == nil && bytes.Equal(n.Data, bytes.Repeat([]byte{byte(key)}, 1000*int(key))) { + if n.ReadData(dat, offset.ToActualOffset(), size, sb.Version) == nil && bytes.Equal(n.Data, bytes.Repeat([]byte{byte(key)}, 1000*int(key))) { intact = append(intact, uint64(key)) } return nil