Search in sources :

Example 1 with NotReplicatedException

use of org.apache.ratis.protocol.exceptions.NotReplicatedException in project incubator-ratis by apache.

the class ClientProtoUtils method toRaftClientReply.

static RaftClientReply toRaftClientReply(RaftClientReplyProto replyProto) {
    final RaftRpcReplyProto rp = replyProto.getRpcReply();
    final RaftGroupMemberId serverMemberId = ProtoUtils.toRaftGroupMemberId(rp.getReplyId(), rp.getRaftGroupId());
    final RaftException e;
    if (replyProto.getExceptionDetailsCase().equals(NOTLEADEREXCEPTION)) {
        NotLeaderExceptionProto nleProto = replyProto.getNotLeaderException();
        final RaftPeer suggestedLeader = nleProto.hasSuggestedLeader() ? ProtoUtils.toRaftPeer(nleProto.getSuggestedLeader()) : null;
        final List<RaftPeer> peers = ProtoUtils.toRaftPeers(nleProto.getPeersInConfList());
        e = new NotLeaderException(serverMemberId, suggestedLeader, peers);
    } else if (replyProto.getExceptionDetailsCase() == NOTREPLICATEDEXCEPTION) {
        final NotReplicatedExceptionProto nre = replyProto.getNotReplicatedException();
        e = new NotReplicatedException(nre.getCallId(), nre.getReplication(), nre.getLogIndex());
    } else if (replyProto.getExceptionDetailsCase().equals(STATEMACHINEEXCEPTION)) {
        e = toStateMachineException(serverMemberId, replyProto.getStateMachineException());
    } else if (replyProto.getExceptionDetailsCase().equals(DATASTREAMEXCEPTION)) {
        e = ProtoUtils.toThrowable(replyProto.getDataStreamException(), DataStreamException.class);
    } else if (replyProto.getExceptionDetailsCase().equals(LEADERNOTREADYEXCEPTION)) {
        LeaderNotReadyExceptionProto lnreProto = replyProto.getLeaderNotReadyException();
        e = new LeaderNotReadyException(ProtoUtils.toRaftGroupMemberId(lnreProto.getServerId()));
    } else if (replyProto.getExceptionDetailsCase().equals(ALREADYCLOSEDEXCEPTION)) {
        e = toAlreadyClosedException(replyProto.getAlreadyClosedException());
    } else if (replyProto.getExceptionDetailsCase().equals(LEADERSTEPPINGDOWNEXCEPTION)) {
        e = ProtoUtils.toThrowable(replyProto.getLeaderSteppingDownException(), LeaderSteppingDownException.class);
    } else if (replyProto.getExceptionDetailsCase().equals(TRANSFERLEADERSHIPEXCEPTION)) {
        e = ProtoUtils.toThrowable(replyProto.getTransferLeadershipException(), TransferLeadershipException.class);
    } else {
        e = null;
    }
    return RaftClientReply.newBuilder().setClientId(ClientId.valueOf(rp.getRequestorId())).setServerId(serverMemberId).setCallId(rp.getCallId()).setSuccess(rp.getSuccess()).setMessage(toMessage(replyProto.getMessage())).setException(e).setLogIndex(replyProto.getLogIndex()).setCommitInfos(replyProto.getCommitInfosList()).build();
}
Also used : RaftException(org.apache.ratis.protocol.exceptions.RaftException) NotLeaderException(org.apache.ratis.protocol.exceptions.NotLeaderException) NotReplicatedException(org.apache.ratis.protocol.exceptions.NotReplicatedException) LeaderNotReadyException(org.apache.ratis.protocol.exceptions.LeaderNotReadyException) LeaderSteppingDownException(org.apache.ratis.protocol.exceptions.LeaderSteppingDownException)

Example 2 with NotReplicatedException

use of org.apache.ratis.protocol.exceptions.NotReplicatedException in project incubator-ratis by apache.

the class WatchRequestTests method assertNotReplicatedException.

static void assertNotReplicatedException(long logIndex, ReplicationLevel replication, Throwable t) {
    Assert.assertSame(NotReplicatedException.class, t.getClass());
    final NotReplicatedException nre = (NotReplicatedException) t;
    Assert.assertNotNull(nre);
    Assert.assertEquals(logIndex, nre.getLogIndex());
    Assert.assertEquals(replication, nre.getRequiredReplication());
}
Also used : NotReplicatedException(org.apache.ratis.protocol.exceptions.NotReplicatedException)

Example 3 with NotReplicatedException

