Artifact cc0430ff7d4d70cdf1e359e25d62d8782aea59dad88bf3762e4b5b5cceac6df3:
- File
internal/shun/chunked_test.go
— part of check-in
[1fd12b3ed3]
at
2026-10-28 21:53:09
on branch feat/chunked-blobs
— Store blobs over a hosted value limit across blobpart rows
A hosted SQLite that caps value size (a Durable Object's 2 MB) cannot hold a large file's stored blob in one blob.content value. With the new db.DriverConfig.MaxValueBytes set, a stored value over the limit is written in 1,000,000-byte parts to blobpart(rid, seq, content), created on first use, leaving blob.content NULL and blob.size the expanded length, so phantoms (size < 0) stay unambiguous. Chunking sits below compression: hashes, deltas and the wire format are unchanged.
internal/blob owns the seam (ReadStored, WriteStored, InsertStored, StoredHead, DropStored, SweepParts and two scan expressions), and every direct reader or writer of blob.content now goes through it: delta rewrite and undelta, receive, clone send and walk, compaction, sparse demotion, seed drop, shun purge, horizon cost and cone preparation.
Zero, the default, keeps every value inline and creates no table, so local stores stay byte-identical. A store with blobpart rows is not readable by stock fossil; enable it only for hosted backends.
Closes #459 (user: [email protected], size: 1322) [annotate] [blame] [check-ins using]
package shun_test import ( "bytes" "math/rand" "testing" "github.com/danmestas/go-libfossil/internal/blob" "github.com/danmestas/go-libfossil/internal/content" "github.com/danmestas/go-libfossil/internal/shun" ) // Purging a chunked base deletes its parts, and its dependent, rewritten as // full content, is chunked in turn. func TestPurgeChunked(t *testing.T) { t.Cleanup(blob.SetMaxValueBytes(1_990_000)) d := setupDB(t) base := make([]byte, 2_100_000) _, _ = rand.New(rand.NewSource(1)).Read(base) dependent := bytes.Clone(base) copy(dependent[100:], "dependent") ridA, uuidA, err := blob.Store(d, base) if err != nil { t.Fatal(err) } ridB, _, err := blob.StoreDelta(d, dependent, ridA) if err != nil { t.Fatal(err) } if err := shun.Add(d, uuidA, "purge chunked"); err != nil { t.Fatal(err) } if _, err := shun.Purge(d); err != nil { t.Fatalf("Purge: %v", err) } var parts, partsB int if err := d.QueryRow("SELECT count(*), count(*) FILTER (WHERE rid=?) FROM blobpart", ridB). Scan(&parts, &partsB); err != nil { t.Fatal(err) } if parts != 3 || partsB != 3 { t.Fatalf("parts = %d (dependent %d), want only the dependent's 3", parts, partsB) } got, err := content.Expand(d, ridB) if err != nil || !bytes.Equal(got, dependent) { t.Fatalf("Expand dependent: %v", err) } }