JacksonYao287 edited a comment on pull request #500:
URL: https://github.com/apache/ratis/pull/500#issuecomment-921432428


   @szetszwo thanks for the review!
   >In requestVote(..), the leader recognizes a candidate only if the candidate 
has a higher term. Therefore, the leader should change to follower even if it 
will reject the vote from the candidate.
   
   yes , so , we can say that when the leader rejects a vote, it means the 
candidate must have a term lower or equal than the leader. if a candidate has a 
higher term, the leader should vote for it and step down to follower. 
   
   so my point is that , before `changeToFollower` , we should check whether 
vote is granted.
   if vote is granted , it means the candidate has a higher term , so it make 
sense to `changeToFollower`
   if vote is not granted, it means the candidate has a equal or lower term,  
`changeToFollower` should not be called.
   so there does not exist any case that the leader reject the vote and 
meanwhile `changeToFollower`.
   
   pleaser see the attached log below which i have uploaded in this jira.
   ```
   2021-09-15 18:21:07,529 [grpc-default-executor-617] INFO 
org.apache.ratis.server.impl.VoteContext: 
a075f477-2523-4b79-991f-ecbe8ee00d0d@group-8BCFDCD73BCA-LEADER: reject ELECTION 
from b7bb63db-f11b-49c0-8269-2acf98d5fdd6: our last entry (t:3, i:432782) > 
candidate's last entry (t:3, i:302053)
   2021-09-15 18:21:07,529 [grpc-default-executor-617] INFO 
org.apache.ratis.server.RaftServer$Division: 
a075f477-2523-4b79-991f-ecbe8ee00d0d@group-8BCFDCD73BCA: change Leader from 
a075f477-2523-4b79-991f-ecbe8ee00d0d to null at term 4 for updateCurrentTerm
   2021-09-15 18:21:07,529 [grpc-default-executor-617] INFO 
org.apache.ratis.server.RaftServer$Division: 
a075f477-2523-4b79-991f-ecbe8ee00d0d@group-8BCFDCD73BCA: changes role from    
LEADER to FOLLOWER at term 4 for candidate:b7bb63db-f11b-49c0-8269-2acf98d5fdd6
   ```
   it show that the leader reject the vote because the candidate has a less 
up-to-date log(same term, but smaller index). after    this rejection, the 
leader does not check whether the candidate has a higher term(voteGranted), and 
just go ahead to call `changeToFollower`,in which `state.updateCurrentTerm` is 
called.  so , this is what the current patch fixed


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to