简体   繁体   English

kafka如何删除没有领导者的话题

[英]kafka how to delete topic with no leader

I can't delete / reassign / make any change to topics without leader 没有领导者,我无法删除/重新分配/对主题进行任何更改

reproduce: 复制:

  1. Create a topic with ReplicationFactor=1 使用ReplicationFactor = 1创建一个主题
  2. Shutdown the only one broker host 关闭唯一的经纪人主机
  3. Use kafka-topic --delete to delete the topic 使用kafka-topic --delete删除主题
  4. Delete process will never end (I waited for more than 6 month, and it starting to get hurt) 删除过程将永远不会结束(我等待了6个月以上,开始受到伤害)

describe of topic 描述主题

Topic:topic_73  PartitionCount:1    ReplicationFactor:1
Configs:unclean.leader.election.enable=true
Topic: topic_73 Partition: 0    Leader: -1  Replicas: 755   Isr:

broker 755 can never gone back how can i fix this? 经纪人755永不回头,我该如何解决?

You can try this script to clear metadata from zookeeper and directly delete the kafka logs. 您可以尝试使用此脚本清除Zookeeper中的元数据,然后直接删除kafka日志。

./clear.sh /path-to-kafka-logs sampletopic /path-to-kafka-bin-dir

clear.sh content is as below: clear.sh的内容如下:

#!/bin/bash
# this script is for the situation that leader is set to -1 and there is no ISR
ZK_HOST=`hostname`
ROOT_DIR=$1
TOPIC=$2
KAFKA_LOG_DIR=$3

# make sure kafka service is stopped while running this
rm -rf ${KAFKA_LOG_DIR}/${TOPIC}*
${ROOT_DIR}/kafka/bin/kafka-topics.sh --zookeeper ${ZK_HOST}:2181 --topic ${TOPIC} --delete
${ROOT_DIR}/kafka/bin/zookeeper-shell.sh ${ZK_HOST}:2181 rmr /brokers/topics/${TOPIC}
${ROOT_DIR}/kafka/bin/zookeeper-shell.sh ${ZK_HOST}:2181 rmr /admin/delete_topics/${TOPIC}

make sure chmod +x clear.sh before using it. 使用前请确保chmod +x clear.sh

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM