peterxcli commented on code in PR #7988:
URL: https://github.com/apache/ozone/pull/7988#discussion_r1979124342
##########
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;
+ }
Review Comment:
Could be another type of exception like `NodeIdMistach`
##########
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:
Should this return an error that is something like "OmNodeId specify, but
COMMAND_TYPE is not supported to read from follower"?
```suggestion
if (raftServerStatus == LEADER_AND_READY ||
request.getCmdType().equals(PrepareStatus)) {
return handler.handleReadRequest(request);
} else if (raftServerStatus == NOT_LEADER && readFromFollower(omRequest))
// handle follower read
boolean handle = false
if (isSnapshotCmd(omRequest)) {
try {
allowSnapshotReadFromFollower(request)
} catch(FollowerReadException) {
...
}
} else {
throw ServiceException(new FollowerReadUnsopportedCmdExCeption());
}
if (handle) return handler.handleReadRequest(request);
} else {
throw createLeaderErrorException(raftServerStatus);
}
}
private boolean readFromFollower(OMRequest omRequest) {
return omRequest.hasOmNodeId();
}
private boolean allowSnapshotReadFromFollower(OMRequest omRequest) throw
SnapshotFollowerReadException {
if (!omRequest.getOmNodeId().equals(ozoneManager.getOMNodeId())) {
return false;
}
switch (omRequest.getCmdType()) {
case SnapshotDiff:
case ListSnapshot:
case GetSnapshotInfo:
case ListSnapshotDiffJobs:
case CancelSnapshotDiff:
return true;
default:
throw SnapshotFollowerUnSupportedCmdException(omRequest.getCmdType());
}
}
```
above is just a rough suggestion.
--
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]