1

As the documentation of function GetMetaData:

// GetMetadata queries broker for cluster and topic metadata.
// If topic is non-nil only information about that topic is returned, else if
// allTopics is false only information about locally used topics is returned,
// else information about all topics is returned.
// GetMetadata is equivalent to listTopics, describeTopics and describeCluster in the Java API.
func (a *AdminClient) GetMetadata(topic *string, allTopics bool, timeoutMs int) (*Metadata, error) {
    return getMetadata(a, topic, allTopics, timeoutMs)
}

So I guess if the topic is non-nil, the result always returns only the specific topic information. However, when I try to test, I see the very strange result.

Let say I I already have a Kafka topic. Then I call the method GetMetadata as the below code:

topic := "sample_topic"
admin.GetMetadata(nil, false, timeout)
admin.GetMetadata(nil, true, timeout)
admin.GetMetadata(&topic, false, timeout)
admin.GetMetadata(&topic, true, timeout)

Only admin.GetMetadata(&topic, false, timeout) returns the topic information. All other cases return all topics information.

However, when testing on a non-exist topic in the cluster, only the call admin.GetMetadata(&topic, false, timeout) will yield the error.

data, err := admin.GetMetadata(&topic, false, admin.timeOutMs())
fmt.Println(data.Topics[topic]) //   Broker: Unknown topic or partition

When re-order the code, the result also changes.

I read the source code and I see that it uses some functions from librdkafka such as rd_kafka_metadata or _getMetadata_broker_element. But it is hard for me to understand those functions.

I tested on the Kafka cluster with 3 brokers. Please explain for me what is the logic behind.

Trần Kim Dự
  • 5,872
  • 12
  • 55
  • 107

0 Answers0