store

package
v0.0.0-...-b510d8c Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2021 License: MIT Imports: 11 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

This section is empty.

Functions

This section is empty.

Types

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(inmem bool) *Store

New returns a new Store.

func (*Store) Delete

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

Delete deletes the given key.

func (*Store) Get

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

Get returns the value for the given key.

func (*Store) GetInfo

func (s *Store) GetInfo() (*StoreInfo, error)

func (*Store) Join

func (s *Store) Join(nodeID, 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) 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.

type StoreInfo

type StoreInfo struct {
	// Leader indicates which raft addr is the leader
	Leader string `json:"leader"`

	// State indicates the current state of the node
	State string `json:"state"`
}

Jump to

Keyboard shortcuts

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