You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ke...@apache.org on 2020/09/30 16:41:01 UTC

[skywalking] branch muse-bug-bash/Bytebufferbackingarray created (now 8d4f7fd)

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

kezhenxu94 pushed a change to branch muse-bug-bash/Bytebufferbackingarray
in repository https://gitbox.apache.org/repos/asf/skywalking.git.


      at 8d4f7fd  Only get backing array of ByteBuffer when it has one

This branch includes the following new commits:

     new 8d4f7fd  Only get backing array of ByteBuffer when it has one

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[skywalking] 01/01: Only get backing array of ByteBuffer when it has one

Posted by ke...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kezhenxu94 pushed a commit to branch muse-bug-bash/Bytebufferbackingarray
in repository https://gitbox.apache.org/repos/asf/skywalking.git

commit 8d4f7fd3fdd196a6b585b20f7235de500702f647
Author: kezhenxu94 <ke...@163.com>
AuthorDate: Thu Oct 1 00:38:06 2020 +0800

    Only get backing array of ByteBuffer when it has one
    
    ByteBuffer.array() shouldn't be called unless ByteBuffer.arrayOffset() is used or if the ByteBuffer was initialized using ByteBuffer.wrap() or ByteBuffer.allocate().
---
 .../apm/plugin/avro/SWServerRPCPlugin.java          | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/apm-sniffer/apm-sdk-plugin/avro-plugin/src/main/java/org/apache/skywalking/apm/plugin/avro/SWServerRPCPlugin.java b/apm-sniffer/apm-sdk-plugin/avro-plugin/src/main/java/org/apache/skywalking/apm/plugin/avro/SWServerRPCPlugin.java
index d4014ed..113acbe 100644
--- a/apm-sniffer/apm-sdk-plugin/avro-plugin/src/main/java/org/apache/skywalking/apm/plugin/avro/SWServerRPCPlugin.java
+++ b/apm-sniffer/apm-sdk-plugin/avro-plugin/src/main/java/org/apache/skywalking/apm/plugin/avro/SWServerRPCPlugin.java
@@ -19,10 +19,10 @@
 package org.apache.skywalking.apm.plugin.avro;
 
 import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
 import java.util.Map;
 import org.apache.avro.ipc.RPCContext;
 import org.apache.avro.ipc.RPCPlugin;
-import org.apache.avro.util.Utf8;
 import org.apache.skywalking.apm.agent.core.context.CarrierItem;
 import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
 import org.apache.skywalking.apm.agent.core.context.ContextManager;
@@ -43,14 +43,27 @@ public class SWServerRPCPlugin extends RPCPlugin {
 
     @Override
     public void serverReceiveRequest(RPCContext context) {
-        Map meta = context.requestCallMeta();
+        Map<String, ByteBuffer> meta = context.requestCallMeta();
 
         ContextCarrier carrier = new ContextCarrier();
         CarrierItem items = carrier.items();
         while (items.hasNext()) {
             items = items.next();
-            ByteBuffer buffer = (ByteBuffer) meta.get(new Utf8(items.getHeadKey()));
-            items.setHeadValue(new String(buffer.array()));
+            ByteBuffer buffer = meta.get(items.getHeadKey());
+            String headValue;
+            if (buffer.hasArray()) {
+                headValue = new String(buffer.array());
+            } else {
+                buffer.mark();
+
+                byte[] bs = new byte[buffer.remaining()];
+                buffer.get(bs);
+
+                headValue = new String(bs, StandardCharsets.UTF_8);
+
+                buffer.reset();
+            }
+            items.setHeadValue(headValue);
         }
 
         String operationName = prefix + context.getMessage().getName();