[ 
https://issues.apache.org/jira/browse/RATIS-998?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Glen Geng updated RATIS-998:
----------------------------
    Description: 
 

I assume that {{shouldWithholdVotes()}} is used to handle request vote request 
with higher candidate term from disruptive server, but currently it just 
ignored such requests, since it only take effect when {{(state.getCurrentTerm() 
>= candidateTerm)}} .

shouldWithholdVotes() should be triggered for handling higher term. If 
currentTerm is larger or equal to candidateTerm, just reject the request vote, 
no need further handling.

 

Current code is 
{code:java}
private boolean shouldWithholdVotes(long candidateTerm) {
  if (state.getCurrentTerm() < candidateTerm) {
    return false; 
  } else if (isLeader()) {
    return true; 
  } else {
    // following a leader and not yet timeout
    return isFollower() && state.hasLeader()
        && 
role.getFollowerState().map(FollowerState::shouldWithholdVotes).orElse(false);
  }
}
{code}
Modify to 
{code:java}
private boolean shouldWithholdVotes(long candidateTerm) {
  if (state.getCurrentTerm() >= candidateTerm) {
    return false; 
  } else if (isLeader()) {
    return true; 
  } else {
    // following a leader and not yet timeout
    return isFollower() && state.hasLeader()
        && 
role.getFollowerState().map(FollowerState::shouldWithholdVotes).orElse(false);
  }
}
{code}
 

  was:
 

shouldWithholdVotes() should be triggered for handling higher term. If 
currentTerm is larger or equal to candidateTerm, just reject the request vote, 
no need further handling.

 

Current code is 
{code:java}
private boolean shouldWithholdVotes(long candidateTerm) {
  if (state.getCurrentTerm() < candidateTerm) {
    return false; 
  } else if (isLeader()) {
    return true; 
  } else {
    // following a leader and not yet timeout
    return isFollower() && state.hasLeader()
        && 
role.getFollowerState().map(FollowerState::shouldWithholdVotes).orElse(false);
  }
}
{code}
Modify to 
{code:java}
private boolean shouldWithholdVotes(long candidateTerm) {
  if (state.getCurrentTerm() >= candidateTerm) {
    return false; 
  } else if (isLeader()) {
    return true; 
  } else {
    // following a leader and not yet timeout
    return isFollower() && state.hasLeader()
        && 
role.getFollowerState().map(FollowerState::shouldWithholdVotes).orElse(false);
  }
}
{code}
 


> shouldWithholdVotes() should be triggered for handling higher term
> ------------------------------------------------------------------
>
>                 Key: RATIS-998
>                 URL: https://issues.apache.org/jira/browse/RATIS-998
>             Project: Ratis
>          Issue Type: Bug
>          Components: server
>    Affects Versions: 0.5.0
>            Reporter: Glen Geng
>            Assignee: Glen Geng
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
>  
> I assume that {{shouldWithholdVotes()}} is used to handle request vote 
> request with higher candidate term from disruptive server, but currently it 
> just ignored such requests, since it only take effect when 
> {{(state.getCurrentTerm() >= candidateTerm)}} .
> shouldWithholdVotes() should be triggered for handling higher term. If 
> currentTerm is larger or equal to candidateTerm, just reject the request 
> vote, no need further handling.
>  
> Current code is 
> {code:java}
> private boolean shouldWithholdVotes(long candidateTerm) {
>   if (state.getCurrentTerm() < candidateTerm) {
>     return false; 
>   } else if (isLeader()) {
>     return true; 
>   } else {
>     // following a leader and not yet timeout
>     return isFollower() && state.hasLeader()
>         && 
> role.getFollowerState().map(FollowerState::shouldWithholdVotes).orElse(false);
>   }
> }
> {code}
> Modify to 
> {code:java}
> private boolean shouldWithholdVotes(long candidateTerm) {
>   if (state.getCurrentTerm() >= candidateTerm) {
>     return false; 
>   } else if (isLeader()) {
>     return true; 
>   } else {
>     // following a leader and not yet timeout
>     return isFollower() && state.hasLeader()
>         && 
> role.getFollowerState().map(FollowerState::shouldWithholdVotes).orElse(false);
>   }
> }
> {code}
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to