Documentation ¶
Index ¶
- Variables
- func CheckRaftConfig(conf raft.Configuration) error
- func RecoverNode(dir string, logs raft.LogStore, stable raft.StableStore, ...) error
- type Config
- type RaftStore
- type Store
- func (s *Store) Apply(l *raft.Log) interface{}
- func (s *Store) Close() error
- func (s *Store) Delete(key []byte) error
- func (s *Store) Get(key []byte) ([]byte, error)
- func (s *Store) GetConfig() (raft.Configuration, error)
- func (s *Store) GetServers() ([]*messages.Server, error)
- func (s *Store) IsLeader() bool
- func (s *Store) Join(id, addr string) error
- func (s *Store) LeaderAddr() string
- func (s *Store) LeaderID() (string, error)
- func (s *Store) Leave(id string) error
- func (s *Store) Put(key, value []byte) error
- func (f *Store) Restore(rc io.ReadCloser) error
- func (f *Store) Snapshot() (raft.FSMSnapshot, error)
- func (s *Store) WaitForLeader(timeout time.Duration) (string, error)
- type Transport
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTimeoutExpired is for when waiting for a leader node to be elected // we run out of the given timeout. ErrTimeoutExpired = errors.New("timeout expired") // ErrNotLeader is for when a voter/non-voter node tries to execute an action // that is leader-only. ErrNotLeader = errors.New("not leader") // ErrJoinSelf is for when a node tries to join itself. ErrJoinSelf = errors.New("trying to join self") // ErrValuesAreNil is for when either a key or value that are given to // raft.Apply are nil, even though they should contain []byte data. ErrValuesAreNil = errors.New("values are nil") )
Functions ¶
func CheckRaftConfig ¶
func CheckRaftConfig(conf raft.Configuration) error
CheckRaftConfig checks that a given raft config is valid. This is used for recovering a raft cluster.
func RecoverNode ¶
func RecoverNode(dir string, logs raft.LogStore, stable raft.StableStore, snaps raft.SnapshotStore, tn raft.Transport, conf raft.Configuration, ) error
RecoverNode tries to recover a Raft cluster from a given recovery configuration file.
Types ¶
type Config ¶
type Config struct { Bootstrap bool SnapshotThreshold uint64 StrongConsistency bool BindAddr string CommitTimeout time.Duration LocalID raft.ServerID HeartbeatTimeout time.Duration ElectionTimeout time.Duration LeaderLeaseTimeout time.Duration Transport *Transport }
Config contains the user-configurable values for the store.
type RaftStore ¶
type RaftStore interface { Get(key []byte) (val []byte, err error) Put(key []byte, val []byte) error Leave(id string) error Join(id, addr string) error GetServers() ([]*messages.Server, error) LeaderAddr() string }
RaftStore shows what methods a given Raft cluster should implement.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func New ¶
New creates a new instance of an store. It sets up the data directory, raft directory raft databases, internal database and raft connections. It also checks for possible recovery files to recover a failed cluster.
func (*Store) Delete ¶
Delete deletes the key-value pair with the given key. It is an leader-only operation.
func (*Store) Get ¶
Get finds a given key from the raft cluster. If StrongConsistency is enabled, the get request will be redirected to the leader node. Otherwise the value is read from the given node. Getting from a non-leader node means that the value might be old or non-existant.
func (*Store) GetConfig ¶
func (s *Store) GetConfig() (raft.Configuration, error)
GetConfig handles the GetConfiguration future and returns the raft config.
func (*Store) GetServers ¶
GetServers returns all of the servers that belong to the raft cluster.
func (*Store) Join ¶
Join handles a given node joining the whole raft cluster. The joining has to be done using the leader node.
func (*Store) LeaderAddr ¶
LeaderAddr returns the leader node address.
func (*Store) Restore ¶
func (f *Store) Restore(rc io.ReadCloser) error
Restore takes in the data created by snapshot.Persist() and creates the internal database based on that data.
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport handles communications between different raft nodes.
func NewTransport ¶
func (*Transport) Accept ¶
Accept acceps a given dial and checks that the RaftRPC identifier is defined at the start; if not then just return an error.