Reputation: 15
Running following command on topic my.topic.test
gives description on both my.topic.test
and my.topic_test
(notice the dot and underscore difference in the names) topics.
Is that desired behavior or a bug (I would lean towards a bug)?
kafka-topics --describe --zookeeper my_zookeeper_ip:2181 --topic my.topic.test
Topic:my.topic.test PartitionCount:4 ReplicationFactor:1 Configs:
Topic: my.topic.test Partition: 0 Leader: 2 Replicas: 2 Isr: 2
Topic: my.topic.test Partition: 1 Leader: 3 Replicas: 3 Isr: 3
Topic: my.topic.test Partition: 2 Leader: 4 Replicas: 4 Isr: 4
Topic: my.topic.test Partition: 3 Leader: 0 Replicas: 0 Isr: 0
Topic:my.topic_test PartitionCount:5 ReplicationFactor:4 Configs:
Topic: my.topic_test Partition: 0 Leader: 4 Replicas: 3,4,5,1 Isr: 4,1,3
Topic: my.topic_test Partition: 1 Leader: 4 Replicas: 1,3,4 Isr: 4,1,3
Topic: my.topic_test Partition: 2 Leader: 4 Replicas: 4,2,5,3 Isr: 4,3,2
Topic: my.topic_test Partition: 3 Leader: 4 Replicas: 5,1,4 Isr: 4,1
Topic: my.topic_test Partition: 4 Leader: 1 Replicas: 5,1,3,0 Isr: 1,0,3
Upvotes: 1
Views: 13110
Reputation: 470
first of all ,it's not bug. according to source-code of kafka-10.2 in topic part Kafka-source,
val legalChars = "[a-zA-Z0-9\\._\\-]"
private val maxNameLength = 249
private val rgx = new Regex(legalChars + "+")
max length of your topic-name can be 249 words,and its treats dot(.) and underscore( _ ) are treated equal.That is your topic name
my.topic.test, my.topic_test, my_topic.test are same . you should either use ( _ )underscore or dot ( . ) but not both.
for best practice i'll recommend you to use hyphen ( - ) like i prefer to use.
Upvotes: 2
Reputation: 26895
When run with --describe
, kafka-topics
accepts a regex for the --topic
argument. In a regex, .
matches any characters so you see the expected behaviour.
That said, kafka-topics prints a warning when creating a topic with dots or underscores and should have prevented creating 2 topics with such names as metrics would collide:
WARNING: Due to limitations in metric names, topics with a period ('.') or underscore ('_') could collide. To avoid issues it is best to use either, but not both.
How did you create the topics ?
Upvotes: 4