bucket

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 7 Imported by: 0 modules, 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 bucket is the object store seam of the store service. One Store is one bucket of immutable objects. Implementations: Google Cloud Storage (bucket/gcs), an S3-compatible service (bucket/s3) and a filesystem directory (bucket/fs). The conformance suite is bucket/buckettest.

Index

Constants

View Source
const (
	OpGet      = "get"
	OpGetRange = "get_range"
)

Read kinds that Observe reports.

View Source
const (
	KindTimeout = "timeout"
	Kind5xx     = "5xx"
	KindOther   = "other"
)

Error kinds of a failed read, as ErrorKind names them.

Variables

View Source
var ErrChanged = errors.New("bucket: object changed")

ErrChanged is a Delete of an object whose version is not the one named.

View Source
var ErrNotFound = errors.New("bucket: object not found")

ErrNotFound is a read of a key that no object holds.

Functions

func ErrorKind added in v0.16.0

func ErrorKind(err error) (kind string, ok bool)

ErrorKind names the kind of a failed read: a timeout, a server error that WithStatus marked, or another error. A read that the caller cancelled, and a missing key, are not failures and have no kind (ok is false).

func WithStatus added in v0.16.0

func WithStatus(err error, code int) error

WithStatus marks err as a failure that the service answered with the HTTP status code.

Types

type HedgeConfig added in v0.16.0

type HedgeConfig struct {
	// Ratio is the share of reads that may have a duplicate, from 0 to 1. Zero turns hedging off.
	Ratio float64
	// Min and Max bound the time that a read waits before its duplicate starts. The wait is the 95th percentile of the
	// recent reads of the same size class, and Max until enough reads have finished.
	Min, Max time.Duration
}

HedgeConfig tunes Hedge.

type HedgeStats added in v0.16.0

type HedgeStats struct {
	// Hedges is the duplicates that started, Wins those whose answer came first, and Skipped the reads that waited
	// longer than their delay but had no token or no budget for a duplicate.
	Hedges, Wins, Skipped int64
}

HedgeStats counts the duplicates of a Hedged store.

type Hedged added in v0.16.0

type Hedged struct {
	Store
	// contains filtered or unexported fields
}

Hedged reads from a primary store and, when a read is slow, starts one duplicate on another store and returns the answer that comes first.

func Hedge added in v0.16.0

func Hedge(primary, alt Store, cfg HedgeConfig) *Hedged

Hedge returns a store whose range reads have a duplicate on alt, as "The Tail at Scale" describes. A duplicate of a read starts when the read outlasts the recent 95th percentile of its size class, within cfg, and only while the duplicates stay under cfg.Ratio of the reads (a token bucket) and under their memory budget. The loser is cancelled. alt may be the same store as primary, but a store on other connections gives the duplicate a path that a stalled connection does not block. The first success wins. A first answer that is an error other than ErrNotFound waits for the other read, so one bad connection does not fail the read. Other methods, a read of a whole object and a range too large for the duplicate budget use the primary only.

func (*Hedged) GetRange added in v0.16.0

func (h *Hedged) GetRange(ctx context.Context, key string, off, n int64) ([]byte, error)

func (*Hedged) HedgeStats added in v0.16.0

func (h *Hedged) HedgeStats() HedgeStats

HedgeStats returns the counters of the duplicates.

type Store

type Store interface {
	// Create writes data when key is absent and reports whether it wrote. A
	// stored object is never replaced. Of concurrent creators of one key,
	// exactly one gets created true. A later read of the key sees the whole
	// object.
	Create(ctx context.Context, key string, data []byte) (created bool, err error)
	// Get returns the object, or ErrNotFound.
	Get(ctx context.Context, key string) ([]byte, error)
	// GetRange returns up to n bytes from off, fewer at the end of the
	// object, and none when off is at or past the end. A negative n reads to
	// the end. A missing key is ErrNotFound.
	GetRange(ctx context.Context, key string, off, n int64) ([]byte, error)
	// Version returns an opaque name of the object as it is now, or
	// ErrNotFound. An object that is deleted and stored again has another
	// version, even with the same bytes, where the backend can tell (see
	// Delete).
	Version(ctx context.Context, key string) (string, error)
	// Delete removes the object when its version is version, as Version
	// returned it. A missing key is not an error. An object of another
	// version stays, and Delete returns ErrChanged. A backend that cannot
	// test the version atomically removes the object whatever its version:
	// bucket/s3 does, because an ETag is the same for the same bytes. Only
	// the removal of a retired file calls it.
	Delete(ctx context.Context, key, version string) error
}

func Observe added in v0.16.0

func Observe(s Store, fn func(op string, d time.Duration, err error)) Store

Observe returns a Store that calls fn after each Get and GetRange with the read kind, the time it took and its error. Other methods pass through. fn runs on the goroutine of the read, before the read returns, and concurrent reads call it concurrently.

Directories

Path Synopsis
Package buckettest is the conformance suite of bucket.Store.
Package buckettest is the conformance suite of bucket.Store.
Package fs backs the bucket seam with a directory.
Package fs backs the bucket seam with a directory.
Package gcs backs the bucket seam with Google Cloud Storage.
Package gcs backs the bucket seam with Google Cloud Storage.
Package s3 backs the bucket seam with an S3-compatible object store: AWS S3, Cloudflare R2 or MinIO.
Package s3 backs the bucket seam with an S3-compatible object store: AWS S3, Cloudflare R2 or MinIO.

Jump to

Keyboard shortcuts

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