store

package
v0.0.0-...-d69b747 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2020 License: MIT Imports: 12 Imported by: 0

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

Constants

This section is empty.

Variables

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

type Store struct {
	RaftDir  string
	RaftBind string
	// contains filtered or unexported fields
}

Store is a simple key-value store, where all changes are made via Raft consensus.

func New

func New() *Store

New returns a new Store.

func (*Store) Delete

func (s *Store) Delete(key string) error

Delete deletes the given key.

func (*Store) DeleteMeta

func (s *Store) DeleteMeta(key string) error

func (*Store) Get

func (s *Store) Get(key string, lvl ConsistencyLevel) (string, error)

Get returns the value for the given key.

func (*Store) GetMeta

func (s *Store) GetMeta(key string) (string, error)

func (*Store) Join

func (s *Store) Join(nodeID, httpAddr string, addr string) error

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 (s *Store) LeaderAPIAddr() string

func (*Store) LeaderAddr

func (s *Store) LeaderAddr() string

func (*Store) LeaderID

func (s *Store) LeaderID() (string, error)

LeaderID returns the node ID of the Raft leader. Returns a blank string if there is no leader, or an error.

func (*Store) Open

func (s *Store) Open(enableSingle bool, localID string) error

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

func (s *Store) Set(key, value string) error

Set sets the value for the given key.

func (*Store) SetMeta

func (s *Store) SetMeta(key, value string) error

func (*Store) WaitForApplied

func (s *Store) WaitForApplied(timeout time.Duration) error

WaitForApplied waits for all Raft log entries to to be applied to the underlying database.

func (*Store) WaitForAppliedIndex

func (s *Store) WaitForAppliedIndex(idx uint64, timeout time.Duration) error

WaitForAppliedIndex blocks until a given log index has been applied, or the timeout expires.

func (*Store) WaitForLeader

func (s *Store) WaitForLeader(timeout time.Duration) (string, error)

WaitForLeader blocks until a leader is detected, or the timeout expires.

Jump to

Keyboard shortcuts

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