From acb09b9853a175460258a5bbc43dcdc828dc2c36 Mon Sep 17 00:00:00 2001 From: Jackie Wang Date: Mon, 23 Jun 2014 09:41:45 -0700 Subject: [PATCH] The first live broker in ISR was used as new leader. Since the order of liveBrokersInIsr list is not event distributed within live brokers, all partitions will be hosted on one broker as time goes on. Now use the first live replica broker in ISR (liveAssignedReplicas filtered by liveBrokersInIsr) as the replica order is strictly evenly distributed. Changes to be committed: modified: core/src/main/scala/kafka/controller/PartitionLeaderSelector.scala --- core/src/main/scala/kafka/controller/PartitionLeaderSelector.scala | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/main/scala/kafka/controller/PartitionLeaderSelector.scala b/core/src/main/scala/kafka/controller/PartitionLeaderSelector.scala index d3b25fa..4a31c72 100644 --- a/core/src/main/scala/kafka/controller/PartitionLeaderSelector.scala +++ b/core/src/main/scala/kafka/controller/PartitionLeaderSelector.scala @@ -83,7 +83,8 @@ class OfflinePartitionLeaderSelector(controllerContext: ControllerContext, confi new LeaderAndIsr(newLeader, currentLeaderEpoch + 1, List(newLeader), currentLeaderIsrZkPathVersion + 1) } case false => - val newLeader = liveBrokersInIsr.head + val liveReplicasInIsr = liveAssignedReplicas.filter(r => liveBrokersInIsr.contains(r)) + val newLeader = liveReplicasInIsr.head debug("Some broker in ISR is alive for %s. Select %d from ISR %s to be the leader." .format(topicAndPartition, newLeader, liveBrokersInIsr.mkString(","))) new LeaderAndIsr(newLeader, currentLeaderEpoch + 1, liveBrokersInIsr.toList, currentLeaderIsrZkPathVersion + 1) @@ -210,4 +211,4 @@ class NoOpLeaderSelector(controllerContext: ControllerContext) extends Partition warn("I should never have been asked to perform leader election, returning the current LeaderAndIsr and replica assignment.") (currentLeaderAndIsr, controllerContext.partitionReplicaAssignment(topicAndPartition)) } -} \ No newline at end of file +} -- 1.8.5.2 (Apple Git-48)