objectstorage

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 35 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

Index

Constants

View Source
const DefaultUploadMemory int64 = 512 << 20

DefaultUploadMemory is the shared reservation budget for snapshot compression and upload buffers. It is not a limit on the process's total memory.

Variables

View Source
var ErrObjectNotFound = errors.New("object not found in storage backend")

ErrObjectNotFound reports the object or its bucket is absent from the storage backend, as opposed to a transient fetch failure.

Functions

func FetchFileFromGCSWithZstd

func FetchFileFromGCSWithZstd(ctx context.Context, client ObjectStorage, gsURL string, localFile *os.File) error

FetchFileFromGCSWithZstd downloads and decompresses into an already-open file. The caller retains ownership of localFile.

func FetchFromGCS

func FetchFromGCS(ctx context.Context, client ObjectStorage, gsURL string) ([]byte, error)

func FetchLocalFileFromGCSWithZstd

func FetchLocalFileFromGCSWithZstd(ctx context.Context, client ObjectStorage, gsURL string, localFilePath string) (err error)

func NewS3ClientFromEnv

func NewS3ClientFromEnv(ctx context.Context) (*s3.Client, error)

NewS3ClientFromEnv builds an S3 client from the standard AWS environment variables. AWS_S3_USE_PATH_STYLE=true selects path-style addressing.

func ObjectSize

func ObjectSize(r io.Reader) (int64, bool)

ObjectSize returns the size of the object r, a reader GetObject returned, reads, and false if its backend did not report one.

func Open

func Open(ctx context.Context, client ObjectStorage, gsURL string) (io.ReadCloser, error)

Open streams the object at gsURL; the caller must Close the returned reader. Unlike FetchFromGCS it does not buffer the whole object in memory.

func SendLocalFileToGCSWithZstd

func SendLocalFileToGCSWithZstd(ctx context.Context, client ObjectStorage, gsURL string, localFilePath string) (err error)

func UsesS3

func UsesS3() bool

UsesS3 reports whether ATE_STORAGE_BACKEND selects S3. Any other value selects GCS, the default.

Types

type ObjectStorage

type ObjectStorage interface {
	GetObject(ctx context.Context, bucket, object string) (io.ReadCloser, error)
	PutObject(ctx context.Context, bucket, object string, reader io.Reader) error
}

func NewFromEnv

func NewFromEnv(ctx context.Context) (ObjectStorage, error)

NewFromEnv builds the ObjectStorage for the backend UsesS3 selects.

func NewGCSClient

func NewGCSClient(ctx context.Context, opts ...option.ClientOption) (ObjectStorage, error)

NewGCSClient returns a GCS-backed ObjectStorage. It builds its own storage.Client from opts (and more from the same opts for the connection pool, see newPool) rather than accepting one, because it installs a RetryAlways policy (see setRetry) that is only safe for this package's own operations and must not leak onto a client shared with other code.

func NewS3Client

func NewS3Client(client *s3.Client) ObjectStorage

type ServiceError

type ServiceError struct {
	// HTTPStatus is the status of the service's response.
	HTTPStatus int
	// Code is the service's error code, such as "PreconditionFailed", if the
	// backend reports one.
	Code string
	// Message is the service's own description, if the backend reports one
	// it knows names no caller, resource or credential.
	Message string
}

ServiceError describes a storage service's failed response in terms its backend has judged safe to log: never a URI, header or credential.

func DescribeServiceError

func DescribeServiceError(err error) (ServiceError, bool)

DescribeServiceError describes the storage service response that err carries, if any. Each backend decides what of its errors is safe to describe; an error in err's chain from any other source with an HTTPStatusCode() int method, as the S3 SDK's response errors have, is described by its status alone.

type SizedReader

type SizedReader interface {
	io.ReadCloser
	// ObjectSize is the whole object's size in bytes, as the backend reported
	// it, or a negative number if it is unknown.
	ObjectSize() int64
}

SizedReader is implemented by the readers GetObject returns when the backend reported the object's size as it opened it. The GCS and S3 clients in this package return one whenever the response carries the size.

type Uploader

type Uploader struct {
	// contains filtered or unexported fields
}

Uploader shares a memory reservation budget across concurrent uploads. Reuse one Uploader for all snapshot requests served by a node. Reservations cover compression and the GCS/S3 clients' buffering, and last until both finish. Other ObjectStorage implementations must bound their own upload buffers. Runtime overhead, downloads, and memory awaiting garbage collection are not covered by the reservation budget.

func NewUploader

func NewUploader(client ObjectStorage, capacity int64) (*Uploader, error)

NewUploader creates an uploader with capacity bytes of reservations. Capacity must fit one compression worker plus the backend's upload buffers; larger files use fewer workers when necessary rather than waiting for an impossible request.

func (*Uploader) Send

func (u *Uploader) Send(ctx context.Context, url string, content io.Reader) error

Send uploads uncompressed content, using the same budget as SendFile. This is used for snapshot manifests; the reader is streamed without retaining its body.

func (*Uploader) SendFile

func (u *Uploader) SendFile(ctx context.Context, url string, file *os.File) error

SendFile compresses and uploads an already-open snapshot file. The caller keeps ownership of the file. Waiting for memory is canceled with ctx.

func (*Uploader) WithClient

func (u *Uploader) WithClient(client ObjectStorage) *Uploader

uploadBufferMemory includes buffers retained while the compressor is running. WithClient returns an Uploader that sends through client and shares u's memory budget, for a transfer that runs with its own credentials. client must be the same kind of backend as u's, since the budget was sized for it.

Jump to

Keyboard shortcuts

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