diff --git a/raft.go b/raft.go index 3357ae45..5b3c7fac 100644 --- a/raft.go +++ b/raft.go @@ -1075,17 +1075,22 @@ func (r *raft) Step(m pb.Message) error { r.id, last.term, last.index, r.Vote, m.Type, m.From, m.LogTerm, m.Index, r.Term, r.electionTimeout-r.electionElapsed) return nil } - } - switch { - case m.Type == pb.MsgPreVote: - // Never change our term in response to a PreVote - case m.Type == pb.MsgPreVoteResp && !m.Reject: + + if m.Type == pb.MsgPreVote { + // Never change our term in response to a PreVote + } else { + // m.Type == pb.MsgVote + r.logger.Infof("%x [term: %d] received a pb.MsgVote message with higher term from %x [term: %d]", + r.id, r.Term, m.From, m.Term) + r.becomeFollower(m.Term, None) + } + } else if m.Type == pb.MsgPreVoteResp && !m.Reject { // We send pre-vote requests with a term in our future. If the // pre-vote is granted, we will increment our term when we get a // quorum. If it is not, the term comes from the node that // rejected our vote so we should become a follower at the new // term. - default: + } else { r.logger.Infof("%x [term: %d] received a %s message with higher term from %x [term: %d]", r.id, r.Term, m.Type, m.From, m.Term) if m.Type == pb.MsgApp || m.Type == pb.MsgHeartbeat || m.Type == pb.MsgSnap {