raftsqlite

package module
v0.0.0-...-6d5b668 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: MIT Imports: 9 Imported by: 0

README

raft-sqlite

This is a sqlite backend for hashicorp/raft.

NOTE: this is slower than a proper key-value backend, in fact it's not recommended to use this in production if you are looking for performance. Stick to the default raft-boltdb or raft-mdb backends.

Usage

go get -u github.com/mauri870/raft-sqlite
//...
sqliteStore, err := raftsqlite.NewStore(filepath.Join(raftDir, "raft.db"))
//...
logStore := sqliteStore
stableStore := sqliteStore
_,_ := raft.NewRaft(config, (*fsm)(s), logStore, stableStore, snapshots, transport)

It is also possible to use the in-memory sqlite store:

sqliteStore, err := raftsqlite.NewStore("file::memory:?cache=shared")

NOTE: Never use just ":memory:", as it will create a new database for each connection instead of a shared database.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// An error indicating a given key does not exist
	ErrKeyNotFound = errors.New("not found")
)

Functions

This section is empty.

Types

type SqliteStore

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

SqliteStore provides a raft.LogStore to store and retrieve Raft log entries from a sqlite database. It also provides a raft.StableStore for storage of key/value pairs.

func NewStore

func NewStore(path string) (*SqliteStore, error)

NewStore takes a file path and returns a connected Raft backend.

func (*SqliteStore) Close

func (s *SqliteStore) Close() error

Close is used to gracefully close the DB connection.

func (*SqliteStore) DeleteRange

func (s *SqliteStore) DeleteRange(min, max uint64) error

DeleteRange is used to delete logs within a given range inclusively.

func (*SqliteStore) FirstIndex

func (s *SqliteStore) FirstIndex() (uint64, error)

FirstIndex returns the first known index from the Raft log.

func (*SqliteStore) Get

func (s *SqliteStore) Get(k []byte) ([]byte, error)

Get is used to retrieve a value from the k/v store by key

func (*SqliteStore) GetLog

func (s *SqliteStore) GetLog(idx uint64, log *raft.Log) error

GetLog is used to retrieve a log at a given index.

func (*SqliteStore) GetUint64

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

GetUint64 is like Get, but handles uint64 values

func (*SqliteStore) LastIndex

func (s *SqliteStore) LastIndex() (uint64, error)

LastIndex returns the last known index from the Raft log.

func (*SqliteStore) Set

func (s *SqliteStore) Set(k, v []byte) error

Set is used to set a key/value set outside of the raft log

func (*SqliteStore) SetUint64

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

SetUint64 is like Set, but handles uint64 values

func (*SqliteStore) StoreLog

func (s *SqliteStore) StoreLog(log *raft.Log) error

StoreLog is used to store a single raft log

func (*SqliteStore) StoreLogs

func (s *SqliteStore) StoreLogs(logs []*raft.Log) error

StoreLogs is used to store a set of raft logs

Jump to

Keyboard shortcuts

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