showuon commented on code in PR #15133: URL: https://github.com/apache/kafka/pull/15133#discussion_r1462970366
########## core/src/main/java/kafka/log/remote/RemoteLogManager.java: ########## @@ -1650,15 +1650,27 @@ private static void shutdownAndAwaitTermination(ExecutorService pool, String poo } private void removeRemoteTopicPartitionMetrics(TopicIdPartition topicIdPartition) { - BrokerTopicMetrics topicMetrics = brokerTopicStats.topicStats(topicIdPartition.topic()); - int partition = topicIdPartition.partition(); - topicMetrics.removeRemoteCopyLagBytes(partition); - topicMetrics.removeRemoteCopyLagSegments(partition); - topicMetrics.removeRemoteDeleteLagBytes(partition); - topicMetrics.removeRemoteDeleteLagSegments(partition); - topicMetrics.removeRemoteLogMetadataCount(partition); - topicMetrics.removeRemoteLogSizeComputationTime(partition); - topicMetrics.removeRemoteLogSizeBytes(partition); + String topic = topicIdPartition.topic(); + if (!brokerTopicStats.isTopicStatsExisted(topicIdPartition.topic())) { + // The topic metrics are already removed, removing this topic key from broker-level metrics + brokerTopicStats.removeBrokerLevelRemoteCopyLagBytes(topic); Review Comment: @kamalcph , when running `ReplicaManager#stopPartitions`, it'll call [maybeRemoveTopicMetrics](https://github.com/apache/kafka/blob/trunk/core/src/main/scala/kafka/server/ReplicaManager.scala#L604), and the specific topic metrics will be removed if all partitions are offline (i.e. topics deletion). And the metrics removal will also remove the topic key from brokerTopicStats [here](https://github.com/apache/kafka/blob/trunk/core/src/main/scala/kafka/server/KafkaRequestHandler.scala#L646). That's when it will be deleted. So, it the topic metrics are all deleted, we also need to remove the topic key from broker-level allTopics metrics. Hope that's clear. -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org