Skip to content

KAFKA-20845: Don't flush empty batch when appending large records in group coordinator (4.2) - #23207

Merged
chia7712 merged 1 commit into
apache:4.2from
dajac:KAFKA-20845-4.2
Aug 20, 2026
Merged

KAFKA-20845: Don't flush empty batch when appending large records in group coordinator (4.2)#23207
chia7712 merged 1 commit into
apache:4.2from
dajac:KAFKA-20845-4.2

Conversation

@dajac

@dajac dajac commented Aug 20, 2026

Copy link
Copy Markdown
Member

When appending records, we create a new batch if no batch exists.
KAFKA-19760 introduced a flush of any existing batch when appending
large records, to maximize our chances of compressing the records under
the max.message.bytes. When these two things happen in the same append
operation, we flush an empty batch.

Flushing an empty batch is written to fail and revert the coordinator
state. This would be harmless, except some group coordinator operations
update the coordinator state directly without replay. Upon appending
their records and triggering the empty batch flush, their state changes
are then reverted while their records are written. The group
coordinator's in-memory state diverges from the on-disk state and
subsequent writes for the group can be invalid for the on-disk state.
eg. we may have a consumer group downgraded to a classic group, followed
by consumer group records which is invalid.

Do not flush empty batches when appending large records.

Backport of #22969 to 4.2. The test is adapted to the
CoordinatorRuntime API of this branch.

Reviewers: Chia-Ping Tsai chia7712@gmail.com

…group coordinator (4.2)

When appending records, we create a new batch if no batch exists.
KAFKA-19760 introduced a flush of any existing batch when appending
large records, to maximize our chances of compressing the records under
the max.message.bytes. When these two things happen in the same append
operation, we flush an empty batch.

Flushing an empty batch is written to fail and revert the coordinator
state. This would be harmless, except some group coordinator operations
update the coordinator state directly without replay. Upon appending
their records and triggering the empty batch flush, their state changes
are then reverted while their records are written. The group
coordinator's in-memory state diverges from the on-disk state and
subsequent writes for the group can be invalid for the on-disk state.
eg. we may have a consumer group downgraded to a classic group, followed
by consumer group records which is invalid.

Do not flush empty batches when appending large records.

Backport of apache#22969 to 4.2. The test is adapted to the
`CoordinatorRuntime` API of this branch.

(cherry picked from commit 475e0a1)
@dajac
dajac requested a review from squah-confluent August 20, 2026 07:17

@chia7712 chia7712 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.

LGTM

@chia7712
chia7712 merged commit 4ffb203 into apache:4.2 Aug 20, 2026
20 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.

3 participants