Documentation
¶
Index ¶
Constants ¶
const ( // GRPCAddress defines the default address to run the grpc server GRPCAddress string = "127.0.0.1" // GRPCPort define the default port to run the grpc server GRPCPort uint16 = 50051 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Peer ¶
type Peer struct { // Address is the address of a peer node, must be just the ip or ip:port Address string // contains filtered or unexported fields }
type Rafty ¶
type Rafty struct { // LeaderLastContactDate is the last date we heard from the leader LeaderLastContactDate *time.Time // Logger expose zerolog so it can be override Logger *zerolog.Logger Status // PreCandidatePeers hold the list of the peers // that will be use to elect a new leader // if no leader has been detected PreCandidatePeers []Peer // Peers hold the list of the peers Peers []Peer // TimeMultiplier is a scaling factor that will be used during election timeout // by electionTimeoutMin/electionTimeoutMax/leaderHeartBeatTimeout in order to avoid cluster instability // The default value is 1 and the maximum is 10 TimeMultiplier uint // MinimumClusterSize is the size minimum to have before starting prevote or election campain // default is 3 // all members of the cluster will be contacted before any other tasks MinimumClusterSize uint64 // MaxAppendEntries will hold how much append entries the leader will send to the follower at once MaxAppendEntries uint64 // DataDir is the default data directory that will be used to store all data on the disk // Defaults to os.TempDir()/rafty ex: /tmp/rafty DataDir string // PersistDataOnDisk is a boolean that allow us to persist data on disk PersistDataOnDisk bool // contains filtered or unexported fields }
Rafty is a struct representing the raft requirements
func NewServer ¶
NewServer instantiate default configuration of the gRPC server and rafty to later start or stop it
func (*Rafty) SendGetLeaderRequest ¶
func (r *Rafty) SendGetLeaderRequest()
SendGetLeaderRequest allow the current node ask to other nodes who is the actual leader it also permit to get id of other nodes
func (*Rafty) Start ¶
Start permits to start the gRPC server with the provided configuration ready parameter is the channel that will be used by server to accept client requests
func (*Rafty) Stop ¶
func (r *Rafty) Stop()
Stop permits to stop the gRPC server and Rafty with the provided configuration
func (*Rafty) SubmitCommand ¶
type State ¶
type State uint32
State represent the current status of the raft server. The state can only be Leader, Candidate, Follower, ReadOnly, Down
const ( // Down state is a node that has been unreachable for a long period of time Down State = iota // ReadOnly state is a node that does not pariticipate into the voting campain // It's a passive node that issue no requests on his own but simply respond from the leader // This node can never become a follower ReadOnly // Follower state is a node that participate into the voting campain // It's a passive node that issue no requests on his own but simply respond from the leader // This node can become a Precandidate if all requirements are available Follower // Candidate state is a node that participate into the voting campain. // It can become a Leader Candidate // Leader state is a node that was previously a Candidate // It received the majority of the votes including itself and get elected as the Leader. // It will then handle all client requests // Writes requests can only be done on the leader Leader )
type Status ¶
type Status struct { // ID of the current raft server ID string // Address is the current address of the raft server Address net.TCPAddr // State of the current raft server // Can only be Leader, Candidate, Follower, ReadOnly, Down State // CurrentTerm is latest term seen during the voting campain CurrentTerm uint64 // CurrentCommitIndex is the index of the highest log entry know to be commited CurrentCommitIndex uint64 // LastApplied is the index of the highest log entry applied to the current raft server LastApplied uint64 }
Status of the raft server