Documentation
¶
Index ¶
- Constants
- Variables
- func GetConcurrencyHint(s ObjectStore, defaultConcurrency int) int
- func HTTPRangeHeader(offset, length int64) string
- type ConcurrencyHinter
- type DebugStore
- func (s *DebugStore) Delete(ctx context.Context, key string) error
- func (s *DebugStore) Exists(ctx context.Context, key string) (bool, error)
- func (s *DebugStore) Flush(ctx context.Context) error
- func (s *DebugStore) Get(ctx context.Context, key string) ([]byte, error)
- func (s *DebugStore) GetRange(ctx context.Context, key string, offset, length int64) ([]byte, error)
- func (s *DebugStore) List(ctx context.Context, prefix string) ([]string, error)
- func (s *DebugStore) Put(ctx context.Context, key string, data []byte) error
- func (s *DebugStore) Size(ctx context.Context, key string) (int64, error)
- func (s *DebugStore) TotalSize(ctx context.Context) (int64, error)
- func (s *DebugStore) Unwrap() ObjectStore
- type ObjectStore
- type QuotaStore
- type RangeGetter
- type Unwrapper
Constants ¶
const KeySlotPrefix = "keys/"
KeySlotPrefix is the object key prefix for encryption key slot objects. These objects are stored unencrypted (they contain already-wrapped keys) so they can be read without the encryption key — avoiding a chicken-and-egg problem during key loading.
It lives in the contract package rather than with the encryption layer because it is a repository key-namespace fact that pkg/keychain also needs, alongside the chunk/, snapshot/ and index/ conventions.
Variables ¶
var ErrNotFound = errors.New("object not found")
ErrNotFound is the sentinel error returned by Get when the requested key does not exist. Each backend translates its own not-found signal — a missing file, an S3 NoSuchKey/404, an SFTP no-such-file, a B2 404 — into this sentinel, wrapped with the key, so callers can use errors.Is(err, ErrNotFound) instead of treating every Get failure (network error, permission error, corrupt response, ...) as "the object isn't there".
var ErrQuotaExceeded = errors.New("storage quota exceeded during backup")
Functions ¶
func GetConcurrencyHint ¶ added in v1.4.3
func GetConcurrencyHint(s ObjectStore, defaultConcurrency int) int
GetConcurrencyHint walks the store wrapper chain and returns the first ConcurrencyHint it finds, defaulting to defaultConcurrency if none exists.
func HTTPRangeHeader ¶ added in v1.18.0
HTTPRangeHeader renders an inclusive byte range for backends that speak HTTP range requests, for use when implementing RangeGetter. The end offset is inclusive, which is the classic off-by-one in this header.
Types ¶
type ConcurrencyHinter ¶ added in v1.4.3
type ConcurrencyHinter interface {
ConcurrencyHint() int
}
ConcurrencyHinter is an optional interface that ObjectStore implementations can implement to indicate the optimal number of concurrent operations. Remote stores (S3) benefit from high concurrency; local stores do not.
type DebugStore ¶ added in v1.2.0
type DebugStore struct {
// contains filtered or unexported fields
}
DebugStore wraps an ObjectStore and logs every operation with timing information. Output goes to the provided writer, which should be a ui.SafeLogWriter so lines coexist with progress bars.
func NewDebugStore ¶ added in v1.2.0
func NewDebugStore(inner ObjectStore, w io.Writer) *DebugStore
func (*DebugStore) Delete ¶ added in v1.2.0
func (s *DebugStore) Delete(ctx context.Context, key string) error
func (*DebugStore) GetRange ¶ added in v1.16.0
func (s *DebugStore) GetRange(ctx context.Context, key string, offset, length int64) ([]byte, error)
GetRange implements RangeGetter. DebugStore only logs, so it is safe to pass a ranged read straight through — and it has to, or wrapping a backend in --debug would silently turn every footer read into a full object transfer.
Declaring this method makes DebugStore satisfy RangeGetter unconditionally, including over an inner store that cannot range, so the fallback is explicit rather than inherited.
func (*DebugStore) TotalSize ¶ added in v1.2.0
func (s *DebugStore) TotalSize(ctx context.Context) (int64, error)
func (*DebugStore) Unwrap ¶ added in v1.4.3
func (s *DebugStore) Unwrap() ObjectStore
type ObjectStore ¶
type ObjectStore interface {
// Put must not retain data beyond the call: read or copy it synchronously
// before returning. Callers (chunking in particular) pool and reuse their
// write buffers the instant Put returns, so an implementation that keeps
// the slice — instead of the bytes — would see it mutated out from under
// a previously "stored" value.
Put(ctx context.Context, key string, data []byte) error
Get(ctx context.Context, key string) ([]byte, error)
Exists(ctx context.Context, key string) (bool, error)
Delete(ctx context.Context, key string) error
List(ctx context.Context, prefix string) ([]string, error)
Size(ctx context.Context, key string) (int64, error)
TotalSize(ctx context.Context) (int64, error)
Flush(ctx context.Context) error
}
ObjectStore is the interface for content-addressable object storage. Keys are slash-separated paths like "chunk/<hash>" or "snapshot/<hash>".
type QuotaStore ¶
type QuotaStore struct {
ObjectStore
// contains filtered or unexported fields
}
QuotaStore wraps an ObjectStore and cancels the backup context when cumulative bytes written exceed the remaining budget.
func NewQuotaStore ¶
func NewQuotaStore(inner ObjectStore, budget int64, cancel context.CancelCauseFunc) *QuotaStore
func (*QuotaStore) Unwrap ¶ added in v1.4.3
func (q *QuotaStore) Unwrap() ObjectStore
func (*QuotaStore) Written ¶
func (q *QuotaStore) Written() int64
Written returns the total bytes successfully written through this store.
type RangeGetter ¶ added in v1.15.0
type RangeGetter interface {
GetRange(ctx context.Context, key string, offset, length int64) ([]byte, error)
}
RangeGetter is an optional interface for backends that can read a byte range without transferring the whole object. It lets PackStore read a packfile's trailing footer without downloading the entire 8 MB pack.
Implementations return exactly length bytes starting at offset, or an error. Backends that cannot do this simply do not implement it; callers fall back to a full Get, which is correct everywhere and merely slower.
type Unwrapper ¶ added in v1.4.3
type Unwrapper interface {
Unwrap() ObjectStore
}
Unwrapper is an optional interface for wrapper stores (CompressedStore, EncryptedStore, etc.) to expose their inner store for introspection.