RobertIndie opened a new pull request, #21048:
URL: https://github.com/apache/pulsar/pull/21048
<!--
### Contribution Checklist
- PR title format should be *[type][component] summary*. For details, see
*[Guideline - Pulsar PR Naming
Convention](https://pulsar.apache.org/contribute/develop-semantic-title/)*.
- Fill out the template below to describe the changes contributed by the
pull request. That will give reviewers the context they need to do the review.
- Each pull request should address only one issue, not mix up code from
multiple issues.
- Each commit in the pull request has a meaningful commit message
- Once all items of the checklist are addressed, remove the above text and
this checklist, leaving only the filled out template below.
-->
Fixes https://github.com/apache/pulsar/issues/20934
## Motivation
If the consumer receives a chunked message, it currently couldn't retry it
or send it to the DLQ. It will throw an exception like this:
```
java.util.concurrent.CompletionException:
org.apache.pulsar.client.api.PulsarClientException$InvalidMessageException: The
producer xxx of the topic persistent://a/b/c sends a message with 8085120 bytes
that exceeds 5242880 bytes
```
This is because we don't enable the chunking for the retry producer and the
DLQ producer in the consumer.
This PR enables the chunking feature for retry and DLQ producers. But
currently we couldn't enable the chunking and batching together. So the side
effect of this change is that we need to disable the batching for the DLQ
producer, while the retry producer already disables the batching. It's OK to do
that because the DLQ producer generally has little traffic. It does not
significantly affect the producer's performance.
This PR also fixes the two following issues:
### Issue A: Consumers can't redeliver chunked messages
If the consumer tries to redeliver a chunked message, the message ID is
reconstructed in `discardBatch` and causes this message ID to lose information
about the chunk. The comparison in the `unAckedChunkedMessageIdSequenceMap`
will be failed. The consumer will never redeliver chunked messages.
We shouldn't reconstruct the chunked message ID in `discardBatch`. The chunk
message ID also doesn't contain batch.
### Issue B: The chunked message couldn't be resent
When the producer resend the chunked message, the chunk id in the message
metadata of all subsequent chunk will be set to the last chunk id.
The root cause is that the producer shares the same MessageMetadata for all
chunks in a chunked message.
https://github.com/apache/pulsar/blob/4634311e75176f9acec16e37e2900945a8e2040e/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java#L696-L700
Therefore, when `op.rePopulate` is called. the chunk id in
`finalMsgMetadata` is pointed to the last chunk. Suppose we have a large
message with 3 chunks. The producer may eventually send all 3 messages with the
same chunk id `3`. The consumer will treat these messages as corrupted and
ignore them, causing it to not be able to receive any of these messages.
## Modification
- Enable chunking and disable batching for retry and DLQ producers.
- Don't discard the batch for the chunked message ID to fix Issue A.
- Don't redeliver the chunk message ID itself when redelivering unacked
messages. Just need to redeliver the message ID for all single chunks.
- Reset the chunkID when resending the chunk message to fix Issue B.
- Add chunk messages test case for `testDeadLetterTopic`.
### Verifying this change
This change added tests.
### Does this pull request potentially affect one of the following parts:
<!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
*If the box was checked, please highlight the changes*
- [ ] Dependencies (add or upgrade a dependency)
- [ ] The public API
- [ ] The schema
- [ ] The default values of configurations
- [ ] The threading model
- [ ] The binary protocol
- [ ] The REST endpoints
- [ ] The admin CLI options
- [ ] The metrics
- [ ] Anything that affects deployment
### Documentation
<!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
- [ ] `doc` <!-- Your PR contains doc changes. -->
- [ ] `doc-required` <!-- Your PR changes impact docs and you will update
later -->
- [x] `doc-not-needed` <!-- Your PR changes do not impact docs -->
- [ ] `doc-complete` <!-- Docs have been already added -->
### Matching PR in forked repository
PR in forked repository: <!-- ENTER URL HERE -->
<!--
After opening this PR, the build in apache/pulsar will fail and instructions
will
be provided for opening a PR in the PR author's forked repository.
apache/pulsar pull requests should be first tested in your own fork since
the
apache/pulsar CI based on GitHub Actions has constrained resources and quota.
GitHub Actions provides separate quota for pull requests that are executed
in
a forked repository.
The tests will be run in the forked repository until all PR review comments
have
been handled, the tests pass and the PR is approved by a reviewer.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]