Documentation
¶
Overview ¶
Package backend provides object storage for content-addressed chunks.
Index ¶
- Variables
- func ValidateArray(o ArrayOptions) error
- type Afero
- func (b *Afero) Delete(ctx context.Context, key string) error
- func (b *Afero) Get(ctx context.Context, key string) (io.ReadCloser, error)
- func (b *Afero) List(ctx context.Context, prefix string) ([]Object, error)
- func (b *Afero) Put(ctx context.Context, key string, r io.Reader, size int64) error
- func (b *Afero) PutImmutable(ctx context.Context, key string, r io.Reader, size int64) error
- func (b *Afero) Stat(ctx context.Context, key string) (Object, error)
- type AferoOptions
- type Array
- func (a *Array) Delete(ctx context.Context, key string) error
- func (a *Array) Get(ctx context.Context, key string) (io.ReadCloser, error)
- func (a *Array) List(ctx context.Context, prefix string) ([]Object, error)
- func (a *Array) Put(ctx context.Context, key string, r io.Reader, size int64) error
- func (a *Array) PutImmutable(ctx context.Context, key string, r io.Reader, size int64) error
- func (a *Array) Repair(ctx context.Context, key string) error
- func (a *Array) Stat(ctx context.Context, key string) (Object, error)
- func (a *Array) StorageIdentity() string
- func (a *Array) StorageSpace(ctx context.Context) ([]Space, error)
- type ArrayConfig
- type ArrayMember
- type ArrayOptions
- type Backend
- type FileImporter
- type FileOpener
- type ImmutablePutter
- type Local
- func (b *Local) Delete(ctx context.Context, key string) error
- func (b *Local) Get(ctx context.Context, key string) (io.ReadCloser, error)
- func (b *Local) ImportFile(ctx context.Context, key string, source *os.File, size int64) error
- func (b *Local) List(ctx context.Context, prefix string) ([]Object, error)
- func (b *Local) OpenFile(ctx context.Context, key string) (*os.File, error)
- func (b *Local) Put(ctx context.Context, key string, r io.Reader, size int64) error
- func (b *Local) PutImmutable(ctx context.Context, key string, r io.Reader, size int64) error
- func (b *Local) Stat(ctx context.Context, key string) (Object, error)
- func (b *Local) StorageSpace(ctx context.Context) ([]Space, error)
- type MemberConfig
- type Memory
- func (b *Memory) Delete(ctx context.Context, key string) error
- func (b *Memory) Get(ctx context.Context, key string) (io.ReadCloser, error)
- func (b *Memory) List(ctx context.Context, prefix string) ([]Object, error)
- func (b *Memory) Put(ctx context.Context, key string, r io.Reader, size int64) error
- func (b *Memory) PutImmutable(ctx context.Context, key string, r io.Reader, size int64) error
- func (b *Memory) Stat(ctx context.Context, key string) (Object, error)
- type Object
- type Prefix
- func (p Prefix) Delete(ctx context.Context, key string) error
- func (p Prefix) Get(ctx context.Context, key string) (io.ReadCloser, error)
- func (p Prefix) ImportFile(ctx context.Context, key string, source *os.File, size int64) error
- func (p Prefix) List(ctx context.Context, prefix string) ([]Object, error)
- func (p Prefix) OpenFile(ctx context.Context, key string) (*os.File, error)
- func (p Prefix) Put(ctx context.Context, key string, r io.Reader, size int64) error
- func (p Prefix) PutImmutable(ctx context.Context, key string, r io.Reader, size int64) error
- func (p Prefix) Stat(ctx context.Context, key string) (Object, error)
- func (p Prefix) StorageIdentity() string
- func (p Prefix) StorageSpace(ctx context.Context) ([]Space, error)
- type S3
- func (b *S3) Delete(ctx context.Context, key string) error
- func (b *S3) Get(ctx context.Context, key string) (io.ReadCloser, error)
- func (b *S3) List(ctx context.Context, prefix string) ([]Object, error)
- func (b *S3) Put(ctx context.Context, key string, r io.Reader, size int64) error
- func (b *S3) PutImmutable(ctx context.Context, key string, r io.Reader, size int64) error
- func (b *S3) Stat(ctx context.Context, key string) (Object, error)
- type S3Config
- type Space
- type SpaceReporter
Constants ¶
This section is empty.
Variables ¶
var ErrArrayLayout = errors.New("array layout mismatch")
ErrArrayUnavailable means the requested durability or reconstruction threshold cannot be met. Missing/corrupt pieces are never returned as successful data.
var ErrExists = errors.New("backend object already exists")
ErrExists means an immutable import found an already published object. Callers must inspect its stored representation rather than overwrite it.
var ErrNotFound = errors.New("backend object not found")
var ErrNotSupported = errors.New("backend operation not supported")
ErrNotSupported means an optional backend capability is unavailable. Import callers may fall back to streaming Put; an unsupported ImportFile must not publish an object before returning this error.
Functions ¶
func ValidateArray ¶ added in v1.0.2
func ValidateArray(o ArrayOptions) error
ValidateArray checks geometry without opening or writing storage.
Types ¶
type Afero ¶
type Afero struct {
// contains filtered or unexported fields
}
Afero stores objects in a caller-owned filesystem. The filesystem must provide atomic file Rename and meaningful file/directory Sync for durable storage. Use one Afero instance per root: publication is serialized within this instance, since afero.Fs has no portable cross-process rename-without-replacement API. The caller must not modify this root through another writer.
func NewAfero ¶
NewAfero creates an object root without taking ownership of fs. Afero does not expose host file descriptors or close the supplied filesystem. At most one AferoOptions value is accepted; omitting it disables the object read cache.
func (*Afero) PutImmutable ¶
PutImmutable preserves an existing object, including concurrent publications through this same backend instance.
type AferoOptions ¶
type AferoOptions struct {
// Cache uses an existing cache and its capacity budget. The caller retains
// ownership; do not also set CacheRoot or CacheBytes.
Cache *cache.Cache
// CacheRoot and CacheBytes create a local disk cache, independently of the
// supplied afero.Fs. Both are required together; CacheBytes must be positive.
// Keep the cache outside the source object root.
CacheRoot string
CacheBytes int64
}
AferoOptions configures an optional bounded, local-disk object read cache. Zero values disable caching. This cache never acknowledges pending writes.
type Array ¶ added in v1.0.2
type Array struct {
// contains filtered or unexported fields
}
Array borrows resources supplied to NewArray. One writer instance must own an array; operations on that instance are concurrency safe. All selected members must persist data and commit records before a write succeeds. Reads can reconstruct already committed objects with failed members.
func NewArray ¶ added in v1.0.2
func NewArray(ctx context.Context, options ArrayOptions) (*Array, error)
NewArray checks persistent member identities. Entirely empty arrays are initialized; a missing member in a nonempty array stays degraded until Repair. Wrong IDs, order or geometry are rejected, including when data is still cached.
func (*Array) PutImmutable ¶ added in v1.0.2
func (*Array) Repair ¶ added in v1.0.2
Repair verifies the logical object, reconstructs missing/corrupt parts, and restores the selected group's member identities and commit records. Member configuration/IDs must match the original array; this does not reshape it.
func (*Array) Stat ¶ added in v1.0.2
Stat also completes interrupted commit-record replication. It never lets a failed partial write be accepted as a fully redundant deduplication hit.
func (*Array) StorageIdentity ¶ added in v1.0.2
func (*Array) StorageSpace ¶ added in v1.0.3
StorageSpace reports the distinct physical filesystems behind RAID0 members. It does not predict compression/deduplication gains, placement balance or metadata/spool limits. Mirror and parity layouts need different accounting.
type ArrayConfig ¶ added in v1.0.2
type ArrayConfig struct {
ID string `toml:"id" mapstructure:"id"`
Level string `toml:"level" mapstructure:"level"`
Members []MemberConfig `toml:"members" mapstructure:"members"`
DataShards int `toml:"data_shards,omitempty" mapstructure:"data_shards"`
ParityShards int `toml:"parity_shards,omitempty" mapstructure:"parity_shards"`
GroupSize int `toml:"group_size,omitempty" mapstructure:"group_size"`
TempDir string `toml:"temp_dir,omitempty" mapstructure:"temp_dir"`
Parallel int `toml:"parallel,omitempty" mapstructure:"parallel"`
}
func (ArrayConfig) Open ¶ added in v1.0.2
func (c ArrayConfig) Open(ctx context.Context) (*Array, error)
Open builds independent leaf backends, then checks the persisted array identities. It never formats devices or creates an S3 bucket.
func (ArrayConfig) Validate ¶ added in v1.0.2
func (c ArrayConfig) Validate() error
Validate checks geometry and independent namespaces without touching members.
type ArrayMember ¶ added in v1.0.2
ArrayMember is an independent object namespace. ID and order are persistent. Replacing a failed member keeps its ID and requires Repair.
type ArrayOptions ¶ added in v1.0.2
type ArrayOptions struct {
ID string
Level string
Members []ArrayMember
DataShards int
ParityShards int
GroupSize int
// TempDir holds private streaming spool files, removed before return/Close.
// Memory is bounded by group width, not object or metadata-backup size.
TempDir string
Parallel int
}
ArrayOptions places encoded objects across storage members. Level is raid0, raid1, raid5, raid6, raid10, raid50, raid60 or ec. RAID0 stripes objects, not sectors. RAID10/50/60 stripe objects across fixed mirror/parity groups.
type Backend ¶
type Backend interface {
Put(ctx context.Context, key string, r io.Reader, size int64) error
Get(ctx context.Context, key string) (io.ReadCloser, error)
Stat(ctx context.Context, key string) (Object, error)
Delete(ctx context.Context, key string) error
List(ctx context.Context, prefix string) ([]Object, error)
}
Backend is the storage contract shared by local and object-storage implementations. The namespace currently persists through its own meta.Engine. Put consumes its reader before returning; it must not retain caller buffers. Get returns a reader owned and closed by the caller. List uses lexical key prefixes, not directory names.
type FileImporter ¶
type FileImporter interface {
ImportFile(ctx context.Context, key string, source *os.File, size int64) error
}
FileImporter optionally commits a complete immutable local file without copying its data. The source inode must remain immutable even after return: an implementation may share it with the object. Closing or unlinking the source pathname is allowed. A successful import is durable and survives it.
type FileOpener ¶
FileOpener optionally opens an immutable local object with a read-only fd. The caller owns and closes the fd. Unsupported backends return ErrNotSupported immediately, without fetching the object. An open fd survives unlink/eviction.
type ImmutablePutter ¶
type ImmutablePutter interface {
PutImmutable(ctx context.Context, key string, r io.Reader, size int64) error
}
ImmutablePutter atomically publishes an absent object, returning ErrExists without replacing a concurrent writer's representation. Mutable metadata continues using Backend.Put. The reader must be consumed before return; callers may then reuse its backing buffer.
type Local ¶
type Local struct {
Root string
// contains filtered or unexported fields
}
Local stores backend objects in a directory. Writes are staged in the same directory and atomically renamed, so readers never observe partial chunks.
func (*Local) ImportFile ¶
ImportFile hard-links an immutable open file when both paths share a filesystem. Linux publishes directly from the descriptor; other systems validate a temporary pathname link against the fd before publication. Unsupported or unlinked sources fall back to streaming in the chunk store.
func (*Local) PutImmutable ¶
type MemberConfig ¶ added in v1.0.2
type MemberConfig struct {
ID string `toml:"id" mapstructure:"id"`
Type string `toml:"type" mapstructure:"type"`
Path string `toml:"path,omitempty" mapstructure:"path"`
S3 S3Config `toml:"s3,omitempty" mapstructure:"s3"`
}
MemberConfig is a serializable leaf namespace. Memory is intentionally ephemeral and exists for tests; S3 credentials can use the AWS provider chain.
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory is a concurrency-safe backend used by tests and small embedded deployments.
func (*Memory) PutImmutable ¶ added in v1.0.2
PutImmutable publishes one representation under the same lock as Put/Delete.
type Prefix ¶
Prefix returns a backend view that prefixes every key. It is useful for sharing a bucket or local root between several compactfs instances.
func (Prefix) ImportFile ¶
func (Prefix) PutImmutable ¶
func (Prefix) StorageIdentity ¶ added in v1.0.2
type S3 ¶
type S3 struct {
// contains filtered or unexported fields
}
S3 stores objects with signed streaming requests. It owns no bucket or caller resources and performs no bucket creation. Conditional writes must be supported by the endpoint; PutImmutable never falls back to an unconditional write.
func (*S3) PutImmutable ¶
type S3Config ¶
type S3Config struct {
// URL optionally supplies bucket and prefix as s3://bucket/prefix. Explicit
// Bucket/Prefix values must agree with the URL when both are supplied.
URL string `toml:"url,omitempty" mapstructure:"url"`
Bucket string `toml:"bucket,omitempty" mapstructure:"bucket"`
Region string `toml:"region,omitempty" mapstructure:"region"`
Endpoint string `toml:"endpoint,omitempty" mapstructure:"endpoint"`
Prefix string `toml:"prefix,omitempty" mapstructure:"prefix"`
UsePathStyle bool `toml:"path_style,omitempty" mapstructure:"path_style"`
// AddressingStyle is auto (default), path or virtual. UsePathStyle remains
// supported for callers using the earlier boolean option.
AddressingStyle string `toml:"addressing_style,omitempty" mapstructure:"addressing_style"`
// AccessKeyID and SecretAccessKey must be provided together. SessionToken is
// optional. Static credentials and a Credentials provider are mutually exclusive.
AccessKeyID string `toml:"access_key_id,omitempty" mapstructure:"access_key_id"`
SecretAccessKey string `toml:"secret_access_key,omitempty" mapstructure:"secret_access_key"`
SessionToken string `toml:"session_token,omitempty" mapstructure:"session_token"`
// TempDir holds temporary uploads for non-seekable readers. Empty uses the
// system temporary directory. The files are closed and removed before return.
TempDir string `toml:"temp_dir,omitempty" mapstructure:"temp_dir"`
Credentials aws.CredentialsProvider `toml:"-" mapstructure:"-"`
HTTPClient aws.HTTPClient `toml:"-" mapstructure:"-"`
}
S3Config selects an existing bucket in AWS S3 or a compatible object store. Empty Region uses the SDK configuration, then us-east-1. Without explicit credentials, the SDK uses its environment/shared-file/workload-identity chain.
type Space ¶ added in v1.0.3
type Space struct {
ID string
TotalBytes, FreeBytes, AvailableBytes uint64
Files, FreeFiles uint64
}
Space describes one backing filesystem, not the logical size of its objects. ID identifies the same space across directory and Prefix views. Bytes include other users of that filesystem; AvailableBytes excludes reserved free space.
type SpaceReporter ¶ added in v1.0.3
SpaceReporter optionally reports all backing filesystems as an owned snapshot. Unknown or incomplete capacity must return ErrNotSupported or an error rather than a successful partial list. Querying space does not scan or sync objects.