lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject lucene-solr:branch_7x: SOLR-12594: MetricsHistoryHandler.getOverseerLeader fails when hostname contains hyphen.
Date Thu, 02 Aug 2018 17:48:35 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7x 32e417959 -> b03c1ad6f


SOLR-12594: MetricsHistoryHandler.getOverseerLeader fails when hostname contains hyphen.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/b03c1ad6
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/b03c1ad6
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/b03c1ad6

Branch: refs/heads/branch_7x
Commit: b03c1ad6f6ccf5a90a221d667152946f5c3dead3
Parents: 32e4179
Author: Andrzej Bialecki <ab@apache.org>
Authored: Thu Aug 2 18:47:58 2018 +0200
Committer: Andrzej Bialecki <ab@apache.org>
Committed: Thu Aug 2 18:48:42 2018 +0200

----------------------------------------------------------------------
 solr/CHANGES.txt                                         |  2 ++
 .../apache/solr/handler/admin/MetricsHistoryHandler.java | 11 +++++++----
 .../solr/metrics/reporters/solr/SolrClusterReporter.java | 11 +++++++----
 .../apache/solr/metrics/rrd/SolrRrdBackendFactory.java   |  9 +++++++--
 .../solr/handler/admin/MetricsHistoryHandlerTest.java    |  4 +---
 5 files changed, 24 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b03c1ad6/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index e04048d..4c15502 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -170,6 +170,8 @@ Bug Fixes
 
 * SOLR-12344: SolrSlf4jReporter doesn't set MDC context. (ab)
 
+* SOLR-12594: MetricsHistoryHandler.getOverseerLeader fails when hostname contains hyphen.
(ab)
+
 Optimizations
 ----------------------
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b03c1ad6/solr/core/src/java/org/apache/solr/handler/admin/MetricsHistoryHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/MetricsHistoryHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/MetricsHistoryHandler.java
index 419f021..9a46d04 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/MetricsHistoryHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/MetricsHistoryHandler.java
@@ -62,6 +62,7 @@ import org.apache.solr.client.solrj.cloud.SolrCloudManager;
 import org.apache.solr.client.solrj.cloud.autoscaling.ReplicaInfo;
 import org.apache.solr.client.solrj.cloud.autoscaling.VersionedData;
 import org.apache.solr.client.solrj.impl.HttpClientUtil;
+import org.apache.solr.cloud.LeaderElector;
 import org.apache.solr.cloud.Overseer;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.cloud.ClusterState;
@@ -332,12 +333,14 @@ public class MetricsHistoryHandler extends RequestHandlerBase implements
Permiss
     if (oid == null) {
       return null;
     }
