Documentation
¶
Overview ¶
Package chunk defines the immutable content-addressed units used by compactfs.
Index ¶
- Constants
- Variables
- func Hash(data []byte) string
- func Key(hash string) (string, error)
- type Metrics
- type Ref
- type Span
- type Splitter
- type Store
- func (s *Store) Get(ctx context.Context, ref Ref, dst io.Writer) error
- func (s *Store) Metrics() Metrics
- func (s *Store) OpenRawRange(ctx context.Context, ref Ref, offset, size int64) (*os.File, error)
- func (s *Store) Put(ctx context.Context, raw []byte) (Ref, error)
- func (s *Store) PutFile(ctx context.Context, source *os.File) (Ref, error)
- func (s *Store) PutFileWithHash(ctx context.Context, source *os.File, expectedHash string) (Ref, error)
Constants ¶
const ( // HashAlgorithm identifies content addressing in backend keys and diagnostics. HashAlgorithm = "xxh3-128" // HashSize is the byte length of an uncompressed chunk's content digest. HashSize = 16 // StagedCodec identifies durable raw data awaiting background encoding. // These references require the matching local writeback cache to mount. StagedCodec = "compactfs-raw-v1" // DefaultSize is the default uncompressed chunk size. It is large enough to // amortize object-storage requests while keeping random reads bounded. DefaultSize = 4 * 1024 * 1024 )
Variables ¶
var ErrChecksumMismatch = errors.New("chunk checksum mismatch")
ErrChecksumMismatch means staged bytes no longer match their content address.
Functions ¶
Types ¶
type Metrics ¶
type Metrics struct {
PutOps int64
PutBytes int64
PutNanos int64
PutErrors int64
EncodeOps int64
EncodeBytes int64
EncodeNanos int64
EncodeErrors int64
EncodeBufferAllocations int64
EncodeBufferReuses int64
EncodeBufferPoolBytes int64
BackendStatOps int64
BackendStatNanos int64
BackendStatErrors int64
BackendPutOps int64
BackendPutBytes int64
BackendPutNanos int64
BackendPutErrors int64
BackendImportOps int64
BackendImportBytes int64
BackendImportNanos int64
BackendImportFallbacks int64
BackendRangeOps int64
BackendRangeBytes int64
BackendGetOps int64
BackendGetBytes int64
BackendGetNanos int64
BackendGetErrors int64
CacheGetOps int64
CacheGetBytes int64
CacheGetNanos int64
CacheGetErrors int64
CacheHits int64
CacheMisses int64
CachePutOps int64
CachePutBytes int64
CachePutNanos int64
CachePutErrors int64
DecodeOps int64
DecodeBytes int64
DecodeNanos int64
DecodeErrors int64
}
Metrics is a cumulative snapshot of chunk-store activity. Durations are in nanoseconds so callers can calculate throughput without depending on a particular presentation format.
type Ref ¶
type Ref struct {
Hash string `json:"hash"`
RawSize int64 `json:"raw_size"`
StoredSize int64 `json:"stored_size"`
Codec string `json:"codec"`
ContentType string `json:"content_type,omitempty"`
}
Ref identifies one compressed chunk in a file manifest.
type Splitter ¶
type Splitter struct {
Size int
}
Splitter cuts data into fixed-size, non-overlapping spans. Fixed chunks make random FUSE writes predictable and allow direct chunk-index replacement.
type Store ¶
type Store struct {
Backend backend.Backend
Codec codec.Codec
Fallback codec.Codec
Cache *cache.Cache
// SkipWriteCache avoids storing a second encoded copy when a durable raw
// writeback cache already owns newly written data. Backend reads may still
// populate Cache for objects whose raw copy has been evicted.
SkipWriteCache bool
// Decoders contains codecs that may be referenced by existing chunk
// metadata even when Codec has since changed. Built-in gzip and zstd
// decoders are supplied automatically; this map is for application codecs.
Decoders map[string]codec.Codec
// MaxAttempts is the total number of attempts for one immutable chunk. A
// value below two disables retries. The filesystem config supplies a
// bounded default for asynchronous write-back.
MaxAttempts int
// RetryBackoff is the delay before the second attempt. Each subsequent
// delay doubles and is capped at one second.
RetryBackoff time.Duration
// contains filtered or unexported fields
}
Store owns immutable compressed chunks and performs content-addressed deduplication. The hash is always over raw bytes, so codec changes do not silently alias incompatible data.
func (*Store) OpenRawRange ¶
OpenRawRange opens a read-only local object without materializing its whole chunk. Only raw references qualify. The caller owns the immutable fd and may read the validated range [offset, offset+size). ErrNotSupported requests the normal cache/decode path without performing remote I/O. BackendGetBytes and BackendRangeBytes count requested logical range bytes, not disk sector I/O.
func (*Store) PutFile ¶
PutFile stores one immutable regular file as a chunk. Linux maps its bytes read-only instead of copying the whole chunk into another anonymous buffer. Raw representations can use backend.FileImporter to reuse durable file data. Its offset and ownership are preserved. The source inode must remain immutable even after return because a backend may share it with the object; callers may close or unlink the source. Hashing and retries match Put.
func (*Store) PutFileWithHash ¶
func (s *Store) PutFileWithHash(ctx context.Context, source *os.File, expectedHash string) (Ref, error)
PutFileWithHash verifies a staged file against its expected content address before encoding or publishing it. The immutability and ownership requirements are the same as PutFile. A mismatch returns ErrChecksumMismatch without any backend publication; expectedHash must be a canonical XXH3-128 digest.