Skip to content

KAFKA-21068: Use batch.size as the producer record builder's write limit. - #23442

Open
chickenchickenlove wants to merge 1 commit into
apache:trunkfrom
chickenchickenlove:KAFKA-21068
Open

chickenchickenlove wants to merge 1 commit into
apache:trunkfrom
chickenchickenlove:KAFKA-21068

Conversation

@chickenchickenlove

@chickenchickenlove chickenchickenlove commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

The producer currently uses the allocated buffer's remaining capacity as
the MemoryRecordsBuilder write limit. For an oversized record, this
capacity can exceed batch.size, leaving the batch unready until
linger.ms expires even though its estimated size already exceeds the
configured batch size.

This PR passes batch.size as the write limit while retaining a buffer
large enough to hold the record.

Tests cover immediate readiness for oversized batches, linger behavior
when the compressed size estimate is below batch.size, and preventing
additional records from being appended to oversized batches. The
existing partitioner test is also updated to reflect earlier selection
of the next partition.

Reviewers: Lianet Magrans lmagrans@confluent.io

@github-actions github-actions Bot added triage PRs from the community producer clients labels Sep 12, 2026
@chickenchickenlove

Copy link
Copy Markdown
Contributor Author

@lianetm Hi!
I've created a new PR to address KAFKA-21068.
When you get a chance, please take a look. 🙇‍♂️

@lianetm lianetm added ci-approved and removed triage PRs from the community labels Sep 14, 2026

@lianetm lianetm left a comment

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.

Thanks @chickenchickenlove ! Took a first look.

One high level thought, could we add test coverage for the batch.size=0 case? That one I expect was partly broken too but unnoticed. It should disable batch (allow the single record in but nothing else), and not wait (even if linger > 0). I expect this PR fixes the no-wait part, and that we had no test covering it


final ByteBuffer batchBuffer = buffer;
RecordAppendResult appendResult = appendNewBatch(tp, dq, timestamp, key, value, headers, callbacks,
() -> MemoryRecords.builder(batchBuffer, RecordBatch.CURRENT_MAGIC_VALUE, compression, TimestampType.CREATE_TIME, 0L),

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.

This fix addresses only the "full" strategy, but the "incremental" seems to have the exact same issue here

Could we fix both consistently with this PR?

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.

Yes, You are right!
Let me prepare another PR to address it with some additional test codes.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants