bob-barrett commented on a change in pull request #9054: URL: https://github.com/apache/kafka/pull/9054#discussion_r458994628
########## File path: core/src/test/scala/unit/kafka/log/LogManagerTest.scala ########## @@ -563,4 +565,39 @@ class LogManagerTest { logManager.topicConfigUpdated("test-topic") assertTrue(logManager.partitionsInitializing.isEmpty) } + + @Test + def testMetricsExistWhenLogIsRecreatedBeforeDeletion(): Unit = { + val topicName = "metric-test" + def logMetrics = KafkaYammerMetrics.defaultRegistry.allMetrics.keySet.asScala. + filter(_.getType == "Log").filter(_.getScope.contains(topicName)) + + val tp = new TopicPartition(topicName, 0) + logManager.getOrCreateLog(tp, () => logConfig) + + val metricTag = s"topic=${tp.topic},partition=${tp.partition}" + + assertEquals(LogMetricNames.allMetricNames.size, logMetrics.size) + logMetrics.foreach { metric => + assertTrue(metric.getMBeanName.contains(metricTag)) + } + + logManager.asyncDelete(tp) + + assertTrue(logMetrics.isEmpty) + + logManager.getOrCreateLog(tp, () => logConfig) + + assertEquals(LogMetricNames.allMetricNames.size, logMetrics.size) + logMetrics.foreach { metric => + assertTrue(metric.getMBeanName.contains(metricTag)) + } + + time.sleep(logConfig.fileDeleteDelayMs + 1) Review comment: It causes enough "time" to elapse that the actual file deletion is triggered. Having it here tests that we still have metrics after the deletion occurs. I'll add a comment to that effect. ########## File path: core/src/main/scala/kafka/log/LogManager.scala ########## @@ -978,6 +978,7 @@ class LogManager(logDirs: Seq[File], checkpointRecoveryOffsetsAndCleanSnapshotsInDir(logDir, logsToCheckpoint, ArrayBuffer.empty) checkpointLogStartOffsetsInDir(logDir, logsToCheckpoint) } + removedLog.removeLogMetrics() Review comment: That's a good catch, thanks. I'll add that. ---------------------------------------------------------------- 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