Files
zeekayandGitHub ce86a2ddd6 Rebuild the volume on chunks, shards and a fenced Head (#8)
Rebuilds the volume engine on content-defined chunks, a Merkle tree of sealed shards, and one fenced Head object committed by a single conditional write. Replaces the old 4 KiB block store; there is one layout, with no version number, and no code reads any other.

What it is: FastCDC chunks of 64 KiB to 4 MiB sealed one by one and packed into ~16 MiB objects; metadata as sharded, content-addressed Merkle nodes with files up to 16 KiB inline; a Head (Seq, Root, Next, ID, Seed, Journal, Needs, then a TLV Tail with strictly increasing tags and reserved tags/bits for snapshots, links and base) committed by one conditional PUT under a monotone Round fence; sealed objects bound to volume, kind and place by a fixed-length context with a 32-byte tag keyed from the secret identity (post-quantum hybrid age by default, keys supplied by the caller); sparse extents that cost nothing (a 1 PiB truncate flushes in milliseconds); extension objects under ext/<name>/<keyed hash>; Reseal to move a volume; a FUSE front on which no request is ever answered EINTR except a 3 s grace for cold lookup/getattr/readdir, and fsync waits. docs/SPECIFICATION.md is the normative contract; the HIP is hanzoai/hips#13.

Testing: CI run 43908676601: 16 parallel gates, each under 5 minutes (longest 193 s), real-server gates pinned by image digest and failing on a skip. Real kernels: go test -tags fuse ./pkg/mount ./internal/sqlitecheck 10 of 10 on arm64 Linux 7.0 and 10 of 10 on amd64 Linux 6.8 (TestFUSESQLite failed 7 of 7 before the fsync fix); C callers under SIGALRM 5,000 fsync+close with ~19,000 signals and 0 EINTR; 60,000 stats with and without SA_RESTART 0 EINTR; 6 GiB cold reads under signals 0 EINTR/EIO; 564 acknowledged fsyncs over 4 daemon SIGKILLs, 0 missing. Head parser: 3,000,000 differential inputs against an independent decoder plus 8.2M native fuzz executions, no divergence, every accepted Head re-encodes byte for byte; extension names match 300 vectors from an independent BLAKE3; real hanzoai/s3 server passes the shared backend suite. Seven review rounds; 250 of 250 mutations killed on the final tree. Object cost: 14,690 to 34,937 objects for a 150 GiB tree (39,321,600 in the old layout); 3.2 objects per 20 KiB file through the mount with a commit per close.

Risk: the layout freezes with this merge and every Volume written by any earlier build of this branch will not open (no migration; nothing in production writes any layout). Known limits, all in SPEC 11 with numbers: store calls have no deadlines, so while the store is stalled every call that needs it waits and SIGKILL frees no caller (kill the daemon: ~20 ms, uncommitted writes lost); ~134 KiB per abandoned request; SIGTERM against a stalled store takes up to 21 s and exits non-zero; every close is a full commit (~143 files/s); rename, links, symlinks, chmod, chown, utimens, xattr, statfs and unlink-while-open are not built (git, tar, npm fail on the mount); no GC, quota or snapshots yet; tenants must not hold store write credentials. Not for tenant sandboxes until the journal integration, deadlines and a supervisor watchdog land.

How to revert: revert this commit and retag the previous patch release. Volumes created by this build do not open in the code before it; copy their files out through a mount of this build first. Nothing else in the repository depends on the layout (the journal and tools packages are standalone).

Claude-Session: https://claude.ai/code/session_015XYKLnBbrbajqj1GpRydF8
2026-11-16 08:50:54 -08:00

85 lines
2.2 KiB
Go

package vfs
import (
"encoding/binary"
"errors"
"math"
)
// ErrCorrupt is returned when an object fails to authenticate, hash to its name,
// or decode: it was damaged, swapped or forged. A Volume never guesses past it.
var ErrCorrupt = errors.New("vfs: object is corrupt")
// writer appends the varint-framed encoding every record and node uses.
type writer struct{ b []byte }
func (w *writer) uvarint(x uint64) { w.b = binary.AppendUvarint(w.b, x) }
func (w *writer) varint(x int64) { w.b = binary.AppendVarint(w.b, x) }
func (w *writer) raw(p []byte) { w.b = append(w.b, p...) }
func (w *writer) bytes(p []byte) { w.uvarint(uint64(len(p))); w.raw(p) }
// reader decodes what writer wrote. The first malformed read latches err and
// every later read returns zero values, so a decoder checks once at the end.
type reader struct {
b []byte
err error
}
func (r *reader) fail() { r.err = ErrCorrupt; r.b = nil }
// uvarint reads an unsigned integer in its shortest form: an encoding that ends in a
// zero byte after a continuation (0x80 0x00 for 0) is another spelling of a number that
// has one, so two byte strings would be one record, and it is refused.
func (r *reader) uvarint() uint64 {
x, n := binary.Uvarint(r.b)
if n <= 0 || n > 1 && r.b[n-1] == 0 {
r.fail()
return 0
}
r.b = r.b[n:]
return x
}
// uvarint32 reads an unsigned integer that its field holds in 32 bits: a wider value is
// not truncated into one that fits, it is refused.
func (r *reader) uvarint32() uint32 {
x := r.uvarint()
if x > math.MaxUint32 {
r.fail()
return 0
}
return uint32(x)
}
// varint reads a signed integer in its shortest form (the zigzag of it is shortest).
func (r *reader) varint() int64 {
x, n := binary.Varint(r.b)
if n <= 0 || n > 1 && r.b[n-1] == 0 {
r.fail()
return 0
}
r.b = r.b[n:]
return x
}
// raw returns the next n bytes without copying.
func (r *reader) raw(n uint64) []byte {
if n > uint64(len(r.b)) {
r.fail()
return nil
}
p := r.b[:n:n]
r.b = r.b[n:]
return p
}
func (r *reader) bytes() []byte { return r.raw(r.uvarint()) }
// done reports the latched error, or ErrCorrupt if bytes remain unread.
func (r *reader) done() error {
if r.err == nil && len(r.b) != 0 {
r.fail()
}
return r.err
}