storage

package
v0.0.0-...-be3b37f Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidStore is returned when calling NewStore() with an invalid or unspproted
	// store type. Support stores are: memory, disk, bitcask
	ErrInvalidStore = errors.New("error: invalid or unsupproted store")
)
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 BitcaskStore

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

func (*BitcaskStore) Get

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

func (*BitcaskStore) Put

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

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 Blake2b 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 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 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 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.

func NewBitcaskStore

func NewBitcaskStore(dbPath string) (Store, error)

func NewStore

func NewStore(store string) (Store, error)

NewStore constructs a new store from the `store` uri and returns a `Store` interfaces matching the store type in `<type>://...`

type StoreURI

type StoreURI struct {
	Type string
	Path string
}

StoreURI holds configuration parameters for a store parsed from a string such as <type://<host|path>?<param1>=<value1>

func ParseStoreURI

func ParseStoreURI(uri string) (*StoreURI, error)

func (StoreURI) IsZero

func (u StoreURI) IsZero() bool

func (StoreURI) String

func (u StoreURI) String() string

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