You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2020/04/27 21:11:16 UTC

[GitHub] [kafka] ijuma commented on a change in pull request #8524: KAFKA-9866: Avoid election for topics where preferred leader is not in ISR

ijuma commented on a change in pull request #8524:
URL: https://github.com/apache/kafka/pull/8524#discussion_r416151605



##########
File path: core/src/main/scala/kafka/controller/KafkaController.scala
##########
@@ -1068,12 +1068,23 @@ class KafkaController(val config: KafkaConfig,
         val candidatePartitions = topicsNotInPreferredReplica.keys.filter(tp => controllerContext.isReplicaOnline(leaderBroker, tp) &&
           controllerContext.partitionsBeingReassigned.isEmpty &&
           !topicDeletionManager.isTopicQueuedUpForDeletion(tp.topic) &&
-          controllerContext.allTopics.contains(tp.topic))
+          controllerContext.allTopics.contains(tp.topic) &&
+          canPreferredReplicaBeLeader(tp)
+       )
         onReplicaElection(candidatePartitions.toSet, ElectionType.PREFERRED, AutoTriggered)
       }
     }
   }
 
+  private def canPreferredReplicaBeLeader(tp: TopicPartition): Boolean = {
+    val assignment = controllerContext.partitionReplicaAssignment(tp)
+    val liveReplicas = assignment.filter(replica => controllerContext.isReplicaOnline(replica, tp))

Review comment:
       We also do `controllerContext.isReplicaOnline(leaderBroker, tp)` in the caller. Do we also need it here?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org