Documentation
¶
Overview ¶
Package blob is the content-addressed blob store (ADR-0004). Blobs live under a tenant prefix in a single bucket opened from a file, S3, GCS or Azure URL. The embedded profile keeps data in a local directory and serves proxied read and upload URLs; the cloud profile uses the provider's presigned PUT and GET URLs (ADR-0013). Clients stage bodies through StartUpload and Commit.
Staging slots are serialized in-process by a per-(tenant, staging key) lock. Commit holds that lock for the whole operation. A proxied PUT streams the body into the bucket writer without the lock (O(copy-buffer) memory, not O(max)), then takes the lock only to re-check the slot and call Close, which publishes the staged object. A failed or refused Close aborts the writer and leaves any prior staged object in place. The lock does not span cloud replicas: two commits on different hosts may return the same content key.
Commit spends a slot by writing a commit record after the content blob is stored. If that write fails, Commit returns unavailable and the slot stays open for an idempotent retry. After the record is durable, Commit returns the content key even when deleting the staged object fails; expiry sweep removes leftover staging objects, commit records and metadata together.
Expired embedded slots are swept lazily: after signature-verified handler or store calls, at most once per maximum URL lifetime, with a one-minute retry after a failed list. Sweeps list each tenant's stage/ prefix only and ignore keys that are not well-formed staging slots (including stranded *.tmp partial writes an operator may remove when no upload is in flight).
Tenant ids must satisfy REQ-CORE-005; only core.TenantFrom decides validity.
Index ¶
- Constants
- func ContentKeyOf(data []byte) string
- func HandlerRoute() string
- func HexOf(k string) (string, error)
- func ValidateContentKey(k string) bool
- func ValidateStagingKey(k string) bool
- type Options
- type Store
- func (s *Store) Close() error
- func (s *Store) Commit(ctx context.Context, stagingKey string) (string, error)
- func (s *Store) ContentType(ctx context.Context, key string) (string, error)
- func (s *Store) Delete(ctx context.Context, key string) error
- func (s *Store) Exists(ctx context.Context, key string) (bool, error)
- func (s *Store) Get(ctx context.Context, key string) (io.ReadCloser, error)
- func (s *Store) Put(ctx context.Context, key string, r io.Reader, contentType string) error
- func (s *Store) SignedURL(ctx context.Context, key string, ttl time.Duration) (string, error)
- func (s *Store) StartUpload(ctx context.Context, o platform.UploadOptions) (platform.Upload, error)
- type URLHandler
- type UploadHandler
Constants ¶
const DefaultMaxURLTTL = 7 * 24 * time.Hour
DefaultMaxURLTTL is the longest proxied or presigned read URL lifetime (REQ-BLOB-017).
Variables ¶
This section is empty.
Functions ¶
func ContentKeyOf ¶
ContentKeyOf returns the content key for literal bytes.
func HandlerRoute ¶
func HandlerRoute() string
HandlerRoute returns the path prefix kit serve should mount.
func ValidateContentKey ¶
ValidateContentKey reports whether k is a well-formed content key.
func ValidateStagingKey ¶
ValidateStagingKey reports whether k matches the staging key grammar.
Types ¶
type Options ¶
type Options struct {
// Clock supplies time for URL expiry; defaults to core.SystemClock{}.
Clock core.Clock
// MaxURLTTL caps SignedURL lifetimes; defaults to DefaultMaxURLTTL.
MaxURLTTL time.Duration
// BaseURL is required on a file-backed store for SignedURL: the public origin
// of proxied read URLs (scheme + host + HandlerRoute prefix). Wiring sets it.
BaseURL string
// SignKey is required on a file-backed store for SignedURL and the proxied
// read handler. When non-empty it must be at least 32 bytes. An empty key
// means proxied URLs are disabled. Wiring sets it.
SignKey []byte
// RandReader supplies random bytes for staging keys; defaults to
// crypto/rand.Reader.
RandReader io.Reader
}
Options configure a store opened from a URL.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a tenant-scoped content store over one bucket.
func Open ¶
Open selects an implementation from the location URL (REQ-BLOB-018).
For file:// locations, temporary write files are created next to the final object path (fileblob no_tmp_dir) so the data directory may live on a mount other than the system temp directory. A process killed mid-write can leave stranded "<object>.<hex>.tmp" files with partial data; an operator may remove them when no write is in flight.
func (*Store) Commit ¶
Commit implements platform.Blob. After the content blob is stored, it writes the commit record (which spends the slot) and then deletes the staged object. A failure to write the commit record returns unavailable and leaves the slot open so a retry can re-read the staged object and Put the same content again. Once the commit record is written, Commit succeeds with the content key even if deleting the staged object fails; the record prevents reuse and sweepSlot removes leftover staging keys at expiry.
func (*Store) ContentType ¶
ContentType returns the stored content type for key, or "" if unset. Tenancy is taken from ctx, never from an argument.
func (*Store) Get ¶
Get returns a reader for key. The tenant comes from ctx; a missing object is not_found.
func (*Store) Put ¶
Put stores content under a content key. The tenant comes from ctx. It returns invalid_argument for a malformed key, for content that does not hash to the key, or for a source reader that fails; cancelled when ctx is done; unavailable for a backend or writer failure. For an existing object the new content is verified against the key and the first content type wins per process.
New keys stream once to the final object path, hashing as they go. On copy error, cancellation or hash mismatch the writer context is cancelled before Close and nothing is deleted. After a matching hash the sidecar is written, then Close commits the object. Two replicas writing the same new key commit identical bytes (content-addressed); the in-process keyed lock enforces first content type per process. On S3, cancelling a multipart upload may leave parts at the provider; operators should use an AbortIncompleteMultipartUpload lifecycle rule.
func (*Store) SignedURL ¶
SignedURL returns a proxied or presigned read URL for key (tenant from ctx).
func (*Store) StartUpload ¶
StartUpload implements platform.Blob.
type URLHandler ¶
type URLHandler struct {
Store *Store
}
URLHandler serves proxied blob read URLs for the embedded store.
func (*URLHandler) Mount ¶
func (h *URLHandler) Mount() http.Handler
Mount strips HandlerRoute from requests before ServeHTTP.
func (*URLHandler) ServeHTTP ¶
func (h *URLHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler.
type UploadHandler ¶
type UploadHandler struct {
Store *Store
}
UploadHandler serves proxied upload URLs for the embedded store (ADR-0013).
func (*UploadHandler) ServeHTTP ¶
func (h *UploadHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package conformance runs blob BDD scenarios against the S3 simulator backend.
|
Package conformance runs blob BDD scenarios against the S3 simulator backend. |