mark-s-taylor opened a new pull request, #24121:
URL: https://github.com/apache/kafka/pull/24121

   NOTE: This PR builds upon #23363 that is still awaiting merge. Will require 
a rebase before merging.
   
   ## Switch `InternalTopicManager` retry backoff from fixed to exponential
   
   This change replaces the fixed `retryBackOffMs` delay used throughout 
`InternalTopicManager` with an `ExponentialBackoff` instance, so that retry 
delays grow geometrically between rounds instead of staying constant.
   
   ### What changed and why
   
   Previously, every retry loop in `InternalTopicManager` (topic creation, 
validation, cleanup, and describe) would sleep for the same fixed 
`retry.backoff.ms` value after each failed attempt. This means that under 
transient pressure — for example, a topic in the middle of an async broker-side 
delete — the client hammers the cluster at a constant, potentially high rate 
for the entire `retryTimeoutMs` window.
   
   Kafka's client libraries already provide `ExponentialBackoff` (used by 
producers, consumers, and the admin client itself). This PR wires the same 
mechanism into `InternalTopicManager`:
   
   - **Initial delay**: `retry.backoff.ms` (unchanged from before — no 
regression for existing configs).
   - **Cap**: `max(retry.backoff.ms, 
CommonClientConfigs.DEFAULT_RETRY_BACKOFF_MAX_MS)` — Streams has no 
`retry.backoff.max.ms` config, so the standard client default is used as the 
ceiling, but it is never allowed to be *lower* than the configured initial 
backoff.
   - **Base and jitter**: `CommonClientConfigs.RETRY_BACKOFF_EXP_BASE` and 
`CommonClientConfigs.RETRY_BACKOFF_JITTER`, consistent with the rest of the 
Kafka client stack.
   
   Each retry loop now tracks an `attempts` counter and passes 
`retryBackoff.backoff(attempts++)` into `maybeSleep` and directly into 
`Utils.sleep` call-sites. This ensures the backoff value logged in messages and 
the value actually slept are always the same.
   
   #### Additional cleanup
   - The timeout/sleep logic that was duplicated inside `createTopics` has been 
removed; the outer `makeReady` loop already owns the deadline check and sleep, 
so the inner copy was redundant and caused a second sleep per round.
   - `Utils.sleep` inside `maybeSleep` has been replaced with `time.sleep` so 
that tests using `MockTime` can observe and control the clock advancement 
without real wall-clock delays.
   - Trailing whitespace and a missing final newline have been fixed.
   
   ### Design decisions to review
   - **No `retry.backoff.max.ms` in Streams.** The cap is 
`max(retry.backoff.ms, CommonClientConfigs.DEFAULT_RETRY_BACKOFF_MAX_MS)` (1000 
ms by default).
   - **Sleeps are not capped by the remaining time.** The deadline 
(`max.poll.interval.ms / 2`) is checked before a sleep, so a method can run at 
most one backoff past it. With defaults that is about 1.2 s against a 150 s 
budget. It looks like it'd matter most if `max.poll.interval.ms` is small or 
`retry.backoff.ms` is large. We have the option to cap each sleep at `deadline 
- now`.
   
   ### Tests
   - `shouldBackOffBetweenRoundsWhenTopicIsMarkedForDeletion` no longer asserts 
exactly 50 ms. It asserts the jitter bounds of three rounds (10, 20, 40 ms), 
computed from the `CommonClientConfigs` constants as the client tests do.
   - New test `shouldIncreaseBackOffBetweenRoundsWhenTopicIsMarkedForDeletion` 
records each sleep and checks that each is within its round's bounds.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to