You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by gu...@apache.org on 2021/09/01 01:54:53 UTC

[dubbo] branch 3.0 updated: [3.0-Triple] Remove throwable tw-bin header and truncate exception (#8642)

This is an automated email from the ASF dual-hosted git repository.

guohao pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.0 by this push:
     new 8a30700  [3.0-Triple] Remove throwable tw-bin header and truncate exception  (#8642)
8a30700 is described below

commit 8a3070055f92886205e98d30c6862f26e24f18d4
Author: GuoHao <gu...@gmail.com>
AuthorDate: Wed Sep 1 09:54:33 2021 +0800

    [3.0-Triple] Remove throwable tw-bin header and truncate exception  (#8642)
    
    * Remove throwable tw-bin header
    
    * Remove unused code
---
 .../dubbo/rpc/protocol/tri/AbstractStream.java     | 18 +------
 .../dubbo/rpc/protocol/tri/ExceptionUtils.java     |  8 ++-
 .../dubbo/rpc/protocol/tri/TripleHeaderEnum.java   |  3 +-
 .../dubbo/rpc/protocol/tri/UnaryClientStream.java  | 60 +++++++---------------
 4 files changed, 27 insertions(+), 62 deletions(-)

diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/AbstractStream.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/AbstractStream.java
index 9b74798..f3e9813 100644
--- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/AbstractStream.java
+++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/AbstractStream.java
@@ -29,7 +29,6 @@ import org.apache.dubbo.remoting.exchange.Request;
 import org.apache.dubbo.rpc.model.MethodDescriptor;
 import org.apache.dubbo.rpc.model.ServiceDescriptor;
 import org.apache.dubbo.rpc.protocol.tri.GrpcStatus.Code;
-import org.apache.dubbo.triple.TripleWrapper;
 
 import com.google.protobuf.Any;
 import com.google.rpc.DebugInfo;
@@ -245,7 +244,7 @@ public abstract class AbstractStream implements Stream {
             return metadata;
         }
         DebugInfo debugInfo = DebugInfo.newBuilder()
-                .addAllStackEntries(ExceptionUtils.getStackFrameList(throwable))
+                .addAllStackEntries(ExceptionUtils.getStackFrameList(throwable,10))
                 // can not use now
                 // .setDetail(throwable.getMessage())
                 .build();
@@ -253,21 +252,6 @@ public abstract class AbstractStream implements Stream {
         Status status = builder.build();
         metadata.put(TripleHeaderEnum.STATUS_DETAIL_KEY.getHeader(),
                 TripleUtil.encodeBase64ASCII(status.toByteArray()));
-        // only wrapper mode support exception serialization
-        if (getMethodDescriptor() != null && !getMethodDescriptor().isNeedWrap()) {
-            return metadata;
-        }
-        try {
-            TripleWrapper.TripleExceptionWrapper exceptionWrapper = TripleUtil.wrapException(getUrl(), throwable,
-                    getSerializeType(), getMultipleSerialization());
-            String exceptionStr = TripleUtil.encodeBase64ASCII(exceptionWrapper.toByteArray());
-            if (!TripleUtil.overEachHeaderListSize(exceptionStr)) {
-                metadata.put(TripleHeaderEnum.EXCEPTION_TW_BIN.getHeader(), exceptionStr);
-            }
-        } catch (Throwable t) {
-            LOGGER.warn("Encode triple exception to trailers failed", t);
-        }
-
         return metadata;
     }
 
diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ExceptionUtils.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ExceptionUtils.java
index ed37cfa..6f9de11 100644
--- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ExceptionUtils.java
+++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ExceptionUtils.java
@@ -64,14 +64,18 @@ public class ExceptionUtils {
         return list.toArray(new String[0]);
     }
 
-    public static List<String> getStackFrameList(final Throwable t) {
+    public static List<String> getStackFrameList(final Throwable t, int maxDepth) {
         final String stackTrace = getStackTrace(t);
         final String linebreak = System.lineSeparator();
         final StringTokenizer frames = new StringTokenizer(stackTrace, linebreak);
         final List<String> list = new ArrayList<>();
-        while (frames.hasMoreTokens()) {
+        for (int i = 0; i < maxDepth && frames.hasMoreTokens(); i++) {
             list.add(frames.nextToken());
         }
         return list;
     }
+
+    public static List<String> getStackFrameList(final Throwable t) {
+        return getStackFrameList(t, Integer.MAX_VALUE);
+    }
 }
diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleHeaderEnum.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleHeaderEnum.java
index 9c6616b..18a3219 100644
--- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleHeaderEnum.java
+++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleHeaderEnum.java
@@ -40,8 +40,7 @@ public enum TripleHeaderEnum {
     CONSUMER_APP_NAME_KEY("tri-consumer-appname"),
     UNIT_INFO_KEY("tri-unit-info"),
     SERVICE_VERSION("tri-service-version"),
-    SERVICE_GROUP("tri-service-group"),
-    EXCEPTION_TW_BIN("tri-exception-tw-bin");
+    SERVICE_GROUP("tri-service-group");
 
     static Map<String, TripleHeaderEnum> enumMap = new HashMap<>();
 
diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/UnaryClientStream.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/UnaryClientStream.java
index d8916e1..a9d4ce8 100644
--- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/UnaryClientStream.java
+++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/UnaryClientStream.java
@@ -22,7 +22,6 @@ import org.apache.dubbo.common.stream.StreamObserver;
 import org.apache.dubbo.remoting.exchange.Response;
 import org.apache.dubbo.remoting.exchange.support.DefaultFuture2;
 import org.apache.dubbo.rpc.AppResponse;
-import org.apache.dubbo.triple.TripleWrapper;
 
 import com.google.protobuf.Any;
 import com.google.rpc.DebugInfo;
@@ -90,50 +89,29 @@ public class UnaryClientStream extends AbstractClientStream implements Stream {
         }
 
         private Throwable getThrowable(Metadata metadata) {
-            // first get throwable from exception tw bin
-            try {
-                if (metadata.contains(TripleHeaderEnum.EXCEPTION_TW_BIN.getHeader())) {
-                    final CharSequence raw = metadata.get(TripleHeaderEnum.EXCEPTION_TW_BIN.getHeader());
-                    byte[] exceptionTwBin = TripleUtil.decodeASCIIByte(raw);
-                    ClassLoader tccl = Thread.currentThread().getContextClassLoader();
-                    try {
-                        TripleWrapper.TripleExceptionWrapper wrapper = TripleUtil.unpack(exceptionTwBin,
-                                TripleWrapper.TripleExceptionWrapper.class);
-                        Throwable throwable = TripleUtil.unWrapException(getUrl(), wrapper, getSerializeType(),
-                                getMultipleSerialization());
-                        if (throwable != null) {
-                            return throwable;
-                        }
-                    } finally {
-                        ClassLoadUtil.switchContextLoader(tccl);
-                    }
-                }
-            } catch (Throwable t) {
-                LOGGER.warn(String.format("Decode exception instance from triple trailers:%s failed", metadata), t);
-            }
             // second get status detail
-            if (metadata.contains(TripleHeaderEnum.STATUS_DETAIL_KEY.getHeader())) {
-                final CharSequence raw = metadata.get(TripleHeaderEnum.STATUS_DETAIL_KEY.getHeader());
-                byte[] statusDetailBin = TripleUtil.decodeASCIIByte(raw);
-                ClassLoader tccl = Thread.currentThread().getContextClassLoader();
-                try {
-                    final Status statusDetail = TripleUtil.unpack(statusDetailBin, Status.class);
-                    List<Any> detailList = statusDetail.getDetailsList();
-                    Map<Class<?>, Object> classObjectMap = TripleUtil.tranFromStatusDetails(detailList);
+            if (!metadata.contains(TripleHeaderEnum.STATUS_DETAIL_KEY.getHeader())) {
+                return null;
+            }
+            final CharSequence raw = metadata.get(TripleHeaderEnum.STATUS_DETAIL_KEY.getHeader());
+            byte[] statusDetailBin = TripleUtil.decodeASCIIByte(raw);
+            ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+            try {
+                final Status statusDetail = TripleUtil.unpack(statusDetailBin, Status.class);
+                List<Any> detailList = statusDetail.getDetailsList();
+                Map<Class<?>, Object> classObjectMap = TripleUtil.tranFromStatusDetails(detailList);
 
-                    // get common exception from DebugInfo
-                    DebugInfo debugInfo = (DebugInfo) classObjectMap.get(DebugInfo.class);
-                    if (debugInfo == null) {
-                        return new TripleRpcException(statusDetail.getCode(),
-                                statusDetail.getMessage(), metadata);
-                    }
-                    String msg = ExceptionUtils.getStackFrameString(debugInfo.getStackEntriesList());
-                    return new TripleRpcException(statusDetail.getCode(), msg, metadata);
-                } finally {
-                    ClassLoadUtil.switchContextLoader(tccl);
+                // get common exception from DebugInfo
+                DebugInfo debugInfo = (DebugInfo) classObjectMap.get(DebugInfo.class);
+                if (debugInfo == null) {
+                    return new TripleRpcException(statusDetail.getCode(),
+                            statusDetail.getMessage(), metadata);
                 }
+                String msg = ExceptionUtils.getStackFrameString(debugInfo.getStackEntriesList());
+                return new TripleRpcException(statusDetail.getCode(), msg, metadata);
+            } finally {
+                ClassLoadUtil.switchContextLoader(tccl);
             }
-            return null;
         }
     }
 }