in ratis-server/src/main/java/org/apache/ratis/server/leader/LogAppenderDefault.java [181:214]
private void handleReply(AppendEntriesReplyProto reply, long requestFirstIndex)
throws IllegalArgumentException {
if (reply != null) {
switch (reply.getResult()) {
case SUCCESS:
final long oldNextIndex = getFollower().getNextIndex();
final long nextIndex = reply.getNextIndex();
if (nextIndex < oldNextIndex) {
throw new IllegalStateException("nextIndex=" + nextIndex
+ " < oldNextIndex=" + oldNextIndex
+ ", reply=" + ServerStringUtils.toAppendEntriesReplyString(reply));
}
if (nextIndex > oldNextIndex) {
getFollower().updateMatchIndex(nextIndex - 1);
getFollower().increaseNextIndex(nextIndex);
getLeaderState().onFollowerSuccessAppendEntries(getFollower());
}
break;
case NOT_LEADER:
// check if should step down
onFollowerTerm(reply.getTerm());
break;
case INCONSISTENCY:
getFollower().setNextIndex(getNextIndexForInconsistency(requestFirstIndex, reply.getNextIndex()));
break;
case UNRECOGNIZED:
LOG.warn("{}: received {}", this, reply.getResult());
break;
default: throw new IllegalArgumentException("Unable to process result " + reply.getResult());
}
getLeaderState().onAppendEntriesReply(this, reply);
}
}