You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/06/03 10:55:14 UTC

[GitHub] [pulsar] gaoran10 opened a new pull request #10811: [Schema] Fix AutoConsumeSchema decode null schema version data

gaoran10 opened a new pull request #10811:
URL: https://github.com/apache/pulsar/pull/10811


   ### Motivation
   
   Currently, the AutoConsumeSchema decode messages which has a null schema version will cause the NPE problem.
   
   ```
   java.lang.NullPointerException: null
   	at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936) ~[?:1.8.0_181]
   	at java.util.concurrent.ConcurrentHashMap.containsKey(ConcurrentHashMap.java:964) ~[?:1.8.0_181]
   	at org.apache.pulsar.client.impl.schema.AutoConsumeSchema.ensureSchemaInitialized(AutoConsumeSchema.java:73) ~[io.streamnative-pulsar-client-original-2.8.0-rc-202105291235.jar:2.8.0-rc-202105291235]
   	at org.apache.pulsar.client.impl.schema.AutoConsumeSchema.decode(AutoConsumeSchema.java:110) ~[io.streamnative-pulsar-client-original-2.8.0-rc-202105291235.jar:2.8.0-rc-202105291235]
   	at org.apache.pulsar.client.impl.schema.AutoConsumeSchema.decode(AutoConsumeSchema.java:45) ~[io.streamnative-pulsar-client-original-2.8.0-rc-202105291235.jar:2.8.0-rc-202105291235]
   	at org.apache.pulsar.client.api.Schema.decode(Schema.java:107) ~[io.streamnative-pulsar-client-api-2.8.0-rc-202105291235.jar:2.8.0-rc-202105291235]
   	at org.apache.pulsar.client.impl.MessageImpl.decode(MessageImpl.java:469) ~[io.streamnative-pulsar-client-original-2.8.0-rc-202105291235.jar:2.8.0-rc-202105291235]
   	at org.apache.pulsar.client.impl.MessageImpl.getValue(MessageImpl.java:449) ~[io.streamnative-pulsar-client-original-2.8.0-rc-202105291235.jar:2.8.0-rc-202105291235]
   	at org.apache.pulsar.functions.source.PulsarRecord.getValue(PulsarRecord.java:81) ~[io.streamnative-pulsar-functions-instance-2.8.0-rc-202105291235.jar:2.8.0-rc-202105291235]
   	at org.apache.pulsar.functions.instance.JavaInstanceRunnable.readInput(JavaInstanceRunnable.java:386) ~[io.streamnative-pulsar-functions-instance-2.8.0-rc-202105291235.jar:2.8.0-rc-202105291235]
   	at org.apache.pulsar.functions.instance.JavaInstanceRunnable.run(JavaInstanceRunnable.java:248) ~[io.streamnative-pulsar-functions-instance-2.8.0-rc-202105291235.jar:2.8.0-rc-202105291235]
   	at java.lang.Thread.run(Thread.java:748) ~[?:1.8.0_181]
   
   ```
   
   ### Modifications
   
   Check the schema version, if the schema version is null, fallback uses the BYTES schema to decode.
   
   ### Verifying this change
   
   Test decode message data which has a null schema version.
   
   ### Does this pull request potentially affect one of the following parts:
   
   *If `yes` was chosen, please highlight the changes*
   
     - Dependencies (does it add or upgrade a dependency): (no)
     - The public API: (no)
     - The schema: (no)
     - The default values of configurations: (no)
     - The wire protocol: (no)
     - The rest endpoints: (no)
     - The admin cli options: (no)
     - Anything that affects deployment: (no)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] gaoran10 commented on a change in pull request #10811: [Schema] Fix AutoConsumeSchema decode null schema version data

Posted by GitBox <gi...@apache.org>.
gaoran10 commented on a change in pull request #10811:
URL: https://github.com/apache/pulsar/pull/10811#discussion_r644972844



