[GitHub] [kafka] leonardge commented on a change in pull request #8524: KAFKA-9866: Avoid election for topics where preferred leader is not in ISR
leonardge commented on a change in pull request #8524: URL: https://github.com/apache/kafka/pull/8524#discussion_r416186838 ## 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: Sure thing! 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: us...@infra.apache.org
[GitHub] [kafka] leonardge commented on a change in pull request #8524: KAFKA-9866: Avoid election for topics where preferred leader is not in ISR
leonardge commented on a change in pull request #8524: URL: https://github.com/apache/kafka/pull/8524#discussion_r415085874 ## 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) && + isPreferredLeaderInSync(tp) + ) onReplicaElection(candidatePartitions.toSet, ElectionType.PREFERRED, AutoTriggered) } } } + private def isPreferredLeaderInSync(tp: TopicPartition): Boolean = { Review comment: Done! 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: us...@infra.apache.org
[GitHub] [kafka] leonardge commented on a change in pull request #8524: KAFKA-9866: Avoid election for topics where preferred leader is not in ISR
leonardge commented on a change in pull request #8524: URL: https://github.com/apache/kafka/pull/8524#discussion_r414467090 ## File path: core/src/main/scala/kafka/controller/KafkaController.scala ## @@ -1068,7 +1068,12 @@ 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) && + PartitionLeaderElectionAlgorithms.preferredReplicaPartitionLeaderElection( +controllerContext.partitionReplicaAssignment(tp), +controllerContext.partitionLeadershipInfo(tp).leaderAndIsr.isr, +controllerContext.liveBrokerIds.toSet).nonEmpty Review comment: Done! And after using the mentioned implementation the code block gets cluttered so I extracted it into a helper method. 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: us...@infra.apache.org
[GitHub] [kafka] leonardge commented on a change in pull request #8524: KAFKA-9866: Avoid election for topics where preferred leader is not in ISR
leonardge commented on a change in pull request #8524: URL: https://github.com/apache/kafka/pull/8524#discussion_r414012223 ## File path: core/src/main/scala/kafka/controller/KafkaController.scala ## @@ -1068,7 +1068,9 @@ 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) && + controllerContext.partitionLeadershipInfo.get(tp).forall(l => l.leaderAndIsr.isr.contains(leaderBroker)) Review comment: Done! 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: us...@infra.apache.org
[GitHub] [kafka] leonardge commented on a change in pull request #8524: KAFKA-9866: Avoid election for topics where preferred leader is not in ISR
leonardge commented on a change in pull request #8524: URL: https://github.com/apache/kafka/pull/8524#discussion_r412857024 ## File path: core/src/main/scala/kafka/controller/KafkaController.scala ## @@ -1066,6 +1066,7 @@ class KafkaController(val config: KafkaConfig, // do this check only if the broker is live and there are no partitions being reassigned currently // and preferred replica election is not in progress val candidatePartitions = topicsNotInPreferredReplica.keys.filter(tp => controllerContext.isReplicaOnline(leaderBroker, tp) && + controllerContext.partitionLeadershipInfo(tp).leaderAndIsr.isr.contains(leaderBroker) && Review comment: Done. 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: us...@infra.apache.org