Gargi-jais11 commented on code in PR #11763:
URL: https://github.com/apache/ozone/pull/11763#discussion_r4385812615
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManagerServiceGrpc.java:
##########
@@ -108,10 +109,8 @@ public void submitRequest(OMRequest request,
responseObserver.onNext(omResponse);
} catch (Throwable e) {
LOG.error("Failed to submit request", e);
- IOException ex = new IOException(e.getCause());
- responseObserver.onError(
- Status.INTERNAL.withDescription(ex.getMessage())
- .asRuntimeException());
+ Throwable omException = e instanceof ServiceException ? e.getCause() : e;
Review Comment:
Nit: a `ServiceExecption `with no cause can make omException null
```suggestion
Throwable omException = e instanceof ServiceException && e.getCause()
!= null ? e.getCause() : e;
```
##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/grpc/OMGrpcError.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om.protocolPB.grpc;
+
+import io.grpc.Metadata;
+import io.grpc.Status;
+import io.grpc.StatusRuntimeException;
+import io.grpc.protobuf.ProtoUtils;
+import java.io.IOException;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.exceptions.OMLeaderNotReadyException;
+import org.apache.hadoop.ozone.om.exceptions.OMNotLeaderException;
+import
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMGrpcErrorProto;
+import org.apache.ratis.protocol.exceptions.ReadException;
+import org.apache.ratis.protocol.exceptions.ReadIndexException;
+
+/**
+ * The Java form of {@link OMGrpcErrorProto}, the error that the OM gRPC
server sends in the gRPC trailers.
+ * It converts between this error and the exception thrown by OM.
+ */
+public final class OMGrpcError {
+ private static final Metadata.Key<OMGrpcErrorProto> ERROR_KEY =
Metadata.Key.of("om-grpc-error-bin",
+ ProtoUtils.metadataMarshaller(OMGrpcErrorProto.getDefaultInstance()));
+
+ private OMGrpcError() {
+ }
+
+ /** @return the gRPC error for the given exception thrown by OM. */
+ public static StatusRuntimeException toStatusRuntimeException(Throwable
omException) {
+ final Metadata trailers = new Metadata();
+ trailers.put(ERROR_KEY, toProto(omException));
+ // NOTE: gRPC clients of old versions read the exception class and message
from the description.
+ return
Status.INTERNAL.withDescription(omException.toString()).asRuntimeException(trailers);
+ }
+
+ /**
+ * @return the exception thrown by OM that the gRPC error carries,
+ * or null if the error does not come from OM.
+ */
+ public static IOException toOMException(StatusRuntimeException e) {
+ final Metadata trailers = e.getTrailers();
+ final OMGrpcErrorProto error = trailers == null ? null :
trailers.get(ERROR_KEY);
+ if (error == null) {
+ return null;
+ }
+ final String message = error.hasMessage() ? error.getMessage() : null;
+ switch (error.getErrorCase()) {
+ case NOTLEADER:
+ return new OMNotLeaderException(message,
error.getNotLeader().hasSuggestedLeaderNodeId()
+ ? error.getNotLeader().getSuggestedLeaderNodeId() : null);
+ case LEADERNOTREADY:
+ return new OMLeaderNotReadyException(message);
+ case READINDEXFAILED:
+ return new ReadIndexException(message);
+ case READFAILED:
+ return new ReadException(message);
+ default:
+ return new OMException(message, OMException.ResultCodes.INTERNAL_ERROR);
+ }
+ }
+
+ private static OMGrpcErrorProto toProto(Throwable omException) {
+ final OMGrpcErrorProto.Builder error = OMGrpcErrorProto.newBuilder();
+ if (omException.getMessage() != null) {
+ error.setMessage(omException.getMessage());
+ }
Review Comment:
Not a blocker -> this message now goes out twice in the trailers: once in
grpc-message (the description) and once in om-grpc-error-bin and I believe the
client's default limit on incoming metadata is 8 KiB. An unusual long message,
most likely can happen in the default case, could exceed it and turn a clean
**INTERNAL error** into a transport error. Not likely, but you could leave the
message out of the proto for the default case, since the description already
carries it or may be cap it's length.
--
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]