|
@@ -183,6 +183,17 @@ func (r *raft) softState() *SoftState {
|
|
|
return &SoftState{Lead: r.lead, RaftState: r.state, Nodes: r.nodes()}
|
|
return &SoftState{Lead: r.lead, RaftState: r.state, Nodes: r.nodes()}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func (r *raft) q() int { return len(r.prs)/2 + 1 }
|
|
|
|
|
+
|
|
|
|
|
+func (r *raft) nodes() []uint64 {
|
|
|
|
|
+ nodes := make([]uint64, 0, len(r.prs))
|
|
|
|
|
+ for k := range r.prs {
|
|
|
|
|
+ nodes = append(nodes, k)
|
|
|
|
|
+ }
|
|
|
|
|
+ sort.Sort(uint64Slice(nodes))
|
|
|
|
|
+ return nodes
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// send persists state to stable storage and then sends to its mailbox.
|
|
// send persists state to stable storage and then sends to its mailbox.
|
|
|
func (r *raft) send(m pb.Message) {
|
|
func (r *raft) send(m pb.Message) {
|
|
|
m.From = r.id
|
|
m.From = r.id
|
|
@@ -293,8 +304,6 @@ func (r *raft) reset(term uint64) {
|
|
|
r.pendingConf = false
|
|
r.pendingConf = false
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (r *raft) q() int { return len(r.prs)/2 + 1 }
|
|
|
|
|
-
|
|
|
|
|
func (r *raft) appendEntry(e pb.Entry) {
|
|
func (r *raft) appendEntry(e pb.Entry) {
|
|
|
e.Term = r.Term
|
|
e.Term = r.Term
|
|
|
e.Index = r.raftLog.lastIndex() + 1
|
|
e.Index = r.raftLog.lastIndex() + 1
|
|
@@ -599,15 +608,6 @@ func (r *raft) needSnapshot(i uint64) bool {
|
|
|
return i < r.raftLog.firstIndex()
|
|
return i < r.raftLog.firstIndex()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (r *raft) nodes() []uint64 {
|
|
|
|
|
- nodes := make([]uint64, 0, len(r.prs))
|
|
|
|
|
- for k := range r.prs {
|
|
|
|
|
- nodes = append(nodes, k)
|
|
|
|
|
- }
|
|
|
|
|
- sort.Sort(uint64Slice(nodes))
|
|
|
|
|
- return nodes
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
// promotable indicates whether state machine can be promoted to leader,
|
|
// promotable indicates whether state machine can be promoted to leader,
|
|
|
// which is true when its own id is in progress list.
|
|
// which is true when its own id is in progress list.
|
|
|
func (r *raft) promotable() bool {
|
|
func (r *raft) promotable() bool {
|