##########
File path: pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/AutoConsumeSchemaTest.java
##########
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.client.impl.schema;
+
+import java.nio.ByteBuffer;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.pulsar.client.api.Schema;
+import org.apache.pulsar.client.api.schema.GenericRecord;
+import org.apache.pulsar.client.impl.MessageImpl;
+import org.apache.pulsar.common.api.proto.MessageMetadata;
+import org.junit.Assert;
+import org.testng.annotations.Test;
+
+/**
+ * AutoConsumeSchema test.
+ */
+@Slf4j
+public class AutoConsumeSchemaTest {
+
+    @Test
+    public void decodeDataWithNullSchemaVersion() {
+        Schema<GenericRecord> autoConsumeSchema = new AutoConsumeSchema();
+        byte[] bytes = "bytes data".getBytes();
+        MessageImpl<GenericRecord> message = MessageImpl.create(
+                new MessageMetadata(), ByteBuffer.wrap(bytes), autoConsumeSchema);
+        Assert.assertNull(message.getSchemaVersion());

Review comment:
       If using Python client produces messages without specifying a schema, the schema version will be null.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] eolivelli merged pull request #10811: [Schema] Fix AutoConsumeSchema decode null schema version data

Posted by GitBox <gi...@apache.org>.
eolivelli merged pull request #10811:
URL: https://github.com/apache/pulsar/pull/10811


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] eolivelli commented on a change in pull request #10811: [Schema] Fix AutoConsumeSchema decode null schema version data

Posted by GitBox <gi...@apache.org>.
eolivelli commented on a change in pull request #10811:
URL: https://github.com/apache/pulsar/pull/10811#discussion_r644778867



##########
File path: pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/AutoConsumeSchemaTest.java
##########
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.client.impl.schema;
+
+import java.nio.ByteBuffer;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.pulsar.client.api.Schema;
+import org.apache.pulsar.client.api.schema.GenericRecord;
+import org.apache.pulsar.client.impl.MessageImpl;
+import org.apache.pulsar.common.api.proto.MessageMetadata;
+import org.junit.Assert;
+import org.testng.annotations.Test;
+
+/**
+ * AutoConsumeSchema test.
+ */
+@Slf4j
+public class AutoConsumeSchemaTest {
+
+    @Test
+    public void decodeDataWithNullSchemaVersion() {
+        Schema<GenericRecord> autoConsumeSchema = new AutoConsumeSchema();
+        byte[] bytes = "bytes data".getBytes();
+        MessageImpl<GenericRecord> message = MessageImpl.create(
+                new MessageMetadata(), ByteBuffer.wrap(bytes), autoConsumeSchema);
+        Assert.assertNull(message.getSchemaVersion());

Review comment:
       how can it happen that we receive a message with null schemaVersion ?
   Autoconsume is meant to be used only on the Consumer side, on a real message.

##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AutoConsumeSchema.java
##########
@@ -308,13 +311,26 @@ public void fetchSchemaIfNeeded(SchemaVersion schemaVersion) throws SchemaSerial
         }
     }
 
+    private SchemaVersion getSchemaVersion(byte[] schemaVersion) {

Review comment:
       static ?

##########
File path: pulsar-client/src/test/java/org/apache/pulsar/client/impl/TypedMessageBuilderImplTest.java
##########
@@ -225,5 +226,12 @@ public void testSetKeyBytesEncodingTypeSeparated() {
         }
     }
 
+    @Test
+    public void test() {
+        producerBase = mock(ProducerBase.class);
+        TypedMessageBuilderImpl builder =  new TypedMessageBuilderImpl(producerBase, null);
+        AutoConsumeSchema autoConsumeSchema = new AutoConsumeSchema();

Review comment:
       I do not understand this test.
   
   what is it supposed to test ? autoConsumeSchema is not used




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] gaoran10 commented on a change in pull request #10811: [Schema] Fix AutoConsumeSchema decode null schema version data

Posted by GitBox <gi...@apache.org>.
gaoran10 commented on a change in pull request #10811:
URL: https://github.com/apache/pulsar/pull/10811#discussion_r644973644



##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AutoConsumeSchema.java
##########
@@ -308,13 +311,26 @@ public void fetchSchemaIfNeeded(SchemaVersion schemaVersion) throws SchemaSerial
         }
     }
 
+    private SchemaVersion getSchemaVersion(byte[] schemaVersion) {

Review comment:
       Does the static method have some advantage?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] gaoran10 commented on a change in pull request #10811: [Schema] Fix AutoConsumeSchema decode null schema version data

Posted by GitBox <gi...@apache.org>.
gaoran10 commented on a change in pull request #10811:
URL: https://github.com/apache/pulsar/pull/10811#discussion_r644971477



##########
File path: pulsar-client/src/test/java/org/apache/pulsar/client/impl/TypedMessageBuilderImplTest.java
##########
@@ -225,5 +226,12 @@ public void testSetKeyBytesEncodingTypeSeparated() {
         }
     }
 
