Uploaded image for project: 'Ratis'
  1. Ratis
  2. RATIS-1268

Fix leader can not vote for candidate

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 2.0.0
    • None
    • None

    Description

      What's the problem ?
      For example, when s0 is leader, and s1 askForVote, in the first rpc of askForVote, s0 can not vote for s1, even though s1's log catch up. When s1 askForVote the second time, s0 has become follower in the first askForVote, so s0 can vote for s1, waste one rpc call.

      What's the reason ?
      As the following code shows, when s0 is leader, role.getFollowerState().orElse(null) should return null,
      then can not pass check if (fs != null && candidate != null) because fs is null, so s0 can not vote for s1.

            FollowerState fs = role.getFollowerState().orElse(null);
            if (shouldWithholdVotes(candidateTerm)) {
              ...
            } else if (state.recognizeCandidate(candidateId, candidateTerm)) {
              final boolean termUpdated = changeToFollower(candidateTerm, true, "recognizeCandidate:" + candidateId);
              RaftPeer candidate = getRaftConf().getPeer(candidateId);
              if (fs != null && candidate != null) {
               ...
             }
      

      How to fix ?

      After leader final boolean termUpdated = changeToFollower(candidateTerm, true, "recognizeCandidate:" + candidateId);, we can get fs again.

      Attachments

        Issue Links

          Activity

            People

              yjxxtd runzhiwang
              yjxxtd runzhiwang
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h 50m
                  1h 50m