cadonna commented on code in PR #14873:
URL: https://github.com/apache/kafka/pull/14873#discussion_r1418729793
##########
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:
If the heartbeat request manager ignores the response, why does it call
`onResponse()`? Does the heartbeat request manager continue to send heartbeats
although the consumer left the group? If yes, what is the reason for it?
Another question, how does the consumer avoid that offsets are committed
when the poll timer expired and the consumer is in the staled state? Probably
the broker will reject the commit, but actually the consumer proactively left
the group, so it knows that it is not part of the group anymore and it could
just not send the offset commit.
--
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]