
object
Index
- Variables
- func AdvancePastEmittedCommonPrefix(prefix, delimiter, cursor string, seen map[string]bool) string
- func HashBody(data []byte) string
- func ParsePlaintextRange(rangeHeader string, plaintextSize int64) (start, end int64, ok bool)
- type DeleteObjectResult
- type Deps
- type ListObjectsV2Result
- type LocationCache
- type Manager
- func New(d *Deps) *Manager
- func (o *Manager) BackendCapacityStats(ctx context.Context) map[string]core.QuotaStat
- func (o *Manager) CanAcceptWrite(size int64) bool
- func (o *Manager) CopyObject(ctx context.Context, sourceKey, destKey string) (string, error)
- func (o *Manager) DeleteObject(ctx context.Context, key string) error
- func (o *Manager) DeleteObjects(ctx context.Context, keys []string) []DeleteObjectResult
- func (o *Manager) GetObject(ctx context.Context, key string, rangeHeader string) (*s3be.GetObjectResult, error)
- func (o *Manager) HeadObject(ctx context.Context, key string) (*s3be.HeadObjectResult, error)
- func (o *Manager) ListObjects(ctx context.Context, prefix, delimiter, startAfter string, maxKeys int) (*ListObjectsV2Result, error)
- func (o *Manager) LocationCache() *LocationCache
- func (o *Manager) ObjectExists(ctx context.Context, key string) (bool, error)
- func (o *Manager) PutObject(ctx context.Context, key string, body io.Reader, size int64, contentType string, metadata map[string]string) (string, error)
- type ObjectCoordinator
- type ObjectCore
- type VerifyingReader
- func NewVerifyingReader(r io.ReadCloser) *VerifyingReader
- func (vr *VerifyingReader) Close() error
- func (vr *VerifyingReader) Read(p []byte) (int, error)
- func (vr *VerifyingReader) SetVerification(expected string, onMismatch func(expected, actual string))
- func (vr *VerifyingReader) Verify(expected string) error
Variables
ListObjectsMaxPages caps DB round trips per ListObjects request so a single client call cannot drag the database through unbounded scans on pathological prefix layouts. Exposed as a var (rather than const) so tests can lower it without generating hundreds of mock pages.
func AdvancePastEmittedCommonPrefix
AdvancePastEmittedCommonPrefix rewrites a continuation cursor so the next ListObjects call cannot re-emit a CommonPrefix the current call already returned. The seen map is local to a single ListObjects invocation, so without this rewrite a cursor that lands inside an already-emitted CP (e.g., maxPages cap reached deep in a tenant’s keys or the page boundary aligned mid-group) would let the next call walk the same group and emit its CP a second time.
The rewrite increments the last byte of the CP, producing the smallest string lex-greater than every key starting with that CP. The store’s next-page WHERE object_key > cursor then skips the rest of the group cleanly. Returns the input unchanged when the delimiter is unset, the cursor does not fall inside an emitted CP, or the last byte is 0xff (no representable advance - accept potential re-emission rather than corrupt the cursor).
func HashBody
HashBody computes the SHA-256 hex digest of a byte slice.
func ParsePlaintextRange
ParsePlaintextRange extracts the start and end byte offsets from an HTTP Range header value (e.g., “bytes=0-99”). Suffix ranges and open-ended ranges are resolved against plaintextSize.
type DeleteObjectResult
DeleteObjectResult holds the outcome of a single key within a batch delete.
type Deps
Deps bundles the dependencies New needs so the call signature stays under the parameter-count ceiling. Core and Coord are consumer-declared interfaces; the concrete *infra.Core and *writepath.Coordinator that BackendManager builds satisfy them implicitly.
type ListObjectsV2Result
ListObjectsV2Result holds the processed result for the S3 ListObjectsV2 response.
type LocationCache
LocationCache is a TTL-based cache mapping object keys to backend names. It delegates storage and eviction to a generic TTLCache and applies random jitter (+/-20%) on each Set to stagger expiry times.
func NewLocationCache
NewLocationCache creates a location cache with the given TTL. If ttl > 0, a background goroutine periodically evicts expired entries.
func (*LocationCache) Clear
Clear removes all entries from the cache.
func (*LocationCache) Close
Close stops the background eviction goroutine. Safe to call multiple times.
func (*LocationCache) Delete
Delete removes a single key from the cache.
func (*LocationCache) Get
Get returns the cached backend for a key, or false if not cached or expired.
func (*LocationCache) Len
Len returns the number of entries in the cache, including expired entries not yet swept by the background eviction goroutine.
func (*LocationCache) Set
Set stores a key-to-backend mapping with the configured TTL. A random jitter of +/-20% is applied to prevent synchronized cache expiry storms.
type Manager
Manager handles object-level CRUD operations with read failover, broadcast reads during degraded mode, and location caching.
func New
New creates a Manager sharing the given core infrastructure and write coordinator. All dependencies must be non-nil; nothing is patched in post-construction. The component-scoped logger is built in the constructor body per the project’s logging convention. The read-failover orchestrator is built once and reused for every GET / HEAD; it captures the same Core, Stores, LocationCache, and the parallelBroadcast flag, so per-call read paths stay short.
func (*Manager) BackendCapacityStats
BackendCapacityStats returns the current per-backend used/limit byte snapshot. Used by the InsufficientStorage error path so the response body can name the backends that are at capacity instead of returning a generic message. Returns nil on a DB lookup failure so the caller can fall back to its terse default.
func (*Manager) CanAcceptWrite
CanAcceptWrite reports whether any backend can accept a write of the given size. Used by the HTTP handler to reject uploads before the request body is transmitted (Expect: 100-Continue support).
func (*Manager) CopyObject
CopyObject copies an object from sourceKey to destKey. Materializes the source body into a seekable buffer - in-memory for small objects, a self-unlinking tempfile above materializeMemThreshold - before handing it to the destination PutObject. A non-seekable body would force the AWS SDK onto its streaming-unsigned-payload signing path, which uses chunked transfer encoding and drops Content-Length; S3 implementations that require Content-Length (notably OCI) then reject the upload with HTTP 411. Supports cross-backend copies and read failover from replicas.
func (*Manager) DeleteObject
DeleteObject removes an object from the backend where it’s stored.
func (*Manager) DeleteObjects
DeleteObjects deletes multiple objects in a single request. Metadata removal happens in a single transaction via DeleteObjectsBatch; backend S3 deletes run concurrently with bounded parallelism to avoid overwhelming backends.
func (*Manager) GetObject
GetObject retrieves an object from the backend where it’s stored. Tries the primary copy first, then falls back to replicas if the primary fails. When the object is encrypted, the response body is transparently decrypted and the reported size reflects the original plaintext size.
func (*Manager) HeadObject
HeadObject retrieves object metadata. Tries the primary copy first, then falls back to replicas if the primary fails. When the object is encrypted, the reported size reflects the original plaintext size.
func (*Manager) ListObjects
ListObjects returns objects matching the given prefix with optional delimiter support for virtual directory grouping. When a delimiter is set, many raw objects may collapse into a single CommonPrefix, so the loop fetches store pages until maxKeys post-grouping items are collected or the store is exhausted.
func (*Manager) LocationCache
LocationCache returns the location cache the manager holds. Exposed for BackendManager and tests so the lifecycle (Close, Clear) can be driven from the root package without reaching into the unexported field.
func (*Manager) ObjectExists
ObjectExists reports whether at least one location row exists for key. Used by the conditional-write path (If-None-Match: *) to fail-fast before the body upload. Best-effort: a concurrent racing PUT can land between this read and the eventual RecordObject commit, matching AWS S3’s documented best-effort precondition semantic. ErrObjectNotFound is the canonical “no row” signal and is normalised to (false, nil).
func (*Manager) PutObject
PutObject uploads an object to the first backend with available quota. If the upload fails, it retries on remaining eligible backends before returning an error to the caller (write failover).
type ObjectCoordinator
ObjectCoordinator is the subset of *writepath.Coordinator the object Manager needs. RecoverFromRecordFailure is here for the drain-race abort path in attemptPutOnBackend: when the post-PUT IsDraining re-check fires, the orchestrator reuses the existing post-record- failure recovery sequence to delete the orphaned bytes and account for the cleanup DELETE.
type ObjectCore
ObjectCore is the subset of *infra.Core the object Manager needs. BackendOrder is here for *readpath.Failover, which Manager constructs from its own ObjectCore; the transitive requirement satisfies its type-check at this boundary. IsDraining is here for the post-PUT drain-race re-check in attemptPutOnBackend (the upstream EligibleForWrite filter is racy; the re-check closes the window).
type VerifyingReader
VerifyingReader wraps an io.ReadCloser and computes SHA-256 as data is read. After the underlying reader returns EOF, call Verify to check the hash.
func NewVerifyingReader
NewVerifyingReader wraps r with a streaming SHA-256 computation.
func (*VerifyingReader) Close
Close closes the underlying reader. If an OnMismatch callback is set and verification fails, it is called before returning.
func (*VerifyingReader) Read
Read implements io.Reader. Data passes through to the caller while being hashed incrementally.
func (*VerifyingReader) SetVerification
SetVerification configures the reader to check the hash on Close and call onMismatch if the digest doesn’t match. This allows the caller to trigger cleanup of corrupted copies after streaming completes.
func (*VerifyingReader) Verify
Verify checks the computed hash against the expected hex digest. Returns nil if they match, or an error describing the mismatch. Returns nil if expected is empty (object has no stored hash).
Generated by gomarkdoc