Preferred leader election restores a partition’s designated leader after recovery. The preferred replica is the first broker in the partition’s replica list and must be synchronized before taking leadership. section 5.3
Recovering a partition leader
If Broker 3 leads Partition 1 and fails, Kafka promotes an in-sync replica such as Broker 1. After Broker 3 rejoins and catches up, leadership remains with Broker 1 until automatic rebalancing occurs or an operator triggers a preferred election.
$ kafka-topics.sh --create \
--topic products.prices.changelog.replication-3 \
--replication-factor 3 \
--partitions 3 \
--config min.insync.replicas=2 \
--bootstrap-server localhost:9092
Created topic products.prices.changelog.replication-3.
Use kafka-leader-election.sh with --election-type=preferred to rebalance all topic partitions or target a specific topic. Avoid unclean elections except in extreme emergencies because out-of-sync replicas can lose data. section 5.3
