Confusion about delete Kafka Topic

24,785

Solution 1

My Kakfa version is kafka_2.10-0.8.2.2, below link works for me (from Delete topic in Kafka 0.8.1.1)

Add below line in ${kafka_home}/config/server.properties

delete.topic.enable=true   

Restart the kafka server with new config:

${kafka_home}/bin/kafka-server-start.sh ~/kafka/config/server.properties

Delete the topics you wish to:

${kafka_home}/bin/kafka-topics.sh --delete --zookeeper localhost:2181 --topic daemon12

More information from Kafka FAQ:

Deleting a topic is supported since 0.8.2.x. You will need to enable topic deletion (setting delete.topic.enable to true) on all brokers first.

Solution 2

  1. Make sure that, In kafka's config.poperties file 'delete.topic.enable' property should be true.
  2. use below command

    bin/kafka-topics.sh --delete --zookeeper localhost:2181 --topic test

Even if topic is not deleted then follow next steps.

  1. open terminal zookeeper client mode:

    A. stop zookeeper

    B. rmr /broker/topics

    C. check given topic using below command

    /bin/kafka-topics.sh --zookeeper maxiq:2181 --list

Solution 3

If delete.topic.enable is set to false by default, the topics are not deleted on execution of --delete command (as displayed in the command response).

Topic test is marked for deletion.
Note: This will have no impact if delete.topic.enable is not set to true.

In order to overcome this, use steps mentioned by @Shawn

Solution 4

The best and easy to make delete.topic.enable=true is not modify the server.property file.

Because, if kafka restart from ambari, it will overwrite this file, delete.topic.enable =false again.

Only at ambari, click on kafak/config/advance kafka broker/delete.topic.enable =true, it will work.

I just found that out as now.

Solution 5

Delete topic in kafka step 1 -->> cd /usr/lib/zookeeper/bin

step 2 -->> zkCli.sh -server 127.0.0.1:2181

step 3 -->>rmr /brokers/topics/topic_name

Share:
24,785
Jack
Author by

Jack

Many years experience in search engine and Hadoop Expertise And Love Java,Network! Some experiences in Spark,Blink,Data Mining

Updated on July 09, 2022

Comments

  • Jack
    Jack almost 2 years

    I'm using Kafka 0.8.0, it's Cloudera version. When I deleted the topic such as: kafka-topics --zookeeper 10.0.0.11:2181/ --delete --topic test it response:

    Topic test is already marked for deletion.
    

    But afterwards I recreated it, it throw exception as following:

    kafka-topics --create --zookeeper 10.0.0.11:2181 --partitions 90 --replication-factor 2 --topic test
    
    Error while executing topic command Topic "test" already exists.
    kafka.common.TopicExistsException: Topic "test" already exists.
    

    Any ideas please? How should I delete the topic and it's data.