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/08/12 04:36:10 UTC

[dubbo] branch 3.0 updated: Remove auto wrap when attachment is an object instance & remove excpption metadata when handled & fix typo (#8473)

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 08eb01b  Remove auto wrap when attachment is an object instance & remove excpption metadata when handled & fix typo (#8473)
08eb01b is described below

commit 08eb01be723c20ff44e9e58c478f783aff20ab6e
Author: GuoHao <gu...@gmail.com>
AuthorDate: Thu Aug 12 12:35:56 2021 +0800

    Remove auto wrap when attachment is an object instance & remove excpption metadata when handled & fix typo (#8473)
---
 .../dubbo/rpc/protocol/tri/AbstractStream.java     | 37 ++++------------------
 .../dubbo/rpc/protocol/tri/UnaryClientStream.java  |  5 +--
 2 files changed, 10 insertions(+), 32 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 81f1b44..323df47 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
@@ -23,7 +23,6 @@ import org.apache.dubbo.common.extension.ExtensionLoader;
 import org.apache.dubbo.common.serialize.MultipleSerialization;
 import org.apache.dubbo.common.stream.StreamObserver;
 import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory;
-import org.apache.dubbo.common.utils.ConfigUtils;
 import org.apache.dubbo.common.utils.StringUtils;
 import org.apache.dubbo.config.Constants;
 import org.apache.dubbo.remoting.exchange.Request;
@@ -37,7 +36,6 @@ import com.google.rpc.DebugInfo;
 import com.google.rpc.Status;
 import io.netty.handler.codec.http2.Http2Headers;
 
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -51,13 +49,11 @@ import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 
 public abstract class AbstractStream implements Stream {
-    public static final boolean ENABLE_ATTACHMENT_WRAP = Boolean.parseBoolean(
-            ConfigUtils.getProperty("triple.attachment", "false"));
     protected static final String DUPLICATED_DATA = "Duplicated data";
     private static final List<Executor> CALLBACK_EXECUTORS = new ArrayList<>(4);
 
     static {
-        ThreadFactory tripleTF = new NamedInternalThreadFactory("tri-callbcak", true);
+        ThreadFactory tripleTF = new NamedInternalThreadFactory("tri-callback", true);
         for (int i = 0; i < 4; i++) {
             final ThreadPoolExecutor tp = new ThreadPoolExecutor(1, 1, 0, TimeUnit.DAYS,
                     new LinkedBlockingQueue<>(1024),
@@ -278,16 +274,6 @@ public abstract class AbstractStream implements Stream {
                 continue;
             }
 
-            if (ENABLE_ATTACHMENT_WRAP) {
-                if (key.endsWith("-tw-bin") && key.length() > 7) {
-                    try {
-                        attachments.put(key.substring(0, key.length() - 7),
-                                TripleUtil.decodeObjFromHeader(url, header.getValue(), multipleSerialization));
-                    } catch (Exception e) {
-                        LOGGER.error("Failed to parse response attachment key=" + key, e);
-                    }
-                }
-            }
             if (key.endsWith("-bin") && key.length() > 4) {
                 try {
                     attachments.put(key.substring(0, key.length() - 4), TripleUtil.decodeASCIIByte(header.getValue()));
@@ -314,22 +300,13 @@ public abstract class AbstractStream implements Stream {
 
     private void convertSingleAttachment(Metadata metadata, String key, Object v) {
         try {
-            if (!ENABLE_ATTACHMENT_WRAP) {
-                if (v instanceof String) {
-                    metadata.put(key, (String) v);
-                } else if (v instanceof byte[]) {
-                    metadata.put(key + "-bin", TripleUtil.encodeBase64ASCII((byte[]) v));
-                }
-            } else {
-                if (v instanceof String || serializeType == null) {
-                    metadata.put(key, v.toString());
-                } else {
-                    String encoded = TripleUtil.encodeWrapper(url, v, this.serializeType, getMultipleSerialization());
-                    metadata.put(key + "-tw-bin", encoded);
-                }
+            if (v instanceof String) {
+                metadata.put(key, (String) v);
+            } else if (v instanceof byte[]) {
+                metadata.put(key + "-bin", TripleUtil.encodeBase64ASCII((byte[]) v));
             }
-        } catch (IOException e) {
-            LOGGER.warn("Meet exception when convert single attachment key:" + key, e);
+        } catch (Throwable t) {
+            LOGGER.warn("Meet exception when convert single attachment key:" + key + " value=" + v, t);
         }
     }
 
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 d43d241..959ac7b 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
@@ -76,6 +76,9 @@ public class UnaryClientStream extends AbstractClientStream implements Stream {
             response.setErrorMessage(status.description);
             final AppResponse result = new AppResponse();
             result.setException(getThrowable(this.getTrailers()));
+            // avoid subsequent parse header problems
+            this.getTrailers().remove(TripleConstant.EXCEPTION_TW_BIN);
+            this.getTrailers().remove(TripleConstant.STATUS_KEY);
             result.setObjectAttachments(UnaryClientStream.this.parseMetadataToMap(this.getTrailers()));
             response.setResult(result);
             if (!result.hasException()) {
@@ -103,8 +106,6 @@ public class UnaryClientStream extends AbstractClientStream implements Stream {
                     } finally {
                         ClassLoadUtil.switchContextLoader(tccl);
                     }
-                    // avoid subsequent parse header problems
-                    metadata.remove(TripleConstant.EXCEPTION_TW_BIN);
                 }
             } catch (Throwable t) {
                 LOGGER.warn(String.format("Decode exception instance from triple trailers:%s failed", metadata), t);