storage

package
v0.0.0-...-2ad55f5 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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) Close

func (ms *MemStore) Close() error

Close performs a no-op on a MemStore.

func (*MemStore) Get

func (ms *MemStore) Get(key []byte) ([]byte, error)

Get returns a value for a given key. If the key does not exist, an error is returned.

func (*MemStore) GetLastLogIndex

func (ms *MemStore) GetLastLogIndex() uint64

GetLastLogIndex returns the last stored log index. If no logs have been stored, then zero is returned.

func (*MemStore) GetLog

func (ms *MemStore) GetLog(index uint64) (types.Log, error)

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

func (ms *MemStore) GetUint64(key []byte) (uint64, error)

GetUint64 returns an unsigned 64-bit value for a given key. If the key does not exist, an error is returned.

func (*MemStore) LogsIter

func (ms *MemStore) LogsIter(start, end uint64, cb func(log types.Log) error) error

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

func (ms *MemStore) Set(key, value []byte) error

Set inserts a value for a given key. An error is returned upon failure. An error is returned upon failure.

func (*MemStore) SetLog

func (ms *MemStore) SetLog(log types.Log) error

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.

func (*MemStore) SetLogs

func (ms *MemStore) SetLogs(logs []types.Log) error

SetLogs inserts a batch of logs where each log should contain an incremented index. An error is returned if any log cannot be serialized or if insertion fails.

Contract: No log should exist for that given index.

func (*MemStore) SetUint64

func (ms *MemStore) SetUint64(key []byte, value uint64) error

SetUint64 inserts an unsigned 64-bit value for a given key. An error is returned upon failure.

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

func (rs *RaftStore) Close() error

Close releases all database resources. It will block waiting for any open transactions to finish before closing the database and returning.

func (*RaftStore) Get

func (rs *RaftStore) Get(key []byte) ([]byte, error)

Get returns a value for a given key. If the key does not exist, an error is returned.

func (*RaftStore) GetLastLogIndex

func (rs *RaftStore) GetLastLogIndex() uint64

GetLastLogIndex returns the last stored log index. If no logs have been stored, then zero is returned.

func (*RaftStore) GetLog

func (rs *RaftStore) GetLog(index uint64) (types.Log, error)

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

func (rs *RaftStore) GetUint64(key []byte) (uint64, error)

GetUint64 returns an unsigned 64-bit value for a given key. If the key does not exist, an error is returned.

func (*RaftStore) LogsIter

func (rs *RaftStore) LogsIter(start, end uint64, cb func(log types.Log) error) error

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) Set

func (rs *RaftStore) Set(key, value []byte) error

Set inserts a value for a given key. An error is returned upon failure.

func (*RaftStore) SetLog

func (rs *RaftStore) SetLog(log types.Log) error

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.

func (*RaftStore) SetLogs

func (rs *RaftStore) SetLogs(logs []types.Log) error

SetLogs inserts a batch of logs where each log should contain an incremented index. An error is returned if any log cannot be serialized or if insertion fails.

Contract: No log should exist for that given index.

func (*RaftStore) SetUint64

func (rs *RaftStore) SetUint64(key []byte, value uint64) error

SetUint64 inserts an unsigned 64-bit value for a given key. An error is returned upon failure.

type RaftStoreOpts

type RaftStoreOpts bolt.Options

RaftStoreOpts defines a type alias for BoltDB connection and configuration options.

Jump to

Keyboard shortcuts

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