store

package
v0.0.0-...-73ed01f Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2021 License: MIT Imports: 6 Imported by: 0

README

Store

The store package implements the StableStore interface and the LogStore which are required for constructing a new raft node

These interfaces are used for storing and retrieving logs and other key configurations of the node.

StableStore Interface

StableStore is used to provide stable storage of key configurations to ensure safety.The Set/Get and SetUint64/GetUint64 functions are used to set/get key-value pairs of type []byte and uint64 respectively.

LogStore Interface

The LogStore interface stores and retrieves the logs in a persistent manner.

  • The FirstIndex and LastIndex functions return the index property of the first and last log respectively. These functions are used to check whether the logs of the follower are consistent with that of the leader.

  • The GetLog function gets the log with the given index and writes it to the pointer of type Log passed to it.

  • The StoreLog function is used to store a single Log to disk. It calls the StoreLogs function passing it an array of the given log.

  • The StoreLogs function is perhaps the most important function in this interface. It takes in an array of logs and actually persists that data onto disk using BadgerDB. It is used by the new nodes to store all the logs it receives from the leader or by the existing nodes to store individual logs.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RavelLogStore

type RavelLogStore struct {
	Db *db.RavelDatabase
}

RavelLogStore implements raft.LogStore interface. The functions define the operations possible on the Logs which is maintained by every instance of raft.Raft

func NewRavelLogStore

func NewRavelLogStore(logDBPath string) (*RavelLogStore, error)

NewRavelLogStore creates a new instance of RavelLogStore, logDBPath specifies the directory path to initialise the internal db.RavelDatabase instance. An entry in the Logs is of type raft.Log

func (*RavelLogStore) DeleteRange

func (r *RavelLogStore) DeleteRange(min uint64, max uint64) error

DeleteRange deletes the entries from "min" to "max" position (both inclusive) in the Logs

func (*RavelLogStore) FirstIndex

func (r *RavelLogStore) FirstIndex() (uint64, error)

FirstIndex returns the Index property of the first entry in the Logs.

func (*RavelLogStore) GetLog

func (r *RavelLogStore) GetLog(index uint64, raftLog *raft.Log) error

GetLog writes the log on position "index" to the pointer "raftLog"

func (*RavelLogStore) LastIndex

func (r *RavelLogStore) LastIndex() (uint64, error)

LastIndex returns the Index property of the last entry in the Logs

func (*RavelLogStore) StoreLog

func (r *RavelLogStore) StoreLog(l *raft.Log) error

StoreLog inserts a single raft.Log at the end of the Logs

func (*RavelLogStore) StoreLogs

func (r *RavelLogStore) StoreLogs(logs []*raft.Log) error

StoreLogs inserts []raft.Log at the end of the Logs

type RavelStableStore

type RavelStableStore struct {
	Db *db.RavelDatabase
}

RavelStableStore implements the raft.StableStore interface. It stores the configuration for raft.Raft

func NewRavelStableStore

func NewRavelStableStore(stableStoreDBPath string) (*RavelStableStore, error)

NewRavelStableStore creates a new instance of RavelStableStore

func (*RavelStableStore) Get

func (s *RavelStableStore) Get(key []byte) ([]byte, error)

Get returns the value for the provided key

func (*RavelStableStore) GetUint64

func (s *RavelStableStore) GetUint64(key []byte) (uint64, error)

GetUint64 returns the value for the given key

func (*RavelStableStore) Set

func (s *RavelStableStore) Set(key []byte, val []byte) error

Set stores Key configuration in a stable manner.

func (*RavelStableStore) SetUint64

func (s *RavelStableStore) SetUint64(key []byte, val uint64) error

SetUint64 sets val as uint64 for the provided key

Jump to

Keyboard shortcuts

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