Documentation
¶
Overview ¶
Package storage contains the interfaces for storing and retrieving data about the state of the mesh and maintaining consensus.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotStorageNode is returned when a storage operation is attempted on a non-storage node. ErrNotStorageNode = fmt.Errorf("not a storage node") // ErrStarted is returned when the storage provider is already started. ErrStarted = fmt.Errorf("storage provider already started") // ErrClosed is returned when the storage provider is closed. ErrClosed = fmt.Errorf("storage provider is closed") // ErrNotImplemented is returned when a method is not implemented. ErrNotImplemented = fmt.Errorf("not implemented") // ErrNoLeader is returned when there is no leader. ErrNoLeader = fmt.Errorf("no leader") // ErrNotLeader is returned when the node is not the leader. ErrNotLeader = fmt.Errorf("not leader") // ErrNotVoter is returned when the node is not a voter. ErrNotVoter = fmt.Errorf("not voter") // ErrAlreadyBootstrapped is returned when the storage provider is already bootstrapped. ErrAlreadyBootstrapped = fmt.Errorf("already bootstrapped") // ErrKeyNotFound is the error returned when a key is not found. ErrKeyNotFound = errors.New("key not found") // ErrInvalidKey is the error returned when a key is invalid. ErrInvalidKey = errors.New("invalid key") // ErrInvalidPrefix is the error returned when a prefix is invalid. ErrInvalidPrefix = errors.New("invalid prefix") )
Common errors for storage providers to use.
var ReservedPrefixes = []Prefix{ RegistryPrefix, ConsensusPrefix, }
ReservedPrefixes is a list of all reserved prefixes.
Functions ¶
func IsKeyNotFoundError ¶ added in v0.3.0
IsKeyNotFoundError returns true if the given error is a ErrKeyNotFound error.
func IsReservedPrefix ¶ added in v0.6.0
IsReservedPrefix returns true if the given key is reserved.
func NewKeyNotFoundError ¶ added in v0.3.0
NewKeyNotFoundError returns a new ErrKeyNotFound error.
Types ¶
type Consensus ¶ added in v0.7.0
type Consensus interface {
// IsLeader returns true if the node is the leader of the storage group.
IsLeader() bool
// IsMember returns true if the node is a member of the storage group.
IsMember() bool
// GetPeers returns the peers of the storage group.
GetPeers(context.Context) ([]*v1.StoragePeer, error)
// GetLeader returns the leader of the storage group.
GetLeader(context.Context) (*v1.StoragePeer, error)
// AddVoter adds a voter to the consensus group.
AddVoter(context.Context, *v1.StoragePeer) error
// AddObserver adds an observer to the consensus group.
AddObserver(context.Context, *v1.StoragePeer) error
// DemoteVoter demotes a voter to an observer.
DemoteVoter(context.Context, *v1.StoragePeer) error
// RemovePeer removes a peer from the consensus group. If wait
// is true, the function will wait for the peer to be removed.
RemovePeer(ctx context.Context, peer *v1.StoragePeer, wait bool) error
}
Consensus is the interface for configuring storage consensus.
type ConsensusStorage ¶ added in v0.7.2
type ConsensusStorage interface {
io.Closer
raft.LogStore
raft.StableStore
// Snapshot returns a snapshot of the storage.
Snapshot(ctx context.Context) (io.Reader, error)
// Restore restores a snapshot of the storage.
Restore(ctx context.Context, r io.Reader) error
}
ConsensusStorage is the interface for storing and retrieving data about the state of consensus. This is currently only used by the built-in raftstorage implementation.
type DualStorage ¶ added in v0.3.0
type DualStorage interface {
MeshStorage
ConsensusStorage
}
DualStorage represents a storage interface that can serve as both a mesh and consensus storage.
type MeshStorage ¶ added in v0.3.0
type MeshStorage interface {
io.Closer
// GetValue returns the value of a key.
GetValue(ctx context.Context, key []byte) ([]byte, error)
// PutValue sets the value of a key. TTL is optional and can be set to 0.
PutValue(ctx context.Context, key, value []byte, ttl time.Duration) error
// Delete removes a key.
Delete(ctx context.Context, key []byte) error
// ListKeys returns all keys with a given prefix.
ListKeys(ctx context.Context, prefix []byte) ([][]byte, error)
// IterPrefix iterates over all keys with a given prefix. It is important
// that the iterator not attempt any write operations as this will cause
// a deadlock. The iteration will stop if the iterator returns an error.
IterPrefix(ctx context.Context, prefix []byte, fn PrefixIterator) error
// Subscribe will call the given function whenever a key with the given prefix is changed.
// The returned function can be called to unsubscribe.
Subscribe(ctx context.Context, prefix []byte, fn SubscribeFunc) (context.CancelFunc, error)
}
MeshStorage is the interface for storing and retrieving data about the state of the mesh.
type Prefix ¶ added in v0.6.0
type Prefix []byte
Prefix is a prefix in the storage.
func (Prefix) Contains ¶ added in v0.6.0
Contains returns true if the given key is contained in the prefix.
func (Prefix) ForString ¶ added in v0.8.0
ForString is a helper method for creating a key for the prefix.
type PrefixIterator ¶
PrefixIterator is the function signature for iterating over all keys with a given prefix.
type Provider ¶ added in v0.7.0
type Provider interface {
// Close should close the underlying storage as well as any other resources
// that the provider may have allocated.
io.Closer
// MeshStorage returns the underlying MeshStorage instance. The provider does not
// need to guarantee consistency on read operations.
MeshStorage() MeshStorage
// Consensus returns the underlying Consensus instance.
Consensus() Consensus
// Start should start the provider and any resources that it may need.
Start(context.Context) error
// Bootstrap should bootstrap the provider for first-time usage.
Bootstrap(context.Context) error
// Status returns the status of the storage provider.
Status() *v1.StorageStatus
// ListenPort should return the TCP port that the storage provider is listening on.
ListenPort() uint16
}
Provider is a provider of MeshStorage.
type SubscribeFunc ¶
type SubscribeFunc func(key, value []byte)
SubscribeFunc is the function signature for subscribing to changes to a key.
Directories
¶
| Path | Synopsis |
|---|---|
|
backends
|
|
|
badgerdb
Package badgerdb implements the storage backends using BadgerDB.
|
Package badgerdb implements the storage backends using BadgerDB. |
|
providers
|
|
|
external
Package external provides a storage provider that uses a storage plugin to manage mesh storage and consensus.
|
Package external provides a storage provider that uses a storage plugin to manage mesh storage and consensus. |
|
passthrough
Package passthrough provides a passthrough storage provider.
|
Package passthrough provides a passthrough storage provider. |
|
raftstorage
Package raftstorage implements a Raft-backed storage provider.
|
Package raftstorage implements a Raft-backed storage provider. |
|
raftstorage/fsm
Package fsm implements the Raft FSM.
|
Package fsm implements the Raft FSM. |
|
Package storageutil contains utility functions for mesh database interactions.
|
Package storageutil contains utility functions for mesh database interactions. |
|
Package testutil contains testing utilities for storage providers and backends.
|
Package testutil contains testing utilities for storage providers and backends. |