重新启动代理后,我发现一个主题的领导者中的所有分区都是
全部在经纪人3中,我已经设定
imbalance.check.interval.seconds
300,auto.leader.rebalance.enable
是
但是300秒后什么也没发生。
因此我使用了bin/kafka-preferred-replica-election.sh
,并且得到了我所期望的,
领导者被平衡成经纪人1、2、3。
我想知道为什么自动平衡没有发生? kafka-preferred-replica-election.sh
和auto.leader.rebalance.enable
有什么区别?
控制器日志:
[2019-08-14 09:31:33,454]信息[Controller id = 3]自动处理 首选副本领导者选举(kafka.controller.KafkaController) [2019-08-14 09:31:33,454]跟踪[Controller id = 3]正在检查是否需要 触发自动组长平衡(kafka.controller.KafkaController) [2019-08-14 09:31:33,455]调试[Controller id = 3]首选副本 由经纪人Map(2-> Map(__ consumer_offsets-22-> Vector(2), __consumer_offsets-4-> Vector(2),__consumer_offsets-7-> Vector(2),__consumer_offsets-46-> Vector(2),__consumer_offsets-25-> Vector(2),__consumer_offsets-49-> Vector(2), __consumer_offsets-16 -> Vector(2),__consumer_offsets-28-> Vector(2),__consumer_offsets-31-> Vector(2),__consumer_offsets-37-> Vector(2),__consumer_offsets-19-> Vector(2),__consumer_offsets-13 -> Vector(2),four_topic-1-> Vector(2,3,1),__consumer_offsets-43-> Vector(2),__consumer_offsets-1-> Vector(2),__consumer_offsets-34-> Vector(2) ,__consumer_offsets-10-> Vector(2),__consumer_offsets-40-> Vector(2)),1-> Map(__ consumer_offsets-30-> Vector(1),__consumer_offsets-21-> Vector(1),__consumer_offsets-27 -> Vector(1),__consumer_offsets-9-> Vector(1),__consumer_offsets-33-> Vector(1),__consumer_offsets-36-> Vector(1),__consumer_offsets-42-> Vector(1),__consumer_offsets-3 ->向量(1),__consumer_offsets-18->向量(1),__consumer_offsets-15->向量(1),__consumer_offsets-24->向量(1),__consumer_offsets-48 -> Vector(1),__consumer_offsets-6-> Vector(1),four_topic-0-> Vector(1、2、3),__consumer_offsets-0-> Vector(1), __consumer_offsets-39->向量(1),__consumer_offsets-12->向量(1),__consumer_offsets-45->向量(1)),3-> 映射(__consumer_offsets-8-> Vector(3),__consumer_offsets-35-> Vector(3),__consumer_offsets-41-> Vector(3),__consumer_offsets-23 -> Vector(3),__consumer_offsets-47-> Vector(3),Fourth_topic-2-> Vector(3,1,2),__consumer_offsets-38-> Vector(3), __consumer_offsets-17-> Vector(3),__consumer_offsets-11-> Vector(3),__consumer_offsets-2-> Vector(3),__consumer_offsets-14-> Vector(3),__consumer_offsets-20-> Vector(3),__consumer_offsets-44 -> Vector(3),__consumer_offsets-5-> Vector(3),__consumer_offsets-26-> Vector(3),__consumer_offsets-29-> Vector(3),__consumer_offsets-32-> Vector(3)))(kafka .controller.KafkaController)[2019-08-14 09:31:33,455]调试 [Controller id = 3]主题不在代理2的首选副本中 地图(fourth_topic-1-> Vector(2,3,1)) (kafka.controller.KafkaController)[2019-08-14 09:31:33,455]调试 [Controller id = 3]主题不在代理2的首选副本中 地图(fourth_topic-1-> Vector(2,3,1)) (kafka.controller.KafkaController)[2019-08-14 09:31:33,456]跟踪 [Controller id = 3]经纪人2的领导者失衡比率为 0.05555555555555555(kafka.controller.KafkaController)[2019-08-14 09:31:33,456]调试[Controller id = 3]主题不在首选副本中 适用于经纪人1地图(fourth_topic-0-> Vector(1、2、3)) (kafka.controller.KafkaController)[2019-08-14 09:31:33,456]跟踪 [Controller id = 3]经纪人1的领导者失衡率为 0.05555555555555555(kafka.controller.KafkaController)[2019-08-14 09:31:33,456]调试[Controller id = 3]主题不在首选副本中 适用于代理3 Map()(kafka.controller.KafkaController)[2019-08-14 09:31:33,456] TRACE [Controller id = 3]领导者的不平衡率 经纪人3为0.0(kafka.controller.KafkaController)
但是fourth_topic分区的领导者仍然全部位于代理3中:
bin/kafka-topics.sh --zookeeper 10.xx.xx.xx:2181/kafka --topic fourth_topic --describe
Topic:fourth_topic PartitionCount:3 ReplicationFactor:3 Configs:
Topic: fourth_topic Partition: 0 Leader: 3 Replicas: 1,2,3 Isr: 3,1,2
Topic: fourth_topic Partition: 1 Leader: 3 Replicas: 2,3,1 Isr: 3,1,2
Topic: fourth_topic Partition: 2 Leader: 3 Replicas: 3,1,2 Isr: 3,1,2
答案 0 :(得分:1)
运行kafka-preferred-replica-election.sh
时,它将强制为所有分区选择首选副本。
另一方面,当您将auto.leader.rebalance.enable
设置为true时,控制器将定期检查不平衡状态(每个leader.imbalance.check.interval.seconds
)。但是,为避免对集群造成不必要的负载,仅当不平衡率高于leader.imbalance.per.broker.percentage
(默认值为10%)时,领导者才会自动重新平衡。
您可以在控制器日志中查看当前的不平衡率(默认为${kafka.logs.dir}/controller.log
)。