Documentation
¶
Index ¶
- Variables
- type Options
- type SQLiteStore
- func (s *SQLiteStore) Close() error
- func (s *SQLiteStore) DeleteRange(min, max uint64) error
- func (s *SQLiteStore) FirstIndex() (uint64, error)
- func (s *SQLiteStore) Get(key []byte) ([]byte, error)
- func (s *SQLiteStore) GetLog(index uint64, log *raft.Log) error
- func (s *SQLiteStore) GetUint64(key []byte) (uint64, error)
- func (s *SQLiteStore) LastIndex() (uint64, error)
- func (s *SQLiteStore) Set(key []byte, val []byte) error
- func (s *SQLiteStore) SetUint64(key []byte, val uint64) error
- func (s *SQLiteStore) StoreLog(log *raft.Log) error
- func (s *SQLiteStore) StoreLogs(logs []*raft.Log) error
- type SnapshotStore
- type SnapshotStoreOptions
Constants ¶
This section is empty.
Variables ¶
var ( // ErrKeyNotFound indicates a given key does not exist. ErrKeyNotFound = errors.New("not found") )
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// Path is the file path to the SQLite database.
//
// Either Path or TxFactory must be set, but not both.
Path string
// TxFactory is an optional function that can be used to provide custom
// transaction handling. If set, the store will use this function to create
// transactions instead of opening a database at Path.
//
// Either TxFactory or Path must be set, but not both.
TxFactory func(context.Context, *sql.TxOptions) (*sql.Tx, error)
// Logf is an optional log function for diagnostic messages.
// If nil, log messages are discarded.
Logf func(string, ...any)
}
Options contains all the configuration used to open the SQLite store.
type SQLiteStore ¶
type SQLiteStore struct {
// contains filtered or unexported fields
}
SQLiteStore provides access to a SQLite database for Raft to store and retrieve log entries. It also provides key/value storage, and can be used as a LogStore and StableStore.
func New ¶
func New(options Options) (*SQLiteStore, error)
New uses the supplied options to open the SQLite database and prepare it for use as a raft backend.
func NewSQLiteStore ¶
func NewSQLiteStore(path string) (*SQLiteStore, error)
NewSQLiteStore takes a file path and returns a connected Raft backend.
func (*SQLiteStore) Close ¶
func (s *SQLiteStore) Close() error
Close cancels background goroutines and closes the database connection.
func (*SQLiteStore) DeleteRange ¶
func (s *SQLiteStore) DeleteRange(min, max uint64) error
DeleteRange deletes a range of log entries. The range is inclusive.
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(key []byte) ([]byte, error)
Get is used to retrieve a value from the k/v store by key.
func (*SQLiteStore) GetLog ¶
func (s *SQLiteStore) GetLog(index uint64, log *raft.Log) error
GetLog gets a log entry 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(key []byte, val []byte) error
Set is used to set a key/value pair 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.
type SnapshotStore ¶
type SnapshotStore struct {
// contains filtered or unexported fields
}
SnapshotStore is an implementation of raft.SnapshotStore that uses SQLite as the backend.
func NewSnapshotStore ¶
func NewSnapshotStore(options SnapshotStoreOptions) (*SnapshotStore, error)
NewSnapshotStore uses the supplied options to open the SQLite database and prepare it for use as a raft snapshot store.
func (*SnapshotStore) Close ¶
func (s *SnapshotStore) Close() error
Close cancels background goroutines and closes the database connection.
func (*SnapshotStore) Create ¶
func (s *SnapshotStore) Create(version raft.SnapshotVersion, index, term uint64, configuration raft.Configuration, configurationIndex uint64, trans raft.Transport) (raft.SnapshotSink, error)
Create is used to begin a snapshot at a given index and term, and with the given committed configuration. The version parameter controls which snapshot version to create.
func (*SnapshotStore) List ¶
func (s *SnapshotStore) List() ([]*raft.SnapshotMeta, error)
List is used to list the available snapshots in the store. It returns them in descending order, with the highest index first.
func (*SnapshotStore) Open ¶
func (s *SnapshotStore) Open(id string) (*raft.SnapshotMeta, io.ReadCloser, error)
Open takes a snapshot ID and provides a ReadCloser. Once close is called it is assumed the snapshot is no longer needed.
type SnapshotStoreOptions ¶
type SnapshotStoreOptions struct {
// Path is the file path to the SQLite database.
//
// Either Path or TxFactory must be set, but not both.
Path string
// TxFactory is an optional function that can be used to provide custom
// transaction handling. If set, the store will use this function to create
// transactions instead of opening a database at Path.
//
// Either TxFactory or Path must be set, but not both.
TxFactory func(context.Context, *sql.TxOptions) (*sql.Tx, error)
// Logf is an optional log function for diagnostic messages.
// If nil, log messages are discarded.
Logf func(string, ...any)
// Retain is the number of snapshots to retain. Must be >= 1.
Retain int
}
SnapshotStoreOptions contains all the configuration used to open the snapshot store.