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 2020/02/25 16:03:30 UTC

[GitHub] [pulsar] shiv4289 opened a new issue #6420: AvroSchema::decode(byte[] bytes, byte[] schemaVersion) crashes

shiv4289 opened a new issue #6420: AvroSchema::decode(byte[] bytes, byte[] schemaVersion) crashes
URL: https://github.com/apache/pulsar/issues/6420
 
 
   **Describe the bug**
   
   Add the following in SimpleSchemaTest.java at the end. Run the below test. It will crash in last line
   
       @Test
       public void testSchemaVersionUpdate() throws PulsarClientException, PulsarAdminException, ExecutionException, InterruptedException, NoSuchFieldException {
           final String topic = "persistent://my-property/my-ns/testAvroSchemaUpgrade";
   
           Producer producer1 = pulsarClient.newProducer(Schema.AVRO(V1Data.class))
                   .topic(topic)
                   .create();
   
           Consumer consumer = pulsarClient.newConsumer(Schema.AUTO_CONSUME())
                   .topic(topic)
                   .subscriptionName("schemaUpdate1")
                   .subscribe();
   
           producer1.send(new V1Data(1));
   
           Message msg = consumer.receive();
   
           MultiVersionSchemaInfoProvider schemaProvider = new MultiVersionSchemaInfoProvider(TopicName.get(topic), (PulsarClientImpl) pulsarClient);
           String avroSchemaInJson = new String(schemaProvider.getSchemaByVersion(msg.getSchemaVersion()).get().getSchema());
           AvroSchema schema = (AvroSchema) Schema.AVRO(SchemaDefinition.builder().withJsonDef(avroSchemaInJson).build());
   
           System.out.println(schema.decode(msg.getData(), msg.getSchemaVersion()));
       }
   
   ** stacktrace**
   
   ```
   com.google.common.util.concurrent.UncheckedExecutionException: java.lang.NullPointerException
   
   	at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2050)
   	at com.google.common.cache.LocalCache.get(LocalCache.java:3951)
   	at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3973)
   	at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4957)
   	at org.apache.pulsar.client.impl.schema.StructSchema.decode(StructSchema.java:98)
   	at org.apache.pulsar.client.api.SimpleSchemaTest.testSchemaVersionUpdate(SimpleSchemaTest.java:668)
   	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   	at java.lang.reflect.Method.invoke(Method.java:498)
   	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
   	at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
   	at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
   	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
   	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
   	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
   	at org.testng.TestRunner.privateRun(TestRunner.java:648)
   	at org.testng.TestRunner.run(TestRunner.java:505)
   	at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
   	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
   	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
   	at org.testng.SuiteRunner.run(SuiteRunner.java:364)
   	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
   	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
   	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
   	at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
   	at org.testng.TestNG.runSuites(TestNG.java:1049)
   	at org.testng.TestNG.run(TestNG.java:1017)
   	at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:73)
   	at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)
   Caused by: java.lang.NullPointerException
   	at org.apache.pulsar.client.impl.schema.StructSchema.getSchemaInfoByVersion(StructSchema.java:172)
   	at org.apache.pulsar.client.impl.schema.AvroSchema.loadReader(AvroSchema.java:104)
   	at org.apache.pulsar.client.impl.schema.StructSchema$1.load(StructSchema.java:72)
   	at org.apache.pulsar.client.impl.schema.StructSchema$1.load(StructSchema.java:69)
   	at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3527)
   	at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2276)
   	at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2154)
   	at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2044)
   	... 29 more
   ```
   Perhaps related to this commit id : 900d81ae701b3199a86b3a026eb120747da23987
   

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [pulsar] congbobo184 commented on issue #6420: AvroSchema::decode(byte[] bytes, byte[] schemaVersion) crashes

Posted by GitBox <gi...@apache.org>.
congbobo184 commented on issue #6420: AvroSchema::decode(byte[] bytes, byte[] schemaVersion) crashes
URL: https://github.com/apache/pulsar/issues/6420#issuecomment-593273164
 
 
   I followed your steps, didn't appear exception. I think you upgrade client and broker version, the schema did't have schema version, cause it had been created before.

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [pulsar] shiv4289 edited a comment on issue #6420: AvroSchema::decode(byte[] bytes, byte[] schemaVersion) crashes

