test(chunkstore): publish integration fixtures as segmented HEADs

This commit is contained in:
pingqiu committed 2026-11-21 10:46:58 -08:00
1 parent 1628604983
commit 10e88f765e
3 files changed
+42 -22

No files matched your search

@@ -167,6 +167,29 @@ func (c *weedCluster) remote(t *testing.T, root string) *ChunkRemote {
return r
}
// publishIntegrationHead uses the real format-3 manifest path before publishing data.
func publishIntegrationHead(t *testing.T, r *ChunkRemote, base, next storage.ChunkHead, chunkBytes uint64) storage.ChunkHead {
t.Helper()
ctx := context.Background()
next, intents, err := r.PrepareManifest(ctx, base, next, chunkBytes)
if err != nil {
t.Fatal(err)
}
next.Gen, err = r.CASHead(ctx, storage.ChunkHeadVersion{Gen: base.Gen, Epoch: base.Epoch}, next)
if err != nil {
t.Fatal(err)
}
if next.Gen != base.Gen+1 {
t.Fatalf("published generation %d, want %d", next.Gen, base.Gen+1)
}
for _, id := range intents {
if err := r.DeleteIntent(ctx, id); err != nil {
t.Fatal(err)
}
}
return next
}
func TestIntegration_ChunkRemoteContract(t *testing.T) {
c := startWeed(t)
ctx := context.Background()
@@ -191,10 +214,7 @@ func TestIntegration_ChunkRemoteContract(t *testing.T) {
t.Fatalf("Get from another client: %d bytes, %v", len(got), err)
}
h1 := storage.ChunkHead{Epoch: 1, Holder: "a", RemoteLSN: 7, Chunks: map[uint64]storage.ChunkRef{4: ref(key, d)}}
if gen, err := a.CASHead(ctx, storage.ChunkHeadVersion{}, h1); err != nil || gen != 1 {
t.Fatalf("first CAS = %d, %v", gen, err)
}
h1 := publishIntegrationHead(t, a, storage.ChunkHead{}, storage.ChunkHead{Epoch: 1, Holder: "a", RemoteLSN: 7, Chunks: map[uint64]storage.ChunkRef{4: ref(key, d)}}, 16384)
if _, err := b.CASHead(ctx, storage.ChunkHeadVersion{}, h1); !isPrecondition(err) {
t.Fatalf("racing first CAS: %v; want precondition (real o_excl)", err)
}
@@ -203,7 +223,9 @@ func TestIntegration_ChunkRemoteContract(t *testing.T) {
t.Fatalf("HEAD from another client = %+v, %v", got, err)
}
// Takeover at epoch 2, then the old holder's CAS at the version it read.
if gen, err := b.CASHead(ctx, storage.ChunkHeadVersion{Gen: 1, Epoch: 1}, storage.ChunkHead{Epoch: 2, Holder: "b", RemoteLSN: 7, Chunks: h1.Chunks}); err != nil || gen != 2 {
takeover := h1
takeover.Epoch, takeover.Holder = 2, "b"
if gen, err := b.CASHead(ctx, storage.ChunkHeadVersion{Gen: 1, Epoch: 1}, takeover); err != nil || gen != 2 {
t.Fatalf("takeover CAS = %d, %v", gen, err)
}
_, err = a.CASHead(ctx, storage.ChunkHeadVersion{Gen: 1, Epoch: 1}, storage.ChunkHead{Epoch: 1, Holder: "a", RemoteLSN: 9})
@@ -50,11 +50,7 @@ func TestIntegration_RetainAndUsage(t *testing.T) {
t.Fatal(err)
}
next := storage.ChunkHead{Epoch: 1, Holder: "h1", RemoteLSN: uint64(step), Chunks: map[uint64]storage.ChunkRef{0: ref(key, data)}}
gen, err := r.CASHead(ctx, storage.ChunkHeadVersion{Gen: cur.Gen, Epoch: cur.Epoch}, next)
if err != nil {
t.Fatal(err)
}
next.Gen = gen
next = publishIntegrationHead(t, r, cur, next, full)
cur = next
clock = clock.Add(time.Minute)
if _, err := cat.CreateSnapshot(ctx, "v1", SnapshotRequest{Name: name, RequestID: "r-" + name, Class: class}, next); err != nil {
@@ -73,7 +69,7 @@ func TestIntegration_RetainAndUsage(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if len(before.Snapshots) != n+7 || before.StoredBindings != n+7 || before.StoredUpperBound || before.LiveBytes != full {
if len(before.Snapshots) != n+7 || before.StoredBindings != 2*(n+7) || before.ManifestBindings != n+7 || before.StoredUpperBound || before.LiveBytes != full {
t.Fatalf("before: %d snapshots, %d bindings, upper=%t, live=%d", len(before.Snapshots), before.StoredBindings, before.StoredUpperBound, before.LiveBytes)
}
exclusive := func(u VolumeUsage) uint64 {
@@ -131,7 +127,7 @@ func TestIntegration_RetainAndUsage(t *testing.T) {
if got := exclusive(after); got != uint64(n+1)*full {
t.Fatalf("after: exclusive %d, want %d", got, uint64(n+1)*full)
}
if after.StoredBindings != n+7 || !after.StoredUpperBound {
if after.StoredBindings != 2*(n+7) || after.ManifestBindings != n+7 || !after.StoredUpperBound {
t.Fatalf("after: %d bindings, upper=%t; want all still stored (no GC yet), flagged as an upper bound", after.StoredBindings, after.StoredUpperBound)
}
}
@@ -166,9 +162,7 @@ func TestIntegration_RetainIgnoresIncompleteForks(t *testing.T) {
t.Fatal(err)
}
head := storage.ChunkHead{Epoch: 1, Holder: "h1", RemoteLSN: 1, Chunks: map[uint64]storage.ChunkRef{0: ref("chunks/e1/c0/k", data)}}
if head.Gen, err = r.CASHead(ctx, storage.ChunkHeadVersion{Gen: cur.Gen, Epoch: cur.Epoch}, head); err != nil {
t.Fatal(err)
}
head = publishIntegrationHead(t, r, cur, head, uint64(full))
clock := time.Now().Add(-72 * time.Hour)
cat.SetClock(func() time.Time { clock = clock.Add(time.Second); return clock }) // every read advances
for i := 0; i < 3; i++ {
@@ -51,10 +51,7 @@ func TestIntegration_DeleteVolumeThenGC(t *testing.T) {
t.Fatal(err)
}
next := storage.ChunkHead{Epoch: epoch, Holder: holder, RemoteLSN: cur.RemoteLSN + 1, Chunks: chunks, State: storage.ChunkHeadActive}
if next.Gen, err = r.CASHead(ctx, storage.ChunkHeadVersion{Gen: cur.Gen, Epoch: cur.Epoch}, next); err != nil {
t.Fatal(err)
}
return next
return publishIntegrationHead(t, r, cur, next, uint64(full))
}
detach := func(r *ChunkRemote) {
t.Helper()
@@ -95,7 +92,7 @@ func TestIntegration_DeleteVolumeThenGC(t *testing.T) {
for k, v := range fh.Chunks {
chunks[k] = v
}
publish(w2, "h2", 1, chunks)
h3 := publish(w2, "h2", 1, chunks)
// An attached volume is refused (w1 is held by h1; w2 by h2).
for _, vol := range []string{"w1", "w2"} {
@@ -139,9 +136,16 @@ func TestIntegration_DeleteVolumeThenGC(t *testing.T) {
for _, o := range gr.WouldDelete {
got = append(got, o.Volume+":"+o.Key)
}
want := []string{"w1:chunks/e1/c0/a", "w2:chunks/e1/c2/d"}
for _, h := range []storage.ChunkHead{h1, h3} {
for _, segment := range h.Segments {
want = append(want, segment.Owner+":"+segment.Key)
}
}
sort.Strings(want)
sort.Strings(got)
if fmt.Sprint(got) != "[w1:chunks/e1/c0/a w2:chunks/e1/c2/d]" || gr.Reclaimed != 2 {
t.Fatalf("GC reclaimed %v (%d); want exactly w1's A and w2's D", got, gr.Reclaimed)
if fmt.Sprint(got) != fmt.Sprint(want) || gr.Reclaimed != len(want) {
t.Fatalf("GC reclaimed %v (%d); want exactly w1's A, w2's D and their unreachable manifests", got, gr.Reclaimed)
}
for _, kept := range []string{bb.Key, cc.Key} {
if _, err := w1.Get(ctx, kept); err != nil {