Repository navigation
Fix usage of seekAsync in MessageImpl.hasMessageAvailable and flaky-test - #10190
Conversation
|
What about changing the Title and explicitly point out that we are modifying the behaviour of "hasMessageAvailableAsync" ? The title reads about fixing a flaky test but we are touching ConsumerImpl |
OK, do you have any good suggestions ? |
|
What about "Fix usage of seekAsync in MessageImpl.hasMessageAvailable" ? |
Em...But I fixed 2 bugs in total, not only |
# Conflicts: # pulsar-broker/src/test/java/org/apache/pulsar/client/impl/MultiTopicsReaderTest.java
codelipenghui
left a comment
There was a problem hiding this comment.
Seems the root cause is the reader uses a incorrect start message ID to subscribe to a topic during the reconnection. I think the right way to fix this problem is fix the start message ID that the reader used for subscribe to the topic and the topic always apply the reader's start message ID since the reader always uses the exclusive non-durable subscription. And the case of the reader never consume any messages due to the reconnection and users uses the latest position as the initial start message ID, this might introduce uncertain behavior during the reconnection. My suggestion is if uses the latest positioin as the nitial start message ID for a reader, we can get the last message ID from the broker first and then use this message ID as the start message ID to subscribe to the topic, so that as long as the consumer does not crashes, it will always uses the certain message ID to subscribe to the topic when it never receives any messages.
|
I tried to handle this situation in connectionOpen, but failed: Because the sub command does not have an inclusive option, it can only be read from the next item of startMessageId. And I can't set entryId or ledger -1, otherwise the client may read forward after multiple reconnections. Unless I change the proto, add the inclusive option. |
|
Record the process:
Finally, I can only temporarily use seek to solve this problem. If anyone wants to use subscription to solve this problem, they can open another issue. |
eolivelli
left a comment
There was a problem hiding this comment.
LGTM
I believe this fix does not fix 2.7.2, it is better to keep it only on master branch and give time to settle
|
@codelipenghui can you please take a final look ? |
|
This PR can also fix these problems:
Although it is not a perfect solution, it is solved |
### Motivation I temporarily fixed this problem in PR #10190. Now we have found a better way, this way can avoid the seek, then avoid trigger another reconnection. Thank you @codelipenghui to troubleshoot this issue with me all night. We have added a lot of log and found that this issue is caused by some race condition problems. Here is the first reason: https://github.com/apache/pulsar/blob/f2d72c9fc13a33df584ec1bd96a4c147774b858d/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java#L1808-L1818 Now we have an acknowledgmentsGroupingTracker to filter duplicate messages, and this Tracker will be cleaned up after seek. However, it is possible that the connection is ready and Broker has pushed message, but `acknowledgmentsGroupingTracker.flushAndClean(); ` has not been executed yet. Finally hasMessageAvailableAsync returns true, but the message cannot be read because it is filtered by the acknowledgmentsGroupingTracker ### Modifications clean the tracker when connection was open ### Verifying this change
) ### Motivation I temporarily fixed this problem in PR apache#10190. Now we have found a better way, this way can avoid the seek, then avoid trigger another reconnection. Thank you @codelipenghui to troubleshoot this issue with me all night. We have added a lot of log and found that this issue is caused by some race condition problems. Here is the first reason: https://github.com/apache/pulsar/blob/f2d72c9fc13a33df584ec1bd96a4c147774b858d/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java#L1808-L1818 Now we have an acknowledgmentsGroupingTracker to filter duplicate messages, and this Tracker will be cleaned up after seek. However, it is possible that the connection is ready and Broker has pushed message, but `acknowledgmentsGroupingTracker.flushAndClean(); ` has not been executed yet. Finally hasMessageAvailableAsync returns true, but the message cannot be read because it is filtered by the acknowledgmentsGroupingTracker ### Modifications clean the tracker when connection was open ### Verifying this change
…est (apache#10190) (cherry picked from commit 46cfd8e)
### Motivation I temporarily fixed this problem in PR #10190. Now we have found a better way, this way can avoid the seek, then avoid trigger another reconnection. Thank you @codelipenghui to troubleshoot this issue with me all night. We have added a lot of log and found that this issue is caused by some race condition problems. Here is the first reason: https://github.com/apache/pulsar/blob/f2d72c9fc13a33df584ec1bd96a4c147774b858d/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java#L1808-L1818 Now we have an acknowledgmentsGroupingTracker to filter duplicate messages, and this Tracker will be cleaned up after seek. However, it is possible that the connection is ready and Broker has pushed message, but `acknowledgmentsGroupingTracker.flushAndClean(); ` has not been executed yet. Finally hasMessageAvailableAsync returns true, but the message cannot be read because it is filtered by the acknowledgmentsGroupingTracker ### Modifications clean the tracker when connection was open ### Verifying this change (cherry picked from commit f69a03b)
…est (apache#10190) (cherry picked from commit 46cfd8e)
) I temporarily fixed this problem in PR apache#10190. Now we have found a better way, this way can avoid the seek, then avoid trigger another reconnection. Thank you @codelipenghui to troubleshoot this issue with me all night. We have added a lot of log and found that this issue is caused by some race condition problems. Here is the first reason: https://github.com/apache/pulsar/blob/f2d72c9fc13a33df584ec1bd96a4c147774b858d/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java#L1808-L1818 Now we have an acknowledgmentsGroupingTracker to filter duplicate messages, and this Tracker will be cleaned up after seek. However, it is possible that the connection is ready and Broker has pushed message, but `acknowledgmentsGroupingTracker.flushAndClean(); ` has not been executed yet. Finally hasMessageAvailableAsync returns true, but the message cannot be read because it is filtered by the acknowledgmentsGroupingTracker clean the tracker when connection was open (cherry picked from commit f69a03b)
Fixes #10152
Motivation
1
When the connection is reset, message received by reader may be duplicated, so I remove the judgment of whether the key is unique
Repeated scene:
start to read -> 1255:0 threadId:68
after read,update read position -> 1255:1 threadId:68
start to read -> 1255:1 threadId:68
[pulsar-external-listener-39-1] WARN org.apache.pulsar.client.impl.ConsumerImpl - [persistent://my-property/my-ns/my-reader-topic-with-batching-inclusivebdcf4a3e-6c2e-4d36-b362-52c066d14da0-partition-2] [d975f7e2-7b8f-467a-a56b-b3c1e96ec75f] Could not get connection while getLastMessageId -- Will try again in 190 ms
[pulsar-external-listener-39-1] INFO org.apache.pulsar.client.impl.ConsumerImpl - [persistent://my-property/my-ns/my-reader-topic-with-batching-inclusivebdcf4a3e-6c2e-4d36-b362-52c066d14da0-partition-2][d975f7e2-7b8f-467a-a56b-b3c1e96ec75f] Get topic last message Id
[pulsar-client-io-38-1] INFO org.apache.pulsar.client.impl.ConsumerImpl - [persistent://my-property/my-ns/
my-reader-topic-with-batching-inclusivebdcf4a3e-6c2e-4d36-b362-52c066d14da0-partition-2][d975f7e2-7b8f-467a-a56b-b3c1e96ec75f] Successfully getLastMessageId 1255:0
[pulsar-client-io-38-1] INFO org.apache.pulsar.client.impl.ConsumerImpl - [persistent://my-property/my-ns/my-reader-topic-with-batching-inclusivebdcf4a3e-6c2e-4d36-b362-52c066d14da0-partition-2][d975f7e2-7b8f-467a-a56b-b3c1e96ec75f] Seek subscription to the message 1255:0:2:4
2
When I fixed bug 1, I found bug 2
normal situation:
abnormal situation:
When 2 is triggered, the message in incomeQueue is cleaned, and startMessageId is no longer equal to latest, so seek will not be triggered anymore, resulting in the cleaned message cannot be read
The only time to trigger seek now is:
lastDequeuedMessageId == MessageId.earliest
and
startMessageId.equals(MessageId.latest)
and
resetIncludeHead == true
Modifications
1)remove ·
assertTrue(set.remove(key))in uniteTest, because message may be duplicated2)add seek in hasMessageAvailableAsync