Documentation ¶
Overview ¶
Package store provides a simple distributed key-value store. The keys and associated values are changed via distributed consensus, meaning that the values are changed only when a majority of nodes in the cluster agree on the new value.
Distributed consensus is provided via the Raft algorithm, specifically the Hashicorp implementation.
Index ¶
- Variables
- func Build(message *Message) []byte
- func BytesToString(b []byte) string
- func StringToBytes(s string) []byte
- type BoltStore
- func (b *BoltStore) Close() error
- func (b *BoltStore) Count() uint64
- func (b *BoltStore) DeleteRange(min, max uint64) error
- func (b *BoltStore) FirstIndex() (uint64, error)
- func (b *BoltStore) Get(k []byte) ([]byte, error)
- func (b *BoltStore) GetLog(idx uint64, log *raft.Log) error
- func (b *BoltStore) GetUint64(key []byte) (uint64, error)
- func (b *BoltStore) LastIndex() (uint64, error)
- func (b *BoltStore) RemoveAll() error
- func (b *BoltStore) Set(k, v []byte) error
- func (b *BoltStore) SetUint64(key []byte, val uint64) error
- func (b *BoltStore) StoreLog(log *raft.Log) error
- func (b *BoltStore) StoreLogs(logs []*raft.Log) error
- func (b *BoltStore) Sync() error
- type KV
- type Message
- type Op
- type Options
- type Store
- func (s *Store) All() []*KV
- func (s *Store) BootstrapCluster(ok bool)
- func (s *Store) Clear() error
- func (s *Store) Delete(key string) error
- func (s *Store) Get(key string) ([]byte, error)
- func (s *Store) Join(addr string) error
- func (s *Store) Leave(addr string) error
- func (s *Store) Open() error
- func (s *Store) Raft() *raft.Raft
- func (s *Store) Set(key string, value []byte) error
- func (s *Store) Shutdown() raft.Future
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidMessage = errors.New("invalid message")
var ( // ErrKeyNotFound // An error indicating a given key does not exist ErrKeyNotFound = errors.New("not found") )
Functions ¶
func BytesToString ¶
func StringToBytes ¶
Types ¶
type BoltStore ¶
type BoltStore struct {
// contains filtered or unexported fields
}
BoltStore provides access to BoltDB for Raft to store and retrieve log entries. It also provides key/value storage, and can be used as a LogStore and StableStore.
func NewBolt ¶
NewBolt New uses the supplied options to open the BoltDB and prepare it for use as a raft backend.
func NewBoltStore ¶
NewBoltStore takes a file path and returns a connected Raft backend.
func (*BoltStore) DeleteRange ¶
DeleteRange is used to delete logs within a given range inclusively.
func (*BoltStore) FirstIndex ¶
FirstIndex returns the first known index from the Raft log.
type KV ¶
type KV struct { Key string `json:"key"` Value jsoniter.RawMessage `json:"value"` }
type Message ¶
func ParseMulti ¶
type Options ¶
type Options struct { // Path is the file path to the BoltDB to use Path string // BoltOptions contains any specific BoltDB options you might // want to specify [e.g. open timeout] BoltOptions *bolt.Options // NoSync causes the database to skip fsync calls after each // write to the log. This is unsafe, so it should be used // with caution. NoSync bool }
Options contains all the configuration used to open the BoltDB
type Store ¶
type Store struct { RaftDir string RaftAddr string OnLeaderChange func(leader raft.LeaderObservation) OnPeerChange func(leader raft.PeerObservation) OnKeyChange func(op *Message) Ready chan bool IsReady bool // contains filtered or unexported fields }
Store is a simple key-value store, where all changes are made via Raft consensus.
func (*Store) BootstrapCluster ¶
BootstrapCluster MUST SET ONE
func (*Store) Open ¶
Open opens the store. If enableSingle is set, and there are no existing peers, then this node becomes the first node, and therefore leader, of the cluster. localID should be the server identifier for this node.