store

package
v0.0.0-...-d88c8fd Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 26 Imported by: ? 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 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

Constants

This section is empty.

Variables

View Source
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")
)
View Source
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.

func NewFile

func NewFile(root string) (*File, error)

NewFile opens (creating) the directory root.

func (*File) Delete

func (f *File) Delete(_ context.Context, key string) error

func (*File) Get

func (f *File) Get(_ context.Context, key string, max int64) ([]byte, Version, error)

func (*File) GetRange

func (f *File) GetRange(_ context.Context, key string, off, length int64) ([]byte, int64, error)

func (*File) Head

func (f *File) Head(_ context.Context, key string) (ObjInfo, error)

func (*File) List

func (f *File) List(_ context.Context, prefix string) ([]ObjInfo, error)

func (*File) Put

func (f *File) Put(_ context.Context, key string, data []byte, cond Cond) (Version, error)

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

func NewGCS(ctx context.Context, bucket, base string, creds CredentialSource) (*GCS, error)

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.

func (*GCS) Delete

func (g *GCS) Delete(ctx context.Context, key string) error

func (*GCS) Get

func (g *GCS) Get(ctx context.Context, key string, max int64) ([]byte, Version, error)

func (*GCS) GetRange

func (g *GCS) GetRange(ctx context.Context, key string, off, length int64) ([]byte, int64, error)

func (*GCS) Head

func (g *GCS) Head(ctx context.Context, key string) (ObjInfo, error)

func (*GCS) List

func (g *GCS) List(ctx context.Context, prefix string) ([]ObjInfo, error)

func (*GCS) Put

func (g *GCS) Put(ctx context.Context, key string, data []byte, cond Cond) (Version, error)

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.

func NewMemory

func NewMemory() *Memory

NewMemory is an empty bucket.

func (*Memory) Delete

func (m *Memory) Delete(_ context.Context, key string) error

func (*Memory) Get

func (m *Memory) Get(_ context.Context, key string, max int64) ([]byte, Version, error)

func (*Memory) GetRange

func (m *Memory) GetRange(_ context.Context, key string, off, length int64) ([]byte, int64, error)

func (*Memory) Head

func (m *Memory) Head(_ context.Context, key string) (ObjInfo, error)

func (*Memory) List

func (m *Memory) List(_ context.Context, prefix string) ([]ObjInfo, error)

func (*Memory) Put

func (m *Memory) Put(_ context.Context, key string, data []byte, cond Cond) (Version, error)

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.

func NewS3

func NewS3(ctx context.Context, bucket string, creds CredentialSource) (*S3, error)

NewS3 opens a bucket with the AWS config chain, or the credentials given.

func (*S3) Delete

func (b *S3) Delete(ctx context.Context, key string) error

func (*S3) Get

func (b *S3) Get(ctx context.Context, key string, max int64) ([]byte, Version, error)

func (*S3) GetRange

func (b *S3) GetRange(ctx context.Context, key string, off, length int64) ([]byte, int64, error)

func (*S3) Head

func (b *S3) Head(ctx context.Context, key string) (ObjInfo, error)

func (*S3) List

func (b *S3) List(ctx context.Context, prefix string) ([]ObjInfo, error)

func (*S3) Put

func (b *S3) Put(ctx context.Context, key string, data []byte, cond Cond) (Version, error)

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

func (Static) Invalidate() bool

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 New

func New(b Backend, prefix, url string) *Store

New is a store over a backend, at a prefix in it.

func Open

func Open(ctx context.Context, rawURL string, opts Options) (*Store, error)

Open opens file:///abs/dir, s3://bucket/prefix, gs://bucket/prefix or memory://name.

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

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

Delete removes an object; deleting one that does not exist is not an error.

func (*Store) Get

func (s *Store) Get(ctx context.Context, key string) ([]byte, error)

Get reads an object that must exist.

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

func (s *Store) GetRange(ctx context.Context, key string, off, length int64) ([]byte, error)

GetRange reads a range of an object that must exist.

func (*Store) List

func (s *Store) List(ctx context.Context, prefix string) ([]ObjInfo, error)

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

func (s *Store) Put(ctx context.Context, key string, data []byte) error

Put writes unconditionally (side records: intents, reflogs, drafts' scratch).

func (*Store) PutNew

func (s *Store) PutNew(ctx context.Context, key string, data []byte) (bool, error)

PutNew writes an immutable object and reports whether it created it. Retrying is safe: content addressing means an existing object holds the same bytes.

func (*Store) ReadRange

func (s *Store) ReadRange(ctx context.Context, key string, off, length int64) (data []byte, size int64, ok bool, err error)

ReadRange reads length bytes at off (length < 0: to the end) and the object's size; ok is false if it does not exist.

func (*Store) Stat

func (s *Store) Stat(ctx context.Context, key string) (info ObjInfo, ok bool, err error)

Stat is an object's metadata; ok is false if it does not exist.

type Version

type Version struct {
	ETag       string `json:"etag,omitempty"`
	Generation string `json:"version,omitempty"`
}

Version is a mutable object's version token: an S3 ETag, a GCS generation (with its ETag), or a local file's content digest.

Jump to

Keyboard shortcuts

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