+    @Test
+    public void test() {
+        producerBase = mock(ProducerBase.class);
+        TypedMessageBuilderImpl builder =  new TypedMessageBuilderImpl(producerBase, null);
+        AutoConsumeSchema autoConsumeSchema = new AutoConsumeSchema();

Review comment:
       Oh, I forgot to remove this, thanks.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] gaoran10 commented on a change in pull request #10811: [Schema] Fix AutoConsumeSchema decode null schema version data

Posted by GitBox <gi...@apache.org>.
gaoran10 commented on a change in pull request #10811:
URL: https://github.com/apache/pulsar/pull/10811#discussion_r645244558



##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AutoConsumeSchema.java
##########
@@ -308,13 +311,26 @@ public void fetchSchemaIfNeeded(SchemaVersion schemaVersion) throws SchemaSerial
         }
     }
 
+    private SchemaVersion getSchemaVersion(byte[] schemaVersion) {

Review comment:
       Ok, I'll fix this, thanks.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] codelipenghui commented on pull request #10811: [Schema] Fix AutoConsumeSchema decode null schema version data

Posted by GitBox <gi...@apache.org>.
codelipenghui commented on pull request #10811:
URL: https://github.com/apache/pulsar/pull/10811#issuecomment-855484403


   @sijie I have moved the label `release/2.7.3` since the issue is only happens in the master branch


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] gaoran10 commented on a change in pull request #10811: [Schema] Fix AutoConsumeSchema decode null schema version data

Posted by GitBox <gi...@apache.org>.
gaoran10 commented on a change in pull request #10811:
URL: https://github.com/apache/pulsar/pull/10811#discussion_r645244558



##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AutoConsumeSchema.java
##########
@@ -308,13 +311,26 @@ public void fetchSchemaIfNeeded(SchemaVersion schemaVersion) throws SchemaSerial
         }
     }
 
+    private SchemaVersion getSchemaVersion(byte[] schemaVersion) {

Review comment:
       Ok, I'll fix this.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] gaoran10 commented on a change in pull request #10811: [Schema] Fix AutoConsumeSchema decode null schema version data

Posted by GitBox <gi...@apache.org>.
gaoran10 commented on a change in pull request #10811:
URL: https://github.com/apache/pulsar/pull/10811#discussion_r644969977



##########
File path: pulsar-client/src/test/java/org/apache/pulsar/client/impl/TypedMessageBuilderImplTest.java
##########
@@ -225,5 +226,12 @@ public void testSetKeyBytesEncodingTypeSeparated() {
         }
     }
 
+    @Test
+    public void test() {
+        producerBase = mock(ProducerBase.class);
+        TypedMessageBuilderImpl builder =  new TypedMessageBuilderImpl(producerBase, null);
+        AutoConsumeSchema autoConsumeSchema = new AutoConsumeSchema();

Review comment:
       The method `message.getValue()` will use the AutoConsumeSchema to decode data.
   Because the schema version is null, so fallback uses the BYTES schema to decode data.

##########
File path: pulsar-client/src/test/java/org/apache/pulsar/client/impl/TypedMessageBuilderImplTest.java
##########
@@ -225,5 +226,12 @@ public void testSetKeyBytesEncodingTypeSeparated() {
         }
     }
 
+    @Test
+    public void test() {
+        producerBase = mock(ProducerBase.class);
+        TypedMessageBuilderImpl builder =  new TypedMessageBuilderImpl(producerBase, null);
+        AutoConsumeSchema autoConsumeSchema = new AutoConsumeSchema();

Review comment:
       Oh, I forgot to remove this, thanks.

##########
File path: pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/AutoConsumeSchemaTest.java
##########
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.client.impl.schema;
+
+import java.nio.ByteBuffer;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.pulsar.client.api.Schema;
+import org.apache.pulsar.client.api.schema.GenericRecord;
+import org.apache.pulsar.client.impl.MessageImpl;
+import org.apache.pulsar.common.api.proto.MessageMetadata;
+import org.junit.Assert;
+import org.testng.annotations.Test;
+
+/**
+ * AutoConsumeSchema test.
+ */
+@Slf4j
+public class AutoConsumeSchemaTest {
+
+    @Test
+    public void decodeDataWithNullSchemaVersion() {
+        Schema<GenericRecord> autoConsumeSchema = new AutoConsumeSchema();
+        byte[] bytes = "bytes data".getBytes();
+        MessageImpl<GenericRecord> message = MessageImpl.create(
+                new MessageMetadata(), ByteBuffer.wrap(bytes), autoConsumeSchema);
+        Assert.assertNull(message.getSchemaVersion());

Review comment:
       If using Python client produces messages without specifying a schema, the schema version will be null.

##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AutoConsumeSchema.java
##########
@@ -308,13 +311,26 @@ public void fetchSchemaIfNeeded(SchemaVersion schemaVersion) throws SchemaSerial
         }
     }
 
+    private SchemaVersion getSchemaVersion(byte[] schemaVersion) {

Review comment:
       Does the static method have some advantage?

##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AutoConsumeSchema.java
##########
@@ -308,13 +311,26 @@ public void fetchSchemaIfNeeded(SchemaVersion schemaVersion) throws SchemaSerial
         }
     }
 