Posted by GitBox <gi...@apache.org>.
shiv4289 edited a comment on issue #6420: AvroSchema::decode(byte[] bytes, byte[] schemaVersion) crashes
URL: https://github.com/apache/pulsar/issues/6420#issuecomment-591266529
 
 
   The issue with my test above was that I did not set a schemaInfoProvider explicitly(second last line in below code). Updated test below does not crash as mentioned above. We can close this issue if that is accepted.
   
       @Test
       public void testSchemaVersionUpdate() throws PulsarClientException, PulsarAdminException, ExecutionException, InterruptedException, NoSuchFieldException {
           final String topic = "persistent://my-property/my-ns/testAvroSchemaUpgrade";
   
           Producer producer1 = pulsarClient.newProducer(Schema.AVRO(V1Data.class))
                   .topic(topic)
                   .create();
   
           Consumer consumer = pulsarClient.newConsumer(Schema.AUTO_CONSUME())
                   .topic(topic)
                   .subscriptionName("schemaUpdate1")
                   .subscribe();
   
           producer1.send(new V1Data(1));
   
           Message msg = consumer.receive();
   
           MultiVersionSchemaInfoProvider schemaProvider = new MultiVersionSchemaInfoProvider(TopicName.get(topic), (PulsarClientImpl) pulsarClient);
           String avroSchemaInJson = new String(schemaProvider.getSchemaByVersion(msg.getSchemaVersion()).get().getSchema());
           AvroSchema schema = (AvroSchema) Schema.AVRO(SchemaDefinition.builder().withJsonDef(avroSchemaInJson).build());
           schema.setSchemaInfoProvider(new MultiVersionSchemaInfoProvider(TopicName.get(topic), (PulsarClientImpl) pulsarClient));
           schema.decode(msg.getData(), msg.getSchemaVersion());
       }
   
   The only **minor** issue i see here is that maybe avro instantiation should set schemaInfoProvider. Need to check if this possible and close if not.

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [pulsar] codelipenghui commented on issue #6420: AvroSchema::decode(byte[] bytes, byte[] schemaVersion) crashes

Posted by GitBox <gi...@apache.org>.
codelipenghui commented on issue #6420: AvroSchema::decode(byte[] bytes, byte[] schemaVersion) crashes
URL: https://github.com/apache/pulsar/issues/6420#issuecomment-591175353
 
 
   @shiv4289 The last line should be ` schema.decode(msg.getData())` if you want to deserialize by writer schema. 

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [pulsar] shiv4289 edited a comment on issue #6420: AvroSchema::decode(byte[] bytes, byte[] schemaVersion) crashes

Posted by GitBox <gi...@apache.org>.
shiv4289 edited a comment on issue #6420: AvroSchema::decode(byte[] bytes, byte[] schemaVersion) crashes
URL: https://github.com/apache/pulsar/issues/6420#issuecomment-591273871
 
 
   > @shiv4289 The last line should be ` schema.decode(msg.getData())` if you want to deserialize by writer schema.
   
   @codelipenghui The current code is a workaround because I had hit issue#6419. But the current code should work too, 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


With regards,
Apache Git Services

[GitHub] [pulsar] shiv4289 edited a comment on issue #6420: AvroSchema::decode(byte[] bytes, byte[] schemaVersion) crashes

