Java Code Examples for io.atomix.protocols.raft.protocol.AppendResponse#lastLogIndex()

The following examples show how to use io.atomix.protocols.raft.protocol.AppendResponse#lastLogIndex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractAppender.java    From atomix with Apache License 2.0 5 votes vote down vote up
/**
 * Handles a {@link RaftResponse.Status#OK} response.
 */
protected void handleAppendResponseOk(RaftMemberContext member, AppendRequest request, AppendResponse response) {
  // Reset the member failure count and update the member's availability status if necessary.
  succeedAttempt(member);

  // If replication succeeded then trigger commit futures.
  if (response.succeeded()) {
    updateMatchIndex(member, response);

    // If there are more entries to send then attempt to send another commit.
    if (request.prevLogIndex() != response.lastLogIndex() && hasMoreEntries(member)) {
      appendEntries(member);
    }
  }
  // If we've received a greater term, update the term and transition back to follower.
  else if (response.term() > raft.getTerm()) {
    raft.setTerm(response.term());
    raft.setLeader(null);
    raft.transition(RaftServer.Role.FOLLOWER);
  }
  // If the response failed, the follower should have provided the correct last index in their log. This helps
  // us converge on the matchIndex faster than by simply decrementing nextIndex one index at a time.
  else {
    resetMatchIndex(member, response);
    resetNextIndex(member, response);
    resetSnapshotIndex(member, response);

    // If there are more entries to send then attempt to send another commit.
    if (response.lastLogIndex() != request.prevLogIndex() && hasMoreEntries(member)) {
      appendEntries(member);
    }
  }
}
 
Example 2
Source File: AbstractAppender.java    From atomix with Apache License 2.0 5 votes vote down vote up
/**
 * Resets the match index when a response fails.
 */
protected void resetMatchIndex(RaftMemberContext member, AppendResponse response) {
  if (response.lastLogIndex() < member.getMatchIndex()) {
    member.setMatchIndex(response.lastLogIndex());
    log.trace("Reset match index for {} to {}", member, member.getMatchIndex());
  }
}
 
Example 3
Source File: AbstractAppender.java    From atomix with Apache License 2.0 5 votes vote down vote up
/**
 * Resets the next index when a response fails.
 */
protected void resetNextIndex(RaftMemberContext member, AppendResponse response) {
  long nextIndex = response.lastLogIndex() + 1;
  if (member.getLogReader().getNextIndex() != nextIndex) {
    member.getLogReader().reset(nextIndex);
    log.trace("Reset next index for {} to {}", member, nextIndex);
  }
}