blob

package
v0.0.0-...-ecee8c2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 30 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func ContentKeyOf(data []byte) string

ContentKeyOf returns the content key for literal bytes.

func HandlerRoute

func HandlerRoute() string

HandlerRoute returns the path prefix kit serve should mount.

func HexOf

func HexOf(k string) (string, error)

HexOf returns the 64 lowercase hex digits of k, or an error.

func ValidateContentKey

func ValidateContentKey(k string) bool

ValidateContentKey reports whether k is a well-formed content key.

func ValidateStagingKey

func ValidateStagingKey(k string) bool

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

func Open(ctx context.Context, raw string, opts Options) (*Store, http.Handler, error)

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) Close

func (s *Store) Close() error

Close releases the underlying bucket.

func (*Store) Commit

func (s *Store) Commit(ctx context.Context, stagingKey string) (string, error)

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

func (s *Store) ContentType(ctx context.Context, key string) (string, error)

ContentType returns the stored content type for key, or "" if unset. Tenancy is taken from ctx, never from an argument.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, key string) error

Delete removes key for the tenant in ctx; a missing object is not_found.

func (*Store) Exists

func (s *Store) Exists(ctx context.Context, key string) (bool, error)

Exists reports whether key is stored for the tenant in ctx.

func (*Store) Get

func (s *Store) Get(ctx context.Context, key string) (io.ReadCloser, error)

Get returns a reader for key. The tenant comes from ctx; a missing object is not_found.

func (*Store) Put

func (s *Store) Put(ctx context.Context, key string, r io.Reader, contentType string) error

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

func (s *Store) SignedURL(ctx context.Context, key string, ttl time.Duration) (string, error)

SignedURL returns a proxied or presigned read URL for key (tenant from ctx).

func (*Store) StartUpload

func (s *Store) StartUpload(ctx context.Context, o platform.UploadOptions) (platform.Upload, error)

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.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL