Documentation
¶
Overview ¶
Package backend provides object storage for content-addressed chunks.
Index ¶
- Variables
- 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 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)
- 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) 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)
- 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
Constants ¶
This section is empty.
Variables ¶
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 file import not supported")
ErrNotSupported asks the caller to fall back to streaming Put. ImportFile must not publish an object when returning this error.
Functions ¶
This section is empty.
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 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 Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory is a concurrency-safe backend used by tests and small embedded deployments.
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 ¶
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
Bucket string
Region string
Endpoint string
Prefix string
UsePathStyle bool
// AddressingStyle is auto (default), path or virtual. UsePathStyle remains
// supported for callers using the earlier boolean option.
AddressingStyle string
// AccessKeyID and SecretAccessKey must be provided together. SessionToken is
// optional. Static credentials and a Credentials provider are mutually exclusive.
AccessKeyID string
SecretAccessKey string
SessionToken string
// TempDir holds temporary uploads for non-seekable readers. Empty uses the
// system temporary directory. The files are closed and removed before return.
TempDir string
Credentials aws.CredentialsProvider
HTTPClient aws.HTTPClient
}
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.