Documentation ¶
Overview ¶
Package storage contains the interfaces for storing and retrieving data about the state of the mesh and maintaining consensus.
Index ¶
- Variables
- func IsKeyNotFoundError(err error) bool
- func IsReservedPrefix(key string) bool
- func NewKeyNotFoundError(key string) error
- func RunDualStorageConformance(t *testing.T, dualStorage DualStorage)
- func RunMeshStorageConformance(t *testing.T, meshStorage MeshStorage)
- func RunRaftStorageConformance(t *testing.T, raftStorage RaftStorage)
- type Consensus
- type DropStorage
- type DualStorage
- type MeshStorage
- type Prefix
- type PrefixIterator
- type Provider
- type RaftStorage
- type SubscribeFunc
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") )
Common errors for storage providers to use.
var ErrKeyNotFound = errors.New("key not found")
ErrKeyNotFound is the error returned when a key is not found.
var ReservedPrefixes = []Prefix{ RegistryPrefix, RaftPrefix, }
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.
func RunDualStorageConformance ¶ added in v0.3.0
func RunDualStorageConformance(t *testing.T, dualStorage DualStorage)
RunDualStorageConformance tests that the DualStorage interface is implemented correctly.
func RunMeshStorageConformance ¶ added in v0.3.0
func RunMeshStorageConformance(t *testing.T, meshStorage MeshStorage)
RunMeshStorageConformance tests that the MeshStorage interface is implemented correctly.
func RunRaftStorageConformance ¶ added in v0.3.0
func RunRaftStorageConformance(t *testing.T, raftStorage RaftStorage)
RunRaftStorageConformance tests that the RaftStorage interface is implemented correctly.
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 // 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 DropStorage ¶ added in v0.6.0
type DropStorage interface { // DropAll drops all data from the storage. This is primarily used // for testing. DropAll(ctx context.Context) error }
DropStorage is a storage interface that can be dropped entirely. This is primarily used for testing.
type DualStorage ¶ added in v0.3.0
type DualStorage interface { MeshStorage RaftStorage }
DualStorage represents a storage interface that can serve as both a mesh and Raft 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 string) (string, error) // PutValue sets the value of a key. TTL is optional and can be set to 0. PutValue(ctx context.Context, key, value string, ttl time.Duration) error // Delete removes a key. Delete(ctx context.Context, key string) error // List returns all keys with a given prefix. List(ctx context.Context, prefix string) ([]string, 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 string, 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 string, 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 string
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.
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 RaftStorage ¶ added in v0.3.0
type RaftStorage 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 }
RaftStorage is the interface for storing and retrieving data about the state of the mesh. This interface is used by mesh members that are part of the Raft cluster.
type SubscribeFunc ¶
type SubscribeFunc func(key, value string)
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. |
memory
Package memory implements an in-memory storage backend suitable for testing.
|
Package memory implements an in-memory storage backend suitable for testing. |
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. |