store

package
v0.2.26 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2024 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 FSM

type FSM Store

func (*FSM) Apply

func (f *FSM) Apply(l *raft.Log) interface{}

Apply applies a Raft log entry to the key-value store.

func (*FSM) Restore

func (f *FSM) Restore(rc io.ReadCloser) error

Restore stores the key-value store to a previous state.

func (*FSM) Snapshot

func (f *FSM) Snapshot() (raft.FSMSnapshot, error)

Snapshot returns a snapshot of the key-value store.

type FSMResponse

type FSMResponse struct {
	// contains filtered or unexported fields
}

type FSMSnapshot

type FSMSnapshot struct {
	// contains filtered or unexported fields
}

func (*FSMSnapshot) Persist

func (f *FSMSnapshot) Persist(sink raft.SnapshotSink) error

func (*FSMSnapshot) Release

func (f *FSMSnapshot) Release()

type Store

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

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

func New

func New(logger *logrus.Logger) *Store

New returns a new Store.

func (*Store) Acquire

func (s *Store) Acquire(key string, ttl int) error

Acquire acquires a lock the given key if it wasn't acquired by somebody else.

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) ListenToLeaderChanges added in v0.1.14

func (s *Store) ListenToLeaderChanges()

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

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

Release releases a lock for the given key.

func (*Store) RunValueLogGC added in v0.2.2

func (s *Store) RunValueLogGC()

func (*Store) SetLeaderChangeFunc added in v0.1.15

func (s *Store) SetLeaderChangeFunc(leaderChangeFn func(bool))

Jump to

Keyboard shortcuts

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