Issue 16802: fix Repeated messages of shared dispatcher - #16812
Conversation
Changes: sendMessagesToConsumer must block reads of new entries otherwise we will end up in reading duplicates
| break; | ||
| sendInProgress = true; | ||
| try { | ||
| if (needTrimAckedMessages()) { |
There was a problem hiding this comment.
Could you move this try block to another method to avoid so many code changes? For example,
private void trySendMessagesToConsumers(ReadType readType, List<Entry> entries) {
/* ... */
}
protected synchronized void sendMessagesToConsumers(ReadType readType, List<Entry> entries) {
sendInProgress = true;
try {
trySendMessagesToConsumers(readType, entries);
} finally {
sendInProgress = false;
}
readMoreEntries();
}In addition, the following code in your original code can be removed because in the finally block sendInProgress would be false, then readMoreEntries will be called after that.
if (entriesToDispatch == 0) {
sendInProgress = false;
readMoreEntries();
return;
}
BewareMyPower
left a comment
There was a problem hiding this comment.
LGTM. Thanks for your quick fix!
| readMoreEntries(); | ||
| } | ||
|
|
||
| protected synchronized void trySendMessagesToConsumers(ReadType readType, List<Entry> entries) { |
There was a problem hiding this comment.
The PersistentStickyKeyDispatcherMultipleConsumers should also override this method.
There was a problem hiding this comment.
you are right, thanks for the heads up
I will also add a comment for future people who will put their hands here
| for (int i = 0; i < N; i++) { | ||
| msg = consumer.receive(10, TimeUnit.SECONDS); | ||
| receivedMsgs.add(msg.getValue()); | ||
| consumer.acknowledge(msg); |
There was a problem hiding this comment.
Why need to remove this line?
There was a problem hiding this comment.
I added that line in the PR that created this problem.
this line made the test pass,
with this "fix" now the test still passes
this test is very interesting because it runs many readMoreEntries() in a separate thread, simulating the mess that happens inside the broker
it is important to revert this change to the test
|
/pulsarbot rerun-failure-checks |
|
Please check the failed test |
|
@codelipenghui I am looking into the failed test. |
|
@codelipenghui I have fixed the test, there was a problem in the KEY_SHARED dispatcher |
codelipenghui
left a comment
There was a problem hiding this comment.
I have tried to run some performance test on Shared and Key_Shared subscription. Seems to have no noticeable performance regression
|
@codelipenghui @BewareMyPower I have merged the PR |
| protected boolean shouldRewindBeforeReadingOrReplaying = false; | ||
| protected final String name; | ||
|
|
||
| protected boolean sendInProgress; |
There was a problem hiding this comment.
I think this flag should be volatile?
There was a problem hiding this comment.
Itbis guarded by synchronized blocks. No need to makenit volatile
There was a problem hiding this comment.
I misunderstood something, you're right.
(cherry picked from commit 825b68d)
…sages of shared dispatcher (#16812)
Changes: sendMessagesToConsumer must block reads of new entries otherwise we will end up in reading duplicates
Fixes #16802 #16693
Motivation
As described in #16802 it may happen that multiple calls to
readMoreEntriesare served before the execution ofsendMessagesToConsumerUnfortunately there is no control over the execution of
readMoreEntries, it may happen in many different threadpoolsModifications
Add a flag to prevent concurrent execution of
sendMessagesToConsumerwithreadMoreEntries.Revert aa change to a test modified in #16802 to make the test pass
Verifying this change
This change is already covered by existing tests
doc-not-needed