dajac commented on code in PR #12181:
URL: https://github.com/apache/kafka/pull/12181#discussion_r896470010


##########
core/src/main/scala/kafka/cluster/Partition.scala:
##########
@@ -1569,24 +1628,47 @@ class Partition(val topicPartition: TopicPartition,
   ): Boolean = {
     alterPartitionListener.markFailed()
     error match {
-      case Errors.OPERATION_NOT_ATTEMPTED =>
-        // Since the operation was not attempted, it is safe to reset back to 
the committed state.
-        partitionState = CommittedPartitionState(proposedIsrState.isr, 
LeaderRecoveryState.RECOVERED)
-        debug(s"Failed to alter partition to $proposedIsrState since there is 
a pending AlterPartition still inflight. " +
-          s"partition state has been reset to the latest committed state 
$partitionState")
+      case Errors.OPERATION_NOT_ATTEMPTED | Errors.INELIGIBLE_REPLICA =>
+        // Care must be taken when resetting to the last committed state since 
we may not
+        // know in general whether the request was applied or not taking into 
account retries
+        // and controller changes which might have occurred before we received 
the response.
+        // However, when the controller returns INELIGIBLE_REPLICA (or 
OPERATION_NOT_COMMITTED),
+        // the controller is explicitly telling us 1) that the current 
partition epoch is correct,
+        // and 2) that the request was not applied. Even if the controller 
that sent the response
+        // is stale, we are guaranteed from the monotonicity of the controller 
epoch that the
+        // request could not have been applied by any past or future 
controller.
+        partitionState = proposedIsrState.lastCommittedState

Review Comment:
   We rollback the previous partition state here only if the the partition 
state still matches our proposed partition state. If it does not, it means that 
the partition was updated via the metadata log in the mean time. This check is 
in `submitAlterPartition` before calling `handleAlterPartitionError`.



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