Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

etcdserver/raft.go: separate raft tick and ready #16847

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading