use of org.apache.ratis.proto.RaftProtos.AppendEntriesReplyProto in project incubator-ratis by apache.
the class LogAppenderDefault method run.
@Override
public void run() throws InterruptedException, IOException {
while (isRunning()) {
if (shouldSendAppendEntries()) {
SnapshotInfo snapshot = shouldInstallSnapshot();
if (snapshot != null) {
LOG.info("{}: followerNextIndex = {} but logStartIndex = {}, send snapshot {} to follower", this, getFollower().getNextIndex(), getRaftLog().getStartIndex(), snapshot);
final InstallSnapshotReplyProto r = installSnapshot(snapshot);
if (r != null) {
switch(r.getResult()) {
case NOT_LEADER:
onFollowerTerm(r.getTerm());
break;
case SUCCESS:
case SNAPSHOT_UNAVAILABLE:
case ALREADY_INSTALLED:
getFollower().setAttemptedToInstallSnapshot();
break;
default:
break;
}
}
// otherwise if r is null, retry the snapshot installation
} else {
final AppendEntriesReplyProto r = sendAppendEntriesWithRetries();
if (r != null) {
handleReply(r);
}
}
}
if (isRunning() && !hasAppendEntries()) {
getEventAwaitForSignal().await(getHeartbeatWaitTimeMs(), TimeUnit.MILLISECONDS);
}
getLeaderState().checkHealth(getFollower());
}
}
use of org.apache.ratis.proto.RaftProtos.AppendEntriesReplyProto in project incubator-ratis by apache.
the class LogAppenderDefault method sendAppendEntriesWithRetries.
/**
* Send an appendEntries RPC; retry indefinitely.
*/
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE")
private AppendEntriesReplyProto sendAppendEntriesWithRetries() throws InterruptedException, InterruptedIOException, RaftLogIOException {
int retry = 0;
AppendEntriesRequestProto request = null;
while (isRunning()) {
// keep retrying for IOException
try {
if (request == null || request.getEntriesCount() == 0) {
request = newAppendEntriesRequest(CallId.getAndIncrement(), false);
}
if (request == null) {
LOG.trace("{} no entries to send now, wait ...", this);
return null;
} else if (!isRunning()) {
LOG.info("{} is stopped. Skip appendEntries.", this);
return null;
}
getFollower().updateLastRpcSendTime(request.getEntriesCount() == 0);
final AppendEntriesReplyProto r = getServerRpc().appendEntries(request);
getFollower().updateLastRpcResponseTime();
getLeaderState().onFollowerCommitIndex(getFollower(), r.getFollowerCommit());
return r;
} catch (InterruptedIOException | RaftLogIOException e) {
throw e;
} catch (IOException ioe) {
// TODO should have more detailed retry policy here.
if (retry++ % 10 == 0) {
// to reduce the number of messages
LOG.warn("{}: Failed to appendEntries (retry={}): {}", this, retry++, ioe);
}
handleException(ioe);
}
if (isRunning()) {
getServer().properties().rpcSleepTime().sleep();
}
}
return null;
}
Aggregations