Skip to content

KAFKA-20828: Derive client throttling from response schema - #22908

Merged
junrao merged 4 commits into
apache:trunkfrom
arnabnandy7:fix/client-response-throttling
Jul 27, 2026
Merged

KAFKA-20828: Derive client throttling from response schema#22908
junrao merged 4 commits into
apache:trunkfrom
arnabnandy7:fix/client-response-throttling

Conversation

@arnabnandy7

@arnabnandy7 arnabnandy7 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Description

AbstractResponse.shouldClientThrottle() previously defaulted to
false. As a result, newer response types containing a throttleTimeMs
field did not enable client-side throttling unless they explicitly
overrode this method.

This change derives the default behavior from the response schema. A
client now throttles when the response schema for the negotiated API
version contains the throttle_time_ms field.

Existing overrides remain unchanged to preserve historical
version-specific throttling behavior for older APIs.

This fixes client-side throttling for:

  • ConsumerGroupHeartbeatResponse
  • ShareGroupHeartbeatResponse
  • StreamsGroupHeartbeatResponse

It also prevents newly added response types with a throttle-time field
from accidentally omitting the required behavior.

Testing

Added regression coverage for every supported version of the affected
heartbeat APIs, verifying that shouldClientThrottle() returns true.

The following checks passed:

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

Reviewers: Jun Rao junrao@gmail.com, Hardanish Singh
(github:Hardanish-Singh)

Generated-by: OpenAI Codex
Signed-off-by: Arnab Nandy <arnab_nandy7@yahoo.com>
@github-actions github-actions Bot added triage PRs from the community clients small Small PRs labels Jul 22, 2026

@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 boolean shouldClientThrottle(short version) {
return false;
return apiKey.messageType.responseSchemas()[version].get("throttle_time_ms") != null;

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.

Could we remove all the overrides that return true ?

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.

will work on this :)

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 I've completed the removal, please check and suggest if anything else need to be remediated.

Generated-by: OpenAI Codex
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 updated PR. One more comment.

}

@Test
public void testClientThrottlesResponsesWithThrottleTime() {

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.

This test is ok, but it's not comprehensive. Could we test shouldClientThrottle() on all versions of all ApiKeys? shouldClientThrottle() should only be false if (1) the request version is pre KIP-219 (which we can hardcode) or (2) the response doesn't contain the throttleTimeMs field.

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 it's added, please review

@github-actions github-actions Bot removed the triage PRs from the community label Jul 23, 2026
Signed-off-by: Arnab Nandy <arnab_nandy7@yahoo.com>
@arnabnandy7
arnabnandy7 requested a review from junrao July 23, 2026 04:32
@arnabnandy7

Copy link
Copy Markdown
Contributor Author

The CI failure is unrelated to this PR.

@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 updated PR. Just a minor comment. Also, is the test failure related?

boolean shouldClientThrottle = responseHasThrottleTime &&
version >= postKip219Version.getOrDefault(apiKey, apiKey.oldestVersion());
assertEquals(shouldClientThrottle, getResponse(apiKey, version).shouldClientThrottle(version),
apiKey + " version " + version);

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.

Could we add a more descriptive error message?

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, updating

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 the CI failure is unrelated

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.

updated the message with more information as requested, @junrao

Signed-off-by: Arnab Nandy <arnab_nandy7@yahoo.com>
@github-actions github-actions Bot removed the small Small PRs label Jul 24, 2026
@arnabnandy7
arnabnandy7 requested a review from junrao July 24, 2026 18:40

@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 updated PR. LGTM

@junrao
junrao merged commit 63f445a into apache:trunk Jul 27, 2026
23 checks passed

@Test
public void testClientThrottlesResponsesWithThrottleTime() {
Map<ApiKeys, Short> postKip219Version = Map.ofEntries(

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.

Have we considered moving this map to the production code to slim down the sub-classes?

'''java
public boolean shouldClientThrottle(short version) {
Short minThrottledVersion = POST_KIP_219_VERSIONS.get(this.apiKey());
if (minThrottledVersion != null) {
return version >= minThrottledVersion;
}
return this.hasThrottleTimeMsField();
}
'''

(sorry for the poor formatting, I typed this on my phone)

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.

@chia7712 Thanks for the suggestion. Moving the KIP-219 version mapping into AbstractResponse would centralize the throttling logic and let us remove the remaining version-specific overrides. Since this PR has already been merged, I’ll look into addressing this in a follow-up 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.

@chia7712 I've created a follow up PR #22989 as I've informed above

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.

4 participants