bharatviswa504 commented on a change in pull request #850: HDDS-1551. Implement 
Bucket Write Requests to use Cache and DoubleBuf…
URL: https://github.com/apache/hadoop/pull/850#discussion_r288813544
 
 

 ##########
 File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerRatisServer.java
 ##########
 @@ -97,6 +112,101 @@ private static long nextCallId() {
     return CALL_ID_COUNTER.getAndIncrement() & Long.MAX_VALUE;
   }
 
+  /**
+   * Submit request to Ratis server.
+   * @param omRequest
+   * @return OMResponse - response returned to the client.
+   * @throws ServiceException
+   */
+  public OMResponse submitRequest(OMRequest omRequest) throws ServiceException 
{
+    RaftClientRequest raftClientRequest =
+        createWriteRaftClientRequest(omRequest);
+    RaftClientReply raftClientReply;
+    try {
+      raftClientReply = server.submitClientRequestAsync(raftClientRequest)
+          .get();
+    } catch (Exception ex) {
+      throw new ServiceException(ex.getMessage(), ex);
+    }
+
+    return processReply(omRequest, raftClientReply);
+  }
+
+  /**
+   * Create Write RaftClient request from OMRequest.
+   * @param omRequest
+   * @return
+   */
+  private RaftClientRequest createWriteRaftClientRequest(OMRequest omRequest) {
+    return new RaftClientRequest(clientId, server.getId(), raftGroupId,
+        nextCallId(),
+        Message.valueOf(OMRatisHelper.convertRequestToByteString(omRequest)),
+        RaftClientRequest.writeRequestType(), null);
+  }
+
+  /**
+   * Process the raftClientReply and return OMResponse.
+   * @param omRequest
+   * @param reply
+   * @return
+   * @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.
+    NotLeaderException notLeaderException = reply.getNotLeaderException();
+    if (notLeaderException != null) {
+      throw new ServiceException(notLeaderException);
+    }
+    StateMachineException stateMachineException =
+        reply.getStateMachineException();
+    if (stateMachineException != null) {
+      OMResponse.Builder omResponse = OMResponse.newBuilder();
+      omResponse.setCmdType(omRequest.getCmdType());
+      omResponse.setSuccess(false);
+      omResponse.setMessage(stateMachineException.getCause().getMessage());
+      omResponse.setStatus(parseErrorStatus(
+          stateMachineException.getCause().getMessage()));
+      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.
 
 Review comment:
   Currently using ratisClient there is a TODO for RaftRetry failure exception, 
and I don't see anything is done for handling NotReplicatedException.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org

Reply via email to