mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: add progress into status
This commit is contained in:
parent
0eaaad0e48
commit
b34936b097
16
raft/node.go
16
raft/node.go
@ -192,7 +192,7 @@ type node struct {
|
||||
tickc chan struct{}
|
||||
done chan struct{}
|
||||
stop chan struct{}
|
||||
status chan Status
|
||||
status chan chan Status
|
||||
}
|
||||
|
||||
func newNode() node {
|
||||
@ -206,7 +206,7 @@ func newNode() node {
|
||||
tickc: make(chan struct{}),
|
||||
done: make(chan struct{}),
|
||||
stop: make(chan struct{}),
|
||||
status: make(chan Status),
|
||||
status: make(chan chan Status),
|
||||
}
|
||||
}
|
||||
|
||||
@ -234,11 +234,8 @@ func (n *node) run(r *raft) {
|
||||
lead := None
|
||||
prevSoftSt := r.softState()
|
||||
prevHardSt := r.HardState
|
||||
status := &Status{ID: r.id}
|
||||
|
||||
for {
|
||||
status.update(r)
|
||||
|
||||
if advancec != nil {
|
||||
readyc = nil
|
||||
} else {
|
||||
@ -334,7 +331,8 @@ func (n *node) run(r *raft) {
|
||||
}
|
||||
r.raftLog.stableSnapTo(prevSnapi)
|
||||
advancec = nil
|
||||
case n.status <- status.get():
|
||||
case c := <-n.status:
|
||||
c <- getStatus(r)
|
||||
case <-n.stop:
|
||||
close(n.done)
|
||||
return
|
||||
@ -414,7 +412,11 @@ func (n *node) ApplyConfChange(cc pb.ConfChange) *pb.ConfState {
|
||||
return &cs
|
||||
}
|
||||
|
||||
func (n *node) Status() Status { return <-n.status }
|
||||
func (n *node) Status() Status {
|
||||
c := make(chan Status)
|
||||
n.status <- c
|
||||
return <-c
|
||||
}
|
||||
|
||||
func newReady(r *raft, prevSoftSt *SoftState, prevHardSt pb.HardState) Ready {
|
||||
rd := Ready{
|
||||
|
@ -16,27 +16,33 @@
|
||||
|
||||
package raft
|
||||
|
||||
import (
|
||||
pb "github.com/coreos/etcd/raft/raftpb"
|
||||
)
|
||||
|
||||
type Status struct {
|
||||
ID uint64
|
||||
|
||||
Lead uint64
|
||||
Term uint64
|
||||
Vote uint64
|
||||
pb.HardState
|
||||
SoftState
|
||||
|
||||
AppliedIndex uint64
|
||||
CommitIndex uint64
|
||||
Applied uint64
|
||||
Progress map[uint64]progress
|
||||
}
|
||||
|
||||
func (s *Status) update(r *raft) {
|
||||
s.Lead = r.lead
|
||||
s.Term = r.Term
|
||||
s.Vote = r.Vote
|
||||
func getStatus(r *raft) Status {
|
||||
s := Status{ID: r.id}
|
||||
s.HardState = r.HardState
|
||||
s.SoftState = *r.softState()
|
||||
|
||||
s.AppliedIndex = r.raftLog.applied
|
||||
s.CommitIndex = r.raftLog.committed
|
||||
}
|
||||
s.Applied = r.raftLog.applied
|
||||
|
||||
func (s *Status) get() Status {
|
||||
ns := *s
|
||||
return ns
|
||||
if s.RaftState == StateLeader {
|
||||
s.Progress = make(map[uint64]progress)
|
||||
for id, p := range r.prs {
|
||||
s.Progress[id] = *p
|
||||
}
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user