raftsqlite3

package module
v0.0.0-...-0ab5680 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2022 License: MPL-2.0 Imports: 9 Imported by: 0

README

raft-sqlite3

This repository provides the raftsqlite3 package. The package exports the Sqlite3Store which is an implementation of both a LogStore and StableStore.

It is meant to be used as a backend for the raft package here, and was heavily inspired by raft-boltdb

This implementation uses SQLlite3, via the go-sqlite3 package. This requires CGO to be enabled when compiling. Sorry.

Metrics

The raft-sqlite3 library emits a number of metrics utilizing github.com/armon/go-metrics. Those metrics are detailed in the following table.

Metric Unit Type Description
raft.boltdb.getLog ms timer Measures the amount of time spent reading logs from the db.
raft.boltdb.logBatchSize bytes sample Measures the total size in bytes of logs being written to the db in a single batch.
raft.boltdb.logsPerBatch logs sample Measures the number of logs being written per batch to the db.
raft.boltdb.logSize bytes sample Measures the size of logs being written to the db.
raft.boltdb.storeLogs ms timer Measures the amount of time spent writing logs to the db.
raft.boltdb.writeCapacity logs/second sample Theoretical write capacity in terms of the number of logs that can be written per second. Each sample outputs what the capacity would be if future batched log write operations were similar to this one. This similarity encompasses 4 things: batch size, byte size, disk performance and boltdb performance. While none of these will be static and its highly likely individual samples of this metric will vary, aggregating this metric over a larger time window should provide a decent picture into how this BoltDB store can perform

Documentation

Index

Constants

View Source
const (
	AccessDefault = iota
	AccessRO
	AccessRW
	AccessRWC
	AccessMemory
)

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 AccessMode

type AccessMode int

func (AccessMode) String

func (a AccessMode) String() string

type BusyTimeout

type BusyTimeout time.Duration

func (BusyTimeout) Pragma

func (b BusyTimeout) Pragma() string

func (BusyTimeout) String

func (b BusyTimeout) String() string

type JournalMode

type JournalMode int
const (
	JournalDelete JournalMode = iota
	JournalTruncate
	JournalPersist
	JournalMemory
	JournalWAL
	JournalOff
)

func (JournalMode) Pragma

func (s JournalMode) Pragma() string

func (JournalMode) String

func (j JournalMode) String() string

type OptFunc

type OptFunc func(*Sqlite3Store)

func WithMode

func WithMode(m AccessMode) OptFunc

func WithPragmas

func WithPragmas(pragmas ...Pragmaer) OptFunc

type Pragmaer

type Pragmaer interface {
	Pragma() string
	fmt.Stringer
}

type SecureDeleteMode

type SecureDeleteMode int
const (
	SecureDeleteOff SecureDeleteMode = iota
	SecureDeleteOn
	SecureDeleteFast
)

func (SecureDeleteMode) Pragma

func (s SecureDeleteMode) Pragma() string

func (SecureDeleteMode) String

func (s SecureDeleteMode) String() string

type Sqlite3Store

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

Sqlite3Store provides access to Sqlite3 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(path string, opts ...OptFunc) (*Sqlite3Store, error)

New uses the supplied options to open the Sqlite3 and prepare it for use as a raft backend.

func (*Sqlite3Store) Close

func (b *Sqlite3Store) Close() error

Close is used to gracefully close the DB connection.

func (*Sqlite3Store) DeleteRange

func (b *Sqlite3Store) DeleteRange(min, max uint64) error

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

func (*Sqlite3Store) FirstIndex

func (b *Sqlite3Store) FirstIndex() (uint64, error)

FirstIndex returns the first known index from the Raft log.

func (*Sqlite3Store) Get

func (b *Sqlite3Store) Get(k []byte) ([]byte, error)

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

func (*Sqlite3Store) GetLog

func (b *Sqlite3Store) GetLog(idx uint64, log *raft.Log) error

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

func (*Sqlite3Store) GetUint64

func (b *Sqlite3Store) GetUint64(key []byte) (uint64, error)

GetUint64 is like Get, but handles uint64 values

func (*Sqlite3Store) LastIndex

func (b *Sqlite3Store) LastIndex() (uint64, error)

LastIndex returns the last known index from the Raft log.

func (*Sqlite3Store) Set

func (b *Sqlite3Store) Set(k, v []byte) error

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

func (*Sqlite3Store) SetUint64

func (b *Sqlite3Store) SetUint64(key []byte, val uint64) error

SetUint64 is like Set, but handles uint64 values

func (*Sqlite3Store) StoreLog

func (b *Sqlite3Store) StoreLog(log *raft.Log) error

StoreLog is used to store a single raft log

func (*Sqlite3Store) StoreLogs

func (b *Sqlite3Store) StoreLogs(logs []*raft.Log) error

StoreLogs is used to store a set of raft logs

func (*Sqlite3Store) Sync

func (b *Sqlite3Store) Sync() error

Sync performs an fsync on the database file handle. This is not necessary under normal operation unless NoSync is enabled, in which this forces the database file to sync against the disk.

type SynchronousMode

type SynchronousMode int
const (
	SynchronousOff SynchronousMode = iota
	SynchronousNormal
	SynchronousFull
	SynchronousExtra
)

func (SynchronousMode) Pragma

func (s SynchronousMode) Pragma() string

func (SynchronousMode) String

func (s SynchronousMode) String() string

type VacuumMode

type VacuumMode int
const (
	VacuumNone VacuumMode = iota
	VacuumFull
	VacuumIncremental
)

func (VacuumMode) Pragma

func (v VacuumMode) Pragma() string

func (VacuumMode) String

func (v VacuumMode) String() string

Jump to

Keyboard shortcuts

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