test: publish segmented data in catalog and fork controls

This commit is contained in:
pingqiu committed 2026-11-19 01:13:47 -08:00
1 parent 8d542549a3
commit 1b5f06291a
4 files changed
+29 -9

No files matched your search

@@ -28,8 +28,7 @@ func intentsOf(t *testing.T, f *fakeFiler, vol string) []storage.ChunkIntent {
func sortedKeysOf(h storage.ChunkHead, qualify string) []string {
var out []string
for _, ref := range h.Chunks {
k := ref.Key
for _, k := range headKeys(h) {
if qualify != "" && !strings.HasPrefix(k, "@") {
k = "@" + qualify + "/" + k
}
@@ -196,11 +195,20 @@ func TestFork_IncompleteRetryBoundToOriginalImage(t *testing.T) {
next.Chunks[k] = v
}
next.Chunks[5] = storage.ChunkRef{Key: "chunks/e1/c5/new", SHA256: sha256Of(chunkBytes(0x55))}
next, ids, err := r1.PrepareManifest(ctx, h, next, h.ChunkBytes)
if err != nil {
t.Fatal(err)
}
gen, err := r1.CASHead(ctx, storage.ChunkHeadVersion{Gen: h.Gen, Epoch: 1}, next)
if err != nil {
t.Fatal(err)
}
next.Gen = gen
for _, id := range ids {
if err := r1.DeleteIntent(ctx, id); err != nil {
t.Fatal(err)
}
}
if _, err := c.CreateSnapshot(ctx, "v1", SnapshotRequest{Name: "s1", RequestID: "r-new"}, next); err != nil {
t.Fatal(err)
}
@@ -89,7 +89,10 @@ func chunkBytes(fill byte) []byte {
func catalogFixture(t *testing.T) (*fakeFiler, *fakeBlobs, *Catalog, storage.ChunkHead) {
t.Helper()
f, b := newFakeFiler(), newFakeBlobs()
c := newCat(t, f)
c, err := NewCatalog(manifestFilerBlobs{f, gcBlobs{b}}, catBase)
if err != nil {
t.Fatal(err)
}
if _, err := c.EnsureVolume(context.Background(), "v1", catGeo); err != nil {
t.Fatal(err)
}
@@ -242,7 +245,7 @@ func TestCatalog_DeleteMarksThenIdempotent(t *testing.T) {
}
func TestFork_HeadIsEpochZeroWithQualifiedKeys(t *testing.T) {
f, _, c, h := catalogFixture(t)
f, b, c, h := catalogFixture(t)
ctx := context.Background()
if _, err := c.CreateSnapshot(ctx, "v1", SnapshotRequest{Name: "s1", RequestID: "r"}, h); err != nil {
t.Fatal(err)
@@ -268,7 +271,7 @@ func TestFork_HeadIsEpochZeroWithQualifiedKeys(t *testing.T) {
if got, _ := f.ListEntries(ctx, catBase+"/v2/intents", "", "", 0); len(got) != 0 {
t.Fatalf("fork left %d intents", len(got))
}
r2, _ := NewChunkRemote(f, newFakeBlobs(), catBase+"/v2")
r2, _ := NewChunkRemote(f, b, catBase+"/v2")
head, err := r2.GetHead(ctx)
if err != nil {
t.Fatal(err)
@@ -278,7 +281,7 @@ func TestFork_HeadIsEpochZeroWithQualifiedKeys(t *testing.T) {
}
for idx, ref := range head.Chunks {
src := h.Chunks[idx]
if ref.Key != "@v1/"+src.Key || ref.SHA256 != src.SHA256 {
if ref.Key != qualifyManifestKey("v1", src.Key) || ref.SHA256 != src.SHA256 {
t.Fatalf("chunk %d ref %+v, want @v1/%s with the same hash", idx, ref, src.Key)
}
}
@@ -319,7 +322,7 @@ func TestFork_ForkOfForkKeepsOriginalOwner(t *testing.T) {
r3, _ := NewChunkRemote(f, b, catBase+"/v3")
h3, _ := r3.GetHead(ctx)
for idx, ref := range h3.Chunks {
if ref.Key != "@v1/"+h.Chunks[idx].Key {
if ref.Key != qualifyManifestKey("v1", h.Chunks[idx].Key) {
t.Fatalf("second-level fork chunk %d names %q, want the original owner @v1/%s", idx, ref.Key, h.Chunks[idx].Key)
}
if got, err := r3.Get(ctx, ref.Key); err != nil || sha256.Sum256(got) != ref.SHA256 {
@@ -657,7 +660,7 @@ func TestCatalog_EnsureVolumeCreatesTheInitialHead(t *testing.T) {
if _, err := c.EnsureVolume(ctx, "v2", catGeo); err != nil {
t.Fatal(err)
}
if kept, _, _ := c.ReadHead(ctx, "v2"); kept.Gen != pub.Gen || len(kept.Chunks) != 1 {
if kept, _, _ := c.ReadHead(ctx, "v2"); kept.Gen != pub.Gen || manifestCount(kept) != 1 || kept.Segments[0] != pub.Segments[0] {
t.Fatalf("an existing HEAD was replaced by the initial one: %+v, published %+v", kept, pub)
}
@@ -164,7 +164,7 @@ func TestGC_PublishedUnnamedAttemptRootsUntilDeletingGrace(t *testing.T) {
t.Fatalf("first unrooted mark: %+v %v", result, e)
}
*now = now.Add(time.Hour)
if result, e := g.Run(ctx); e != nil || result.Reclaimed != 1 {
if result, e := g.Run(ctx); e != nil || result.Reclaimed != 2 {
t.Fatalf("deleted attempt retained chunks forever: %+v %v", result, e)
}
if _, e := f.LookupEntry(ctx, path.Dir(oldPath), path.Base(oldPath)); e != nil {
@@ -338,11 +338,20 @@ func publishTagged(t *testing.T, f *fakeFiler, b *fakeBlobs, vol, tag string, ch
if err != nil {
t.Fatal(err)
}
h, ids, err := r.PrepareManifest(ctx, cur, h, uint64(catGeo.BlockSize)*uint64(catGeo.ChunkBlocks))
if err != nil {
t.Fatal(err)
}
gen, err := r.CASHead(ctx, storage.ChunkHeadVersion{Gen: cur.Gen, Epoch: cur.Epoch}, h)
if err != nil {
t.Fatal(err)
}
h.Gen = gen
for _, id := range ids {
if err := r.DeleteIntent(ctx, id); err != nil {
t.Fatal(err)
}
}
return h
}