+    private SchemaVersion getSchemaVersion(byte[] schemaVersion) {

Review comment:
       Ok, I'll fix this.

##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AutoConsumeSchema.java
##########
@@ -308,13 +311,26 @@ public void fetchSchemaIfNeeded(SchemaVersion schemaVersion) throws SchemaSerial
         }
     }
 
+    private SchemaVersion getSchemaVersion(byte[] schemaVersion) {

Review comment:
       Ok, I'll fix this, thanks.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] eolivelli commented on a change in pull request #10811: [Schema] Fix AutoConsumeSchema decode null schema version data

Posted by GitBox <gi...@apache.org>.
eolivelli commented on a change in pull request #10811:
URL: https://github.com/apache/pulsar/pull/10811#discussion_r644778867



##########
File path: pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/AutoConsumeSchemaTest.java
##########
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.client.impl.schema;
+
+import java.nio.ByteBuffer;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.pulsar.client.api.Schema;
+import org.apache.pulsar.client.api.schema.GenericRecord;
+import org.apache.pulsar.client.impl.MessageImpl;
+import org.apache.pulsar.common.api.proto.MessageMetadata;
+import org.junit.Assert;
+import org.testng.annotations.Test;
+
+/**
+ * AutoConsumeSchema test.
+ */
+@Slf4j
+public class AutoConsumeSchemaTest {
+
+    @Test
+    public void decodeDataWithNullSchemaVersion() {
+        Schema<GenericRecord> autoConsumeSchema = new AutoConsumeSchema();
+        byte[] bytes = "bytes data".getBytes();
+        MessageImpl<GenericRecord> message = MessageImpl.create(
+                new MessageMetadata(), ByteBuffer.wrap(bytes), autoConsumeSchema);
+        Assert.assertNull(message.getSchemaVersion());

Review comment:
       how can it happen that we receive a message with null schemaVersion ?
   Autoconsume is meant to be used only on the Consumer side, on a real message.

##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AutoConsumeSchema.java
##########
@@ -308,13 +311,26 @@ public void fetchSchemaIfNeeded(SchemaVersion schemaVersion) throws SchemaSerial
         }
     }
 
+    private SchemaVersion getSchemaVersion(byte[] schemaVersion) {

Review comment:
       static ?

##########
File path: pulsar-client/src/test/java/org/apache/pulsar/client/impl/TypedMessageBuilderImplTest.java
##########
@@ -225,5 +226,12 @@ public void testSetKeyBytesEncodingTypeSeparated() {
         }
     }
 
+    @Test
+    public void test() {
+        producerBase = mock(ProducerBase.class);
+        TypedMessageBuilderImpl builder =  new TypedMessageBuilderImpl(producerBase, null);
+        AutoConsumeSchema autoConsumeSchema = new AutoConsumeSchema();

Review comment:
       I do not understand this test.
   
   what is it supposed to test ? autoConsumeSchema is not used

##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AutoConsumeSchema.java
##########
@@ -308,13 +311,26 @@ public void fetchSchemaIfNeeded(SchemaVersion schemaVersion) throws SchemaSerial
         }
     }
 
