You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ab...@apache.org on 2018/08/07 12:08:24 UTC

lucene-solr:branch_7x: SOLR-12541: Metrics handler throws an error if there are transient cores.

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7x 5a7cb7ed3 -> 4d035a746


SOLR-12541: Metrics handler throws an error if there are transient cores.


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

Branch: refs/heads/branch_7x
Commit: 4d035a7461733f765e9f0dc091028d5d5376f33e
Parents: 5a7cb7e
Author: Andrzej Bialecki <ab...@apache.org>
Authored: Tue Aug 7 13:20:44 2018 +0200
Committer: Andrzej Bialecki <ab...@apache.org>
Committed: Tue Aug 7 13:22:31 2018 +0200

----------------------------------------------------------------------
 solr/CHANGES.txt                                     |  2 ++
 .../org/apache/solr/handler/ReplicationHandler.java  |  4 ++--
 .../src/test/org/apache/solr/core/TestLazyCores.java | 15 +++++++++++++++
 3 files changed, 19 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/4d035a74/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index b6a3348..98d4d63 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -180,6 +180,8 @@ Bug Fixes
 
 * SOLR-11770: NPE in tvrh if no field is specified and document doesn't contain any fields with term vectors
 
+* SOLR-12541: Metrics handler throws an error if there are transient cores. (ab)
+
 Optimizations
 ----------------------
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/4d035a74/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java b/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
index 93b8f25..5041841 100644
--- a/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
@@ -837,13 +837,13 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAw
   public void initializeMetrics(SolrMetricManager manager, String registry, String tag, String scope) {
     super.initializeMetrics(manager, registry, tag, scope);
 
-    manager.registerGauge(this, registry, () -> core != null ? NumberUtils.readableSize(core.getIndexSize()) : "",
+    manager.registerGauge(this, registry, () -> (core != null && !core.isClosed() ? NumberUtils.readableSize(core.getIndexSize()) : ""),
         tag, true, "indexSize", getCategory().toString(), scope);
     manager.registerGauge(this, registry, () -> (core != null && !core.isClosed() ? getIndexVersion().toString() : ""),
         tag, true, "indexVersion", getCategory().toString(), scope);
     manager.registerGauge(this, registry, () -> (core != null && !core.isClosed() ? getIndexVersion().generation : 0),
         tag, true, GENERATION, getCategory().toString(), scope);
-    manager.registerGauge(this, registry, () -> core != null ? core.getIndexDir() : "",
+    manager.registerGauge(this, registry, () -> (core != null && !core.isClosed() ? core.getIndexDir() : ""),
         tag, true, "indexPath", getCategory().toString(), scope);
     manager.registerGauge(this, registry, () -> isMaster,
         tag, true, "isMaster", getCategory().toString(), scope);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/4d035a74/solr/core/src/test/org/apache/solr/core/TestLazyCores.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/core/TestLazyCores.java b/solr/core/src/test/org/apache/solr/core/TestLazyCores.java
index cc980d4..8f7f95b 100644
--- a/solr/core/src/test/org/apache/solr/core/TestLazyCores.java
+++ b/solr/core/src/test/org/apache/solr/core/TestLazyCores.java
@@ -33,9 +33,11 @@ import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.solr.SolrTestCaseJ4;
 import org.apache.solr.common.SolrException;
+import org.apache.solr.common.params.CommonParams;
 import org.apache.solr.common.params.CoreAdminParams;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.handler.admin.CoreAdminHandler;
+import org.apache.solr.handler.admin.MetricsHandler;
 import org.apache.solr.request.LocalSolrQueryRequest;
 import org.apache.solr.request.SolrQueryRequest;
 import org.apache.solr.response.SolrQueryResponse;
@@ -240,6 +242,19 @@ public class TestLazyCores extends SolrTestCaseJ4 {
           "collection8", "collection9");
       checkNotInCores(cc, Arrays.asList("collection2", "collection3"));
 
+      // verify that getting metrics from an unloaded core doesn't cause exceptions (SOLR-12541)
+      MetricsHandler handler = new MetricsHandler(h.getCoreContainer());
+
+      SolrQueryResponse resp = new SolrQueryResponse();
+      handler.handleRequest(makeReq(core1, CommonParams.QT, "/admin/metrics"), resp);
+      NamedList values = resp.getValues();
+      assertNotNull(values.get("metrics"));
+      values = (NamedList) values.get("metrics");
+      NamedList nl = (NamedList) values.get("solr.core.collection2");
+      assertNotNull(nl);
+      Object o = nl.get("REPLICATION./replication.indexPath");
+      assertNotNull(o);
+
 
       // Note decrementing the count when the core is removed from the lazyCores list is appropriate, since the
       // refcount is 1 when constructed. anyone _else_ who's opened up one has to close it.