clolov commented on code in PR #14832:
URL: https://github.com/apache/kafka/pull/14832#discussion_r1422910744


##########
core/src/main/scala/kafka/server/KafkaRequestHandler.scala:
##########
@@ -386,7 +431,26 @@ class BrokerTopicMetrics(name: Option[String], configOpt: 
java.util.Optional[Kaf
       meter.close()
   }
 
-  def close(): Unit = metricTypeMap.values.foreach(_.close())
+  def close(): Unit = {
+    metricTypeMap.values.foreach(_.close())
+    metricGaugeTypeMap.values.foreach(_.close())
+  }
+}
+
+class BrokerTopicAggregatedMetric() {
+  private val partitionMetricValues = new ConcurrentHashMap[Int, 
Long]().asScala
+
+  def setPartitionMetricValue(partition: Int, partitionValue: Long): 
Option[Long] = {
+    partitionMetricValues.put(partition, partitionValue)
+  }
+
+  def removePartition(partition: Int): Option[Long] = {
+    partitionMetricValues.remove(partition)
+  }
+
+  def value(): Long = partitionMetricValues.values.sum

Review Comment:
   I actually have a preference for not updating one variable. The reason I 
don't want to use one variable is that a concurrent map provides fine-grained 
controls out of the box that no one else will be modifying the value while we 
read it. If I use a specific value then I have to acquire a lock. What are your 
thoughts?



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

Reply via email to