New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KAFKA-9866: Avoid election for topics where preferred leader is not in ISR #8524
Changes from 5 commits
44eea04
29632f7
172960f
24c6d42
dc67b99
2fa3cee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = { | ||
val assignment = controllerContext.partitionReplicaAssignment(tp) | ||
val liveReplicas = assignment.filter(replica => controllerContext.isReplicaOnline(replica, tp)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. We can get rid of the isReplicaOnline() check in the caller. @leonardge : Could you summit a followup minor PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure thing! |
||
val isr = controllerContext.partitionLeadershipInfo(tp).leaderAndIsr.isr | ||
PartitionLeaderElectionAlgorithms | ||
.preferredReplicaPartitionLeaderElection(assignment, isr, liveReplicas.toSet) | ||
.nonEmpty | ||
} | ||
|
||
private def processAutoPreferredReplicaLeaderElection(): Unit = { | ||
if (!isActive) return | ||
try { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps a more accurate name is canPreferredReplicaBeLeader()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!