Documentation ¶
Overview ¶
Package store provides a distributed SQLite instance.
Distributed consensus is provided via the Raft algorithm.
Index ¶
- Variables
- func IsNewNode(raftDir string) bool
- type BackupFormat
- type ClusterState
- type DBConfig
- type Listener
- type Server
- type Servers
- type Store
- func (s *Store) Addr() string
- func (s *Store) Apply(l *raft.Log) (e interface{})
- func (s *Store) Backup(leader bool, fmt BackupFormat, dst io.Writer) error
- func (s *Store) Close(wait bool) error
- func (s *Store) Database(leader bool) ([]byte, error)
- func (s *Store) DeregisterObserver(o *raft.Observer)
- func (s *Store) Execute(ex *command.ExecuteRequest) ([]*sql.Result, error)
- func (s *Store) ExecuteOrAbort(ex *command.ExecuteRequest) (results []*sql.Result, retErr error)
- func (s *Store) ID() string
- func (s *Store) IsLeader() bool
- func (s *Store) Join(id, addr string, voter bool, metadata map[string]string) error
- func (s *Store) LeaderAddr() string
- func (s *Store) LeaderID() (string, error)
- func (s *Store) Metadata(id, key string) string
- func (s *Store) Nodes() ([]*Server, error)
- func (s *Store) Noop(id string) error
- func (s *Store) Open(enableBootstrap bool) error
- func (s *Store) Path() string
- func (s *Store) Query(qr *command.QueryRequest) ([]*sql.Rows, error)
- func (s *Store) RegisterObserver(o *raft.Observer)
- func (s *Store) Remove(id string) error
- func (s *Store) Restore(rc io.ReadCloser) error
- func (s *Store) SetMetadata(md map[string]string) error
- func (s *Store) SetRequestCompression(batch, size int)
- func (s *Store) Snapshot() (raft.FSMSnapshot, error)
- func (s *Store) State() ClusterState
- func (s *Store) Stats() (map[string]interface{}, error)
- func (s *Store) WaitForApplied(timeout time.Duration) error
- func (s *Store) WaitForAppliedIndex(idx uint64, timeout time.Duration) error
- func (s *Store) WaitForLeader(timeout time.Duration) (string, error)
- type StoreConfig
- type Transport
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotLeader is returned when a node attempts to execute a leader-only // operation. ErrNotLeader = errors.New("not leader") // ErrStaleRead is returned if the executing the query would violate the // requested freshness. ErrStaleRead = errors.New("stale read") // ErrOpenTimeout is returned when the Store does not apply its initial // logs within the specified time. ErrOpenTimeout = errors.New("timeout waiting for initial logs application") // ErrInvalidBackupFormat is returned when the requested backup format // is not valid. ErrInvalidBackupFormat = errors.New("invalid backup format") )
Functions ¶
Types ¶
type BackupFormat ¶
type BackupFormat int
BackupFormat represents the format of database backup.
const ( // BackupSQL is the plaintext SQL command format. BackupSQL BackupFormat = iota // BackupBinary is a SQLite file backup format. BackupBinary )
type ClusterState ¶
type ClusterState int
ClusterState defines the possible Raft states the current node can be in
const ( Leader ClusterState = iota Follower Candidate Shutdown Unknown )
Represents the Raft cluster states
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 Listener ¶
type Listener interface { net.Listener Dial(address string, timeout time.Duration) (net.Conn, error) }
Listener is the interface expected by the Store for Transports.
type Store ¶
type Store struct { ShutdownOnRemove bool SnapshotThreshold uint64 SnapshotInterval time.Duration LeaderLeaseTimeout time.Duration HeartbeatTimeout time.Duration ElectionTimeout time.Duration ApplyTimeout time.Duration RaftLogLevel string // contains filtered or unexported fields }
Store is a SQLite database, where all changes are made via Raft consensus.
func (*Store) Backup ¶
Backup writes a snapshot of the underlying database to dst
If leader is true, this operation is performed with a read consistency level equivalent to "weak". Otherwise no guarantees are made about the read consistency level.
func (*Store) Database ¶
Database returns a copy of the underlying database. The caller MUST ensure that no transaction is taking place during this call, or an error may be returned. If leader is true, this operation is performed with a read consistency level equivalent to "weak". Otherwise no guarantees are made about the read consistency level.
http://sqlite.org/howtocorrupt.html states it is safe to do this as long as no transaction is in progress.
func (*Store) DeregisterObserver ¶
DeregisterObserver deregisters an observer of Raft events
func (*Store) ExecuteOrAbort ¶
ExecuteOrAbort executes the requests, but aborts any active transaction on the underlying database in the case of any error.
func (*Store) Join ¶
Join joins a node, identified by id and located at addr, to this store. The node must be ready to respond to Raft communications at that address.
func (*Store) LeaderAddr ¶
LeaderAddr returns the address of the current leader. Returns a blank string if there is no leader.
func (*Store) LeaderID ¶
LeaderID returns the node ID of the Raft leader. Returns a blank string if there is no leader, or an error.
func (*Store) Noop ¶
Noop writes a noop command to the Raft log. A noop command simply consumes a slot in the Raft log, but has no other affect on the system.
func (*Store) Open ¶
Open opens the Store. If enableBootstrap is set, then this node becomes a standalone node. If not set, then the calling layer must know that this node has pre-existing state, or the calling layer will trigger a join operation after opening the Store.
func (*Store) RegisterObserver ¶
RegisterObserver registers an observer of Raft events
func (*Store) Restore ¶
func (s *Store) Restore(rc io.ReadCloser) error
Restore restores the node to a previous state. The Hashicorp docs state this will not be called concurrently with Apply(), so synchronization with Execute() is not necessary.To prevent problems during queries, which may not go through the log, it blocks all query requests.
func (*Store) SetMetadata ¶
SetMetadata adds the metadata md to any existing metadata for this node.
func (*Store) SetRequestCompression ¶
SetRequestCompression allows low-level control over the compression threshold for the request marshaler.
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. Hashicorp Raft guarantees that this function will not be called concurrently with Apply, as it states Apply and Snapshot are always called from the same thread. This means there is no need to synchronize this function with Execute(). However queries that involve a transaction must be blocked.
http://sqlite.org/howtocorrupt.html states it is safe to do this as long as no transaction is in progress.
func (*Store) State ¶
func (s *Store) State() ClusterState
State returns the current node's Raft state
func (*Store) WaitForApplied ¶
WaitForApplied waits for all Raft log entries to to be applied to the underlying database.
func (*Store) WaitForAppliedIndex ¶
WaitForAppliedIndex blocks until a given log index has been applied, or the timeout expires.
type StoreConfig ¶
type StoreConfig struct { DBConf *DBConfig // The DBConfig object for this Store. Dir string // The working directory for raft. Tn Transport // The underlying Transport for raft. ID string // Node ID. Logger *log.Logger // The logger to use to log stuff. }
StoreConfig represents the configuration of the underlying Store.
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport is the network service provided to Raft, and wraps a Listener.
func NewTransport ¶
NewTransport returns an initialized Transport.