apache-kafka - 卡夫卡 : how to remove broker from Replica Set

标签 apache-kafka

我有一个包含以下副本的分区:

Topic: topicname    Partition: 10   Leader: 1   Replicas: 1,2,4,3   Isr: 1,2,3

其中 Replica 4 是一个不存在的代理。我不小心把这个经纪人添加到副本集中作为一个打字错误。

我想从副本集中删除 4。但是在运行 kafka-reassign-partitions.sh 之后,删除副本 #4 的重新分配永远不会完成。

kafka-reassign-partitions.sh --zookeeper myzookeeperhost:2181 --reassignment-json-file remove4.txt --execute 

remove4.txt 的样子

{ "partitions": [
     { "topic": "topicname", "partition": 2, "replicas": [1,2,3] }
], "version": 1 }

重新分配卡住了:

kafka-reassign-partitions.sh --zookeeper myzookeeperhost:2181 --reassignment-json-file remove4.txt --verify
Status of partition reassignment:
Reassignment of partition [topicname,10] is still in progress

我检查了 Controller 日志,看起来重新分配命令被拾取了,但之后没有任何反应:

[2017-08-01 06:46:07,653] DEBUG [PartitionsReassignedListener on 101 (the controller broker)]: Partitions reassigned listener fired for path /admin/reassign_partitions. Record partitions to be reassigned {"version":1,"partitions":[{"topic":"topicname","partition":10,"replicas":[1,2,3]}]} (kafka.controller.PartitionsReassignedListener)

关于我做错了什么的任何想法?如何从副本集中删除代理 #4? 更新:我正在运行 kafka 10

最佳答案

我能够通过启动一个新经纪人来解决这个问题,该经纪人的经纪人 ID 与添加的经纪人 ID 匹配(在您的情况下为 4)。

Kafka Quickstart指南向您展示了如何启动具有特定 ID 的经纪人。一旦你的节点启动了 id 4,运行:

./bin/kafka-topics.sh --zookeeper localhost:2181 --topic badbrokertest --describe

您应该看到所有副本都在 isr 列中,如下所示:

Topic:badbrokertest PartitionCount:3    ReplicationFactor:3 Configs:
Topic: badbrokertest    Partition: 0    Leader: 1   Replicas: 1,2,3 Isr: 1,2,3
Topic: badbrokertest    Partition: 1    Leader: 1   Replicas: 1,2,3 Isr: 1,2,3  
Topic: badbrokertest    Partition: 2    Leader: 1   Replicas: 1,2,3,4   Isr: 1,2,3,4

现在您可以重新分配您的分区了!

./bin/kafka-reassign-partitions.sh --reassignment-json-file badbroker2.json  --zookeeper localhost:2181

badbroker2.json 的样子:

{
    "version":1,
    "partitions":[
        {"topic":"badbrokertest","partition":0,"replicas":[1,2,3]},
        {"topic":"badbrokertest","partition":1,"replicas":[1,2,3]},
        {"topic":"badbrokertest","partition":2,"replicas":[1,2,3]}
    ]
}

简而言之,一旦您通过添加缺少的代理同步了所有副本,您就可以删除不需要的代理。

如果您使用多个服务器,请务必在配置中设置监听器字段,以使您的临时代理对其他代理可用。快速入门指南不考虑这种情况。

listeners=PLAINTEXT://10.9.1.42:9093

关于apache-kafka - 卡夫卡 : how to remove broker from Replica Set,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45430936/

相关文章:

java - Kafka创建大量分区(64k)的Topic失败

apache-kafka - 如果 ISR 小于复制因子并且生产者确认设置为全部,生产者将等待多少个确认?

Spring 卡夫卡 : Poll for new messages instead of being notified using `onMessage`

java - Transformer Kafka 中的 ManagedChannel 是线程安全的吗

python - 更新 Kafka 主题中的消息

java - Spring Kafka - 如何使用组 ID 将偏移量重置为最新?

apache-kafka - 每个生产者的 Kafka 主题

apache-kafka - Kafka消息聚合

apache-kafka - kafka 幂等和事务性生产者设置之间的区别?

java - Avro 解码给出 java.io.EOFException