bharatviswa504 commented on a change in pull request #276: HDDS-2637. Handle 
LeaderNot ready exception in OzoneManager StateMachine and upgrade ratis to 
latest version.
URL: https://github.com/apache/hadoop-ozone/pull/276#discussion_r353419474
 
 

 ##########
 File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerRatisServer.java
 ##########
 @@ -156,24 +159,48 @@ private OMResponse processReply(OMRequest omRequest, 
RaftClientReply reply)
     // 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()));
-      if (LOG.isDebugEnabled()) {
-        LOG.debug("Error while executing ratis request. " +
-            "stateMachineException: ", stateMachineException);
+
+    if (!reply.isSuccess()) {
+      NotLeaderException notLeaderException = reply.getNotLeaderException();
+      if (notLeaderException != null) {
+        RaftPeerId suggestedLeader =
+            notLeaderException.getSuggestedLeader() != null ?
+                notLeaderException.getSuggestedLeader().getId() : null;
+        org.apache.hadoop.ozone.om.exceptions.NotLeaderException
+            notLeaderException1;
+        if (suggestedLeader != null) {
+          notLeaderException1 = new org.apache.hadoop.ozone.om.exceptions
+              .NotLeaderException(getRaftPeerId(), suggestedLeader);
+        } else {
+          notLeaderException1 =
+              new org.apache.hadoop.ozone.om.exceptions
+                  .NotLeaderException(getRaftPeerId());
+        }
+        throw new ServiceException(notLeaderException1);
+      }
+
+      LeaderNotReadyException leaderNotReadyException =
+          reply.getLeaderNotReadyException();
+      if (leaderNotReadyException != null) {
+        throw new ServiceException(new RatisLeaderNotReadyException(
+            leaderNotReadyException.getMessage()));
+      }
+
+      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()));
+        if (LOG.isDebugEnabled()) {
+          LOG.debug("Error while executing ratis request. " +
+              "stateMachineException: ", stateMachineException);
+        }
+        return omResponse.build();
 
 Review comment:
   On high level look to ratis, NotReplicatedException is thrown for watch 
requests. As we don't use any watch requests in OM, I think we should be fine, 
as in our case we should never see this kind of exception. I will explore more 
if some handling is needed for this still.

----------------------------------------------------------------
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: ozone-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: ozone-issues-h...@hadoop.apache.org

Reply via email to