pulsar-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] merlimat closed pull request #3158: improve avro schema deserialization by reusing binary decoder
Date Tue, 11 Dec 2018 22:33:01 GMT
merlimat closed pull request #3158: improve avro schema deserialization by reusing binary decoder
URL: https://github.com/apache/pulsar/pull/3158
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/pulsar-client-schema/pom.xml b/pulsar-client-schema/pom.xml
index 3db0cd2ea3..c984dd3b2f 100644
--- a/pulsar-client-schema/pom.xml
+++ b/pulsar-client-schema/pom.xml
@@ -131,16 +131,11 @@
                                     <include>commons-codec:commons-codec</include>
                                     <include>commons-collections:commons-collections</include>
                                     <include>org.asynchttpclient:*</include>
-                                    <include>io.netty:netty-codec-http</include>
-                                    <include>io.netty:netty-transport-native-epoll</include>
                                     <include>org.reactivestreams:reactive-streams</include>
-                                    <include>com.typesafe.netty:netty-reactive-streams</include>
                                     <include>org.javassist:javassist</include>
                                     <include>com.google.guava:guava</include>
                                     <include>com.google.code.gson:gson</include>
                                     <include>com.fasterxml.jackson.core</include>
-                                    <include>io.netty:netty</include>
-                                    <include>io.netty:netty-all</include>
                                     <include>org.apache.bookkeeper:circe-checksum</include>
                                     <include>com.yahoo.datasketches:sketches-core</include>
                                     <include>org.glassfish.jersey*:*</include>
@@ -150,7 +145,6 @@
                                     <include>com.fasterxml.jackson.*:*</include>
                                     <include>io.grpc:*</include>
                                     <include>com.yahoo.datasketches:*</include>
-                                    <include>io.netty:*</include>
                                     <include>com.squareup.*:*</include>
                                     <include>commons-*:*</include>
                                     <include>org.apache.httpcomponents:*</include>
@@ -210,10 +204,6 @@
                                     <pattern>com.fasterxml.jackson</pattern>
                                     <shadedPattern>org.apache.pulsar.shade.com.fasterxml.jackson</shadedPattern>
                                 </relocation>
-                                <relocation>
-                                    <pattern>io.netty</pattern>
-                                    <shadedPattern>org.apache.pulsar.shade.io.netty</shadedPattern>
-                                </relocation>
                                 <relocation>
                                     <pattern>org.apache.pulsar.policies</pattern>
                                     <shadedPattern>org.apache.pulsar.shade.org.apache.pulsar.policies</shadedPattern>
diff --git a/pulsar-client-schema/src/main/java/org/apache/pulsar/client/impl/schema/AvroSchema.java
b/pulsar-client-schema/src/main/java/org/apache/pulsar/client/impl/schema/AvroSchema.java
index 6867fdcb4d..a9f11460db 100644
--- a/pulsar-client-schema/src/main/java/org/apache/pulsar/client/impl/schema/AvroSchema.java
+++ b/pulsar-client-schema/src/main/java/org/apache/pulsar/client/impl/schema/AvroSchema.java
@@ -18,7 +18,9 @@
  */
 package org.apache.pulsar.client.impl.schema;
 
+import io.netty.util.concurrent.FastThreadLocal;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.avro.io.BinaryDecoder;
 import org.apache.avro.io.BinaryEncoder;
 import org.apache.avro.io.DecoderFactory;
 import org.apache.avro.io.EncoderFactory;
@@ -45,6 +47,9 @@
     private BinaryEncoder encoder;
     private ByteArrayOutputStream byteArrayOutputStream;
 
+    private static final FastThreadLocal<BinaryDecoder> decoders =
+            new FastThreadLocal<>();
+
     private AvroSchema(org.apache.avro.Schema schema,
                        Map<String, String> properties) {
         this.schema = schema;
@@ -77,7 +82,12 @@ private AvroSchema(org.apache.avro.Schema schema,
     @Override
     public T decode(byte[] bytes) {
         try {
-            return reader.read(null, DecoderFactory.get().binaryDecoder(bytes, null));
+            BinaryDecoder decoderFromCache = decoders.get();
+            BinaryDecoder decoder = DecoderFactory.get().binaryDecoder(bytes, decoderFromCache);
+            if (decoderFromCache == null) {
+                decoders.set(decoder);
+            }
+            return reader.read(null, DecoderFactory.get().binaryDecoder(bytes, decoder));
         } catch (IOException e) {
             throw new SchemaSerializationException(e);
         }
diff --git a/pulsar-sql/presto-pulsar/src/main/java/org/apache/pulsar/sql/presto/AvroSchemaHandler.java
b/pulsar-sql/presto-pulsar/src/main/java/org/apache/pulsar/sql/presto/AvroSchemaHandler.java
index ed3759a754..41c2f6f1fa 100644
--- a/pulsar-sql/presto-pulsar/src/main/java/org/apache/pulsar/sql/presto/AvroSchemaHandler.java
+++ b/pulsar-sql/presto-pulsar/src/main/java/org/apache/pulsar/sql/presto/AvroSchemaHandler.java
@@ -40,7 +40,7 @@
 
     private final List<PulsarColumnHandle> columnHandles;
 
-    public static final FastThreadLocal<BinaryDecoder> decoders =
+    private static final FastThreadLocal<BinaryDecoder> decoders =
             new FastThreadLocal<>();
 
     private static final Logger log = Logger.get(AvroSchemaHandler.class);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message