Documentation ¶
Index ¶
- Variables
- type Address
- type AppendEntriesReq
- type AppendEntriesResp
- type Candidate
- type Cluster
- type CmdReq
- type CmdResp
- type Command
- type Config
- type ConfigChangeCmd
- type Entry
- type Follower
- type Index
- type Leader
- type Msg
- type MsgType
- type RaftBase
- type RaftObject
- type RequestVoteReq
- type RequestVoteResp
- type StateMachine
- type Term
- type TermHolder
- type TimeoutNowReq
Constants ¶
This section is empty.
Variables ¶
View Source
var InvalidEntry = Entry{ Term: InvalidTerm, Idx: InvalidIndex, Cmd: "", }
View Source
var NullMsg = Msg{Tp: Null}
Functions ¶
This section is empty.
Types ¶
type Address ¶
type Address string
const All Address = "All"
const Composed Address = "Composed"
const InvalidId Address = "InvalidId"
type AppendEntriesReq ¶
type AppendEntriesReq struct { Term Term LeaderId Address PrevLogIndex Index PrevLogTerm Term Entries []Entry LeaderCommit Index }
func (*AppendEntriesReq) GetTerm ¶
func (th *AppendEntriesReq) GetTerm() Term
type AppendEntriesResp ¶
func (*AppendEntriesResp) GetTerm ¶
func (th *AppendEntriesResp) GetTerm() Term
type Candidate ¶
type Candidate struct { RaftBase // contains filtered or unexported fields }
func NewCandidate ¶
func (*Candidate) TakeAction ¶
type ConfigChangeCmd ¶
ConfigChangeCmd save the current and previous config snapshot
The main reason of not use rpc like {Op: Add/Remove, Address: "some-addr"}
is that:
ConfigChangeCmd act as an Entry to replicate self all across the cluster,
we can hardly to maintain this special Entry will be applied only once (unlike other Entries, ConfigChangeCmd must apply before commit). Obviously stateless cmd is more robust than stateful. (just like declarative vs. imperative)
type Follower ¶
type Follower struct{ RaftBase }
func NewFollower ¶
func NewFollower(cfg Config, sm StateMachine) *Follower
func (*Follower) TakeAction ¶
type Index ¶
type Index int64
const InvalidIndex Index = 0
InvalidIndex is the init value of any indexes. First valid index is 1.
type Leader ¶
type Leader struct { RaftBase // contains filtered or unexported fields }
func (*Leader) TakeAction ¶
type RaftBase ¶
type RaftBase struct {
// contains filtered or unexported fields
}
func (*RaftBase) GetAllEntries ¶
func (*RaftBase) GetCluster ¶
type RaftObject ¶
type RequestVoteReq ¶
type RequestVoteReq struct { Term Term CandidateId Address LastLogIndex Index LastLogTerm Term LeaderTransfer bool }
func (*RequestVoteReq) GetTerm ¶
func (th *RequestVoteReq) GetTerm() Term
type RequestVoteResp ¶
func (*RequestVoteResp) GetTerm ¶
func (th *RequestVoteResp) GetTerm() Term
type StateMachine ¶
type StateMachine interface {
Exec(cmd Command) interface{}
}
type Term ¶
type Term int64
const InvalidTerm Term = 0
InvalidTerm is the init value of term, which will become 1 after first follower turn to candidate.
type TermHolder ¶
type TermHolder interface {
GetTerm() Term
}
type TimeoutNowReq ¶
type TimeoutNowReq struct {
Term Term
}
func (*TimeoutNowReq) GetTerm ¶
func (th *TimeoutNowReq) GetTerm() Term
Click to show internal directories.
Click to hide internal directories.