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
- type ConsistencyLevel
- type Store
- func (s *Store) Delete(key string) error
- func (s *Store) DeleteMeta(key string) error
- func (s *Store) Get(key string, lvl ConsistencyLevel) (string, error)
- func (s *Store) GetMeta(key string) (string, error)
- func (s *Store) Join(nodeID, httpAddr string, addr string) error
- func (s *Store) LeaderAPIAddr() string
- func (s *Store) LeaderAddr() string
- func (s *Store) LeaderID() (string, error)
- func (s *Store) Open(enableSingle bool, localID string) error
- func (s *Store) Set(key, value string) error
- func (s *Store) SetMeta(key, value string) error
- func (s *Store) WaitForApplied(timeout time.Duration) error
- func (s *Store) WaitForAppliedIndex(idx uint64, timeout time.Duration) error
- func (s *Store) WaitForLeader(timeout time.Duration) (string, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotLeader is returned when a node attempts to execute a leader-only // operation. ErrNotLeader = errors.New("not leader") // ErrOpenTimeout is returned when the Store does not apply its initial // logs within the specified time. ErrOpenTimeout = errors.New("timeout waiting for initial logs application") )
Functions ¶
This section is empty.
Types ¶
type ConsistencyLevel ¶
type ConsistencyLevel int
const ( Default ConsistencyLevel = iota Stale Consistent )
Represents the available consistency levels.
type Store ¶
Store is a simple key-value store, where all changes are made via Raft consensus.
func (*Store) DeleteMeta ¶
func (*Store) Get ¶
func (s *Store) Get(key string, lvl ConsistencyLevel) (string, error)
Get returns the value for the given key.
func (*Store) Join ¶
Join joins a node, identified by nodeID and located at addr, to this store. The node must be ready to respond to Raft communications at that address.
func (*Store) LeaderAPIAddr ¶
func (*Store) LeaderAddr ¶
func (*Store) LeaderID ¶
LeaderID returns the node ID of the Raft leader. Returns a blank string if there is no leader, or an error.
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.
func (*Store) WaitForApplied ¶
WaitForApplied waits for all Raft log entries to to be applied to the underlying database.
func (*Store) WaitForAppliedIndex ¶
WaitForAppliedIndex blocks until a given log index has been applied, or the timeout expires.