Skip to content

[fix][client] Send the pending batch before a non-batched message so deduplication does not drop it - #616

Open
gusteycamargo wants to merge 1 commit into
apache:mainfrom
gusteycamargo:fix/flush-batch-before-non-batched-message
Open

gusteycamargo wants to merge 1 commit into
apache:mainfrom
gusteycamargo:fix/flush-batch-before-non-batched-message

Conversation

@gusteycamargo

Copy link
Copy Markdown

Fixes #615

Motivation

When batching is enabled, a message that cannot be batched (e.g. a delayed message) is sent immediately, while the messages already in the batch container still wait for the batch to be flushed. The non-batched message took the next sequence id, so it reaches the broker before messages with lower sequence ids. With deduplication enabled, the broker then drops the whole batch as a duplicate, while the producer receives ResultOk for every message.

The Java client avoids it by flushing the batch container before sending any non-batched message (ProducerImpl#processOpSendMsg).

Modifications

  • In ProducerImpl::sendAsync, before sending a message that cannot be added to the batch, send the pending batch (batchMessageAndSend().complete()), the same way the producer already does when the batch container has no room for the next message.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

  • Added ClientDeduplicationBatchingTest.testBatchedMessagesBeforeDelayedMessage, parameterized for DefaultBatching and KeyBasedBatching: with deduplication enabled on the namespace, it sends 10 batched messages asynchronously and then a delayed one, and reads the topic from the earliest position. Without the fix only 1 of the 11 messages is stored, with it all 11 are.

Documentation

  • doc-required
    (Your PR needs to update docs and you will update later)

  • doc-not-needed
    (Bug fix in the producer, no API change)

🤖 Generated with Claude Code

…deduplication does not drop it

Fixes apache#615

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Batched messages are dropped by broker deduplication when a delayed message is sent while the batch is pending

1 participant