Documentation
¶
Overview ¶
Package store is pail's bucket (src/store.rs): immutable content-addressed objects plus compare-and-swap on mutable ones, over GCS, S3, a local directory or memory. Each backend follows one contract, the Quint model verify/store_spec.qnt, which store_refinement_test.go checks it against.
Index ¶
- Variables
- type AWSKeys
- type Backend
- type Cond
- type Credential
- type CredentialSource
- type File
- func (f *File) Delete(_ context.Context, key string) error
- func (f *File) Get(_ context.Context, key string, max int64) ([]byte, Version, error)
- func (f *File) GetRange(_ context.Context, key string, off, length int64) ([]byte, int64, error)
- func (f *File) Head(_ context.Context, key string) (ObjInfo, error)
- func (f *File) List(_ context.Context, prefix string) ([]ObjInfo, error)
- func (f *File) Put(_ context.Context, key string, data []byte, cond Cond) (Version, error)
- type GCS
- func (g *GCS) Delete(ctx context.Context, key string) error
- func (g *GCS) Get(ctx context.Context, key string, max int64) ([]byte, Version, error)
- func (g *GCS) GetRange(ctx context.Context, key string, off, length int64) ([]byte, int64, error)
- func (g *GCS) Head(ctx context.Context, key string) (ObjInfo, error)
- func (g *GCS) List(ctx context.Context, prefix string) ([]ObjInfo, error)
- func (g *GCS) Put(ctx context.Context, key string, data []byte, cond Cond) (Version, error)
- type Memory
- func (m *Memory) Delete(_ context.Context, key string) error
- func (m *Memory) Get(_ context.Context, key string, max int64) ([]byte, Version, error)
- func (m *Memory) GetRange(_ context.Context, key string, off, length int64) ([]byte, int64, error)
- func (m *Memory) Head(_ context.Context, key string) (ObjInfo, error)
- func (m *Memory) List(_ context.Context, prefix string) ([]ObjInfo, error)
- func (m *Memory) Put(_ context.Context, key string, data []byte, cond Cond) (Version, error)
- type ObjInfo
- type Options
- type S3
- func (b *S3) Delete(ctx context.Context, key string) error
- func (b *S3) Get(ctx context.Context, key string, max int64) ([]byte, Version, error)
- func (b *S3) GetRange(ctx context.Context, key string, off, length int64) ([]byte, int64, error)
- func (b *S3) Head(ctx context.Context, key string) (ObjInfo, error)
- func (b *S3) List(ctx context.Context, prefix string) ([]ObjInfo, error)
- func (b *S3) Put(ctx context.Context, key string, data []byte, cond Cond) (Version, error)
- type Static
- type Store
- func (s *Store) Cas(ctx context.Context, key string, data []byte, expected *Version) (v Version, swapped bool, err error)
- func (s *Store) Delete(ctx context.Context, key string) error
- func (s *Store) Get(ctx context.Context, key string) ([]byte, error)
- func (s *Store) GetOpt(ctx context.Context, key string) (data []byte, v Version, ok bool, err error)
- func (s *Store) GetOptMax(ctx context.Context, key string, max int64) (data []byte, v Version, ok bool, err error)
- func (s *Store) GetRange(ctx context.Context, key string, off, length int64) ([]byte, error)
- func (s *Store) List(ctx context.Context, prefix string) ([]ObjInfo, error)
- func (s *Store) Put(ctx context.Context, key string, data []byte) error
- func (s *Store) PutNew(ctx context.Context, key string, data []byte) (bool, error)
- func (s *Store) ReadRange(ctx context.Context, key string, off, length int64) (data []byte, size int64, ok bool, err error)
- func (s *Store) Stat(ctx context.Context, key string) (info ObjInfo, ok bool, err error)
- type Version
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound: the object does not exist. ErrNotFound = errors.New("store: object not found") // ErrPrecondition: a conditional write found the object in another state. ErrPrecondition = errors.New("store: precondition failed") // ErrUnauthenticated: the store refused the credential. ErrUnauthenticated = errors.New("store: unauthenticated") // ErrTooLarge: an object larger than the read allows. ErrTooLarge = errors.New("store: object too large") // ErrPermission: the credential may not do this. ErrPermission = errors.New("store: permission denied") )
var ErrRange = errors.New("store: range not satisfiable")
ErrRange: a read starts past the object's end.
Functions ¶
This section is empty.
Types ¶
type AWSKeys ¶
type AWSKeys struct {
AccessKeyID, SecretAccessKey, SessionToken string
}
AWSKeys are S3 credentials.
type Backend ¶
type Backend interface {
// Get reads a whole object; with max >= 0, one larger than max bytes is ErrTooLarge.
Get(ctx context.Context, key string, max int64) ([]byte, Version, error)
// GetRange reads length bytes at off (length < 0: to the end) and the object's size.
GetRange(ctx context.Context, key string, off, length int64) ([]byte, int64, error)
Head(ctx context.Context, key string) (ObjInfo, error)
Put(ctx context.Context, key string, data []byte, cond Cond) (Version, error)
Delete(ctx context.Context, key string) error
// List returns every object under prefix, recursively.
List(ctx context.Context, prefix string) ([]ObjInfo, error)
}
Backend is one kind of object store. Keys are full object names (the store's prefix included). A conditional write that does not apply returns ErrPrecondition.
type Cond ¶
type Cond struct {
// IfAbsent writes only if no object has the key.
IfAbsent bool
// IfMatch writes only if the object is at this version.
IfMatch *Version
}
Cond is a write's precondition.
type Credential ¶
type Credential struct {
// Token is a GCS OAuth access token or a pail proxy's bearer token.
Token string
// AWS keys sign S3 requests.
AWS *AWSKeys
// ExpiresAt is when to ask for a new one; zero never expires.
ExpiresAt time.Time
}
Credential is what a store request is signed with.
type CredentialSource ¶
type CredentialSource interface {
Credential(ctx context.Context) (Credential, error)
// Invalidate drops a cached credential after the store refused it, and reports
// whether asking again could give a different one.
Invalidate() bool
}
CredentialSource gives the store its credential, for a host that serves many people, each with a store handle of their own.
type File ¶
type File struct {
// contains filtered or unexported fields
}
File is a bucket in a local directory, interchangeable with the Rust pail's file:// store: the same layout, the same version tokens (the first 16 hex digits of the content's BLAKE3) and the same compare-and-swap, under an exclusive lock on <root>/.lock.
type GCS ¶
type GCS struct {
// contains filtered or unexported fields
}
GCS speaks Cloud Storage's XML API, as the Rust pail's object_store client does: writes carry x-goog-if-generation-match (0: create only), versions are generations. It runs unchanged against the pail-gcs-emulator the Rust tests use.
func NewGCS ¶
NewGCS opens a bucket. base is an emulator's URL ("" for Cloud Storage). Without credentials it uses application default credentials, or none against an emulator.
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory is an in-process bucket with GCS's semantics: strongly consistent, and every write takes a fresh generation from a counter that never reuses one.
type ObjInfo ¶
type ObjInfo struct {
Key string
Size int64
Modified time.Time
// Version changes whenever the object is written.
Version string
}
ObjInfo is a listed object.
type Options ¶
type Options struct {
// Credentials to send. Nil uses the cloud SDK's ambient chain (application default
// credentials for GCS, the AWS config chain for S3).
Credentials CredentialSource
// GCSBaseURL points gs:// at an emulator (PAIL_GCS_BASE_URL also does).
GCSBaseURL string
}
Options configures Open.
type S3 ¶
type S3 struct {
// contains filtered or unexported fields
}
S3 writes with S3's conditional puts (If-None-Match: * to create, If-Match: <etag> to swap), as the Rust pail does with object_store's ETagMatch mode. AWS_ENDPOINT (the Rust pail's variable) or AWS_ENDPOINT_URL points it at another S3 API, path-style.
type Static ¶
type Static Credential
Static is a credential that never changes, such as a token the host was handed.
func (Static) Credential ¶
func (s Static) Credential(context.Context) (Credential, error)
func (Static) Invalidate ¶
Invalidate reports false: asking again gives the same credential.
type Store ¶
type Store struct {
// URL is the store's URL as opened.
URL string
// contains filtered or unexported fields
}
Store is a bucket and a prefix in it.
func (*Store) Cas ¶
func (s *Store) Cas(ctx context.Context, key string, data []byte, expected *Version) (v Version, swapped bool, err error)
Cas writes data if the object is at expected (nil: if it does not exist). swapped is false on a conflict. Only a refused credential is retried: a retried swap could not tell its own earlier success from a loss.
func (*Store) GetOpt ¶
func (s *Store) GetOpt(ctx context.Context, key string) (data []byte, v Version, ok bool, err error)
GetOpt reads an object with its version; ok is false if it does not exist.
func (*Store) GetOptMax ¶
func (s *Store) GetOptMax(ctx context.Context, key string, max int64) (data []byte, v Version, ok bool, err error)
GetOptMax is GetOpt refusing an object larger than max bytes with ErrTooLarge (max < 0: any size).
func (*Store) List ¶
List lists the objects under the directory prefix, keys relative to the store, sorted. A local store's lock and temporary files are left out.
func (*Store) PutNew ¶
PutNew writes an immutable object and reports whether it created it. Retrying is safe: content addressing means an existing object holds the same bytes.