Skip to content

restore: batches fit the target topic's max.message.bytes - #9

Merged
solsson merged 1 commit into
mainfrom
restore-max-message-bytes
Oct 22, 2026
Merged

solsson merged 1 commit into
mainfrom
restore-max-message-bytes

Conversation

@solsson

@solsson solsson commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

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).

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>
@solsson
solsson merged commit b8c3160 into main Oct 22, 2026
3 checks passed
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.

1 participant