Documentation
¶
Index ¶
- Variables
- type DB
- type MemStore
- func (ms *MemStore) Close() error
- func (ms *MemStore) Get(key []byte) ([]byte, error)
- func (ms *MemStore) GetLastLogIndex() uint64
- func (ms *MemStore) GetLog(index uint64) (types.Log, error)
- func (ms *MemStore) GetUint64(key []byte) (uint64, error)
- func (ms *MemStore) LogsIter(start, end uint64, cb func(log types.Log) error) error
- func (ms *MemStore) Set(key, value []byte) error
- func (ms *MemStore) SetLog(log types.Log) error
- func (ms *MemStore) SetLogDecoder(_ types.LogDecoder)
- func (ms *MemStore) SetLogEncoder(_ types.LogEncoder)
- func (ms *MemStore) SetLogs(logs []types.Log) error
- func (ms *MemStore) SetUint64(key []byte, value uint64) error
- type RaftDB
- type RaftStore
- func (rs *RaftStore) Close() error
- func (rs *RaftStore) Get(key []byte) ([]byte, error)
- func (rs *RaftStore) GetLastLogIndex() uint64
- func (rs *RaftStore) GetLog(index uint64) (types.Log, error)
- func (rs *RaftStore) GetUint64(key []byte) (uint64, error)
- func (rs *RaftStore) LogsIter(start, end uint64, cb func(log types.Log) error) error
- func (rs *RaftStore) Set(key, value []byte) error
- func (rs *RaftStore) SetLog(log types.Log) error
- func (rs *RaftStore) SetLogDecoder(dec types.LogDecoder)
- func (rs *RaftStore) SetLogEncoder(enc types.LogEncoder)
- func (rs *RaftStore) SetLogs(logs []types.Log) error
- func (rs *RaftStore) SetUint64(key []byte, value uint64) error
- type RaftStoreOpts
Constants ¶
This section is empty.
Variables ¶
var ErrKeyNotFound = errors.New("key does not exist")
ErrKeyNotFound defines an error returned when a given key does not exist.
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB interface { Get(key []byte) ([]byte, error) Set(key, value []byte) error GetUint64(key []byte) (uint64, error) SetUint64(key []byte, value uint64) error Close() error }
DB defines an embedded key/value store database interface.
type MemStore ¶
type MemStore struct {
// contains filtered or unexported fields
}
MemStore implements an in-memory simple Raft stable storage and persistence layer. It implements the RaftDB interface.
func NewMemStore ¶
func NewMemStore() *MemStore
func (*MemStore) Get ¶
Get returns a value for a given key. If the key does not exist, an error is returned.
func (*MemStore) GetLastLogIndex ¶
GetLastLogIndex returns the last stored log index. If no logs have been stored, then zero is returned.
func (*MemStore) GetLog ¶
GetLog returns a log for a given index. If no log exists for such an index or if it cannot be deserialized, an error is returned.
func (*MemStore) GetUint64 ¶
GetUint64 returns an unsigned 64-bit value for a given key. If the key does not exist, an error is returned.
func (*MemStore) LogsIter ¶
LogsIter iterates over a given range of logs by an index range. For each index, a cb function that accepts the given log is called. If the callback executed for any given log returns an error, the iteration exits along with the error being returned to the caller.
func (*MemStore) Set ¶
Set inserts a value for a given key. An error is returned upon failure. An error is returned upon failure.
func (*MemStore) SetLog ¶
SetLog inserts a log by index. An error is returned if the log cannot be serialized or if insertion fails.
Contract: No log should exist for that given index.
func (*MemStore) SetLogDecoder ¶
func (ms *MemStore) SetLogDecoder(_ types.LogDecoder)
SetLogDecoder sets the store's log decoder type.
func (*MemStore) SetLogEncoder ¶
func (ms *MemStore) SetLogEncoder(_ types.LogEncoder)
SetLogEncoder sets the store's log encoder type.
type RaftDB ¶
type RaftDB interface { DB SetLogEncoder(enc types.LogEncoder) SetLogDecoder(dec types.LogDecoder) SetLogs(logs []types.Log) error SetLog(log types.Log) error GetLog(index uint64) (types.Log, error) GetLastLogIndex() uint64 LogsIter(start, end uint64, cb func(log types.Log) error) error }
RaftDB defines a Raft stable storage interface that any persistence layer used in Raft consensus must implement.
type RaftStore ¶
type RaftStore struct {
// contains filtered or unexported fields
}
RaftStore implements the default Raft stable storage and persistence layer. It uses BoltDB as the underlying embedded database and implements the RaftDB interface.
Contract: RaftStore should never persist nil values.
func NewRaftStore ¶
func NewRaftStore(dbPath string, opts RaftStoreOpts) (*RaftStore, error)
NewRaftStore returns a reference to a new RaftStore with a given set of options. It will handle creating a BoltDB connection with the provided options. In addition, during write-mode, log and configuration buckets will be created if they do not already exist. An error will be returned if any required options are missing, the BoltDB connection cannot be established, or if bucket creation fails.
func (*RaftStore) Close ¶
Close releases all database resources. It will block waiting for any open transactions to finish before closing the database and returning.
func (*RaftStore) Get ¶
Get returns a value for a given key. If the key does not exist, an error is returned.
func (*RaftStore) GetLastLogIndex ¶
GetLastLogIndex returns the last stored log index. If no logs have been stored, then zero is returned.
func (*RaftStore) GetLog ¶
GetLog returns a log for a given index. If no log exists for such an index or if it cannot be deserialized, an error is returned.
func (*RaftStore) GetUint64 ¶
GetUint64 returns an unsigned 64-bit value for a given key. If the key does not exist, an error is returned.
func (*RaftStore) LogsIter ¶
LogsIter iterates over a given range of logs by an index range. For each index, a cb function that accepts the given log is called. If the callback executed for any given log returns an error, the iteration exits along with the error being returned to the caller.
func (*RaftStore) SetLog ¶
SetLog inserts a log by index. An error is returned if the log cannot be serialized or if insertion fails.
Contract: No log should exist for that given index.
func (*RaftStore) SetLogDecoder ¶
func (rs *RaftStore) SetLogDecoder(dec types.LogDecoder)
SetLogDecoder sets the store's log decoder type.
func (*RaftStore) SetLogEncoder ¶
func (rs *RaftStore) SetLogEncoder(enc types.LogEncoder)
SetLogEncoder sets the store's log encoder type.
type RaftStoreOpts ¶
RaftStoreOpts defines a type alias for BoltDB connection and configuration options.