cadonna commented on code in PR #14873: URL: https://github.com/apache/kafka/pull/14873#discussion_r1423147503
########## clients/src/main/java/org/apache/kafka/clients/consumer/internals/HeartbeatRequestManager.java: ########## @@ -201,13 +224,35 @@ public long maximumTimeToWait(long currentTimeMs) { return heartbeatNow ? 0L : heartbeatRequestState.nextHeartbeatMs(currentTimeMs); } - private NetworkClientDelegate.UnsentRequest makeHeartbeatRequest() { + /** + * When consumer polls, we need to reset the pollTimer. If the poll timer has expired, we rejoin only when the + * member is in the {@link MemberState#UNSUBSCRIBED} state. + */ + public void resetPollTimer() { + pollTimer.reset(maxPollIntervalMs); + } + + private NetworkClientDelegate.UnsentRequest makeHeartbeatRequest(final long currentTimeMs, + final boolean ignoreResponse) { + NetworkClientDelegate.UnsentRequest request = makeHeartbeatRequest(ignoreResponse); + heartbeatRequestState.onSendAttempt(currentTimeMs); + membershipManager.onHeartbeatRequestSent(); + return request; + } + + private NetworkClientDelegate.UnsentRequest makeHeartbeatRequest(final boolean ignoreResponse) { NetworkClientDelegate.UnsentRequest request = new NetworkClientDelegate.UnsentRequest( - new ConsumerGroupHeartbeatRequest.Builder(this.heartbeatState.buildRequestData()), - coordinatorRequestManager.coordinator()); + new ConsumerGroupHeartbeatRequest.Builder(this.heartbeatState.buildRequestData()), + coordinatorRequestManager.coordinator()); return request.whenComplete((response, exception) -> { if (response != null) { onResponse((ConsumerGroupHeartbeatResponse) response.responseBody(), request.handler().completionTimeMs()); + // The response is only ignore when the member becomes staled. This is because the member needs to + // rejoin on the next poll regardless the server has responded to the heartbeat. + if (!ignoreResponse) { + membershipManager.onHeartbeatResponseReceived(((ConsumerGroupHeartbeatResponse) response.responseBody()).data()); + maybeSendGroupMetadataUpdateEvent(); Review Comment: OK, thank you for the clarification! Sorry, but I still have two comments: 1. Why to we still need to call `onResponse()`? As far as I understand, all what we do there is not strictly needed because we will do the same when we restart heartbeating in the next poll, won't we? Is the error handling in this case so important? Wouldn't it be equally fine to not handle errors until we start heartbeating? I am asking because the code and probably also the reasoning about the code would become simpler if we just completely ignored the response. I also see that it is not a big deal doing it this or the other way. So, if you do not want to change it, it is fine with me. However, I just realized that with this change we will call `membershipManager.onHeartbeatResponseReceived()` and `maybeSendGroupMetadataUpdateEvent()` in the error case, won't we? Before the change these two calls are only done without an error. Is this acceptable? 2. I understand that the commit gets rejected by the brokers. My question was whether we should avoid sending a commit request in the first place, since the consumer actually knows that it is not part of a group anymore. A last question: > That being said, following commit requests issued after the consumer left the group will succeed because they will be sent without member ID or epoch (noticing that the member is not part of the group anymore). I am not sure I understand this. Why does the commit succeed? -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org