log4j.logger.org.apache.kafka.clients.Metadata=TRACE
Metadata
Metadata describes a Kafka cluster (and is created) for KafkaConsumer and KafkaProducer.
| Client | refreshBackoffMs | metadataExpireMs | allowAutoTopicCreation | topicExpiryEnabled |
|---|---|---|---|---|
|
on |
off |
||
|
on |
on |
A (seemingly) common usage pattern is as follows:
-
Request
Metadatafor a update (that simply turns theneedUpdateflag on) -
Request (indirectly)
KafkaClientto wake up if blocked on I/O -
Request
Metadatato wait for metadata change (i.e. until the metadata version has changed)
Metadata manages metadata update listeners that want to be notified about metadata updates. Listeners can be registered and deregistered.
|
Note
|
ConsumerCoordinator is the only entity to register a metadata update listener. |
|
Tip
|
Enable Add the following line to Refer to Logging. |
Checking if Metadata Update was Requested — updateRequested Method
synchronized boolean updateRequested()
updateRequested…FIXME
|
Note
|
|
Recording Update Request Failure — failedUpdate Method
synchronized void failedUpdate(long now, AuthenticationException authenticationException)
failedUpdate…FIXME
|
Note
|
failedUpdate is used when…FIXME
|
getClusterForCurrentTopics Internal Method
Cluster getClusterForCurrentTopics(Cluster cluster)
getClusterForCurrentTopics…FIXME
|
Note
|
getClusterForCurrentTopics is used exclusively when Metadata is requested to update.
|
timeToNextUpdate Method
synchronized long timeToNextUpdate(long nowMs)
timeToNextUpdate…FIXME
|
Note
|
|
Requesting Metadata Update — requestUpdate Method
int requestUpdate()
requestUpdate simply turns the needUpdate flag on and returns the current version.
|
Note
|
|
Waiting for Metadata Update (i.e. Metadata Version Change) — awaitUpdate Method
synchronized void awaitUpdate(
final int lastVersion,
final long maxWaitMs) throws InterruptedException
awaitUpdate…FIXME
|
Note
|
awaitUpdate is used when…FIXME
|
Getting Current Cluster Metadata — fetch Method
synchronized Cluster fetch()
fetch returns current cluster information.
|
Note
|
fetch is used when…FIXME
|
Updating Cluster Metadata — update Method
void update(
Cluster newCluster,
Set<String> unavailableTopics,
long now)
update turns the needUpdate flag off and increments version.
update sets lastRefreshMs and lastSuccessfulRefreshMs internal registries to the given now.
(only when topicExpiryEnabled is enabled, e.g. KafkaProducer) update…FIXME
update notifies the Metadata.Listeners that the metadata has been updated.
update does getClusterForCurrentTopics for the cluster when needMetadataForAllTopics flag is on and turns needUpdate flag off (that may have been turned on…FIXME).
update sets the cluster to the given Cluster when the needMetadataForAllTopics flag is off.
update prints out the following INFO message to the logs with the cluster ID and notifies clusterResourceListeners that cluster has changed (only for a non-bootstrap cluster).
Cluster ID: [clusterId]
In the end, update prints out the following DEBUG message to the logs:
Updated cluster metadata version [version] to [cluster]
|
Note
|
|
Creating Metadata Instance
Metadata takes the following when created:
Metadata initializes the internal registries and counters.
Conditionally Requesting Update For New Topics (for KafkaConsumer) — needMetadataForAllTopics Method
synchronized void needMetadataForAllTopics(boolean needMetadataForAllTopics)
needMetadataForAllTopics requestUpdateForNewTopics when the input needMetadataForAllTopics flag is enabled (i.e. true) and the current needMetadataForAllTopics is disabled (i.e. false).
needMetadataForAllTopics sets needMetadataForAllTopics to be the input needMetadataForAllTopics.
|
Note
|
|
requestUpdateForNewTopics Internal Method
synchronized void requestUpdateForNewTopics()
requestUpdateForNewTopics sets lastRefreshMs to 0 and requests update.
|
Note
|
|
Registering Metadata.Listener — addListener Method
void addListener(Listener listener)
|
Note
|
addListener is used exclusively when ConsumerCoordinator is requested to addMetadataListener (when created).
|
newMetadataRequestBuilder Method
MetadataRequest.Builder newMetadataRequestBuilder()
newMetadataRequestBuilder simply requests the MetadataRequest to create MetadataRequest.Builder for all topics.
|
Note
|
newMetadataRequestBuilder is used exclusively when Metadata is requested to newMetadataRequestAndVersion.
|
newMetadataRequestAndVersion Method
MetadataRequestAndVersion newMetadataRequestAndVersion()
newMetadataRequestAndVersion simply creates a new MetadataRequestAndVersion with MetadataRequest.Builder and the requestVersion.
|
Note
|
newMetadataRequestAndVersion is used exclusively when DefaultMetadataUpdater is requested to maybeUpdate.
|
Internal Properties
| Name | Description |
|---|---|
|
Cluster with a subset of the nodes and topic partitions in a Kafka cluster.
|
|
The time (in millis) of the last successful update (and failed update)
|
|
|
|
|
|
Use updateRequested to know the current value. |
|
|
|