Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.0-Triple]Remove auto wrap when attachment is an object instance #8473

Merged
merged 1 commit into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
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;
Expand All @@ -37,7 +36,6 @@
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;
Expand All @@ -51,13 +49,11 @@
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),
Expand Down Expand Up @@ -278,16 +274,6 @@ protected Map<String, Object> parseMetadataToMap(Metadata metadata) {
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()));
Expand All @@ -314,22 +300,13 @@ protected void convertAttachment(Metadata metadata, Map<String, Object> attachme

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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ protected void onError(GrpcStatus status) {
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()) {
Expand Down Expand Up @@ -103,8 +106,6 @@ private Throwable getThrowable(Metadata metadata) {
} 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);
Expand Down