Repository navigation
restore: batches fit the target topic's max.message.bytes - #9
Merged
Merged
Conversation
The broker limits a record batch, not a record, to the topic's max.message.bytes. The restore producer used librdkafka's default batch.size (1000000 bytes), so restoring into a topic created with a lower limit failed with "Message size too large" although every record fits, as the source's producers wrote them under the same limit. RestoreProducer::open now reads the target topic's effective max.message.bytes (DescribeConfigs on the topic, which reports the broker default when the topic sets none; the broker's message.max.bytes if a broker leaves it out) and opens the producer with it as batch.size. librdkafka closes a batch before the record that would take it over batch.size, counting records at their largest encoding and the request header, so batches are as large as the topic accepts and never larger. message.max.bytes, librdkafka's request and single-record limit, is raised to leave room for that batch when the topic allows more than 1000000 bytes. Compression stays off, so the size librdkafka counts is the size the broker checks. Records are still sent one by one in order, so offsets (preserve and renumber) and delivery checks are unchanged. A record that as a batch of its own (exact v2 encoding) is larger than the limit is refused before it is sent, naming the topic, offset and sizes, instead of failing in the broker. librdkafka's statistics give the batches sent; the restore logs their number and the largest in bytes and records when it finishes. --follow produces through the Kafka destination, one record per request, and is not changed. Tests: unit tests for the sizes, the refusal and the producer config; an e2e scenario restoring 2 kB records into a topic limited to 12000 bytes (preserve, compared record by record) and into one limited to 1500 bytes (refused at offset 0, nothing produced). Without the batch.size setting the first fails with MessageSizeTooLarge. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
max.message.bytes caps both eatch record's payload (possibly with compression) and produce batch size. Found no way to support larger produce messages than record sizes, so we occasionally have to send in smaller batches than we read from mirror (we flush using 1MB buffer).