Documentation ¶
Index ¶
Constants ¶
const ( DefaultHeartbeatPort = 5901 DefaultReplicaPort = 5902 DefaultNumOfLogsToRetain = 20000 DefaultTickInterval = 300 DefaultElectionTick = 3 )
Constants for network port definition.
Variables ¶
var ( ErrNoSuchNode = errors.New("no such node") ErrIllegalAddress = errors.New("illegal address") ErrUnknownSocketType = errors.New("unknown socket type") )
Error definitions.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { NodeID uint64 // Identity of raft server instance. RaftPath string // Path of raft logs IPAddr string // IP address HeartbeatPort int ReplicaPort int NumOfLogsToRetain uint64 // number of logs to be kept after truncation. The default value is 20000. // TickInterval is the interval of timer which check heartbeat and election timeout. // The default value is 300,unit is millisecond. TickInterval int // RecvBufSize is the size of raft receive buffer channel. // The default value is 2048. RecvBufSize int // ElectionTick is the election timeout. If a follower does not receive any message // from the leader of current term during ElectionTick, it will become candidate and start an election. // ElectionTick must be greater than HeartbeatTick. // We suggest to use ElectionTick = 10 * HeartbeatTick to avoid unnecessary leader switching. // The default value is 1s. ElectionTick int }
Config defines the configuration properties for the raft store.
type NodeManager ¶
type NodeManager interface { // add node address with specified port. AddNodeWithPort(nodeID uint64, addr string, heartbeat int, replicate int) // delete node address information DeleteNode(nodeID uint64) }
NodeManager defines the necessary methods for node address management.
type NodeResolver ¶
type NodeResolver interface { raft.SocketResolver NodeManager }
NodeResolver defines the methods for node address resolving and management. It is extended from SocketResolver and NodeManager.
func NewNodeResolver ¶
func NewNodeResolver() NodeResolver
NewNodeResolver returns a new NodeResolver instance for node address management and resolving.
type Partition ¶
type Partition interface { // Submit submits command data to raft log. Submit(cmd []byte) (resp interface{}, err error) // ChangeMember submits member change event and information to raft log. ChangeMember(changeType proto.ConfChangeType, peer proto.Peer, context []byte) (resp interface{}, err error) // Stop removes the raft partition from raft server and shuts down this partition. Stop() error // Delete stops and deletes the partition. Delete() error // Status returns the current raft status. Status() (status *PartitionStatus) // IsRestoring Much faster then status().RestoringSnapshot. IsRestoring() bool // LeaderTerm returns the current term of leader in the raft group. TODO what is term? LeaderTerm() (leaderID, term uint64) // IsRaftLeader returns true if this node is the leader of the raft group it belongs to. IsRaftLeader() bool // AppliedIndex returns the current index of the applied raft log in the raft store partition. AppliedIndex() uint64 // CommittedIndex returns the current index of the applied raft log in the raft store partition. CommittedIndex() uint64 // Truncate raft log Truncate(index uint64) TryToLeader(nodeID uint64) error IsOfflinePeer() bool }
Partition wraps necessary methods for raft store partition operation. Partition is a shard for multi-raft in RaftSore. RaftStore is based on multi-raft which manages multiple raft replication groups at same time through a single raft server instance and system resource.
type PartitionConfig ¶
type PartitionConfig struct { ID uint64 Applied uint64 Leader uint64 Term uint64 Peers []PeerAddress SM PartitionFsm WalPath string }
PartitionConfig defines the configuration properties for the partitions.
type PartitionFsm ¶
type PartitionFsm = raft.StateMachine
PartitionFsm wraps necessary methods include both FSM implementation and data storage operation for raft store partition. It extends from raft StateMachine and Store.
type PartitionStatus ¶
PartitionStatus is a type alias of raft.Status
type PeerAddress ¶
PeerAddress defines the set of addresses that will be used by the peers.
func (PeerAddress) String ¶ added in v1.4.0
func (p PeerAddress) String() string
type RaftStore ¶
type RaftStore interface { CreatePartition(cfg *PartitionConfig) (Partition, error) Stop() RaftConfig() *raft.Config RaftStatus(raftID uint64) (raftStatus *raft.Status) NodeManager RaftServer() *raft.RaftServer }
RaftStore defines the interface for the raft store.
func NewRaftStore ¶
func NewRaftStore(cfg *Config, extendCfg *utilConfig.Config) (mr RaftStore, err error)
NewRaftStore returns a new raft store instance.