0
$ kafka-topics --zookeeper localhost:2181 --list | grep my-topic
my-topic
$ kafka-topics --zookeeper localhost:2181 --delete --topic my-topic
Topic my-topic is marked for deletion.
Note: This will have no impact if delete.topic.enable is not set to true.
$ kafka-topics --zookeeper localhost:2181 --list | grep my-topic
my-topic - marked for deletion

It's been hours since then, and the topic has still not been deleted.

I've seen suggestions that I should put delete.topic.enable in my server.properties and restart kafka. I've tried this. It hasn't worked.

$ grep -F delete.topic.enable /usr/local/etc/kafka/server.properties
delete.topic.enable = true

(Why wouldn't this be set by default?)

In any case, these suggestions have all been for kafka 0.* and I am on a newer version.

$ brew list --versions kafka
kafka 1.1.0

How do I delete topics?

I can shutdown kafka and zookeeper, run rm -r /usr/local/var/lib/kafka-logs /usr/local/var/run/zookeeper/data, then start zookeeper and kafka again. But this is rather drastic. Surely there should be some way of persuading kafka-topics to actually delete a topic?

dave4420
  • 46,404
  • 6
  • 118
  • 152
  • 1
    Sorry, I misread you message and marked my response for deletion to avoid confusion. If you have `delete.topic.enable` set to `true` the topic should automatically get removed in an async fashion. This issue has happened to me a few times before, and it turned out that some producer/consumer process is still running on that topic. After finding the process and killing it, the topic is removed. Have you checked for such processes? – vahid Jun 05 '18 at 17:56
  • 1
    By the way, [as of Kafka 1.0, deletion enabled is the default](https://issues.apache.org/jira/browse/KAFKA-5384) – OneCricketeer Jun 06 '18 at 01:06
  • @vahid I had not checked for these processes. There are none now, but I have regained the ability to delete topics by other means. I will check in the future if the problem reoccurs. – dave4420 Jun 06 '18 at 09:12

2 Answers2

1

The command you're using is the recommended way to delete a topic.

Unfortunately there are a few reasons why a topic can stay stuck in "marked for deletion" state.

If you check the controller logs, you might see why it's not able to delete it. In the controller logs, all lines from the Deletion Manager are prefixed with Topic Deletion Manager.

Periodically, you should see messages like Handling deletion for topics .... In case the controller has given up the deletion, it should have logged it, with this format: Halted deletion of topics ....

If you want to force the deletion, you can try:

  • Deleting the topic details in Zookeeper. Using zookeeper-shell.sh, run rmr /brokers/topics/TOPIC_NAME
  • Bouncing the controller

Finally if none of this works, you can, as hinted, delete the log data on disk/

Mickael Maison
  • 25,067
  • 7
  • 71
  • 68
  • I checked `/usr/local/var/log/kafka/kafka_output.log` and it doesn't contain the messages you describe, unfortunately. The only messages matching `/deletion/i` are along the lines of `Log for partition is renamed to .-delete and is scheduled for deletion (kafka.log.LogManager)` – dave4420 Jun 06 '18 at 08:56
  • 1
    I mean the controller logs. At any time, one broker in your cluster should be the controller. By default, it logs its actions in a file called `controller.log`: https://github.com/apache/kafka/blob/trunk/config/log4j.properties#L48-L52 – Mickael Maison Jun 06 '18 at 11:02
  • Ah, right. Found the file at `/usr/local/Cellar/kafka/1.1.0/libexec/logs/controller.log`. It seems to rotate every hour. No clues in any of them, though. – dave4420 Jun 06 '18 at 11:50
1

On the suggestion of a colleague, I

  • shut down Kafka and Zookeeper
  • added the line listeners=PLAINTEXT://127.0.0.1:9092 to /usr/local/etc/kafka/server.properties
  • restarted Zookeeper and Kafka

Now I can delete topics again. I don't know why this should work, but suspect it is related to a recent macOS upgrade.

dave4420
  • 46,404
  • 6
  • 118
  • 152
  • I don't like this answer because it doesn't provide a reason why it should work. But I'm accepting it because it worked for me. – dave4420 Jun 08 '18 at 13:44