junrao commented on code in PR #13451:
URL: https://github.com/apache/kafka/pull/13451#discussion_r1369359298
##########
core/src/main/scala/kafka/controller/KafkaController.scala:
##########
@@ -1894,10 +1894,16 @@ class KafkaController(val config: KafkaConfig,
val currentAssignment =
controllerContext.partitionFullReplicaAssignment(topicPartition)
val newAssignment = currentAssignment.reassignTo(replicas)
val areNewReplicasAlive =
newAssignment.addingReplicas.toSet.subsetOf(controllerContext.liveBrokerIds)
+ val currentLeader =
controllerContext.partitionLeadershipInfo(topicPartition).get.leaderAndIsr.leader
+ val unneededAddingReplicas =
currentAssignment.replicas.diff(newAssignment.replicas)
if (!areNewReplicasAlive)
Some(new ApiError(Errors.INVALID_REPLICA_ASSIGNMENT,
s"Replica assignment has brokers that are not alive. Replica list: "
+
s"${newAssignment.addingReplicas}, live broker list:
${controllerContext.liveBrokerIds}"))
+ else if (unneededAddingReplicas.contains(currentLeader))
Review Comment:
Hmm, by doing this, if we have current replicas as (0, 1) with 0 as the
leader, it seems that we can't re-assign this partition to (1, 2)?
##########
core/src/test/scala/unit/kafka/controller/ControllerIntegrationTest.scala:
##########
@@ -572,6 +572,48 @@ class ControllerIntegrationTest extends QuorumTestHarness {
"failed to remove reassign partitions path after completion")
}
+ @Test
+ def
testAutoPreferredReplicaLeaderElectionFollowedByAnotherNewReassignment(): Unit
= {
+ servers = makeServers(4, autoLeaderRebalanceEnable = true)
+ val controller = getController().kafkaController
+ val tp = new TopicPartition("t", 0)
+ val assignment = Map(tp.partition -> Seq(0, 2))
+ TestUtils.createTopic(zkClient, tp.topic, partitionReplicaAssignment =
assignment, servers = servers)
+
+ // Shutdown broker 2 and reassign partition tp from [0, 2] to [1, 0, 2] to
create a stuck reassignment.
Review Comment:
In a typical reassignment, we don't change the replication factor. Could we
design the test to change replicas from (0, 2) to (1, 0)? Ditto below.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]