+    private SchemaVersion getSchemaVersion(byte[] schemaVersion) {

Review comment:
       Probably not a big deal from a performance perspective.
   But if a method does not use state from the instance it is better to mark it 'static'.
   
    

##########
File path: pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/AutoConsumeSchemaTest.java
##########
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.client.impl.schema;
+
+import java.nio.ByteBuffer;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.pulsar.client.api.Schema;
+import org.apache.pulsar.client.api.schema.GenericRecord;
+import org.apache.pulsar.client.impl.MessageImpl;
+import org.apache.pulsar.common.api.proto.MessageMetadata;
+import org.junit.Assert;
+import org.testng.annotations.Test;
+
+/**
+ * AutoConsumeSchema test.
+ */
+@Slf4j
+public class AutoConsumeSchemaTest {
+
+    @Test
+    public void decodeDataWithNullSchemaVersion() {
+        Schema<GenericRecord> autoConsumeSchema = new AutoConsumeSchema();
+        byte[] bytes = "bytes data".getBytes();
+        MessageImpl<GenericRecord> message = MessageImpl.create(
+                new MessageMetadata(), ByteBuffer.wrap(bytes), autoConsumeSchema);
+        Assert.assertNull(message.getSchemaVersion());

Review comment:
       Very interesting.
   I didn't know 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] eolivelli commented on pull request #10811: [Schema] Fix AutoConsumeSchema decode null schema version data

Posted by GitBox <gi...@apache.org>.
eolivelli commented on pull request #10811:
URL: https://github.com/apache/pulsar/pull/10811#issuecomment-854105640


   @sijie AutoConsumeSchema code is very different in branch-2.7.
   This patch cannot be cherry picked.
   We should open a new PR if you want this fix for 2.7.3


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] eolivelli commented on a change in pull request #10811: [Schema] Fix AutoConsumeSchema decode null schema version data

Posted by GitBox <gi...@apache.org>.
eolivelli commented on a change in pull request #10811:
URL: https://github.com/apache/pulsar/pull/10811#discussion_r645054271



##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AutoConsumeSchema.java
##########
@@ -308,13 +311,26 @@ public void fetchSchemaIfNeeded(SchemaVersion schemaVersion) throws SchemaSerial
         }
     }
 
+    private SchemaVersion getSchemaVersion(byte[] schemaVersion) {

Review comment:
       Probably not a big deal from a performance perspective.
   But if a method does not use state from the instance it is better to mark it 'static'.
   
    




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] eolivelli commented on pull request #10811: [Schema] Fix AutoConsumeSchema decode null schema version data

Posted by GitBox <gi...@apache.org>.
eolivelli commented on pull request #10811:
URL: https://github.com/apache/pulsar/pull/10811#issuecomment-854105640


   @sijie AutoConsumeSchema code is very different in branch-2.7.
   This patch cannot be cherry picked.
   We should open a new PR if you want this fix for 2.7.3


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] gaoran10 commented on a change in pull request #10811: [Schema] Fix AutoConsumeSchema decode null schema version data

Posted by GitBox <gi...@apache.org>.
gaoran10 commented on a change in pull request #10811:
URL: https://github.com/apache/pulsar/pull/10811#discussion_r644969977



##########
File path: pulsar-client/src/test/java/org/apache/pulsar/client/impl/TypedMessageBuilderImplTest.java
##########
@@ -225,5 +226,12 @@ public void testSetKeyBytesEncodingTypeSeparated() {
         }
     }
 
+    @Test
+    public void test() {
+        producerBase = mock(ProducerBase.class);
+        TypedMessageBuilderImpl builder =  new TypedMessageBuilderImpl(producerBase, null);
+        AutoConsumeSchema autoConsumeSchema = new AutoConsumeSchema();

Review comment:
       The method `message.getValue()` will use the AutoConsumeSchema to decode data.
   Because the schema version is null, so fallback uses the BYTES schema to decode data.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] eolivelli commented on a change in pull request #10811: [Schema] Fix AutoConsumeSchema decode null schema version data

Posted by GitBox <gi...@apache.org>.
eolivelli commented on a change in pull request #10811:
URL: https://github.com/apache/pulsar/pull/10811#discussion_r645054610



##########
File path: pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/AutoConsumeSchemaTest.java
##########
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.client.impl.schema;
+
+import java.nio.ByteBuffer;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.pulsar.client.api.Schema;
+import org.apache.pulsar.client.api.schema.GenericRecord;
+import org.apache.pulsar.client.impl.MessageImpl;
+import org.apache.pulsar.common.api.proto.MessageMetadata;
+import org.junit.Assert;
+import org.testng.annotations.Test;
+
+/**
+ * AutoConsumeSchema test.
+ */
+@Slf4j
+public class AutoConsumeSchemaTest {
+
+    @Test
+    public void decodeDataWithNullSchemaVersion() {
+        Schema<GenericRecord> autoConsumeSchema = new AutoConsumeSchema();
+        byte[] bytes = "bytes data".getBytes();
+        MessageImpl<GenericRecord> message = MessageImpl.create(
+                new MessageMetadata(), ByteBuffer.wrap(bytes), autoConsumeSchema);
+        Assert.assertNull(message.getSchemaVersion());

Review comment:
       Very interesting.
   I didn't know 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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