You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "Onur Karaman (JIRA)" <ji...@apache.org> on 2017/08/18 00:14:00 UTC

[jira] [Commented] (KAFKA-5559) Metrics should throw if two client registers with same ID

    [ https://issues.apache.org/jira/browse/KAFKA-5559?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16131513#comment-16131513 ] 

Onur Karaman commented on KAFKA-5559:
-------------------------------------

[~xiaotao183] I agree that as per the definition of {{client.id}}, it should be possible to have multiple clients on the same jvm with the same {{client.id}}.

I think the solution is the following:
{code}
-    public static void registerAppInfo(String prefix, String id) {
+    // method is synchronized to prevent race where two concurrent client instantiations would try to both register the mbean
+    public static synchronized void registerAppInfo(String prefix, String id) {
         try {
             ObjectName name = new ObjectName(prefix + ":type=app-info,id=" + id);
-            AppInfo mBean = new AppInfo();
-            ManagementFactory.getPlatformMBeanServer().registerMBean(mBean, name);
+            if (!ManagementFactory.getPlatformMBeanServer().isRegistered(name)) {
+                AppInfo mBean = new AppInfo();
+                ManagementFactory.getPlatformMBeanServer().registerMBean(mBean, name);
+            }
         } catch (JMException e) {
             log.warn("Error registering AppInfo mbean", e);
         }
     }

-    public static void unregisterAppInfo(String prefix, String id) {
+    // method is synchronized to prevent race where two concurrent client closes would try to both unregister the mbean
+    public static synchronized void unregisterAppInfo(String prefix, String id) {
{code}
Basically, just don't attempt to reregister if it already exists. I can open up a PR with the above fix.

> Metrics should throw if two client registers with same ID
> ---------------------------------------------------------
>
>                 Key: KAFKA-5559
>                 URL: https://issues.apache.org/jira/browse/KAFKA-5559
>             Project: Kafka
>          Issue Type: Bug
>          Components: metrics
>    Affects Versions: 0.11.0.0
>            Reporter: Matthias J. Sax
>            Assignee: Matthias J. Sax
>
> Currently, {{AppInfoParser}} only logs a WARN message when a bean is registered with an existing name. However, this should be treated as an error and the exception should be rthrown.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)