soondenana commented on a change in pull request #9054: URL: https://github.com/apache/kafka/pull/9054#discussion_r459766825
########## File path: core/src/main/scala/kafka/log/LogManager.scala ########## @@ -1151,6 +1149,16 @@ class LogManager(logDirs: Seq[File], } } } + + private def removeLogAndMetrics(logs: Pool[TopicPartition, Log], tp: TopicPartition): Option[Log] = { + val removedLog = logs.remove(tp) + if (removedLog != null) { + removedLog.removeLogMetrics() + Some(removedLog) + } else { + None + } Review comment: nit: I think just returning `Option(removedLog)` should take care of Some/None part. ########## File path: core/src/main/scala/kafka/log/LogManager.scala ########## @@ -199,27 +199,22 @@ class LogManager(logDirs: Seq[File], if (cleaner != null) cleaner.handleLogDirFailure(dir) - val offlineCurrentTopicPartitions = currentLogs.collect { - case (tp, log) if log.parentDir == dir => tp - } - offlineCurrentTopicPartitions.foreach { topicPartition => { - val removedLog = currentLogs.remove(topicPartition) - if (removedLog != null) { - removedLog.closeHandlers() - removedLog.removeLogMetrics() + def removeOfflineLogs(logs: Pool[TopicPartition, Log]): Iterable[TopicPartition] = { + val offlineTopicPartitions: Iterable[TopicPartition] = logs.collect { + case (tp, log) if log.parentDir == dir => tp } - }} + offlineTopicPartitions.foreach { topicPartition => { + val removedLog = removeLogAndMetrics(logs, topicPartition) + removedLog.foreach { + log => log.closeHandlers() + } Review comment: nit: as its one line, can be abbreviated as `_.closeHandlers()` ---------------------------------------------------------------- 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