kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ij...@apache.org
Subject [kafka] branch 0.11.0 updated: KAFKA-6307: Fix KafkaMbean leak in JmxReporter (#4307)
Date Mon, 14 May 2018 21:12:38 GMT
This is an automated email from the ASF dual-hosted git repository.

ijuma pushed a commit to branch 0.11.0
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/0.11.0 by this push:
     new 70fb5a4  KAFKA-6307: Fix KafkaMbean leak in JmxReporter (#4307)
70fb5a4 is described below

commit 70fb5a42f4a0bbf8a55be424842d14c17b374966
Author: tedyu <yuzhihong@gmail.com>
AuthorDate: Mon Jan 1 02:16:07 2018 -0800

    KAFKA-6307: Fix KafkaMbean leak in JmxReporter (#4307)
    
    We should remove the map entry from mbeans if it becomes
    empty during metric removal.
    
    Reviewers: Manikumar Reddy <manikumar.reddy@gmail.com>, Satish Duggana <satish.duggana@gmail.com>,
Ismael Juma <ismael@juma.me.uk>
    
    The tests were excluded from the backport to the 0.11.0
    branch due to conflicts.
---
 .../java/org/apache/kafka/common/metrics/JmxReporter.java | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/clients/src/main/java/org/apache/kafka/common/metrics/JmxReporter.java b/clients/src/main/java/org/apache/kafka/common/metrics/JmxReporter.java
index 67dfaa8..90ffbeb 100644
--- a/clients/src/main/java/org/apache/kafka/common/metrics/JmxReporter.java
+++ b/clients/src/main/java/org/apache/kafka/common/metrics/JmxReporter.java
@@ -74,6 +74,9 @@ public class JmxReporter implements MetricsReporter {
         }
     }
 
+    boolean containsMbean(String mbeanName) {
+        return mbeans.containsKey(mbeanName);
+    }
     @Override
     public void metricChange(KafkaMetric metric) {
         synchronized (LOCK) {
@@ -85,19 +88,21 @@ public class JmxReporter implements MetricsReporter {
     @Override
     public void metricRemoval(KafkaMetric metric) {
         synchronized (LOCK) {
-            KafkaMbean mbean = removeAttribute(metric);
+            MetricName metricName = metric.metricName();
+            String mBeanName = getMBeanName(prefix, metricName);
+            KafkaMbean mbean = removeAttribute(metric, mBeanName);
             if (mbean != null) {
-                if (mbean.metrics.isEmpty())
+                if (mbean.metrics.isEmpty()) {
                     unregister(mbean);
-                else
+                    mbeans.remove(mBeanName);
+                } else
                     reregister(mbean);
             }
         }
     }
 
-    private KafkaMbean removeAttribute(KafkaMetric metric) {
+    private KafkaMbean removeAttribute(KafkaMetric metric, String mBeanName) {
         MetricName metricName = metric.metricName();
-        String mBeanName = getMBeanName(prefix, metricName);
         KafkaMbean mbean = this.mbeans.get(mBeanName);
         if (mbean != null)
             mbean.removeAttribute(metricName.name());

-- 
To stop receiving notification emails like this one, please contact
ijuma@apache.org.

Mime
View raw message