use of org.apache.ratis.proto.RaftProtos.AppendEntriesRequestProto in project incubator-ratis by apache.
the class GrpcLogAppender method appendLog.
private void appendLog(boolean excludeLogEntries) throws IOException {
final AppendEntriesRequestProto pending;
final AppendEntriesRequest request;
final StreamObserver<AppendEntriesRequestProto> s;
try (AutoCloseableLock writeLock = lock.writeLock(caller, LOG::trace)) {
// prepare and enqueue the append request. note changes on follower's
// nextIndex and ops on pendingRequests should always be associated
// together and protected by the lock
pending = newAppendEntriesRequest(callId++, excludeLogEntries);
if (pending == null) {
return;
}
request = new AppendEntriesRequest(pending, getFollowerId(), grpcServerMetrics);
pendingRequests.put(request);
increaseNextIndex(pending);
if (appendLogRequestObserver == null) {
appendLogRequestObserver = getClient().appendEntries(new AppendLogResponseHandler());
}
s = appendLogRequestObserver;
}
if (isRunning()) {
sendRequest(request, pending, s);
}
}
use of org.apache.ratis.proto.RaftProtos.AppendEntriesRequestProto 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