lianetm commented on code in PR #14873:
URL: https://github.com/apache/kafka/pull/14873#discussion_r1423084344


##########
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:
   To complete the pic regarding the commits, if a commit was sent out right 
before leaving, it will include memberId and epoch that are not valid anymore, 
so the broker will reject as @philipnee mentioned, sending an 
UNKNOWN_MEMBER_ID, and the client will fail the commit with that unrecoverable 
error. 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). That logic 
is in the commitRequestManager but sharing here to connect the dots.  



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

Reply via email to