lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sha...@apache.org
Subject [lucene-solr] branch branch_8x updated: SOLR-13712: JMX MBeans are not exposed because of race condition between creating platform mbean server and registering mbeans
Date Sun, 29 Sep 2019 04:41:32 GMT
This is an automated email from the ASF dual-hosted git repository.

shalin pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/branch_8x by this push:
     new d353c19  SOLR-13712: JMX MBeans are not exposed because of race condition between
creating platform mbean server and registering mbeans
d353c19 is described below

commit d353c19f779f898b7c37ecf4d6183fe4c8f911b1
Author: Shalin Shekhar Mangar <shalin@apache.org>
AuthorDate: Sun Sep 29 10:09:58 2019 +0530

    SOLR-13712: JMX MBeans are not exposed because of race condition between creating platform
mbean server and registering mbeans
    
    (cherry picked from commit 2ba61c8fb9c42586a174072276592ddfdff1563b)
---
 solr/CHANGES.txt                                                 | 3 +++
 .../java/org/apache/solr/metrics/reporters/SolrJmxReporter.java  | 2 +-
 .../apache/solr/metrics/reporters/jmx/JmxMetricsReporter.java    | 4 ----
 solr/core/src/java/org/apache/solr/util/JmxUtil.java             | 9 +++++++--
 4 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index cceda38..ec7f801 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -186,6 +186,9 @@ Bug Fixes
 * SOLR-13417: Handle stats aggregation on date and string fields in SolrJ's JSON facet response
processing
   (Jason Gerlowski, Munendra S N)
 
+* SOLR-13712: JMX MBeans are not exposed because of race condition between creating platform
mbean server and
+  registering mbeans. (shalin)
+
 Other Changes
 ----------------------
 
diff --git a/solr/core/src/java/org/apache/solr/metrics/reporters/SolrJmxReporter.java b/solr/core/src/java/org/apache/solr/metrics/reporters/SolrJmxReporter.java
index 468ba60..54b4530 100644
--- a/solr/core/src/java/org/apache/solr/metrics/reporters/SolrJmxReporter.java
+++ b/solr/core/src/java/org/apache/solr/metrics/reporters/SolrJmxReporter.java
@@ -70,7 +70,7 @@ public class SolrJmxReporter extends FilteringSolrMetricReporter {
   protected synchronized void doInit() {
     if (serviceUrl != null && agentId != null) {
       mBeanServer = JmxUtil.findFirstMBeanServer();
-      log.warn("No more than one of serviceUrl({}) and agentId({}) should be configured,
using first MBeanServer instead of configuration.",
+      log.warn("No more than one of serviceUrl({}) and agentId({}) should be configured,
using first MBeanServer {} instead of configuration.",
           serviceUrl, agentId, mBeanServer);
     } else if (serviceUrl != null) {
       // reuse existing services
diff --git a/solr/core/src/java/org/apache/solr/metrics/reporters/jmx/JmxMetricsReporter.java
b/solr/core/src/java/org/apache/solr/metrics/reporters/jmx/JmxMetricsReporter.java
index 189d14d..56f295f 100644
--- a/solr/core/src/java/org/apache/solr/metrics/reporters/jmx/JmxMetricsReporter.java
+++ b/solr/core/src/java/org/apache/solr/metrics/reporters/jmx/JmxMetricsReporter.java
@@ -28,7 +28,6 @@ import javax.management.Query;
 import javax.management.QueryExp;
 import java.io.Closeable;
 import java.lang.invoke.MethodHandles;
-import java.lang.management.ManagementFactory;
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
@@ -157,9 +156,6 @@ public class JmxMetricsReporter implements Reporter, Closeable {
     }
 
     public JmxMetricsReporter build() {
-      if (mBeanServer == null) {
-        mBeanServer = ManagementFactory.getPlatformMBeanServer();
-      }
       if (tag == null) {
         tag = Integer.toHexString(this.hashCode());
       }
diff --git a/solr/core/src/java/org/apache/solr/util/JmxUtil.java b/solr/core/src/java/org/apache/solr/util/JmxUtil.java
index f27a55e..16dc4e8 100644
--- a/solr/core/src/java/org/apache/solr/util/JmxUtil.java
+++ b/solr/core/src/java/org/apache/solr/util/JmxUtil.java
@@ -23,6 +23,7 @@ import javax.management.remote.JMXConnectorServerFactory;
 import javax.management.remote.JMXServiceURL;
 
 import java.io.IOException;
+import java.lang.management.ManagementFactory;
 import java.util.List;
 
 /**
@@ -31,12 +32,16 @@ import java.util.List;
 public final class JmxUtil {
 
   /**
-   * Retrieve the first MBeanServer found.
+   * Retrieve the first MBeanServer found and if not found return the platform mbean server
    *
    * @return the first MBeanServer found
    */
   public static MBeanServer findFirstMBeanServer() {
-    return findMBeanServerForAgentId(null);
+    MBeanServer mBeanServer = findMBeanServerForAgentId(null);
+    if (mBeanServer == null)  {
+      return ManagementFactory.getPlatformMBeanServer();
+    }
+    return mBeanServer;
   }
 
   /**


Mime
View raw message