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 (internal/bucket/gcs), an S3-compatible service (internal/bucket/s3) and a filesystem directory (internal/bucket/fs), and memory (internal/bucket/mem). The conformance suite is internal/bucket/buckettest.
Index ¶
Constants ¶
const ( OpGet = "get" OpGetRange = "get_range" )
Read kinds that Observe reports.
const ( KindTimeout = "timeout" Kind5xx = "5xx" KindOther = "other" )
Error kinds of a failed read, as ErrorKind names them.
Variables ¶
var ErrChanged = errors.New("bucket: object changed")
ErrChanged is a Delete of an object whose version is not the one named.
var ErrNotFound = errors.New("bucket: object not found")
ErrNotFound is a read of a key that no object holds.
Functions ¶
func DeletesConditionally ¶
DeletesConditionally reports whether Delete of s tests the version.
func ErrorKind ¶
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 ¶
WithStatus marks err as a failure that the service answered with the HTTP status code.
Types ¶
type Capable ¶
type Capable interface {
Caps() Caps
}
Capable is an optional method of a Store, which declares its own Caps.
type Caps ¶
type Caps struct {
// ConditionalDelete: Delete tests the version atomically, so an object that is stored again is never removed by a
// Delete of the older version.
ConditionalDelete bool
// Hedged: range reads have a duplicate on a second connection.
Hedged bool
}
Caps are the properties of a Store that a caller may depend on.
func CapsOf ¶
CapsOf returns the Caps of s. It walks the wrappers of s through Unwrap: Hedged is true when any layer declares it, and ConditionalDelete is the answer of the outermost layer that declares Caps. A layer that declares no Caps is transparent, and a Store with no declaring layer has no capability.
type HedgeConfig ¶
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 ¶
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 ¶
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 ¶
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) Caps ¶
Caps is Hedged, with the ConditionalDelete of the primary store, which serves every Delete.
func (*Hedged) HedgeStats ¶
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:
// internal/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
}
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 mem is a bucket.Store that keeps its objects in memory.
|
Package mem is a bucket.Store that keeps its objects in memory. |
|
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. |