Class HeartbeatRequestManager
- All Implemented Interfaces:
RequestManager
Manages the request creation and response handling for the heartbeat. The module creates a
ConsumerGroupHeartbeatRequest using the state stored in the MembershipManager and enqueue it to
the network queue to be sent out. Once the response is received, the module will update the state in the
MembershipManager and handle any errors.
The manager will try to send a heartbeat when the member is in MemberState.STABLE,
MemberState.JOINING, or MemberState.RECONCILING. Which mean the member is either in a stable
group, is trying to join a group, or is in the process of reconciling the assignment changes.
If the member got kick out of a group, it will try to give up the current assignment by invoking
OnPartitionsLost because reattempting to join again with a zero epoch.
If the member does not have groupId configured or encountering fatal exceptions, a heartbeat will not be sent.
If the coordinator not is not found, we will skip sending the heartbeat and try to find a coordinator first.
If the heartbeat failed due to retriable errors, such as, TimeoutException. The subsequent attempt will be backoff exponentially.
When the member completes the assignment reconciliation, the HeartbeatRequestManager.HeartbeatRequestState will be reset so
that a heartbeat will be sent in the next event loop.
See HeartbeatRequestManager.HeartbeatRequestState for more details.
-
Constructor Summary
ConstructorsConstructorDescriptionHeartbeatRequestManager(org.apache.kafka.common.utils.LogContext logContext, org.apache.kafka.common.utils.Time time, ConsumerConfig config, CoordinatorRequestManager coordinatorRequestManager, SubscriptionState subscriptions, MembershipManager membershipManager, BackgroundEventHandler backgroundEventHandler) -
Method Summary
Modifier and TypeMethodDescriptionlongmaximumTimeToWait(long currentTimeMs) Returns the delay for which the application thread can safely wait before it should be responsive to results from the request managers.Returns theMembershipManagerthat this request manager is using to track the state of the group.poll(long currentTimeMs) This will build a heartbeat request if one must be sent, determined based on the member state.voidresetPollTimer(long pollMs) When consumer polls, we need to reset the pollTimer.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.kafka.clients.consumer.internals.RequestManager
pollOnClose, signalClose
-
Constructor Details
-
HeartbeatRequestManager
public HeartbeatRequestManager(org.apache.kafka.common.utils.LogContext logContext, org.apache.kafka.common.utils.Time time, ConsumerConfig config, CoordinatorRequestManager coordinatorRequestManager, SubscriptionState subscriptions, MembershipManager membershipManager, BackgroundEventHandler backgroundEventHandler)
-
-
Method Details
-
poll
This will build a heartbeat request if one must be sent, determined based on the member state. A heartbeat is sent in the following situations:- Member is part of the consumer group or wants to join it.
- The heartbeat interval has expired, or the member is in a state that indicates that it should heartbeat without waiting for the interval.
- If the member is without a coordinator or is in a failed state, the timer is set to Long.MAX_VALUE, as there's no need to send a heartbeat.
- If the member cannot send a heartbeat due to either exponential backoff, it will return the remaining time left on the backoff timer.
- If the member's heartbeat timer has not expired, It will return the remaining time left on the heartbeat timer.
- If the member can send a heartbeat, the timer is set to the current heartbeat interval.
- Specified by:
pollin interfaceRequestManager- Parameters:
currentTimeMs- The current system time at which the method was called; useful for determining if time-sensitive operations should be performed- Returns:
NetworkClientDelegate.PollResultthat includes a heartbeat request if one must be sent, and the time to wait until the next poll.
-
membershipManager
Returns theMembershipManagerthat this request manager is using to track the state of the group. This is provided so that theApplicationEventProcessorcan access the state for querying or updating. -
maximumTimeToWait
public long maximumTimeToWait(long currentTimeMs) Returns the delay for which the application thread can safely wait before it should be responsive to results from the request managers. For example, the subscription state can change when heartbeats are sent, so blocking for longer than the heartbeat interval might mean the application thread is not responsive to changes.In the event that heartbeats are currently being skipped, this still returns the next heartbeat delay rather than
Long.MAX_VALUEso that the application thread remains responsive.- Specified by:
maximumTimeToWaitin interfaceRequestManager- Parameters:
currentTimeMs- The current system time at which the method was called; useful for determining if time-sensitive operations should be performed- Returns:
- The maximum delay in milliseconds
-
resetPollTimer
public void resetPollTimer(long pollMs) When consumer polls, we need to reset the pollTimer. If the poll timer has expired, we rejoin when the user repoll the consumer.
-