Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix][broker]Fix failover/exclusive consumer cumulate ack not remove msg from UnAckedMessageTracker #18407

Closed
wants to merge 5 commits into from

Conversation

Technoboy-
Copy link
Contributor

Motivation

If the consumer subscription type is Failover, or Exclusive, when do cumulate ack, the msg is not removed from UnAckedMessageTracker, causing the msg to be triggered redeliver by ack timeout.
,

Modifications

Remove the msg from UnAckedMessageTracker when complete acknowledgeCumulativeAsync

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

@Technoboy- Technoboy- added type/bug The PR fixed a bug or issue reported a bug area/broker doc-not-needed Your PR changes do not impact docs release/2.11.0 release/2.11.1 ready-to-test labels Nov 10, 2022
@Technoboy- Technoboy- added this to the 2.12.0 milestone Nov 10, 2022
@Technoboy- Technoboy- self-assigned this Nov 10, 2022
@codecov-commenter
Copy link

codecov-commenter commented Nov 10, 2022

Codecov Report

Merging #18407 (e038106) into master (58ad3d0) will decrease coverage by 1.07%.
The diff coverage is 58.33%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #18407      +/-   ##
============================================
- Coverage     47.67%   46.60%   -1.08%     
+ Complexity     9333     7687    -1646     
============================================
  Files           618      463     -155     
  Lines         58586    51659    -6927     
  Branches       6098     5514     -584     
============================================
- Hits          27933    24077    -3856     
+ Misses        27623    24779    -2844     
+ Partials       3030     2803     -227     
Flag Coverage Δ
unittests 46.60% <58.33%> (-1.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...okkeeper/mledger/impl/ShadowManagedLedgerImpl.java 0.00% <0.00%> (ø)
...kkeeper/mledger/impl/cache/EntryCacheDisabled.java 10.86% <0.00%> (ø)
...che/bookkeeper/mledger/impl/ManagedCursorImpl.java 37.17% <33.33%> (ø)
...keeper/mledger/impl/cache/RangeEntryCacheImpl.java 45.79% <50.00%> (ø)
...che/bookkeeper/mledger/impl/ManagedLedgerImpl.java 54.03% <88.88%> (ø)
...org/apache/bookkeeper/mledger/impl/OpAddEntry.java 64.21% <100.00%> (ø)
...rg/apache/bookkeeper/mledger/impl/OpReadEntry.java 65.55% <100.00%> (ø)
...keeper/mledger/impl/cache/PendingReadsManager.java 40.00% <100.00%> (ø)
...sar/broker/stats/metrics/ManagedLedgerMetrics.java 23.88% <0.00%> (-76.12%) ⬇️
.../pulsar/broker/service/SharedConsumerAssignor.java 3.70% <0.00%> (-57.41%) ⬇️
... and 413 more

@@ -458,7 +458,8 @@ protected CompletableFuture<Void> doAcknowledge(MessageId messageId, AckType ack
Consumer individualConsumer = consumers.get(topicMessageId.getTopicPartitionName());
if (individualConsumer != null) {
MessageId innerId = topicMessageId.getInnerMessageId();
return individualConsumer.acknowledgeCumulativeAsync(innerId);
return individualConsumer.acknowledgeCumulativeAsync(innerId)
.thenAccept(__ -> unAckedMessageTracker.remove(topicMessageId));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.thenAccept(__ -> unAckedMessageTracker.remove(topicMessageId));
.thenAccept(__ -> unAckedMessageTracker.removeMessagesTill(topicMessageId));

.acknowledgmentGroupTime(100, TimeUnit.MILLISECONDS)
.subscriptionInitialPosition(SubscriptionInitialPosition.Latest)
.subscribe();
final MessageId msgId = producer.send("1".getBytes());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we send more than one messages and ack the last one to ensure unAckedMessageTracker.removeMessagesTill works?

Copy link
Member

@mattisonchao mattisonchao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about doReconsumeLater method? and also, I'm wondering if this can work properly with the partitioned topic.
Consider this condition:

  1. We have 4 partitioned topics. the ledgers are ledger id: 1-> partition 1, 'ledger id: 2' -> partition 2 ...
  2. If one of the partitions, for example, partition-2 create a new ledger that id=5.
  3. At that time, the producer sends the message in round-robin mode. So, the message id sequence may be like [1:0, 1:1, 5:0, 5:1, 5:2, 5:3, 3:0, 3:1, 4:1, 4:2] in the consumer incoming queue.
  4. if we try to cumulative ack message 5:0, we will clear [3:0, 3:1, 4:1] in the UnAckedMessageTracker.

I'm not sure if I missing some other logic to avoid this condition. but I think I have to mention it here.

Comment on lines 461 to 462
return individualConsumer.acknowledgeCumulativeAsync(innerId)
.thenAccept(__ -> unAckedMessageTracker.removeMessagesTill(topicMessageId));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unAckedMessageTracker will have the message IDs from all partitions. If we use removeMessagesTill here, the message acknowledgment for partition-0 will also remove the message IDs of other partitions, right?

@@ -461,7 +461,8 @@ protected CompletableFuture<Void> doAcknowledge(MessageId messageId, AckType ack
Consumer individualConsumer = consumers.get(topicMessageId.getTopicPartitionName());
if (individualConsumer != null) {
MessageId innerId = topicMessageId.getInnerMessageId();
return individualConsumer.acknowledgeCumulativeAsync(innerId);
return individualConsumer.acknowledgeCumulativeAsync(innerId)
.thenAccept(__ -> unAckedMessageTracker.remove(topicMessageId));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cumulativeAck, not every message will invoke, so use remove can't remove all. if use removeMessagsTill(), all partitioned topics will be removed, so its better to find a better way to handle this case

@Technoboy- Technoboy- closed this Dec 11, 2022
@Technoboy- Technoboy- deleted the fix-cumulate-ack branch September 14, 2023 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/broker doc-not-needed Your PR changes do not impact docs ready-to-test release/2.11.1 type/bug The PR fixed a bug or issue reported a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants