Skip to content

[fix][client] Fix deserialized BatchMessageIdImpl acknowledgment failure - #19031

Closed
BewareMyPower wants to merge 8 commits into
apache:masterfrom
BewareMyPower:bewaremypower/message-id-deserialization-fix
Closed

BewareMyPower wants to merge 8 commits into
apache:masterfrom
BewareMyPower:bewaremypower/message-id-deserialization-fix

Conversation

@BewareMyPower

Copy link
Copy Markdown
Contributor

Fixes #19030

Motivation

When a BatchMessageIdImpl is created from a deserialization, the BatchMessageAcker object cannot be shared by all instances in the same batch, which leads to an acknowledgment failure when batch index ACK is disabled (by default).

Modifications

Maintain a map from the (ledger id, entry id) pair to the BatchMessageAcker in ConsumerImpl. If the BatchMessageIdImpl doesn't carry a valid BatchMessageAcker, create and cache a BatchMessageAcker instance and remove it when all messages in the batch are acknowledged.

It requires a change in MessageIdImpl#fromByteArray that a BatchMessageAckerDisabled will be created to indicate there is no shared acker.

To avoid making code more complicated, this patch refactors the existing code that many logics about consumer are moved from the ACK tracker to the consumer. It also removes the AckType parameter when acknowledging a list of messages.

Documentation

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

Matching PR in forked repository

PR in forked repository: BewareMyPower#15

@BewareMyPower BewareMyPower self-assigned this Dec 22, 2022
@github-actions github-actions Bot added the doc-not-needed Your PR changes do not impact docs label Dec 22, 2022
@BewareMyPower BewareMyPower added type/bug The PR fixed a bug or issue reported a bug area/client labels Dec 22, 2022
@BewareMyPower
BewareMyPower force-pushed the bewaremypower/message-id-deserialization-fix branch from 329e6ac to ba52f1e Compare December 22, 2022 15:48
@BewareMyPower

Copy link
Copy Markdown
Contributor Author

More explanations to the refactoring parts of this PR:

  1. I don't want to handle the list cumulative acknowledgment. Pulsar never supports this operation. There is no acknowledgeCumulative API that accepts a list of messages.
  2. Process the BatchMessageIdImpl in ConsumerImpl. The previous code processes it mainly in PersistentAcknowledgmentTracker, it appearly does not follow the OOP style and there are a lot of consumer.getXXX() calls. I don't want to write more code based on that, e.g. using consumer.getBatchMessageToAcker() everywhere.

Fixes apache#19030

### Motivation

When a `BatchMessageIdImpl` is created from a deserialization, the
`BatchMessageAcker` object cannot be shared by all instances in the same
batch, which leads to an acknowledgment failure when batch index ACK is
disabled (by default).

### Modifications

Maintain a map from the `(ledger id, entry id)` pair to the
`BatchMessageAcker` in `ConsumerImpl`. If the `BatchMessageIdImpl`
doesn't carry a valid `BatchMessageAcker`, create and cache a
`BatchMessageAcker` instance and remove it when all messages in the
batch are acknowledged.

It requires a change in `MessageIdImpl#fromByteArray` that a
`BatchMessageAckerDisabled` will be created to indicate there is no
shared acker.

To avoid making code more complicated, this patch refactors the existing
code that many logics about consumer are moved from the ACK tracker to
the consumer. It also removes the `AckType` parameter when acknowledging
a list of messages.
@BewareMyPower
BewareMyPower force-pushed the bewaremypower/message-id-deserialization-fix branch from ba52f1e to 1eb278d Compare December 23, 2022 03:18
@BewareMyPower

Copy link
Copy Markdown
Contributor Author

Thanks for your reviews, I'm going to address the comments soon.

@BewareMyPower

Copy link
Copy Markdown
Contributor Author

@congbobo184 You comments are addressed now, PTAL again.



private CompletableFuture<Void> doIndividualAckAsync(MessageIdImpl messageId) {
private void doIndividualAckAsync(MessageIdImpl messageId) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How can an Async variant be void? Especially doIndividualBatchAck below returns CompletableFuture<Void>.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The current names of these two "Async" methods are confusing. I will rename them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Since this PR already includes some refactorings, I might do that in a following PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@BewareMyPower Yeah. That sounds good.

BewareMyPower added a commit to BewareMyPower/pulsar-client-cpp that referenced this pull request Jan 17, 2023
### Motivation

Currently the main branch is broken by the concurrent merge of
apache#153 and
apache#151. It's because when
a batched message id is constructed from deserialization, there is no
`getBitSet` implementation of the internal acker.

### Modifications

Add a `bool` parameter to `MessageIdImpl::getBitSet` to indicate whether
the message ID is batched. The logic is similar with

https://github.com/apache/pulsar/blob/299bd70fdfa023768e94a8ee4347d39337b6cbd4/pulsar-client/src/main/java/org/apache/pulsar/client/impl/PersistentAcknowledgmentsGroupingTracker.java#L325-L327

and

https://github.com/apache/pulsar/blob/299bd70fdfa023768e94a8ee4347d39337b6cbd4/pulsar-client/src/main/java/org/apache/pulsar/client/impl/PersistentAcknowledgmentsGroupingTracker.java#L345-L347

Add a `testMessageIdFromBuild` to test the acknowledgment for a message
ID without an acker could succeed for a consumer that enables batch
index ACK.

### TODO

In future, apache/pulsar#19031 might be migrated
into the C++ client to fix the consumer that disables batch index ACK.
@github-actions

github-actions Bot commented Feb 3, 2023

Copy link
Copy Markdown

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

@michaeljmarshall

Copy link
Copy Markdown
Member

As discussed on the mailing list https://lists.apache.org/thread/w4jzk27qhtosgsz7l9bmhf1t7o9mxjhp, there is no plan to release 2.9.6, so I am going to remove the release/2.9.6 label

@github-actions

Copy link
Copy Markdown

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

@merlimat

Copy link
Copy Markdown
Contributor

Thanks @BewareMyPower, and sorry this sat so long. Since PIP-391 (#24203, 4.1.0) batch index ack is on by default on both client and broker, so a batch id from MessageId.fromByteArray now acks through the batch-index path and the entry completes. The remaining gap is only with batchIndexAckEnabled(false), and a shared acker cache (with the seek/redelivery concerns raised here) doesn't seem worth it for that. PIP-229 also removed BatchMessageAcker, so this would need a full rewrite. I'm closing this as superseded. If you'd like, a PR adding your MessageIdSerializationTest against master would be welcome as a regression guard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/client doc-not-needed Your PR changes do not impact docs ready-to-test Stale 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.

[Bug] Deserialized BatchMessageIdImpl cannot be used for acknowledgment