Copilot commented on code in PR #20735:
URL: https://github.com/apache/kafka/pull/20735#discussion_r2445964154
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/StreamsRebalanceData.java:
##########
@@ -395,4 +398,14 @@ public List<StreamsGroupHeartbeatResponseData.Status>
statuses() {
return statuses.get();
}
+ /** Updated whenever a heartbeat response is received from the broker. */
+ public void setHeartbeatIntervalMs(final int heartbeatIntervalMs) {
+ this.heartbeatIntervalMs.set(heartbeatIntervalMs);
+ }
+
+ /** Returns the heartbeat interval in milliseconds, or -1 if not yet set.
*/
+ public int getHeartbeatIntervalMs() {
+ return heartbeatIntervalMs.get();
+ }
Review Comment:
The getter method's documentation states it returns -1 if not yet set, but
the field is initialized to -1 via `AtomicInteger(-1)` on line 333. Consider
documenting this initialization in the field-level comment or the setter to
clarify when/how the value transitions from -1 to a valid heartbeat interval.
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamThread.java:
##########
@@ -1587,11 +1587,21 @@ public void handleStreamsRebalanceData() {
}
private void handleMissingSourceTopicsWithTimeout(final String
missingTopicsDetail) {
+ // Determine the timeout: use 2 * heartbeatIntervalMs if available,
otherwise fall back to maxPollTimeMs
+ long timeoutMs = maxPollTimeMs;
+ if (streamsRebalanceData.isPresent()) {
+ final int heartbeatIntervalMs =
streamsRebalanceData.get().getHeartbeatIntervalMs();
+ if (heartbeatIntervalMs > 0) {
+ // Use 2 * heartbeatIntervalMs to ensure at least one more
heartbeat is sent
Review Comment:
The comment says 'at least one more heartbeat' but the calculation ensures
at least two heartbeat intervals (2 * heartbeatIntervalMs). Consider updating
the comment to clarify this ensures time for approximately two heartbeats, or
explain why this duration is sufficient.
```suggestion
// Use 2 * heartbeatIntervalMs to allow time for
approximately two heartbeats to be sent
```
--
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]