Documentation ¶
Index ¶
- Constants
- Variables
- func NewBigcache() (*bigcache.BigCache, error)
- func NewFastcache(maxbytes int) *fastcache.Cache
- type Cache
- type Config
- type Store
- func (s *Store) Apply(l *raft.Log) interface{}
- func (s *Store) Close() error
- func (s *Store) Get(key string) ([]byte, error)
- func (s *Store) GetServers() ([]*pb.Server, error)
- func (s *Store) Join(id, addr string) error
- func (s *Store) JoinNonVoter(id, addr string) error
- func (s *Store) LeaderAddr() string
- func (s *Store) Leave(id string) error
- func (s *Store) Restore(rc io.ReadCloser) error
- func (s *Store) Set(key string, value []byte) error
- func (s *Store) Snapshot() (raft.FSMSnapshot, error)
- func (s *Store) Stepdown(wait bool) error
- func (s *Store) WaitForLeader(t time.Duration) (string, error)
- type Transport
Constants ¶
const ( // SetOperation is for handling set operations in raft_apply. SetOperation byte = iota // GetOperation is for handling get operations in raft_apply. GetOperation )
Variables ¶
var ErrJoiningSelf = errors.New("trying to join self")
ErrJoiningSelf represents the situation where a node tries to join itself.
Functions ¶
func NewBigcache ¶
func NewBigcache() (*bigcache.BigCache, error)
NewBigcache creates a big cache interface that implements the Cache interface. Bigcache is slower but can store entries that are larger. While fastcache is suitable for smaller entries and at the same time a bit faster.
func NewFastcache ¶
Types ¶
type Config ¶
type Config struct { DataDir string BindAddr string Bootstrap bool LocalID raft.ServerID SnapshotThreshold uint64 StrongConsistency bool // Timeouts HeartbeatTimeout time.Duration ElectionTimeout time.Duration CommitTimeout time.Duration LeaderLeaseTimeout time.Duration Transport *Transport }
Config represents all of the user configurable fields for the Raft node. Note that without setting these defaults are also fine. Only Transport and LocalID are important.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store represents a Raft node. It also implements the FSM interface that raft provides. So we can directly modify the cache stored in this struct.
func (*Store) Apply ¶
Apply handles the applyRequest made by the createApplyReq function. It returns a applyResult struct such that handler functions can properly handle the given error.
func (*Store) Get ¶
Get finds a value with a given key either from this node's cache, or the leader. If the value is retrieved from a non-leader node, we risk the chance of the value not existing, or being old. On the other hand, request the value from the leader adds a lot of overhead.
func (*Store) GetServers ¶
GetServers returns the server currently present in the node.
func (*Store) Join ¶
Join adds a node with 'id' and 'addr' into the raft cluster. The address is the raft bind address of the node.
func (*Store) JoinNonVoter ¶
JoinNonVoter adds a node that cannot write into the cluster. These are useful for adding more reability to reads.
func (*Store) LeaderAddr ¶
LeaderAddr returns the raft bind address of the leader node.
func (*Store) Leave ¶
Leave removes a node from the cluster with the given id. This function is called by registry to let the raft node know that a node has left the cluster and that raft should not try to contact it anymore.
func (*Store) Restore ¶
func (s *Store) Restore(rc io.ReadCloser) error
Restore takes in the bytes generated by snapshot.Persist() and parses the cache state from that.
func (*Store) Set ¶
Set applies a given key-value pair into the raft cluster. Since writing a key is a leader-only operation, we need to check for that as well.
func (*Store) Snapshot ¶
func (s *Store) Snapshot() (raft.FSMSnapshot, error)
Snapshot takes a snapshot of the current finite state machine and logs the time so we can see how long a snapshot process took.
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport handles communications between different raft nodes.
func NewTLSTransport ¶
NewTLSTransport creates a transport instance with the tls fields populated.
func NewTransport ¶
NewTransport creates a new transport instance.
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.