soarez commented on code in PR #15557:
URL: https://github.com/apache/kafka/pull/15557#discussion_r1546282044


##########
core/src/main/scala/kafka/server/ReplicaAlterLogDirsThread.scala:
##########
@@ -96,57 +97,55 @@ class ReplicaAlterLogDirsThread(name: String,
   }
 
   override def removePartitions(topicPartitions: Set[TopicPartition]): 
Map[TopicPartition, PartitionFetchState] = {
-    // Schedule assignment request to revert any queued request before 
cancelling
-    for {
-      topicPartition <- topicPartitions
-      partitionState <- partitionAssignmentRequestState(topicPartition)
-      if partitionState == QUEUED
-      partition = replicaMgr.getPartitionOrException(topicPartition)
-      topicId <- partition.topicId
-      directoryId <- partition.logDirectoryId()
-      topicIdPartition = new TopicIdPartition(topicId, 
topicPartition.partition())
-    } directoryEventHandler.handleAssignment(topicIdPartition, directoryId, () 
=> ())
+    for (topicPartition <- topicPartitions) {
+      // Revert any reassignments for partitions that did not complete the 
future replica promotion
+      val PromotionState(reassignmentState, topicId, originalDir) = 
this.promotionState(topicPartition)
+      if (reassignmentState.inconsistentMetadata) {
+        directoryEventHandler.handleAssignment(new TopicIdPartition(topicId, 
topicPartition.partition()), originalDir, () => ())
+      }
+
+      this.promotionStates.remove(topicPartition)
+    }
 
     super.removePartitions(topicPartitions)
   }
 
+  private def promotionState(topicPartition: TopicPartition): PromotionState = 
promotionStates.get(topicPartition)
+
+  private def reassignmentState(topicPartition: TopicPartition): 
ReassignmentState = promotionState(topicPartition).reassignmentState
+
   // Visible for testing
-  private[server] def updatedAssignmentRequestState(topicPartition: 
TopicPartition)(state: ReplicaAlterLogDirsThread.DirectoryEventRequestState): 
Unit = {
-    assignmentRequestStates.put(topicPartition, state)
+  private[server] def updateReassignmentState(topicPartition: TopicPartition, 
state: ReassignmentState): Unit = {
+    promotionStates.put(topicPartition, 
promotionState(topicPartition).withAssignment(state))
   }
 
   private def maybePromoteFutureReplica(topicPartition: TopicPartition, 
partition: Partition) = {
     val topicId = partition.topicId
     if (topicId.isEmpty)
       throw new IllegalStateException(s"Topic ${topicPartition.topic()} does 
not have an ID.")
 
-    partitionAssignmentRequestState(topicPartition) match {
-      case None =>
+    reassignmentState(topicPartition) match {
+      case ReassignmentState.None =>
         // Schedule assignment request and don't promote the future replica 
yet until the controller has accepted the request.
         partition.runCallbackIfFutureReplicaCaughtUp(_ => {

Review Comment:
   Yes, I think so. I'll add a debug log to `updateReassignmentState`, so we 
can log every state transition. In that situation, if we don't see the 
respective transition change that would indicate the future log has not caught 
up.



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