Java Code Examples for org.apache.ratis.proto.RaftProtos.AppendEntriesRequestProto#getEntriesCount()

The following examples show how to use org.apache.ratis.proto.RaftProtos.AppendEntriesRequestProto#getEntriesCount() . 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: GrpcLogAppender.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
AppendEntriesRequest(AppendEntriesRequestProto proto, RaftPeerId followerId, GrpcServerMetrics grpcServerMetrics) {
  this.callId = proto.getServerRequest().getCallId();
  this.previousLog = proto.hasPreviousLog()? ServerProtoUtils.toTermIndex(proto.getPreviousLog()): null;
  this.entriesCount = proto.getEntriesCount();
  this.lastEntry = entriesCount > 0? ServerProtoUtils.toTermIndex(proto.getEntries(entriesCount - 1)): null;

  this.timer = grpcServerMetrics.getGrpcLogAppenderLatencyTimer(followerId.toString(), isHeartbeat());
  grpcServerMetrics.onRequestCreate(isHeartbeat());
}
 
Example 2
Source File: GrpcLogAppender.java    From ratis with Apache License 2.0 5 votes vote down vote up
protected synchronized void onSuccess(AppendEntriesReplyProto reply) {
  AppendEntriesRequestProto request = pendingRequests.remove(reply.getServerReply().getCallId());
  if (request == null) {
    // If reply comes after timeout, the reply is ignored.
    LOG.warn("{}: Request not found, ignoring reply: {}", this, ServerProtoUtils.toString(reply));
    return;
  }
  updateCommitIndex(reply.getFollowerCommit());

  final long replyNextIndex = reply.getNextIndex();
  final long lastIndex = replyNextIndex - 1;
  final boolean updateMatchIndex;

  if (request.getEntriesCount() == 0) {
    Preconditions.assertTrue(!request.hasPreviousLog() ||
            lastIndex == request.getPreviousLog().getIndex(),
        "reply's next index is %s, request's previous is %s",
        replyNextIndex, request.getPreviousLog());
    updateMatchIndex = request.hasPreviousLog() && follower.getMatchIndex() < lastIndex;
  } else {
    // check if the reply and the pending request is consistent
    final long lastEntryIndex = request
        .getEntries(request.getEntriesCount() - 1).getIndex();
    Preconditions.assertTrue(lastIndex == lastEntryIndex,
        "reply's next index is %s, request's last entry index is %s",
        replyNextIndex, lastEntryIndex);
    updateMatchIndex = true;
  }
  if (updateMatchIndex) {
    follower.updateMatchIndex(lastIndex);
    submitEventOnSuccessAppend();
  }
}
 
Example 3
Source File: GrpcLogAppender.java    From incubator-ratis with Apache License 2.0 4 votes vote down vote up
private void increaseNextIndex(AppendEntriesRequestProto request) {
  final int count = request.getEntriesCount();
  if (count > 0) {
    getFollower().increaseNextIndex(request.getEntries(count - 1).getIndex() + 1);
  }
}
 
Example 4
Source File: GrpcLogAppender.java    From ratis with Apache License 2.0 4 votes vote down vote up
private void updateNextIndex(AppendEntriesRequestProto request) {
  final int count = request.getEntriesCount();
  if (count > 0) {
    follower.updateNextIndex(request.getEntries(count - 1).getIndex() + 1);
  }
}