junrao commented on code in PR #17796:
URL: https://github.com/apache/kafka/pull/17796#discussion_r1866371497


##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -2455,6 +2455,8 @@ class ReplicaManager(val config: KafkaConfig,
           if (metadataCache.hasAliveBroker(newLeaderBrokerId)) {
             // Only change partition state when the leader is available
             if (partition.makeFollower(partitionState, 
highWatermarkCheckpoints, topicIds(partitionState.topicName))) {
+              // Invoke the follower transition listeners for the partition.
+              partition.invokeLeaderToFollowerListeners()

Review Comment:
   This is the ZK path, which won't be supported in 4.0.



##########
core/src/main/scala/kafka/cluster/Partition.scala:
##########
@@ -82,6 +82,11 @@ trait PartitionListener {
    * that the partition was deleted but only that this broker does not host a 
replica of it any more.
    */
   def onDeleted(partition: TopicPartition): Unit = {}
+
+  /**
+   * Called when the Partition on this broker is transitioned to follower from 
leader.
+   */
+  def onLeaderToFollower(partition: TopicPartition): Unit = {}

Review Comment:
   This method is invoke when a replica becomes a follower and may not be 
previously a leader. So, we could just name this method sth like 
`onBecomingFollower`.



##########
core/src/test/scala/unit/kafka/server/ReplicaManagerTest.scala:
##########
@@ -6798,6 +6798,62 @@ class ReplicaManagerTest {
     assertEquals(Double.NaN, maxMetric.metricValue)
   }
 
+  @Test
+  def testBecomeFollowerInvokeLeaderToFollowerListener(): Unit = {

Review Comment:
   LeaderAndIsrRequest is used in ZK-based controller, which won't be supported 
in 4.0. We want to test KRaft-based controller logic instead.



-- 
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]

Reply via email to