use of org.apache.ratis.protocol.exceptions.NotReplicatedException in project incubator-ratis by apache.

the class ClientProtoUtils method toRaftClientReplyProto.

static RaftClientReplyProto toRaftClientReplyProto(RaftClientReply reply) {
    final RaftClientReplyProto.Builder b = RaftClientReplyProto.newBuilder();
    if (reply != null) {
        b.setRpcReply(toRaftRpcReplyProtoBuilder(reply.getClientId().toByteString(), reply.getServerId().toByteString(), reply.getRaftGroupId(), reply.getCallId(), reply.isSuccess()));
        b.setLogIndex(reply.getLogIndex());
        if (reply.getMessage() != null) {
            b.setMessage(toClientMessageEntryProtoBuilder(reply.getMessage()));
        }
        b.addAllCommitInfos(reply.getCommitInfos());
        final NotLeaderException nle = reply.getNotLeaderException();
        if (nle != null) {
            NotLeaderExceptionProto.Builder nleBuilder = NotLeaderExceptionProto.newBuilder();
            final RaftPeer suggestedLeader = nle.getSuggestedLeader();
            if (suggestedLeader != null) {
                nleBuilder.setSuggestedLeader(suggestedLeader.getRaftPeerProto());
            }
            nleBuilder.addAllPeersInConf(ProtoUtils.toRaftPeerProtos(nle.getPeers()));
            b.setNotLeaderException(nleBuilder.build());
        }
        final NotReplicatedException nre = reply.getNotReplicatedException();
        if (nre != null) {
            final NotReplicatedExceptionProto.Builder nreBuilder = NotReplicatedExceptionProto.newBuilder().setCallId(nre.getCallId()).setReplication(nre.getRequiredReplication()).setLogIndex(nre.getLogIndex());
            b.setNotReplicatedException(nreBuilder);
        }
        final LeaderNotReadyException lnre = reply.getLeaderNotReadyException();
        if (lnre != null) {
            LeaderNotReadyExceptionProto.Builder lnreBuilder = LeaderNotReadyExceptionProto.newBuilder().setServerId(ProtoUtils.toRaftGroupMemberIdProtoBuilder(lnre.getServerId()));
            b.setLeaderNotReadyException(lnreBuilder);
        }
        Optional.ofNullable(reply.getStateMachineException()).map(ClientProtoUtils::toStateMachineExceptionProtoBuilder).ifPresent(b::setStateMachineException);
        Optional.ofNullable(reply.getDataStreamException()).map(ProtoUtils::toThrowableProto).ifPresent(b::setDataStreamException);
        Optional.ofNullable(reply.getAlreadyClosedException()).map(ClientProtoUtils::toAlreadyClosedExceptionProtoBuilder).ifPresent(b::setAlreadyClosedException);
        Optional.ofNullable(reply.getLeaderSteppingDownException()).map(ProtoUtils::toThrowableProto).ifPresent(b::setLeaderSteppingDownException);
        Optional.ofNullable(reply.getTransferLeadershipException()).map(ProtoUtils::toThrowableProto).ifPresent(b::setTransferLeadershipException);
        final RaftClientReplyProto serialized = b.build();
        final RaftException e = reply.getException();
        if (e != null) {
            final RaftClientReply deserialized = toRaftClientReply(serialized);
            if (!Optional.ofNullable(deserialized.getException()).map(Object::getClass).filter(e.getClass()::equals).isPresent()) {
                throw new AssertionError("Corruption while serializing reply= " + reply + " but serialized=" + serialized + " and deserialized=" + deserialized, e);
            }
        }
        return serialized;
    }
    return b.build();
}
Also used : NotLeaderException(org.apache.ratis.protocol.exceptions.NotLeaderException) RaftException(org.apache.ratis.protocol.exceptions.RaftException) LeaderNotReadyException(org.apache.ratis.protocol.exceptions.LeaderNotReadyException) NotReplicatedException(org.apache.ratis.protocol.exceptions.NotReplicatedException)

Aggregations

NotReplicatedException (org.apache.ratis.protocol.exceptions.NotReplicatedException)3 LeaderNotReadyException (org.apache.ratis.protocol.exceptions.LeaderNotReadyException)2 NotLeaderException (org.apache.ratis.protocol.exceptions.NotLeaderException)2 RaftException (org.apache.ratis.protocol.exceptions.RaftException)2 LeaderSteppingDownException (org.apache.ratis.protocol.exceptions.LeaderSteppingDownException)1