-    String[] ids = oid.split("-");
-    if (ids.length != 3) { // unknown format
-      log.warn("Unknown format of leader id, skipping: " + oid);
+    String nodeName = null;
+    try {
+      nodeName = LeaderElector.getNodeName(oid);
+    } catch (Exception e) {
+      log.warn("Unknown format of leader id, skipping: " + oid, e);
       return null;
     }
-    return ids[1];
+    return nodeName;
   }
 
   private boolean amIOverseerLeader() {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b03c1ad6/solr/core/src/java/org/apache/solr/metrics/reporters/solr/SolrClusterReporter.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/metrics/reporters/solr/SolrClusterReporter.java
b/solr/core/src/java/org/apache/solr/metrics/reporters/solr/SolrClusterReporter.java
index 9e8861e..17390e1 100644
--- a/solr/core/src/java/org/apache/solr/metrics/reporters/solr/SolrClusterReporter.java
+++ b/solr/core/src/java/org/apache/solr/metrics/reporters/solr/SolrClusterReporter.java
@@ -28,6 +28,7 @@ import java.util.concurrent.TimeUnit;
 import java.util.function.Supplier;
 
 import org.apache.http.client.HttpClient;
+import org.apache.solr.cloud.LeaderElector;
 import org.apache.solr.cloud.Overseer;
 import org.apache.solr.cloud.ZkController;
 import org.apache.solr.common.cloud.SolrZkClient;
@@ -270,13 +271,15 @@ public class SolrClusterReporter extends SolrCoreContainerReporter {
       if (oid == null) {
         return lastKnownUrl;
       }
-      String[] ids = oid.split("-");
-      if (ids.length != 3) { // unknown format
-        log.warn("Unknown format of leader id, skipping: " + oid);
+      String nodeName = null;
+      try {
+        nodeName = LeaderElector.getNodeName(oid);
+      } catch (Exception e) {
+        log.warn("Unknown format of leader id, skipping: " + oid, e);
         return lastKnownUrl;
       }
       // convert nodeName back to URL
-      String url = zk.getZkStateReader().getBaseUrlForNodeName(ids[1]);
+      String url = zk.getZkStateReader().getBaseUrlForNodeName(nodeName);
       // check that it's parseable
       try {
         new java.net.URL(url);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b03c1ad6/solr/core/src/java/org/apache/solr/metrics/rrd/SolrRrdBackendFactory.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/metrics/rrd/SolrRrdBackendFactory.java b/solr/core/src/java/org/apache/solr/metrics/rrd/SolrRrdBackendFactory.java
index a3c6f64..5448d8f 100644
--- a/solr/core/src/java/org/apache/solr/metrics/rrd/SolrRrdBackendFactory.java
+++ b/solr/core/src/java/org/apache/solr/metrics/rrd/SolrRrdBackendFactory.java
@@ -206,7 +206,8 @@ public class SolrRrdBackendFactory extends RrdBackendFactory implements
SolrClos
         return null;
       }
       if (o instanceof byte[]) {
-        Long time = (Long)doc.getFieldValue("timestamp_l");
+        Object timeObj = doc.getFieldValue("timestamp_l");
+        Long time = timeObj instanceof Number ? ((Number)timeObj).longValue() : Long.parseLong(String.valueOf(timeObj));
         return new SolrRrdBackend.SyncData((byte[])o, time);
       } else {
         throw new SolrServerException("Unexpected value of '" + DATA_FIELD + "' field: "
+ o.getClass().getName() + ": " + o);
@@ -248,7 +249,11 @@ public class SolrRrdBackendFactory extends RrdBackendFactory implements
SolrClos
         SolrDocumentList docs = rsp.getResults();
         if (docs != null) {
           docs.forEach(d -> {
-            Long time = (Long)d.getFieldValue("timestamp_l");
+            Object o = d.getFieldValue("timestamp_l");
+            if (o == null) {
+              return;
+            }
+            Long time = o instanceof Number ? ((Number)o).longValue() : Long.parseLong(String.valueOf(o));
             Pair<String, Long> p = new Pair<>(((String)d.getFieldValue("id")).substring(idPrefixLength),
time);
             byName.put(p.first(), p);
           });

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b03c1ad6/solr/core/src/test/org/apache/solr/handler/admin/MetricsHistoryHandlerTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/handler/admin/MetricsHistoryHandlerTest.java
b/solr/core/src/test/org/apache/solr/handler/admin/MetricsHistoryHandlerTest.java
index dfdecc2..735b427 100644
--- a/solr/core/src/test/org/apache/solr/handler/admin/MetricsHistoryHandlerTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/admin/MetricsHistoryHandlerTest.java
@@ -21,7 +21,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.lucene.util.LuceneTestCase;
 import org.apache.solr.client.solrj.SolrClient;
 import org.apache.solr.client.solrj.cloud.SolrCloudManager;
 import org.apache.solr.client.solrj.cloud.autoscaling.AutoScalingConfig;
@@ -45,7 +44,6 @@ import org.rrd4j.core.RrdDb;
  *
  */
 @LogLevel("org.apache.solr.cloud=DEBUG")
-@LuceneTestCase.BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // added
20-Jul-2018
 public class MetricsHistoryHandlerTest extends SolrCloudTestCase {
 
   private static SolrCloudManager cloudManager;
@@ -60,7 +58,7 @@ public class MetricsHistoryHandlerTest extends SolrCloudTestCase {
 
   @BeforeClass
   public static void beforeClass() throws Exception {
-    simulated = random().nextBoolean() || true;
+    simulated = random().nextBoolean();
     Map<String, Object> args = new HashMap<>();
     args.put(MetricsHistoryHandler.SYNC_PERIOD_PROP, 1);
     args.put(MetricsHistoryHandler.COLLECT_PERIOD_PROP, 1);


Mime
View raw message