Artifact d9b6f68baa7aeb81309f832a8649c15e641ffb8229aef53476488daa43e34cf7:
- File
internal/content/cone_reference_prefix.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: 1471) [annotate] [blame] [check-ins using]
package content import ( "context" "encoding/binary" "fmt" "github.com/danmestas/go-libfossil/db" "github.com/danmestas/go-libfossil/internal/blob" ) // The metadata-only pass must prove total stored bytes first: substr(BLOB) can // materialize the entire value inside SQLite even though it returns six bytes. // Charge those reads separately from later full driver-payload reads. func referencePrefixes( ctx context.Context, q db.Querier, blobs []referenceBlob, budget ReferenceBudget, work *ReferenceWork, inflated *int64, ) error { for i := range blobs { if err := ctx.Err(); err != nil { return err } b := &blobs[i] if b.unreadable { continue } if b.stored > budget.StoredBytes-work.PrefixBytes { return fmt.Errorf("sparse preparation: prefix byte budget exceeded") } work.PrefixReads++ work.PrefixBytes += b.stored stored, prefix, err := blob.StoredHead(q, b.rid, 6) if err != nil { return err } if stored != b.stored { return fmt.Errorf("sparse preparation: stored bytes changed") } b.unreadable = len(prefix) != 6 if !b.unreadable { b.unreadable = prefix[4]&15 != 8 || prefix[4]>>4 > 7 || binary.BigEndian.Uint16(prefix[4:])%31 != 0 } if b.unreadable { continue } b.inflated = int64(binary.BigEndian.Uint32(prefix[:4])) if b.inflated > budget.InflatedBytes-*inflated { return fmt.Errorf("sparse preparation: inflation budget exceeded") } *inflated += b.inflated } return nil }