Search in sources :

Example 1 with RaftClientRequestProto

use of org.apache.ratis.shaded.proto.RaftProtos.RaftClientRequestProto in project incubator-ratis by apache.

the class AppendStreamer method refreshLeader.

private void refreshLeader(RaftPeerId suggestedLeader, RaftPeerId oldLeader) {
    running = RunningState.LOOK_FOR_LEADER;
    refreshLeaderProxy(suggestedLeader, oldLeader);
    reQueuePendingRequests(leaderId);
    final RaftClientRequestProto request = Objects.requireNonNull(dataQueue.poll());
    ackQueue.offer(request);
    try {
        exceptionAndRetry.retryInterval.sleep();
    } catch (InterruptedException ignored) {
    }
    leaderProxy.onNext(request);
}
Also used : RaftClientRequestProto(org.apache.ratis.shaded.proto.RaftProtos.RaftClientRequestProto)

Example 2 with RaftClientRequestProto

use of org.apache.ratis.shaded.proto.RaftProtos.RaftClientRequestProto in project incubator-ratis by apache.

the class AppendStreamer method write.

synchronized void write(ByteString content, long seqNum) throws IOException {
    checkState();
    while (isRunning() && dataQueue.size() >= maxPendingNum) {
        try {
            wait();
        } catch (InterruptedException ignored) {
        }
    }
    if (isRunning()) {
        // wrap the current buffer into a RaftClientRequestProto
        final RaftClientRequestProto request = ClientProtoUtils.toRaftClientRequestProto(clientId, leaderId, groupId, seqNum, seqNum, content);
        if (request.getSerializedSize() > maxMessageSize.getSizeInt()) {
            throw new IOException("msg size:" + request.getSerializedSize() + " exceeds maximum:" + maxMessageSize.getSizeInt());
        }
        dataQueue.offer(request);
        this.notifyAll();
    } else {
        throwException(this + " got closed.");
    }
}
Also used : RaftClientRequestProto(org.apache.ratis.shaded.proto.RaftProtos.RaftClientRequestProto) IOException(java.io.IOException)

Example 3 with RaftClientRequestProto

use of org.apache.ratis.shaded.proto.RaftProtos.RaftClientRequestProto in project incubator-ratis by apache.

the class AppendStreamer method reQueuePendingRequests.

private void reQueuePendingRequests(RaftPeerId newLeader) {
    if (isRunning()) {
        // resend all the pending requests
        while (!ackQueue.isEmpty()) {
            final RaftClientRequestProto oldRequest = ackQueue.pollLast();
            final RaftRpcRequestProto.Builder newRpc = RaftRpcRequestProto.newBuilder(oldRequest.getRpcRequest()).setReplyId(newLeader.toByteString());
            final RaftClientRequestProto newRequest = RaftClientRequestProto.newBuilder(oldRequest).setRpcRequest(newRpc).build();
            dataQueue.offerFirst(newRequest);
        }
    }
}
Also used : RaftRpcRequestProto(org.apache.ratis.shaded.proto.RaftProtos.RaftRpcRequestProto) RaftClientRequestProto(org.apache.ratis.shaded.proto.RaftProtos.RaftClientRequestProto)

Example 4 with RaftClientRequestProto

use of org.apache.ratis.shaded.proto.RaftProtos.RaftClientRequestProto in project incubator-ratis by apache.

the class GrpcClientRpc method sendRequest.

private CompletableFuture<RaftClientReply> sendRequest(RaftClientRequest request, RaftClientProtocolClient proxy) throws IOException {
    final RaftClientRequestProto requestProto = toRaftClientRequestProto(request);
    final CompletableFuture<RaftClientReplyProto> replyFuture = new CompletableFuture<>();
    // create a new grpc stream for each non-async call.
    final StreamObserver<RaftClientRequestProto> requestObserver = proxy.appendWithTimeout(new StreamObserver<RaftClientReplyProto>() {

        @Override
        public void onNext(RaftClientReplyProto value) {
            replyFuture.complete(value);
        }

        @Override
        public void onError(Throwable t) {
            replyFuture.completeExceptionally(RaftGrpcUtil.unwrapIOException(t));
        }

        @Override
        public void onCompleted() {
            if (!replyFuture.isDone()) {
                replyFuture.completeExceptionally(new IOException(clientId + ": Stream completed but no reply for request " + request));
            }
        }
    });
    requestObserver.onNext(requestProto);
    requestObserver.onCompleted();
    return replyFuture.thenApply(ClientProtoUtils::toRaftClientReply);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RaftClientRequestProto(org.apache.ratis.shaded.proto.RaftProtos.RaftClientRequestProto) ClientProtoUtils(org.apache.ratis.client.impl.ClientProtoUtils) RaftClientReplyProto(org.apache.ratis.shaded.proto.RaftProtos.RaftClientReplyProto) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException)

Aggregations

RaftClientRequestProto (org.apache.ratis.shaded.proto.RaftProtos.RaftClientRequestProto)4 IOException (java.io.IOException)2 InterruptedIOException (java.io.InterruptedIOException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ClientProtoUtils (org.apache.ratis.client.impl.ClientProtoUtils)1 RaftClientReplyProto (org.apache.ratis.shaded.proto.RaftProtos.RaftClientReplyProto)1 RaftRpcRequestProto (org.apache.ratis.shaded.proto.RaftProtos.RaftRpcRequestProto)1