Skip to content

KAFKA-20828: Centralize client throttling version logic - #22989

Open
arnabnandy7 wants to merge 2 commits into
apache:trunkfrom
arnabnandy7:fix/centralize-response-throttling
Open

KAFKA-20828: Centralize client throttling version logic#22989
arnabnandy7 wants to merge 2 commits into
apache:trunkfrom
arnabnandy7:fix/centralize-response-throttling

Conversation

@arnabnandy7

@arnabnandy7 arnabnandy7 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Description

Follow-up to KAFKA-20828 and PR #22908.

This change centralizes the historical KIP-219 client-throttling version boundaries in AbstractResponse.shouldClientThrottle().

For APIs that existed before KIP-219, the centralized mapping determines the first version that supports client-side throttling. For newer APIs, the behavior continues to be derived from the presence of throttle_time_ms in the response schema.

This preserves the existing version-specific behavior while removing all 37 shouldClientThrottle() overrides from individual response classes. Future throttling behavior can now be maintained in one place instead of across many subclasses.

Testing

The existing comprehensive regression test checks shouldClientThrottle() for every supported version of every API key. This verifies both:

  • Historical pre-KIP-219 version boundaries.
  • Schema-derived throttling behavior for newer APIs.

The following checks passed:

  • clients:test --tests org.apache.kafka.common.requests.RequestResponseTest

Reviewers: Jun Rao junrao@gmail.com, Chia-Ping Tsai chia7712@gmail.com

Signed-off-by: Arnab Nandy <arnab_nandy7@yahoo.com>

@junrao junrao left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arnabnandy7 : Thanks for the PR. Left a comment.

public static final int DEFAULT_THROTTLE_TIME = 0;

private static final Map<ApiKeys, Short> POST_KIP_219_VERSION = Map.ofEntries(
Map.entry(ApiKeys.PRODUCE, (short) 6),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, is this approach better? If we ever deprecate an old version of a request, this introduces another place that needs to be updated.

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.

@junrao my understanding is that these entries represent the fixed historical version where client-side throttling began, rather than the currently supported or non-deprecated version range.

Deprecating an older version should therefore not require updating this map. An entry may become redundant as the minimum supported version advances, but it would remain behaviorally correct.

That said, if you prefer avoiding the duplicated protocol-version metadata entirely, I’m happy to retain the version-specific overrides in the response classes.

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.

could you add comment for the POST_KIP_219_VERSION? For example:
These values represent immutable historical version boundaries for KIP-219 client-side throttling. They do not change when older API versions are deprecated.

is this approach better?

I love this approach because it is more simple and readable.

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.

sure @chia7712, documenting it better as suggested.

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.

Added the comment as well.

@github-actions github-actions Bot removed the triage PRs from the community label Jul 30, 2026
Signed-off-by: Arnab Nandy <arnab_nandy7@yahoo.com>
@arnabnandy7
arnabnandy7 requested review from chia7712 and junrao July 31, 2026 16:57
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.

3 participants