Java Code Examples for org.apache.ratis.proto.RaftProtos#RaftPeerRole

The following examples show how to use org.apache.ratis.proto.RaftProtos#RaftPeerRole . 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: XceiverServerRatis.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
void handleApplyTransactionFailure(RaftGroupId groupId,
    RaftProtos.RaftPeerRole role) {
  UUID dnId = RatisHelper.toDatanodeId(getServer().getId());
  String msg =
      "Ratis Transaction failure in datanode " + dnId + " with role " + role
          + " .Triggering pipeline close action.";
  triggerPipelineClose(groupId, msg,
      ClosePipelineInfo.Reason.STATEMACHINE_TRANSACTION_FAILED, true);
}
 
Example 2
Source File: LogStateMachine.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
private CompletableFuture<Message> processAppendRequest(TransactionContext trx,
    LogServiceRequestProto logProto) {

  final LogEntryProto entry = trx.getLogEntry();
  AppendLogEntryRequestProto proto = logProto.getAppendRequest();
  final long index = entry.getIndex();
  long newSize = 0;
  Throwable t = verifyState(State.OPEN);
  final List<Long> ids = new ArrayList<Long>();
  if (t == null) {
    try (AutoCloseableLock writeLock = writeLock()) {
        List<byte[]> entries = LogServiceProtoUtil.toListByteArray(proto.getDataList());
        for (byte[] bb : entries) {
          ids.add(this.length);
          newSize += bb.length;
          this.length++;
        }
        this.dataRecordsSize += newSize;
        // TODO do we need this for other write request (close, sync)
        updateLastAppliedTermIndex(entry.getTerm(), index);
    }
  }
  final CompletableFuture<Message> f =
      CompletableFuture.completedFuture(
        Message.valueOf(LogServiceProtoUtil.toAppendLogReplyProto(ids, t).toByteString()));
  final RaftProtos.RaftPeerRole role = trx.getServerRole();
  if (LOG.isTraceEnabled()) {
    LOG.trace("{}:{}-{}: {} new length {}", role, getId(), index,
        TextFormat.shortDebugString(proto), dataRecordsSize);
  }
  return f;
}
 
Example 3
Source File: LogStateMachine.java    From ratis with Apache License 2.0 5 votes vote down vote up
private CompletableFuture<Message> processAppendRequest(TransactionContext trx,
    LogServiceRequestProto logProto) {

  final LogEntryProto entry = trx.getLogEntry();
  AppendLogEntryRequestProto proto = logProto.getAppendRequest();
  final long index = entry.getIndex();
  long total = 0;
  Throwable t = verifyState(State.OPEN);
  if (t == null) {
    try (final AutoCloseableLock writeLock = writeLock()) {
        List<byte[]> entries = LogServiceProtoUtil.toListByteArray(proto.getDataList());
        for (byte[] bb : entries) {
          total += bb.length;
        }
        this.length += total;
        // TODO do we need this for other write request (close, sync)
        updateLastAppliedTermIndex(entry.getTerm(), index);
    }
  }
  List<Long> ids = new ArrayList<Long>();
  ids.add(index);
  final CompletableFuture<Message> f =
      CompletableFuture.completedFuture(
        Message.valueOf(LogServiceProtoUtil.toAppendLogReplyProto(ids, t).toByteString()));
  final RaftProtos.RaftPeerRole role = trx.getServerRole();
  LOG.debug("{}:{}-{}: {} new length {}", role, getId(), index, proto, length);
  if (LOG.isTraceEnabled()) {
    LOG.trace("{}-{}: variables={}", getId(), index, length);
  }
  return f;
}