pulsar icon indicating copy to clipboard operation
pulsar copied to clipboard

[fix][broker]fix Repeated messages of shared dispatcher

Open poorbarcode opened this issue 3 years ago • 1 comments

Fixes #16795

Motivation

In Shard mode:

  1. When redelivering some message, will trigger the next read.
  2. When closing the lastest consumer or adding the first consumer, will trigger cursor.rewind which 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 avatar Oct 28 '22 00:10 poorbarcode

@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.

codelipenghui avatar Oct 28 '22 02:10 codelipenghui

The pr had no activity for 30 days, mark with Stale label.

github-actions[bot] avatar Dec 11 '22 02:12 github-actions[bot]