Closed
Labels
type/bugThe PR fixed a bug or issue reported a bug
Description
Search before asking
- I searched in the issues and found nothing similar.
Read release policy
- I understand that unsupported versions don't get bug fixes. I will attempt to reproduce the issue on a supported version of Pulsar client and Pulsar broker.
Version
Client version: 3.2.2, Server version: 3.2.2
On previous version also notice same behaviour, e.g. 3.1.0, 3.1.2
Minimal reproduce step
Noticed messages loss when we restart all bookies and brokers during processing the data, so data is send to some topic and then our application consumes messages from topic saves msg payload somewhere and acknowledges messages. To be more precise here are steps:
- Simulate data streaming - send 1000000 msgs to topic A in some time, e.g. 1000000 msgs in 2 minutes.
- During the time when messages are sent restart all bookies and brokers at once (in our case we have 8 bookies and 6 brokers).
- In the same time application is consuming messages from topic A, saves message payload somewhere and after successful save acknowledges messages.
What did you expect to see?
No message loss
What did you see instead?
Some messages are lost. So when we send 1000000 messages, in directory where we store messages we see less than 1000000. We can't specify here how much less, because it is a very random situation. Sometimes we have all the messages, but sometimes something is missing.
Anything else?
No response
Are you willing to submit a PR?
- I'm willing to submit a PR!
Metadata
Metadata
Assignees
Labels
type/bugThe PR fixed a bug or issue reported a bug
Type
Projects
- StatusShow more project fieldsDone
Activity
dao-jun commentedon May 14, 2024
It looks a little strange, did you handle the send message result?
I mean, what do you do when send message failed?
It looks you don't handle the send message result, if there are some messages failed to send, you should handle the exception and retry again
In general, Pulsar do not retry to send message automatically, it's user's responsibility
szkoludasebastian commentedon May 15, 2024
I think it's not the case, because we are retrying. We handle message result and retry message if it was not sent correctly. During this test which I described we are sending messages till we won't have 1000000 correctly sent.
So we are sure that on input we have 1000000 messages.
dao-jun commentedon May 15, 2024
Did you mean you send 1000000 messages, the results are succeed, but after restart broker/bookie, some of them lost?
szkoludasebastian commentedon May 15, 2024
I mean we send 1000000 messages and during that time when our script was sending messages we restarted all bookies and brokers and then we were able to observe that some of messages lost. It was random situation for us, so we had to perform this test few times to observe that message loss.
dao-jun commentedon May 15, 2024
can I see your script?
szkoludasebastian commentedon May 15, 2024
I simplified our infrastructure a bit just to show our problem. To be more accurate our test script sends data to the application using websocket and our application sends messages to the topic. Our application responds with either ok or error results and in the case of error the script resends the message. In the case of the script and our application we see that as many messages as we expected were sent correctly.
szkoludasebastian commentedon May 15, 2024
We performed many failover tests using that script and we haven't observed any message loss. Only in this case when we restarted bookies and brokers in same time we observed something like that.
lhotari commentedon May 15, 2024
Which Pulsar client do you use? When you say "sent correctly", how do you define that?
szkoludasebastian commentedon May 15, 2024
We use pulsar client version: 3.2.2 (org.apache.pulsar:pulsar-client-api:3.2.2).
When I say that message was sent correctly I mean that we use something like this:
so we are creating message based on websocket request, then we use sendAsync() and we use thenApply() to return ok response. When any exception appears then we use exceptionallyCompose() and we return error response.
szkoludasebastian commentedon May 15, 2024
Here is our configuration for pulsar client (in comments I put values):
and also configuration for producer:
lhotari commentedon May 15, 2024
@szkoludasebastian This looks correct.
lhotari commentedon May 15, 2024
Another point of view is to say that the messages aren't delivered to the consumer in your test scenario. It's about the same as message loss from your application perspective, but there's a subtle difference. Would you be able to check if the messages are stored ok and would be available for delivery on another subscription and consumer that is started after this failure scenario. It's possible that the message loss happens in delivery on the consumer side.
What subscription type are you using? How do you handle acknowledgements?
When the problem happens, please share the internal stats for the topic and the subscription (use
pulsar-admin topics stats-internal [topicname]to get it) immediately after the problem has happened. That would reveal useful information about the internal states. Please also provide topic stats (pulsar-admin topics stats [topicname]), just to be sure that all available information is available for diagnostics.szkoludasebastian commentedon May 15, 2024
So we are using
Key_Sharedsubscription.So we have these two methods. One for acknowledge messages and second one for negative ack. We consume messages from topic and store them in batches. When it's time to flush batch and it is correctly stored in directory which we want then we are using this method to acknowledge messages by id. When there is some error with storing data in desired directory then we negatively acknowledge messages.
partitioned-stats:partitioned-stats-internal(attached as json file because there is a lot of lines):partitioned-stats-internal.json
szkoludasebastian commentedon May 15, 2024
I've added new subscription and consumer but there was no messages:
30 remaining items
lhotari commentedon Aug 23, 2024
This is a sign that consuming is blocked, at least temporarily.The might be related to #21199
lhotari commentedon Aug 23, 2024
Also here
lhotari commentedon Aug 23, 2024
I'd recommend following this advice as mitigation: #22709 (comment)
lhotari commentedon Sep 5, 2024
I'll rename the title from "Message loss" to "Acknowledgements lost". Technically the messages aren't lost, it's the acknowledgements that are lost. This can currently result in a situation where the messages don't get delivered to the client without reconnecting or unloading the topic.
[-][Bug] Message loss on bookies and brokers restart[/-][+][Bug] Acknowledgements lost on bookies and brokers restart resulting in messages not being delivered[/+]lhotari commentedon Sep 7, 2024
Analysis:
Acknowledgements will get lost in broker restarts. That's part of current design. That will cause Key_Shared consumers to "get stuck" and the messages aren't delivered (not technically lost).
I'm working on a solution to this problem based on the "ack receipt" feature. That has gaps. One of them is #23261 . In addition to that a new mode is needed where acknowledgements get automatically retried.
For detecting application side issues there is #23262 .
The current ack receipt documentation is confusing and wrong, there's #23249 for handling that.
In addition to addressing the lost acks issue, there's also a need for PIP-282 changes #21953 and other PRs #23226 (merged) and #23231 (in-progress).
There are multiple improvements in progress to cover fix this issue.
lhotari commentedon Sep 7, 2024
I have created a proposal "PIP-377: Automatic retry for failed acknowledgements", #23267 (rendered doc) . Discussion thread https://lists.apache.org/thread/7sg7hfv9dyxto36dr8kotghtksy1j0kr
szkoludasebastian commentedon Sep 9, 2024
Thank you for your commitment to analyze this problem. Do you perhaps know when these fixes and proposed change will be available for testing?
lhotari commentedon Sep 9, 2024
There's no published timeline yet. Since there are multiple related issues, I'm planning to create a GitHub project which will make it easier to follow the progress of individual issues.
It's possible that PIP-377 solution isn't required eventually since there could be a way to make improvements so that Key_shared subscriptions wouldn't end up losing acknowledgements during bookie and broker restarts.
Individual reproducer applications or instructions would be useful since they could help validate the solutions along the way.
@szkoludasebastian Contributing a way to reproduce the issues with the given instructions consistently would be a very valuable contribution to this work. Have you had a chance to make progress on that front?
szkoludasebastian commentedon Sep 10, 2024
Unfortunately not much progress in this area. I will inform here about the progress
dominikkulik commentedon Oct 21, 2024
Hi @lhotari
Some time ago we proceeded to create an application that will allow us to reproduce this error. However, it turned out that we are not able to do this.
After thorough analysis, we determined that the problem was in our service. Our deduplication mechanism was not properly implemented, which led to a situation that messages which should not have been acked, were acked after restarting our service. The problem was in our cache implementation.
Multiple attempts to restart bookies and brokers by themselves further confirmed that no message was lost.
Thank you for your commitment and help. Ticket can be closed.
lhotari commentedon Oct 21, 2024
Thanks for confirming, @dominikkulik . I'll close this issue.