store

package
v2.2.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2016 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package store provides a distributed SQLite instance.

Distributed consensus is provided via the Raft algorithm.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrFieldsRequired is returned when a node attempts to execute a leader-only
	// operation.
	ErrNotLeader = errors.New("not leader")
)

Functions

This section is empty.

Types

type ConsistencyLevel

type ConsistencyLevel int
const (
	None ConsistencyLevel = iota
	Weak
	Strong
)

type Store

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

Store is a SQLite database, where all changes are made via Raft consensus.

func New

func New(dbConf *sql.Config, dir, bind string) *Store

New returns a new Store.

func (*Store) Addr

func (s *Store) Addr() net.Addr

func (*Store) Apply

func (s *Store) Apply(l *raft.Log) interface{}

Apply applies a Raft log entry to the database.

func (*Store) Backup

func (s *Store) Backup(leader bool) ([]byte, error)

Backup return a consistent snapshot of the underlying database.

func (*Store) Close

func (s *Store) Close(wait bool) error

Close closes the store. If wait is true, waits for a graceful shutdown.

func (*Store) Execute

func (s *Store) Execute(queries []string, timings, tx bool) ([]*sql.Result, error)

Execute executes queries that return no rows, but do modify the database.

func (*Store) Join

func (s *Store) Join(addr string) error

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) Leader

func (s *Store) Leader() string

Leader returns the current leader. Returns a blank string if there is no leader.

func (*Store) Open

func (s *Store) Open(enableSingle bool) error

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) Path

func (s *Store) Path() string

Path returns the path to the store's storage directory.

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 database 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) Stats

func (s *Store) Stats() (map[string]interface{}, error)

Stats returns stats for the store.

func (*Store) WaitForAppliedIndex

func (s *Store) WaitForAppliedIndex(idx uint64, timeout time.Duration) error

WaitForAppliedIndex blocks until a given log index has been applied, or the timeout expires.

func (*Store) WaitForLeader

func (s *Store) WaitForLeader(timeout time.Duration) (string, error)

WaitForLeader blocks until a leader is detected, or the timeout expires.

Jump to

Keyboard shortcuts

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