ivandika3 commented on code in PR #7988:
URL: https://github.com/apache/ozone/pull/7988#discussion_r1995060974


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/protocolPB/OzoneManagerProtocolServerSideTranslatorPB.java:
##########
@@ -219,14 +219,35 @@ private OMResponse submitReadRequestToOM(OMRequest 
request)
       throws ServiceException {
     // Check if this OM is the leader.
     RaftServerStatus raftServerStatus = omRatisServer.checkLeaderStatus();
-    if (raftServerStatus == LEADER_AND_READY ||
-        request.getCmdType().equals(PrepareStatus)) {
+    if (raftServerStatus == LEADER_AND_READY || 
request.getCmdType().equals(PrepareStatus) ||
+        (raftServerStatus == NOT_LEADER && 
allowSnapshotReadFromFollower(request))) {
       return handler.handleReadRequest(request);
     } else {
       throw createLeaderErrorException(raftServerStatus);
     }
   }
 
+  private boolean allowSnapshotReadFromFollower(OMRequest omRequest) {
+    if (!omRequest.hasOmNodeId()) {
+      return false;
+    }
+
+    if (!omRequest.getOmNodeId().equals(ozoneManager.getOMNodeId())) {
+      return false;
+    }
+
+    switch (omRequest.getCmdType()) {
+    case SnapshotDiff:
+    case ListSnapshot:
+    case GetSnapshotInfo:
+    case ListSnapshotDiffJobs:
+    case CancelSnapshotDiff:
+      return true;
+    default:
+      return false;
+    }
+  }
+

Review Comment:
   Thanks for the review. Throwing a special exception requires further 
handling in the client failover proxy handler, but currently any 
`OMNotLeaderException` from follower will fail the client immediately (see: 
https://github.com/apache/ozone/blob/ba65f759a05b975e788d3cb55d06df6e843aed2b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/ha/SingleOMFailoverProxyProviderBase.java#L174).
 So the behavior should remain unchanged.
   
   I'll keep this in mind if we need this in the future.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to