pulsar
pulsar copied to clipboard
[fix][broker]fix Repeated messages of shared dispatcher
Fixes #16795
Motivation
In Shard mode:
- When redelivering some message, will trigger the next read.
- When closing the lastest consumer or adding the first consumer, will trigger
cursor.rewindwhich moves the read position to the earliest.
When the above two events are executed concurrently, the resulting redelivered message will be consumed twice. E.g:
| step | close the last consumer & create 2 consumer |
redeliver |
|---|---|---|
| 1 | push message(3:1) to redeliver queue |
|
| 2 | trigger next read(readMoreEntries) |
|
| 3 | read entries(3:1) from the redeliver queue |
|
| 4 | clear the redeliver queue | |
| 5 | set the read position of cursor to earliest(3:0) |
|
| 6 | trigger read event for the new consumer B | get next consumer, the result is the new consumer A |
| 7 | read entries 3:0~3:10 |
send message(3:0) to the new consumer |
| 8 | send messages 3:0~3:10 to the new consumer B |
send message(3:0) to the new consumer A |
| 9 | bingo! |
How to reproduce the problem
Run SimpleProducerConsumerTest.concurrentlyRedeliverAndCloseLastConsumer twice.
Modifications
Before step 7 of the flow redeliver, check that the messages are still in queue messagesToRedeliver.
Documentation
- [ ]
doc - [ ]
doc-required - [x]
doc-not-needed - [ ]
doc-complete
Matching PR in forked repository
PR in forked repository:
- https://github.com/poorbarcode/pulsar/pull/32
@poorbarcode Interesting. I think the expected behavior is no matter how many consumers are under a subscription. The subscription should only perform the entry read operation one by one.
The pr had no activity for 30 days, mark with Stale label.