storage

package
v0.0.0-...-f7a59ed Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2021 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound indicates a key is not in the store.
	ErrNotFound = errors.New("not found")
)
View Source
var (
	// ErrStalePut indicates that some client has not see the latest version of the
	// key-value pair being put. The client should get the current version, decide
	// if it still wants to do the put, and in that case do the put with the
	// correct version.
	ErrStalePut = errors.New("stale put")
)
View Source
var (
	ErrTimeout = errors.New("request timed out")
)

Functions

func ApplyMessage

func ApplyMessage(store VersionedStore, in message.Message) (out message.Message)

Types

type BlobStore

type BlobStore interface {
	Get(key []byte) (value []byte, err error)
	Put(value []byte) (key []byte, err error)
}

type BlobStoreWrapper

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

BlobStore wraps a Store to make sure content is never overwritten, by using as key for a value the SHA1 hash of the value. Even if there are concurrent writes for the same key, those would write the same contents (with very high probability).

func NewBlobStore

func NewBlobStore(delegate Store) *BlobStoreWrapper

func (*BlobStoreWrapper) Get

func (s *BlobStoreWrapper) Get(key []byte) (value []byte, err error)

func (*BlobStoreWrapper) Put

func (s *BlobStoreWrapper) Put(value []byte) (key []byte, err error)

type BoltStore

type BoltStore bolt.DB

BoltStore is an implementation of Store whose backend is a Bolt database.

func NewBoltStore

func NewBoltStore(db *bolt.DB) (*BoltStore, error)

func (*BoltStore) Get

func (s *BoltStore) Get(key []byte) (value []byte, err error)

func (*BoltStore) Put

func (s *BoltStore) Put(key []byte, value []byte) error

type Builder

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

func NewBuilder

func NewBuilder(config map[string]interface{}) *Builder

func (*Builder) StoreByName

func (b *Builder) StoreByName(name string) (Store, error)

type ChangeListener

type ChangeListener func(message.Message)

type DiskStore

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

DiskStore implements Store.

func NewDiskStore

func NewDiskStore(dir string) *DiskStore

func (*DiskStore) Get

func (s *DiskStore) Get(key []byte) (value []byte, err error)

func (*DiskStore) Put

func (s *DiskStore) Put(key, value []byte) (err error)

type DynamoDBStore

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

func NewDynamoDBStore

func NewDynamoDBStore(profile, region, table string) (*DynamoDBStore, error)

func (*DynamoDBStore) Get

func (s *DynamoDBStore) Get(key []byte) (value []byte, err error)

func (*DynamoDBStore) Put

func (s *DynamoDBStore) Put(key, value []byte) (err error)

type DynamoDBVersionedStore

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

func NewDynamoDBVersionedStore

func NewDynamoDBVersionedStore(profile, region, table string, opts ...Option) (*DynamoDBVersionedStore, error)

func (*DynamoDBVersionedStore) Get

func (s *DynamoDBVersionedStore) Get(key []byte) (version uint64, value []byte, err error)

func (*DynamoDBVersionedStore) Put

func (s *DynamoDBVersionedStore) Put(version uint64, key []byte, value []byte) (err error)

type InMemoryStore

type InMemoryStore struct {
	sync.Mutex
	// contains filtered or unexported fields
}

InMemoryStore is a Store implementation powered by a map, to be used for testing or caches.

func NewInMemoryStore

func NewInMemoryStore() *InMemoryStore

func (*InMemoryStore) Get

func (s *InMemoryStore) Get(key []byte) (value []byte, err error)

func (*InMemoryStore) Put

func (s *InMemoryStore) Put(key, value []byte) (err error)

type Option

type Option func(*options)

func WithAuthKey

func WithAuthKey(value string) Option

func WithChangeListener

func WithChangeListener(value ChangeListener) Option

func WithRequestTimeout

func WithRequestTimeout(value time.Duration) Option

func WithResponseBackoff

func WithResponseBackoff(value time.Duration) Option

type Paired

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

Paired implements Store wrapping a pair of stores, one fast, one slow. It will handle puts storing data in the fast store and syncing that to the slow store in the background. It will handle gets from the fast store if possible, otherwise from the slow store (and in this case also propagate the data from the slow to the fast store, for next time that piece of data is requested).

func NewPaired

func NewPaired(fast, slow Store) Paired

func (Paired) Get

func (s Paired) Get(key []byte) (value []byte, err error)

func (Paired) Put

func (s Paired) Put(key, value []byte) (err error)

type RemoteStore

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

RemoteStore implements Store. It requires to connect to a blobserver.

func NewRemoteStore

func NewRemoteStore(address string) *RemoteStore

func (*RemoteStore) Get

func (r *RemoteStore) Get(key []byte) (value []byte, err error)

func (*RemoteStore) Put

func (r *RemoteStore) Put(key, value []byte) (err error)

type RemoteVersionedStore

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

RemoteVersionedStore is an implementation of VersionedStore, via a client to a remote metadataserver process.

func NewRemoteVersionedStore

func NewRemoteVersionedStore(remote *client.Client, options ...Option) *RemoteVersionedStore

func (*RemoteVersionedStore) Get

func (rs *RemoteVersionedStore) Get(key []byte) (version uint64, value []byte, err error)

func (*RemoteVersionedStore) Put

func (rs *RemoteVersionedStore) Put(version uint64, key []byte, value []byte) (err error)

func (*RemoteVersionedStore) Start

func (rs *RemoteVersionedStore) Start()

func (*RemoteVersionedStore) Stop

func (rs *RemoteVersionedStore) Stop()

type S3Store

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

S3Store is an implementation of Store backed by AWS S3.

func NewS3Store

func NewS3Store(profile, region, bucket string) (*S3Store, error)

func (*S3Store) Get

func (s *S3Store) Get(key []byte) (value []byte, err error)

func (*S3Store) Put

func (s *S3Store) Put(key, value []byte) (err error)

type Store

type Store interface {
	Put(key, value []byte) (err error)

	// Get should return ErrNotFound if the key is not in the store.
	Get(key []byte) (value []byte, err error)
}

Store represents a key-value store.

type VersionedStore

type VersionedStore interface {
	// Put should return ErrStalePut if the current version is not the version
	// passed as argument minus one. The client should have to prove that they've
	// seen the most current version before trying to update it.
	Put(version uint64, key []byte, value []byte) (err error)

	// Get should return ErrNotFound if the key is not in the store.
	Get(key []byte) (version uint64, value []byte, err error)
}

type VersionedWrapper

type VersionedWrapper struct {
	sync.Mutex
	// contains filtered or unexported fields
}

VersionedWrapper is a VersionedStore implementation wraping a given Store implementation. This is the quickest way of building a VersionedStore, but it's alos the slowest, as it serializes all calls to the underlying Store.

func NewVersionedWrapper

func NewVersionedWrapper(delegate Store) *VersionedWrapper

func (*VersionedWrapper) Get

func (s *VersionedWrapper) Get(key []byte) (version uint64, value []byte, err error)

Get retrieves the value associated with a key and its version number.

func (*VersionedWrapper) Put

func (s *VersionedWrapper) Put(version uint64, key []byte, value []byte) error

Put stores the given value at the given key, provided the passed version number is the current version number. If the put is successful, the version number is incremented by one.

Jump to

Keyboard shortcuts

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