hachikuji commented on a change in pull request #11189:
URL: https://github.com/apache/kafka/pull/11189#discussion_r685417821



##########
File path: core/src/main/scala/kafka/server/ReplicaManager.scala
##########
@@ -2204,27 +2204,32 @@ class ReplicaManager(val config: KafkaConfig,
 
           completeDelayedFetchOrProduceRequests(tp)
 
-          // Create the local replica even if the leader is unavailable. This 
is required
-          // to ensure that we include the partition's high watermark in the 
checkpoint
-          // file (see KAFKA-1647)
-          partition.createLogIfNotExists(isNew, false, offsetCheckpoints, 
Some(info.topicId))
-
           if (shuttingDown) {
             stateChangeLogger.trace(s"Unable to start fetching ${tp} with 
topic " +
               s"ID ${info.topicId} because the replica manager is shutting 
down.")
           } else {
             val listenerName = config.interBrokerListenerName.value()
             val leader = info.partition.leader
-            
Option(newImage.cluster().broker(leader)).flatMap(_.node(listenerName).asScala) 
match {
-              case None => stateChangeLogger.trace(s"Unable to start fetching 
${tp} " +
-                s"with topic ID ${info.topicId} from leader ${leader} because 
it is not " +
-                "alive.")
-              case Some(node) =>
-                val leaderEndPoint = new BrokerEndPoint(node.id(), 
node.host(), node.port())
-                val log = partition.localLogOrException
-                val fetchOffset = initialFetchOffset(log)
-                partitionsToMakeFollower.put(tp,
-                  InitialFetchState(leaderEndPoint, partition.getLeaderEpoch, 
fetchOffset))
+            val state = info.partition.toLeaderAndIsrPartitionState(tp, isNew)
+            if (partition.makeFollower(state, offsetCheckpoints, 
Some(info.topicId))) {
+              
Option(newImage.cluster().broker(leader)).flatMap(_.node(listenerName).asScala) 
match {

Review comment:
       The order here is a little different than in the LeaderAndIsr path. In 
the other path, we skip the call to `makeFollower` if the leader is not 
available. I think that implicitly also handles the case when the current 
leader is -1. I noticed that `Partition.makeFollower` does not check for this 
case when it does the assignment:
   
   ```scala
   leaderReplicaIdOpt = Some(newLeaderBrokerId)
   ```




-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to