Documentation ¶
Overview ¶
Package store provides a distributed SQLite instance.
Distributed consensus is provided via the Raft algorithm.
Index ¶
- Variables
- func NewClusterMeta() *clusterMeta
- type ConsistencyLevel
- type DBConfig
- type Store
- func (s *Store) APIPeers() (map[string]string, error)
- func (s *Store) Addr() net.Addr
- func (s *Store) Apply(l *raft.Log) interface{}
- func (s *Store) Backup(leader bool) ([]byte, error)
- func (s *Store) Close(wait bool) error
- func (s *Store) Execute(queries []string, timings, tx bool) ([]*sql.Result, error)
- func (s *Store) Join(addr string) error
- func (s *Store) JoinRequired() bool
- func (s *Store) Leader() string
- func (s *Store) Open(enableSingle bool) error
- func (s *Store) Path() string
- func (s *Store) Peer(addr string) string
- func (s *Store) Query(queries []string, timings, tx bool, lvl ConsistencyLevel) ([]*sql.Rows, error)
- func (s *Store) Restore(rc io.ReadCloser) error
- func (s *Store) Snapshot() (raft.FSMSnapshot, error)
- func (s *Store) Stats() (map[string]interface{}, error)
- func (s *Store) UpdateAPIPeers(peers map[string]string) error
- func (s *Store) WaitForAppliedIndex(idx uint64, timeout time.Duration) error
- func (s *Store) WaitForLeader(timeout time.Duration) (string, error)
- type Transport
Constants ¶
This section is empty.
Variables ¶
var ( // ErrFieldsRequired is returned when a node attempts to execute a leader-only // operation. ErrNotLeader = errors.New("not leader") )
Functions ¶
func NewClusterMeta ¶
func NewClusterMeta() *clusterMeta
NewClusterMeta returns an initialized cluster meta store.
Types ¶
type ConsistencyLevel ¶
type ConsistencyLevel int
ConsistencyLevel represents the available read consistency levels.
const ( None ConsistencyLevel = iota Weak Strong )
type DBConfig ¶
type DBConfig struct { DSN string // Any custom DSN Memory bool // Whether the database is in-memory only. }
DBConfig represents the configuration of the underlying SQLite database.
func NewDBConfig ¶
NewDBConfig returns a new DB config instance.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a SQLite database, where all changes are made via Raft consensus.
func (*Store) Join ¶
Join joins a node, located at addr, to this store. The node must be ready to respond to Raft communications at that address.
func (*Store) JoinRequired ¶
JoinRequired returns whether the node needs to join a cluster after being opened.
func (*Store) Leader ¶
Leader returns the current leader. Returns a blank string if there is no leader.
func (*Store) Open ¶
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.
func (*Store) Peer ¶
Peer returns the API address for the given addr. If there is no peer for the address, it returns the empty string.
func (*Store) Query ¶
func (s *Store) Query(queries []string, timings, tx bool, lvl ConsistencyLevel) ([]*sql.Rows, error)
Query executes queries that return rows, and do not modify the database.
func (*Store) Restore ¶
func (s *Store) Restore(rc io.ReadCloser) error
Restore restores the node to a previous state.
func (*Store) Snapshot ¶
func (s *Store) Snapshot() (raft.FSMSnapshot, error)
Snapshot returns a snapshot of the database. The caller must ensure that no transaction is taking place during this call. Hashsicorp Raft guarantees that this function will not be called concurrently with Apply.
http://sqlite.org/howtocorrupt.html states it is safe to do this as long as no transaction is in progress.
func (*Store) UpdateAPIPeers ¶
UpdateAPIPeers updates the cluster-wide peer information.
func (*Store) WaitForAppliedIndex ¶
WaitForAppliedIndex blocks until a given log index has been applied, or the timeout expires.