showuon commented on code in PR #15951:
URL: https://github.com/apache/kafka/pull/15951#discussion_r1601510877


##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -2114,19 +2114,16 @@ class ReplicaManager(val config: KafkaConfig,
         partition.log.foreach { _ =>
           val leader = BrokerEndPoint(config.brokerId, "localhost", -1)
 
-          // Add future replica log to partition's map
-          partition.createLogIfNotExists(
-            isNew = false,
-            isFutureReplica = true,
-            offsetCheckpoints,
-            topicIds(partition.topic))
-
-          // pause cleaning for partitions that are being moved and start 
ReplicaAlterDirThread to move
-          // replica from source dir to destination dir
-          logManager.abortAndPauseCleaning(topicPartition)
-
-          futureReplicasAndInitialOffset.put(topicPartition, 
InitialFetchState(topicIds(topicPartition.topic), leader,
-            partition.getLeaderEpoch, futureLog.highWatermark))
+          if (partition.maybeCreateFutureReplica(futureLog.parentDir, 
offsetCheckpoints, topicIds(partition.topic))) {

Review Comment:
   > partition.maybeCreateFutureReplica() only calls 
partition.createLogIfNotExists() if the future replica doesn't yet exist. If 
that happens, partition.futureLog won't be set, so we need to call 
partition.setLog(futureLog, true)?
   
   `partition.setLog(futureLog, true)` is not necessary because when in 
`partition.createLogIfNotExists()`, we'll also set futureLog:
   ```
     if (isFutureReplica) {
         this.futureLog = Some(maybeCreate(this.futureLog))
   ```
   
   > Sincre this section is inside a block of logManager.getLog(topicPartition, 
isFuture = true).foreach { futureLog =>, doesn't that mean this only runs if 
the future replica exists?
   
   Yes, normally, when we created future log is in this path:
   1. ReplicaManager#alterReplicaLogDirs
   2. partition.maybeCreateFutureReplica
   3. partition.createLogIfNotExists
   4. partition.createLog
   5. logManager.getOrCreateLog
   
   So in the end, we'll have future log added in both `logManager#futureLogs` 
map and partition#futureLog` map.
   
   But it's possible that the future log only exists in `logManager#futureLogs` 
map, but not in `partition#futureLog` map, when the future log is created, and 
before alter logDir completed, the broker restarted. So, after restarted, we'll 
add the future log into logManager map during 
[loadLog](https://github.com/apache/kafka/blob/3f8d11f047bf2f388fee7e8b5ddb359b47cee554/core/src/main/scala/kafka/log/LogManager.scala#L370).
 But the `partition#futureLog` map won't be updated, until we got leadership 
update and `ReplicaManager#maybeAddLogDirFetchers` is called. In this case, the 
`partition.maybeCreateFutureReplica` will not create the future log since it's 
existed, but the `partition#futureLog` will get updated with the one in 
logManager.
   
   That means, we have to do the `partition.createLogIfNotExists()` here.



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