mirror of https://github.com/apache/kafka.git
KAFKA-9866: Avoid election for topics where preferred leader is not in ISR (#8524)
In this commit we made sure that the auto leader election only happens after the newly starter broker is in the isr. No accompany tests are added due to the fact that: this is a change to the private method and no public facing change is made it is hard to create tests for this change without considerable effort Reviewers: Stanislav Kozlovski <stanislav_kozlovski@outlook.com>, Jun Rao <junrao@gmail.com>
This commit is contained in:
parent
bd17085ec1
commit
db9e55a50f
|
@ -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))
|
||||
val isr = controllerContext.partitionLeadershipInfo(tp).leaderAndIsr.isr
|
||||
PartitionLeaderElectionAlgorithms
|
||||
.preferredReplicaPartitionLeaderElection(assignment, isr, liveReplicas.toSet)
|
||||
.nonEmpty
|
||||
}
|
||||
|
||||
private def processAutoPreferredReplicaLeaderElection(): Unit = {
|
||||
if (!isActive) return
|
||||
try {
|
||||
|
|
|
@ -433,8 +433,8 @@ class ControllerIntegrationTest extends ZooKeeperTestHarness {
|
|||
TestUtils.createTopic(zkClient, tp.topic, partitionReplicaAssignment = assignment, servers = servers)
|
||||
waitForPartitionState(tp, firstControllerEpoch, otherBrokerId, LeaderAndIsr.initialLeaderEpoch,
|
||||
"failed to get expected partition state upon topic creation")
|
||||
servers(1).shutdown()
|
||||
servers(1).awaitShutdown()
|
||||
servers(otherBrokerId).shutdown()
|
||||
servers(otherBrokerId).awaitShutdown()
|
||||
TestUtils.waitUntilTrue(() => {
|
||||
val leaderIsrAndControllerEpochMap = zkClient.getTopicPartitionStates(Seq(tp))
|
||||
leaderIsrAndControllerEpochMap.contains(tp) &&
|
||||
|
|
Loading…
Reference in New Issue