-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[fix][common]Fix presto sql avro decode error when publish non-batched msgs #17093
[fix][common]Fix presto sql avro decode error when publish non-batched msgs #17093
Conversation
/pulsarbot run-failure-checks |
@codelipenghui @gaoran10 PTAL~ |
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.
Perhaps we can avoid introducing a new boolean flag associated:
diff --git a/pulsar-common/src/main/java/org/apache/pulsar/common/api/raw/RawMes
sageImpl.java b/pulsar-common/src/main/java/org/apache/pulsar/common/api/raw/Raw
MessageImpl.java
index 9f1d493247f..bc2177a25ed 100644
--- a/pulsar-common/src/main/java/org/apache/pulsar/common/api/raw/RawMessageImp
l.java
+++ b/pulsar-common/src/main/java/org/apache/pulsar/common/api/raw/RawMessageImp
l.java
@@ -36,7 +36,7 @@ public class RawMessageImpl implements RawMessage {
private final RawMessageIdImpl messageId = new RawMessageIdImpl();
private ReferenceCountedMessageMetadata msgMetadata;
- private final SingleMessageMetadata singleMessageMetadata = new SingleMessa
geMetadata();
+ private volatile SingleMessageMetadata singleMessageMetadata;
private ByteBuf payload;
private static final Recycler<RawMessageImpl> RECYCLER = new Recycler<RawMessageImpl>() {
@@ -56,7 +56,7 @@ public class RawMessageImpl implements RawMessage {
public void release() {
msgMetadata.release();
msgMetadata = null;
- singleMessageMetadata.clear();
+ singleMessageMetadata = null;
payload.release();
handle.recycle(this);
@@ -71,7 +71,7 @@ public class RawMessageImpl implements RawMessage {
msg.msgMetadata.retain();
if (singleMessageMetadata != null) {
- msg.singleMessageMetadata.copyFrom(singleMessageMetadata);
+ msg.singleMessageMetadata = singleMessageMetadata;
}
msg.messageId.ledgerId = ledgerId;
msg.messageId.entryId = entryId;
... while I'm unsure whether we can hold the reference, or we should deep copy. It seems we can barely hold the ref from my first glance, though.
We didn't know weather There is a field |
@AnonHxy please take a closer look at the patch, it sets |
Now I got that @tisonkun . But I think we have to use deep copy here. The reason is that:
Although we can create a new pulsar/pulsar-common/src/main/java/org/apache/pulsar/common/api/raw/MessageParser.java Lines 157 to 175 in 70020f1
|
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.
Thanks for your explanation @AnonHxy!
LGTM.
Still, I don't like the way introduce an associated boolean flag, so you may think of deep copy based on my suggested patch - that is, set to null
when release
, create a new SingleMessageMetadata
and copyForm
the parameter when get
. This way may have short coming on object reuse so it's not a net win. I'm OK with either approach.
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.
The fix looks good, could you please help add test to avoid the regression?
OK, have add UT, PTAL @codelipenghui |
/pulsarbot run-failure-checks |
1 similar comment
/pulsarbot run-failure-checks |
@Jason918 @Technoboy- Could you also please help take a look |
More context Before this change we can use this |
The modification in Before this modification, the |
…sgs (apache#17093) (cherry picked from commit 4b98b23) (cherry picked from commit 102735f)
Motivation
Finally I find the bug, which makes
org.apache.pulsar.tests.integration.presto.TestBasicPresto#testForSchema
fail, But I still don't know why other PRs can run it successThe
keyByteBuf
we get fromcurrentMessage
is not correct (line545 in code block 1), because we didn't decode the key with Base64 when the message is non-batched published. Explain in details:SingleMessageMetadata
is only set when publish batched messages. So we will useRawMessageImpl#singleMessageMetadata
to decode the key when messages is batched, or useRawMessageImpl#msgMetadata
if messages in non-batched, As line174 in code block 2.RawMessageImpl#singleMessageMetadata
will never be null (line38 code block 3)code block 1: [PulsarRecordCursor.java]:
pulsar/pulsar-sql/presto-pulsar/src/main/java/org/apache/pulsar/sql/presto/PulsarRecordCursor.java
Lines 542 to 547 in 70020f1
code block 2 [step into
currentMessage.getKeyBytes()
inRawMessageImpl.java
]:pulsar/pulsar-common/src/main/java/org/apache/pulsar/common/api/raw/RawMessageImpl.java
Lines 161 to 178 in 70020f1
code block 3 [RawMessageImpl.java]
pulsar/pulsar-common/src/main/java/org/apache/pulsar/common/api/raw/RawMessageImpl.java
Lines 34 to 41 in 70020f1
Modifications
boolean setSingleMessageMetadata
inorg.apache.pulsar.common.api.raw.RawMessageImpl
in order to check ifsingleMessageMetadata
is set or notVerifying this change
org.apache.pulsar.tests.integration.presto.TestBasicPresto#testForSchema
has covered this changeorg.apache.pulsar.common.api.raw.RawMessageImplTest#testNonBatchedMessage
org.apache.pulsar.common.api.raw.RawMessageImplTest#testBatchedMessage
Documentation
Check the box below or label this PR directly.
Need to update docs?
doc-required
(Your PR needs to update docs and you will update later)
doc-not-needed
(Please explain why)
doc
(Your PR contains doc changes)
doc-complete
(Docs have been already added)