Skip to content

Commit

Permalink
etcdserver/raft.go: separate raft tick and ready
Browse files Browse the repository at this point in the history
Signed-off-by: Chao Chen <[email protected]>
  • Loading branch information
chaochn47 committed Oct 30, 2023
1 parent 5fad87c commit 459b66f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion server/etcdserver/api/v3rpc/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func monitorLeader(s *etcdserver.EtcdServer) *streamsMap {
case <-s.StoppingNotify():
return
case <-time.After(election):
if s.Leader() == types.ID(raft.None) {
if s.RaftStatus().Lead == raft.None {
noLeaderCnt++
} else {
noLeaderCnt = 0
Expand Down
13 changes: 11 additions & 2 deletions server/etcdserver/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,23 @@ func (r *raftNode) tick() {
func (r *raftNode) start(rh *raftReadyHandler) {
internalTimeout := time.Second

go func() {
for {
select {
case <-r.ticker.C:
r.tick()
case <-r.done:
return
}
}
}()

go func() {
defer r.onStop()
islead := false

for {
select {
case <-r.ticker.C:
r.tick()
case rd := <-r.Ready():
if rd.SoftState != nil {
newLeader := rd.SoftState.Lead != raft.None && rh.getLead() != rd.SoftState.Lead
Expand Down
8 changes: 4 additions & 4 deletions server/etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1492,9 +1492,9 @@ func (s *EtcdServer) isLearnerReady(id uint64) error {
return err
}

rs := s.raftStatus()
rs := s.RaftStatus()

// leader's raftStatus.Progress is not nil
// leader's RaftStatus.Progress is not nil
if rs.Progress == nil {
return errors.ErrNotLeader
}
Expand Down Expand Up @@ -2451,8 +2451,8 @@ func (s *EtcdServer) IsMemberExist(id types.ID) bool {
return s.cluster.IsMemberExist(id)
}

// raftStatus returns the raft status of this etcd node.
func (s *EtcdServer) raftStatus() raft.Status {
// RaftStatus returns the raft status of this etcd node.
func (s *EtcdServer) RaftStatus() raft.Status {
return s.r.Node.Status()
}

Expand Down

0 comments on commit 459b66f

Please sign in to comment.