Posted by GitBox <gi...@apache.org>.
shiv4289 edited a comment on issue #6420: AvroSchema::decode(byte[] bytes, byte[] schemaVersion) crashes
URL: https://github.com/apache/pulsar/issues/6420#issuecomment-591266529
 
 
   The issue with my test above was that I did not set a schemaInfoProvider explicitly(second last line in below code). Updated test below does not crash as mentioned above. We can close this issue if that is accepted.
   
       @Test
       public void testSchemaVersionUpdate() throws PulsarClientException, PulsarAdminException, ExecutionException, InterruptedException, NoSuchFieldException {
           final String topic = "persistent://my-property/my-ns/testAvroSchemaUpgrade";
   
           Producer producer1 = pulsarClient.newProducer(Schema.AVRO(V1Data.class))
                   .topic(topic)
                   .create();
   
           Consumer consumer = pulsarClient.newConsumer(Schema.AUTO_CONSUME())
                   .topic(topic)
                   .subscriptionName("schemaUpdate1")
                   .subscribe();
   
           producer1.send(new V1Data(1));
   
           Message msg = consumer.receive();
   
           MultiVersionSchemaInfoProvider schemaProvider = new MultiVersionSchemaInfoProvider(TopicName.get(topic), (PulsarClientImpl) pulsarClient);
           String avroSchemaInJson = new String(schemaProvider.getSchemaByVersion(msg.getSchemaVersion()).get().getSchema());
           AvroSchema schema = (AvroSchema) Schema.AVRO(SchemaDefinition.builder().withJsonDef(avroSchemaInJson).build());
           schema.setSchemaInfoProvider(new MultiVersionSchemaInfoProvider(TopicName.get(topic), (PulsarClientImpl) pulsarClient));
           schema.decode(msg.getData(), msg.getSchemaVersion());
       }

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [pulsar] shiv4289 commented on issue #6420: AvroSchema::decode(byte[] bytes, byte[] schemaVersion) crashes

Posted by GitBox <gi...@apache.org>.
shiv4289 commented on issue #6420: AvroSchema::decode(byte[] bytes, byte[] schemaVersion) crashes
URL: https://github.com/apache/pulsar/issues/6420#issuecomment-591273871
 
 
   > @shiv4289 The last line should be ` schema.decode(msg.getData())` if you want to deserialize by writer schema.
   
   The current code is a workaround because I had hit issue#6419. But the current code should work too, 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


With regards,
Apache Git Services

[GitHub] [pulsar] shiv4289 closed issue #6420: AvroSchema::decode(byte[] bytes, byte[] schemaVersion) crashes

Posted by GitBox <gi...@apache.org>.
shiv4289 closed issue #6420: AvroSchema::decode(byte[] bytes, byte[] schemaVersion) crashes
URL: https://github.com/apache/pulsar/issues/6420
 
 
   

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [pulsar] shiv4289 commented on issue #6420: AvroSchema::decode(byte[] bytes, byte[] schemaVersion) crashes

Posted by GitBox <gi...@apache.org>.
shiv4289 commented on issue #6420: AvroSchema::decode(byte[] bytes, byte[] schemaVersion) crashes
URL: https://github.com/apache/pulsar/issues/6420#issuecomment-591266529
 
 
   The issue with my test above was that I did not set a schemaInfoProvider explicitly. Modified test below does not crash as mentioned above. We can close this issue if that is accepted.
   
       @Test
       public void testSchemaVersionUpdate() throws PulsarClientException, PulsarAdminException, ExecutionException, InterruptedException, NoSuchFieldException {
           final String topic = "persistent://my-property/my-ns/testAvroSchemaUpgrade";
   
           Producer producer1 = pulsarClient.newProducer(Schema.AVRO(V1Data.class))
                   .topic(topic)
                   .create();
   
           Consumer consumer = pulsarClient.newConsumer(Schema.AUTO_CONSUME())
                   .topic(topic)
                   .subscriptionName("schemaUpdate1")
                   .subscribe();
   
           producer1.send(new V1Data(1));
   
           Message msg = consumer.receive();
   
           MultiVersionSchemaInfoProvider schemaProvider = new MultiVersionSchemaInfoProvider(TopicName.get(topic), (PulsarClientImpl) pulsarClient);
           String avroSchemaInJson = new String(schemaProvider.getSchemaByVersion(msg.getSchemaVersion()).get().getSchema());
           AvroSchema schema = (AvroSchema) Schema.AVRO(SchemaDefinition.builder().withJsonDef(avroSchemaInJson).build());
           schema.setSchemaInfoProvider(new MultiVersionSchemaInfoProvider(TopicName.get(topic), (PulsarClientImpl) pulsarClient));
           schema.decode(msg.getData(), msg.getSchemaVersion());
       }

----------------------------------------------------------------
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


With regards,
Apache Git Services