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



##########
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:
       Intuitively, we should update `Partition` regardless whether the leader 
is available or not, but I was thinking it might be easier to do that 
separately.




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