Class Fetcher<K,V>
java.lang.Object
org.apache.kafka.clients.consumer.internals.AbstractFetch
org.apache.kafka.clients.consumer.internals.Fetcher<K,V>
- All Implemented Interfaces:
Closeable,AutoCloseable
This class manages the fetching process with the brokers.
Thread-safety: Requests and responses of Fetcher may be processed by different threads since heartbeat thread may process responses. Other operations are single-threaded and invoked only from the thread polling the consumer.
- If a response handler accesses any shared state of the Fetcher (e.g. FetchSessionHandler), all access to that state must be synchronized on the Fetcher instance.
- If a response handler accesses any shared state of the coordinator (e.g. SubscriptionState), it is assumed that all access to that state is synchronized on the coordinator instance by the caller.
- At most one request is pending for each node at any time. Nodes with pending requests are tracked and updated after processing the response. This ensures that any state (e.g. epoch) updated while processing responses on one thread are visible while creating the subsequent request on a different thread.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.kafka.clients.consumer.internals.AbstractFetch
AbstractFetch.ResponseHandler<T> -
Field Summary
Fields inherited from class org.apache.kafka.clients.consumer.internals.AbstractFetch
decompressionBufferSupplier, fetchBuffer, fetchConfig, logContext, metadata, metricsManager, nodesWithPendingFetchRequests, subscriptions, time -
Constructor Summary
ConstructorsConstructorDescriptionFetcher(org.apache.kafka.common.utils.LogContext logContext, ConsumerNetworkClient client, ConsumerMetadata metadata, SubscriptionState subscriptions, FetchConfig fetchConfig, Deserializers<K, V> deserializers, FetchMetricsManager metricsManager, org.apache.kafka.common.utils.Time time, org.apache.kafka.clients.ApiVersions apiVersions) -
Method Summary
Modifier and TypeMethodDescriptionvoidclearBufferedDataForUnassignedPartitions(Collection<org.apache.kafka.common.TopicPartition> assignedPartitions) protected voidcloseInternal(org.apache.kafka.common.utils.Timer timer) This method is called byAbstractFetch.close(Timer)which is guarded by theIdempotentCloser) such as to only be executed once the first time that any of theAbstractFetch.close()methods are called.protected booleanisUnavailable(org.apache.kafka.common.Node node) Check if the node is disconnected and unavailable for immediate reconnection (i.e.protected voidmaybeCloseFetchSessions(org.apache.kafka.common.utils.Timer timer) protected voidmaybeThrowAuthFailure(org.apache.kafka.common.Node node) Checks for an authentication error on a given node and throws the exception if it exists.intSet up a fetch request for any node that we have assigned partitions for which doesn't already have an in-flight fetch or pending fetch data.Methods inherited from class org.apache.kafka.clients.consumer.internals.AbstractFetch
close, close, createFetchRequest, handleCloseFetchSessionFailure, handleCloseFetchSessionSuccess, handleFetchFailure, handleFetchSuccess, hasAvailableFetches, prepareCloseFetchSessionRequests, prepareFetchRequests, sessionHandler
-
Constructor Details
-
Fetcher
public Fetcher(org.apache.kafka.common.utils.LogContext logContext, ConsumerNetworkClient client, ConsumerMetadata metadata, SubscriptionState subscriptions, FetchConfig fetchConfig, Deserializers<K, V> deserializers, FetchMetricsManager metricsManager, org.apache.kafka.common.utils.Time time, org.apache.kafka.clients.ApiVersions apiVersions)
-
-
Method Details
-
maybeThrowAuthFailure
protected void maybeThrowAuthFailure(org.apache.kafka.common.Node node) Description copied from class:AbstractFetchChecks for an authentication error on a given node and throws the exception if it exists.- Specified by:
maybeThrowAuthFailurein classAbstractFetch- Parameters:
node-Nodeto check for a previousAuthenticationException; if found it is thrown- See Also:
-
clearBufferedDataForUnassignedPartitions
public void clearBufferedDataForUnassignedPartitions(Collection<org.apache.kafka.common.TopicPartition> assignedPartitions) -
sendFetches
public int sendFetches()Set up a fetch request for any node that we have assigned partitions for which doesn't already have an in-flight fetch or pending fetch data.- Returns:
- number of fetches sent
-
maybeCloseFetchSessions
protected void maybeCloseFetchSessions(org.apache.kafka.common.utils.Timer timer) -
collectFetch
-
closeInternal
protected void closeInternal(org.apache.kafka.common.utils.Timer timer) This method is called byAbstractFetch.close(Timer)which is guarded by theIdempotentCloser) such as to only be executed once the first time that any of theAbstractFetch.close()methods are called. Subclasses can override this method without the need for extra synchronization at the instance level. Note: this method issynchronizedto reinstitute the 3.5 behavior:Shared states (e.g. sessionHandlers) could be accessed by multiple threads (such as heartbeat thread), hence, it is necessary to acquire a lock on the fetcher instance before modifying the states.
- Overrides:
closeInternalin classAbstractFetch- Parameters:
timer- Timer to enforce time limit