use of org.apache.ratis.proto.RaftProtos.InstallSnapshotReplyProto 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.InstallSnapshotReplyProto in project incubator-ratis by apache.
the class LogAppenderDefault method installSnapshot.
private InstallSnapshotReplyProto installSnapshot(SnapshotInfo snapshot) throws InterruptedIOException {
String requestId = UUID.randomUUID().toString();
InstallSnapshotReplyProto reply = null;
try {
for (InstallSnapshotRequestProto request : newInstallSnapshotRequests(requestId, snapshot)) {
getFollower().updateLastRpcSendTime(false);
reply = getServerRpc().installSnapshot(request);
getFollower().updateLastRpcResponseTime();
if (!reply.getServerReply().getSuccess()) {
return reply;
}
}
} catch (InterruptedIOException iioe) {
throw iioe;
} catch (Exception ioe) {
LOG.warn("{}: Failed to installSnapshot {}: {}", this, snapshot, ioe);
handleException(ioe);
return null;
}
if (reply != null) {
getFollower().setSnapshotIndex(snapshot.getTermIndex().getIndex());
LOG.info("{}: installSnapshot {} successfully", this, snapshot);
getServer().getRaftServerMetrics().onSnapshotInstalled();
}
return reply;
}
Aggregations