-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[Schema] Fix AutoConsumeSchema decode null schema version data #10811
[Schema] Fix AutoConsumeSchema decode null schema version data #10811
Conversation
@@ -308,13 +311,26 @@ public void fetchSchemaIfNeeded(SchemaVersion schemaVersion) throws SchemaSerial | |||
} | |||
} | |||
|
|||
private SchemaVersion getSchemaVersion(byte[] schemaVersion) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the static method have some advantage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll fix this, thanks.
pulsar-client/src/test/java/org/apache/pulsar/client/impl/TypedMessageBuilderImplTest.java
Outdated
Show resolved
Hide resolved
byte[] bytes = "bytes data".getBytes(); | ||
MessageImpl<GenericRecord> message = MessageImpl.create( | ||
new MessageMetadata(), ByteBuffer.wrap(bytes), autoConsumeSchema); | ||
Assert.assertNull(message.getSchemaVersion()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If using Python client produces messages without specifying a schema, the schema version will be null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very interesting.
I didn't know
@sijie AutoConsumeSchema code is very different in branch-2.7. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@sijie I have moved the label |
Motivation
Currently, the AutoConsumeSchema decode messages which has a null schema version will cause the NPE problem.
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