test: align roundtrip and intent tracing with versioned segments

This commit is contained in:
pingqiu committed 2026-11-19 01:02:04 -08:00
1 parent 66c7dd78cd
commit d49f308e92
4 files changed
+14 -2

No files matched your search

@@ -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)
@@ -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 {
@@ -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
}
@@ -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)