hachikuji commented on a change in pull request #9713: URL: https://github.com/apache/kafka/pull/9713#discussion_r546044857
########## File path: core/src/main/scala/kafka/cluster/Partition.scala ########## @@ -1374,46 +1314,29 @@ class Partition(val topicPartition: TopicPartition, } } - private def shrinkIsrWithZk(newIsr: Set[Int]): Unit = { - val newLeaderAndIsr = new LeaderAndIsr(localBrokerId, leaderEpoch, newIsr.toList, zkVersion) - val zkVersionOpt = stateStore.shrinkIsr(controllerEpoch, newLeaderAndIsr) - if (zkVersionOpt.isDefined) { - isrChangeListener.markShrink() - } - maybeUpdateIsrAndVersionWithZk(newIsr, zkVersionOpt) - } - - private def maybeUpdateIsrAndVersionWithZk(isr: Set[Int], zkVersionOpt: Option[Int]): Unit = { - zkVersionOpt match { - case Some(newVersion) => - isrState = CommittedIsr(isr) - zkVersion = newVersion - info("ISR updated to [%s] and zkVersion updated to [%d]".format(isr.mkString(","), zkVersion)) - - case None => - info(s"Cached zkVersion $zkVersion not equal to that in zookeeper, skip updating ISR") - isrChangeListener.markFailed() - } - } - private def sendAlterIsrRequest(proposedIsrState: IsrState): Unit = { val isrToSend: Set[Int] = proposedIsrState match { case PendingExpandIsr(isr, newInSyncReplicaId) => isr + newInSyncReplicaId case PendingShrinkIsr(isr, outOfSyncReplicaIds) => isr -- outOfSyncReplicaIds case state => + isrChangeListener.markFailed() throw new IllegalStateException(s"Invalid state $state for `AlterIsr` request for partition $topicPartition") } val newLeaderAndIsr = new LeaderAndIsr(localBrokerId, leaderEpoch, isrToSend.toList, zkVersion) - val alterIsrItem = AlterIsrItem(topicPartition, newLeaderAndIsr, handleAlterIsrResponse(proposedIsrState)) + val alterIsrItem = AlterIsrItem(topicPartition, newLeaderAndIsr, handleAlterIsrResponse(proposedIsrState), controllerEpoch) - if (!alterIsrManager.enqueue(alterIsrItem)) { + val oldState = isrState + isrState = proposedIsrState + + if (!alterIsrManager.submit(alterIsrItem)) { + // If the ISR manager did not accept our update, we need to revert back to previous state + isrState = oldState isrChangeListener.markFailed() throw new IllegalStateException(s"Failed to enqueue `AlterIsr` request with state " + s"$newLeaderAndIsr for partition $topicPartition") } - isrState = proposedIsrState debug(s"Sent `AlterIsr` request to change state to $newLeaderAndIsr after transition to $proposedIsrState") Review comment: Should we generalize this log message as well? Also the couple `IllegalStateException` messages above. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org