Documentation ¶
Index ¶
- Variables
- func HasData(dir string) (bool, error)
- func IsNewNode(raftDir string) bool
- func IsStaleRead(leaderlastContact time.Time, lastFSMUpdateTime time.Time, ...) bool
- type Atomic
- type AtomicTime
- type CheckAndSet
- type ClusterState
- type Database
- type FSM
- type SnapshotStore
- type Storage
- type Store
- func (s *Store) Addr() string
- func (s *Store) Aggregate(ctx context.Context, req *v1.Aggregate_Request) (*v1.Aggregate_Response, error)
- func (s *Store) Backup(ctx context.Context, br *v1.Backup_Request, dst io.Writer) error
- func (s *Store) Bootstrap(ctx context.Context, ls *v1.Server_List) error
- func (s *Store) Breakdown(ctx context.Context, req *v1.BreakDown_Request) (*v1.BreakDown_Response, error)
- func (s *Store) Close() (retErr error)
- func (s *Store) CommitIndex(ctx context.Context) (uint64, error)
- func (s *Store) Committed(ctx context.Context) (uint64, error)
- func (s *Store) Data(ctx context.Context, req *v1.Data) error
- func (s *Store) HasLeader() bool
- func (s *Store) ID() string
- func (s *Store) IsLeader() bool
- func (s *Store) IsVoter() (bool, error)
- func (s *Store) Join(ctx context.Context, jr *v1.Join_Request) error
- func (s *Store) LeaderAddr(_ context.Context) (string, error)
- func (s *Store) LeaderCommitIndex() (uint64, error)
- func (s *Store) Load(ctx context.Context, req *v1.Load_Request) error
- func (s *Store) Nodes(ctx context.Context) (*v1.Server_List, error)
- func (s *Store) Notify(ctx context.Context, nr *v1.Notify_Request) error
- func (s *Store) Open(ctx context.Context) error
- func (s *Store) Path() string
- func (s *Store) ReadFrom(ctx context.Context, r io.Reader) (int64, error)
- func (s *Store) Ready(ctx context.Context) bool
- func (s *Store) Realtime(ctx context.Context, req *v1.Realtime_Request) (*v1.Realtime_Response, error)
- func (s *Store) Remove(ctx context.Context, rn *v1.RemoveNode_Request) error
- func (s *Store) Snapshot(n uint64) (retError error)
- func (s *Store) State() ClusterState
- func (s *Store) Status() (*v1.Status_Store, error)
- func (s *Store) Timeseries(ctx context.Context, req *v1.Timeseries_Request) (*v1.Timeseries_Response, error)
- func (s *Store) WaitForAllApplied(timeout time.Duration) error
- func (s *Store) WaitForAppliedFSM(timeout time.Duration) (uint64, error)
- func (s *Store) WaitForAppliedIndex(idx uint64, timeout time.Duration) error
- func (s *Store) WaitForCommitIndex(ctx context.Context, idx uint64) error
- func (s *Store) WaitForFSMIndex(idx uint64, timeout time.Duration) (uint64, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotOpen is returned when a Store is not open. ErrNotOpen = errors.New("store not open") // ErrOpen is returned when a Store is already open. ErrOpen = errors.New("store already open") // ErrNotReady is returned when a Store is not ready to accept requests. ErrNotReady = errors.New("store not ready") // ErrNotLeader is returned when a node attempts to execute a leader-only // operation. ErrNotLeader = errors.New("not leader") // ErrNotSingleNode is returned when a node attempts to execute a single-node // only operation. ErrNotSingleNode = errors.New("not single-node") // 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") // ErrWaitForRemovalTimeout is returned when the Store does not confirm removal // of a node within the specified time. ErrWaitForRemovalTimeout = errors.New("timeout waiting for node removal confirmation") // ErrWaitForLeaderTimeout is returned when the Store cannot determine the leader // within the specified time. ErrWaitForLeaderTimeout = errors.New("timeout waiting for leader") // ErrInvalidBackupFormat is returned when the requested backup format // is not valid. ErrInvalidBackupFormat = errors.New("invalid backup format") // ErrInvalidVacuumFormat is returned when the requested backup format is not // compatible with vacuum. ErrInvalidVacuum = errors.New("invalid vacuum") // ErrLoadInProgress is returned when a load is already in progress and the // requested operation cannot be performed. ErrLoadInProgress = errors.New("load in progress") )
var ( // ErrCASConflict is returned when a CAS operation fails. ErrCASConflict = errors.New("CAS conflict") )
Functions ¶
func HasData ¶
HasData returns true if the given dir indicates that at least one FSM entry has been committed to the log. This is true if there are any snapshots, or if there are any entries in the log of raft.LogCommand type. This function will block if the Bolt database is already open.
Types ¶
type AtomicTime ¶
func (*AtomicTime) Add ¶
func (a *AtomicTime) Add(t time.Duration)
func (*AtomicTime) Sub ¶
func (a *AtomicTime) Sub(t *AtomicTime) time.Duration
type CheckAndSet ¶
type CheckAndSet struct {
// contains filtered or unexported fields
}
CheckAndSet is a simple concurrency control mechanism that allows only one goroutine to execute a critical section at a time.
func (*CheckAndSet) Begin ¶
func (c *CheckAndSet) Begin() error
Begin attempts to enter the critical section. If another goroutine is already in the critical section, Begin returns an error.
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 Database ¶
type Database interface { Data(ctx context.Context, req *v1.Data) error Realtime(ctx context.Context, req *v1.Realtime_Request) (*v1.Realtime_Response, error) Aggregate(ctx context.Context, req *v1.Aggregate_Request) (*v1.Aggregate_Response, error) Timeseries(ctx context.Context, req *v1.Timeseries_Request) (*v1.Timeseries_Response, error) Breakdown(ctx context.Context, req *v1.BreakDown_Request) (*v1.BreakDown_Response, error) Load(ctx context.Context, req *v1.Load_Request) error }
type SnapshotStore ¶
type SnapshotStore interface { raft.SnapshotStore // FullNeeded returns true if a full snapshot is needed. FullNeeded() (bool, error) // SetFullNeeded explicitly sets that a full snapshot is needed. SetFullNeeded() error }
type Storage ¶
type Storage interface { Database Committed(ctx context.Context) (uint64, error) CommitIndex(ctx context.Context) (uint64, error) // Remove removes the node from the cluster. Remove(ctx context.Context, rn *v1.RemoveNode_Request) error // LeaderAddr returns the Raft address of the leader of the cluster. LeaderAddr(ctx context.Context) (string, error) // Ready returns whether the Store is ready to service requests. Ready(ctx context.Context) bool // Nodes returns the slice of store.Servers in the cluster Nodes(ctx context.Context) (*v1.Server_List, error) // Backup writes backup of the node state to dst Backup(ctx context.Context, br *v1.Backup_Request, dst io.Writer) error // ReadFrom reads and loads a SQLite database into the node, initially bypassing // the Raft system. It then triggers a Raft snapshot, which will then make // Raft aware of the new data. ReadFrom(ctx context.Context, r io.Reader) (int64, error) Join(ctx context.Context, jr *v1.Join_Request) error Notify(ctx context.Context, nr *v1.Notify_Request) error Status() (*v1.Status_Store, error) }
Storage is the interface the Raft-based database must implement.
type Store ¶
type Store struct { BootstrapExpect int ShutdownOnRemove bool SnapshotThreshold uint64 SnapshotThresholdWALSize uint64 SnapshotInterval time.Duration LeaderLeaseTimeout time.Duration HeartbeatTimeout time.Duration ElectionTimeout time.Duration ApplyTimeout time.Duration RaftLogLevel string NoFreeListSync bool AutoVacInterval time.Duration // contains filtered or unexported fields }
func (*Store) Aggregate ¶
func (s *Store) Aggregate(ctx context.Context, req *v1.Aggregate_Request) (*v1.Aggregate_Response, error)
func (*Store) Bootstrap ¶
Bootstrap executes a cluster bootstrap on this node, using the given Servers as the configuration.
func (*Store) Breakdown ¶
func (s *Store) Breakdown(ctx context.Context, req *v1.BreakDown_Request) (*v1.BreakDown_Response, error)
func (*Store) CommitIndex ¶
CommitIndex returns the Raft commit index.
func (*Store) Committed ¶
Committed blocks until the local commit index is greater than or equal to the Leader index, as checked when the function is called. It returns the committed index. If the Leader index is 0, then the system waits until the commit index is at least 1.
func (*Store) IsVoter ¶
IsVoter returns true if the current node is a voter in the cluster. If there is no reference to the current node in the current cluster configuration then false will also be returned.
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 or if the Store is not open.
func (*Store) LeaderCommitIndex ¶
LeaderCommitIndex returns the Raft leader commit index, as indicated by the latest AppendEntries RPC. If this node is the Leader then the commit index is returned directly from the Raft object.
func (*Store) Notify ¶
Notify notifies this Store that a node is ready for bootstrapping at the given address. Once the number of known nodes reaches the expected level bootstrapping will be attempted using this Store. "Expected level" includes this node, so this node must self-notify to ensure the cluster bootstraps with the *advertised Raft address* which the Store doesn't know about.
Notifying is idempotent. A node may repeatedly notify the Store without issue.
func (*Store) ReadFrom ¶
ReadFrom reads data from r, and loads it into the database, bypassing Raft consensus. Once the data is loaded, a snapshot is triggered, which then results in a system as if the data had been loaded through Raft consensus.
func (*Store) Ready ¶
Ready returns true if the store is ready to serve requests. Ready is defined as having no open channels registered via RegisterReadyChannel and having a Leader.
func (*Store) Realtime ¶
func (s *Store) Realtime(ctx context.Context, req *v1.Realtime_Request) (*v1.Realtime_Response, error)
func (*Store) Snapshot ¶
Snapshot performs a snapshot, leaving n trailing logs behind. If n is greater than zero, that many logs are left in the log after snapshotting. If n is zero, then the number set at Store creation is used. Finally, once this function returns, the trailing log configuration value is reset to the value set at Store creation.
func (*Store) State ¶
func (s *Store) State() ClusterState
State returns the current node's Raft state
func (*Store) Timeseries ¶
func (s *Store) Timeseries(ctx context.Context, req *v1.Timeseries_Request) (*v1.Timeseries_Response, error)
func (*Store) WaitForAllApplied ¶
WaitForApplied waits for all Raft log entries to be applied to the underlying database.
func (*Store) WaitForAppliedFSM ¶
WaitForAppliedFSM waits until the currently applied logs (at the time this function is called) are actually reflected by the FSM, or the timeout expires.
func (*Store) WaitForAppliedIndex ¶
WaitForAppliedIndex blocks until a given log index has been applied, or the timeout expires.
func (*Store) WaitForCommitIndex ¶
WaitForCommitIndex blocks until the local Raft commit index is equal to or greater the given index, or the timeout expires.