Documentation
¶
Index ¶
- Constants
- Variables
- func IsTextHead(head []byte) bool
- func NewObjectBackedBlockStore(dir string) (*DiskBlockStore, *ObjectStore, error)
- type BlockGetter
- type BlockID
- type BlockStore
- type ChunkParams
- type Chunker
- type CoWFile
- type CoWFileView
- type CoWMap
- type DiskBlockStore
- func (s *DiskBlockStore) CollectObjectGarbage(ctx context.Context, live map[BlockID]struct{}, dryRun bool) (ObjectGCResult, error)
- func (s *DiskBlockStore) Compact(orderedLive []BlockID) error
- func (s *DiskBlockStore) CompactOptions(orderedLive []BlockID, opts PackOptions) error
- func (s *DiskBlockStore) Delete(id BlockID) error
- func (s *DiskBlockStore) ForEach(fn func(BlockID) error) error
- func (s *DiskBlockStore) FrameCacheStats() FrameCacheStats
- func (s *DiskBlockStore) Get(id BlockID) ([]byte, error)
- func (s *DiskBlockStore) Has(id BlockID) (bool, error)
- func (s *DiskBlockStore) HasPacks() (bool, error)
- func (s *DiskBlockStore) Put(data []byte) (BlockID, error)
- func (s *DiskBlockStore) PutDeferred(data []byte) (BlockID, error)
- func (s *DiskBlockStore) SetFrameCacheBytes(n int64)
- func (s *DiskBlockStore) Size(id BlockID) (int64, error)
- func (s *DiskBlockStore) Sync() error
- func (s *DiskBlockStore) VerifyPacks() (frames, chunks int, err error)
- func (s *DiskBlockStore) WritePack(ordered []BlockID) error
- func (s *DiskBlockStore) WritePackOptions(ordered []BlockID, opts PackOptions) error
- type FrameCacheStats
- type MaterializeOptions
- type MaterializeResult
- type MemBlockStore
- type MemCoWMap
- type ObjectGCResult
- type ObjectStore
- func (s *ObjectStore) CollectGarbage(ctx context.Context, live map[BlockID]struct{}, dryRun bool) (ObjectGCResult, error)
- func (s *ObjectStore) Compact() error
- func (s *ObjectStore) CompactIfNeeded(journalBytes int64) error
- func (s *ObjectStore) MaterializeBlocks(ctx context.Context, destination string, blocks []BlockID, sizes []int64, ...) (MaterializeResult, error)
- func (s *ObjectStore) Sync() error
- type PackOptions
- type Snapshot
Constants ¶
const DefaultFrameCacheBytes = 64 << 20
DefaultFrameCacheBytes bounds the decompressed frame cache: enough for sequential reads through a mount to hit warm frames, small enough not to compete with the page cache.
Variables ¶
var ErrBlockCorrupt = errors.New("block corrupt: content hash mismatch")
ErrBlockCorrupt is returned by a BlockStore when a stored block's content no longer matches its content-address (BLAKE3) id, i.e. the block has been tampered with or has suffered bit-rot on disk.
var ErrBlockNotFound = errors.New("block not found")
var ErrInvalidOffset = errors.New("invalid offset")
Functions ¶
func IsTextHead ¶
IsTextHead classifies content from its leading bytes: no NUL and at least 70% printable (tab, newlines, printable ASCII, and any byte >= 128 so UTF-8 sequences count). Carved in stone as policy 1 of the format.
func NewObjectBackedBlockStore ¶ added in v0.1.3
func NewObjectBackedBlockStore(dir string) (*DiskBlockStore, *ObjectStore, error)
NewObjectBackedBlockStore opens one block store and its shared object index.
Types ¶
type BlockGetter ¶ added in v0.1.3
type BlockID ¶
type BlockID string
BlockID is a content-address identifier for a stored block. The in-memory implementation uses blake3(data) encoded as hex.
type BlockStore ¶
BlockStore is a minimal content-addressed block store. Implementations should deduplicate by content hash.
type ChunkParams ¶
ChunkParams controls content-defined chunking. Sizes are in bytes. Min == Avg == Max degenerates to fixed-size chunks of exactly Max bytes.
func DefaultChunkParams ¶
func DefaultChunkParams() ChunkParams
DefaultChunkParams are the chunking parameters for format-2 repos. Part of the on-disk format: changing them changes every chunk boundary.
func FixedChunkParams ¶
func FixedChunkParams(blockSize int) ChunkParams
FixedChunkParams returns parameters that reproduce the legacy format-1 fixed-size blocks of blockSize bytes.
func ParamsForContent ¶
func ParamsForContent(policy int, base ChunkParams, head []byte) ChunkParams
ParamsForContent picks the chunking parameters under a policy: policy 0 always uses base; policy 1 switches text-like content to TextChunkParams.
func TextChunkParams ¶
func TextChunkParams() ChunkParams
TextChunkParams is the CDC target for text-like content: small chunks so a scattered one-line edit invalidates kilobytes, not a 16 KiB block.
type Chunker ¶
type Chunker struct {
// contains filtered or unexported fields
}
Chunker splits a stream into content-defined chunks (FastCDC-style gear hash with normalized chunking). Boundaries depend only on content and ChunkParams.
func NewChunker ¶
func NewChunker(r io.Reader, p ChunkParams) (*Chunker, error)
NewChunker returns a Chunker reading from r with the given parameters.
type CoWFile ¶
type CoWFile struct {
// contains filtered or unexported fields
}
func NewCoWFile ¶
func NewCoWFile(store BlockStore, m CoWMap, blockSize int) (*CoWFile, error)
func (*CoWFile) Snapshot ¶
func (f *CoWFile) Snapshot() *CoWFileView
type CoWFileView ¶
type CoWFileView struct {
// contains filtered or unexported fields
}
func (*CoWFileView) Size ¶
func (v *CoWFileView) Size() int64
type CoWMap ¶
type CoWMap interface {
Snapshot() Snapshot
Get(key string) (BlockID, bool)
Set(key string, id BlockID)
}
CoWMap is a minimal copy-on-write key->BlockID map. Snapshot() must return an immutable view that is not affected by future writes.
type DiskBlockStore ¶
type DiskBlockStore struct {
// contains filtered or unexported fields
}
func NewDiskBlockStore ¶
func NewDiskBlockStore(dir string) (*DiskBlockStore, error)
func (*DiskBlockStore) CollectObjectGarbage ¶ added in v0.1.3
func (s *DiskBlockStore) CollectObjectGarbage(ctx context.Context, live map[BlockID]struct{}, dryRun bool) (ObjectGCResult, error)
CollectObjectGarbage removes whole-file objects which contain no live block.
func (*DiskBlockStore) Compact ¶
func (s *DiskBlockStore) Compact(orderedLive []BlockID) error
Compact rewrites the store to contain exactly the given chunks, in the given order: the frame amnesty. Dead chunks in old packs disappear because old packs are deleted after the new one is durable; loose garbage is swept in the same pass.
func (*DiskBlockStore) CompactOptions ¶
func (s *DiskBlockStore) CompactOptions(orderedLive []BlockID, opts PackOptions) error
CompactOptions is Compact with explicit frame geometry.
func (*DiskBlockStore) Delete ¶
func (s *DiskBlockStore) Delete(id BlockID) error
Delete removes a loose block. Deleting a missing block is not an error; chunks living inside packs are reclaimed by Compact (frame amnesty), so deleting them individually is a no-op by design.
func (*DiskBlockStore) ForEach ¶
func (s *DiskBlockStore) ForEach(fn func(BlockID) error) error
ForEach calls fn for every block currently in the store. Temp files from in-flight writes are skipped. Iteration stops at the first error.
func (*DiskBlockStore) FrameCacheStats ¶
func (s *DiskBlockStore) FrameCacheStats() FrameCacheStats
FrameCacheStats returns the current frame cache counters.
func (*DiskBlockStore) Has ¶
func (s *DiskBlockStore) Has(id BlockID) (bool, error)
Has reports whether a block is present without reading it.
func (*DiskBlockStore) HasPacks ¶
func (s *DiskBlockStore) HasPacks() (bool, error)
HasPacks reports whether any pack file exists, so callers can pick the amnesty path over per-chunk sweeping.
func (*DiskBlockStore) PutDeferred ¶
func (s *DiskBlockStore) PutDeferred(data []byte) (BlockID, error)
PutDeferred writes a block but leaves directory durability to Sync.
func (*DiskBlockStore) SetFrameCacheBytes ¶
func (s *DiskBlockStore) SetFrameCacheBytes(n int64)
SetFrameCacheBytes caps the decompressed frame cache at n bytes (<= 0 restores the default), evicting immediately if the cache is over the new cap.
func (*DiskBlockStore) Size ¶
func (s *DiskBlockStore) Size(id BlockID) (int64, error)
Size returns the stored size of a block in bytes.
func (*DiskBlockStore) Sync ¶
func (s *DiskBlockStore) Sync() error
Sync makes prior deferred block renames durable.
func (*DiskBlockStore) VerifyPacks ¶
func (s *DiskBlockStore) VerifyPacks() (frames, chunks int, err error)
VerifyPacks re-reads every pack frame, checking the stored frame checksum against the compressed payload and every chunk's content address against its extracted bytes. It returns how many frames and chunks were verified.
func (*DiskBlockStore) WritePack ¶
func (s *DiskBlockStore) WritePack(ordered []BlockID) error
WritePack stores the given chunks, in the given order, into a new immutable pack file, then removes their loose copies. Order matters: the caller groups related chunks (versions of the same file) so the frame compression window can capture their redundancy.
func (*DiskBlockStore) WritePackOptions ¶
func (s *DiskBlockStore) WritePackOptions(ordered []BlockID, opts PackOptions) error
WritePackOptions is WritePack with explicit frame geometry.
type FrameCacheStats ¶
FrameCacheStats reports the frame cache counters: hits, misses and the decompressed bytes currently held.
type MaterializeOptions ¶ added in v0.1.3
type MaterializeResult ¶ added in v0.1.3
type MemBlockStore ¶
type MemBlockStore struct {
// contains filtered or unexported fields
}
MemBlockStore is a tiny in-memory content-addressed store suitable for unit tests. It deduplicates blocks by blake3(content).
func NewMemBlockStore ¶
func NewMemBlockStore() *MemBlockStore
type MemCoWMap ¶
type MemCoWMap struct {
// contains filtered or unexported fields
}
MemCoWMap is a tiny in-memory CoW map intended for unit tests. Snapshot() clones the map to ensure snapshot isolation.
func NewMemCoWMap ¶
func NewMemCoWMap() *MemCoWMap
type ObjectGCResult ¶ added in v0.1.3
type ObjectStore ¶ added in v0.1.3
type ObjectStore struct {
// contains filtered or unexported fields
}
func OpenObjectStore ¶ added in v0.1.3
func OpenObjectStore(blocks string) (*ObjectStore, error)
func (*ObjectStore) CollectGarbage ¶ added in v0.1.3
func (s *ObjectStore) CollectGarbage(ctx context.Context, live map[BlockID]struct{}, dryRun bool) (ObjectGCResult, error)
func (*ObjectStore) Compact ¶ added in v0.1.3
func (s *ObjectStore) Compact() error
func (*ObjectStore) CompactIfNeeded ¶ added in v0.1.3
func (s *ObjectStore) CompactIfNeeded(journalBytes int64) error
func (*ObjectStore) MaterializeBlocks ¶ added in v0.1.3
func (s *ObjectStore) MaterializeBlocks(ctx context.Context, destination string, blocks []BlockID, sizes []int64, getter BlockGetter, options MaterializeOptions) (MaterializeResult, error)
func (*ObjectStore) Sync ¶ added in v0.1.3
func (s *ObjectStore) Sync() error
type PackOptions ¶
type PackOptions struct {
// FrameTarget is the uncompressed frame size to cut at (default 256 KiB).
FrameTarget int
// BestCompression trades pack-time CPU for size.
BestCompression bool
// LongWindow enables long-distance matching inside frames.
LongWindow bool
}
PackOptions tune the frame geometry and compression effort. Hot packs use small frames for cheap random access; cold history uses large frames and maximum effort, so whole file lineages share one compression window.
func ColdPackOptions ¶
func ColdPackOptions() PackOptions
ColdPackOptions is the cold-tier preset: 4 MiB frames, maximum effort. The first read of an old state costs one bigger decompression, still bounded.