Java Code Examples for org.apache.ratis.protocol.RaftClientReply#getStateMachineException()
The following examples show how to use
org.apache.ratis.protocol.RaftClientReply#getStateMachineException() .
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 |
private void processReply(RaftClientReply reply) throws IOException { // NotLeader exception is thrown only when the raft server to which the // request is submitted is not the leader. The request will be rejected // and will eventually be executed once the request comes via the leader // node. NotLeaderException notLeaderException = reply.getNotLeaderException(); if (notLeaderException != null) { throw notLeaderException; } StateMachineException stateMachineException = reply.getStateMachineException(); if (stateMachineException != null) { throw stateMachineException; } }
Example 2
Source File: FileStoreClient.java From incubator-ratis with Apache License 2.0 | 5 votes |
static ByteString send( ByteString request, CheckedFunction<Message, RaftClientReply, IOException> sendFunction) throws IOException { final RaftClientReply reply = sendFunction.apply(Message.valueOf(request)); final StateMachineException sme = reply.getStateMachineException(); if (sme != null) { throw new IOException("Failed to send request " + request, sme); } Preconditions.assertTrue(reply.isSuccess(), () -> "Failed " + request + ", reply=" + reply); return reply.getMessage().getContent(); }
Example 3
Source File: FileStoreClient.java From ratis with Apache License 2.0 | 5 votes |
static ByteString send( ByteString request, CheckedFunction<Message, RaftClientReply, IOException> sendFunction) throws IOException { final RaftClientReply reply = sendFunction.apply(Message.valueOf(request)); final StateMachineException sme = reply.getStateMachineException(); if (sme != null) { throw new IOException("Failed to send request " + request, sme); } Preconditions.assertTrue(reply.isSuccess(), () -> "Failed " + request + ", reply=" + reply); return reply.getMessage().getContent(); }
Example 4
Source File: OzoneManagerRatisServer.java From hadoop-ozone with Apache License 2.0 | 4 votes |
/** * Process the raftClientReply and return OMResponse. * @param omRequest * @param reply * @return OMResponse - response which is returned to client. * @throws ServiceException */ private OMResponse processReply(OMRequest omRequest, RaftClientReply reply) throws ServiceException { // NotLeader exception is thrown only when the raft server to which the // request is submitted is not the leader. This can happen first time // when client is submitting request to OM. if (!reply.isSuccess()) { NotLeaderException notLeaderException = reply.getNotLeaderException(); if (notLeaderException != null) { throw new ServiceException( OMNotLeaderException.convertToOMNotLeaderException( notLeaderException, getRaftPeerId())); } LeaderNotReadyException leaderNotReadyException = reply.getLeaderNotReadyException(); if (leaderNotReadyException != null) { throw new ServiceException(new OMLeaderNotReadyException( leaderNotReadyException.getMessage())); } StateMachineException stateMachineException = reply.getStateMachineException(); if (stateMachineException != null) { OMResponse.Builder omResponse = OMResponse.newBuilder() .setCmdType(omRequest.getCmdType()) .setSuccess(false) .setTraceID(omRequest.getTraceID()); if (stateMachineException.getCause() != null) { omResponse.setMessage(stateMachineException.getCause().getMessage()); omResponse.setStatus( exceptionToResponseStatus(stateMachineException.getCause())); } else { // Current Ratis is setting cause, this is an safer side check. LOG.error("StateMachine exception cause is not set"); omResponse.setStatus( OzoneManagerProtocolProtos.Status.INTERNAL_ERROR); omResponse.setMessage( StringUtils.stringifyException(stateMachineException)); } if (LOG.isDebugEnabled()) { LOG.debug("Error while executing ratis request. " + "stateMachineException: ", stateMachineException); } return omResponse.build(); } } try { return OMRatisHelper.getOMResponseFromRaftClientReply(reply); } catch (InvalidProtocolBufferException ex) { if (ex.getMessage() != null) { throw new ServiceException(ex.getMessage(), ex); } else { throw new ServiceException(ex); } } // TODO: Still need to handle RaftRetry failure exception and // NotReplicated exception. }