Apache Lucene open-source search software
SOLR-3355: Add shard and collection to SolrCore statistics.
Mark Robert Millerc971f7929afe
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex ef52e60c78f..13c85c5e609 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -59,6 +59,8 @@ Other Changes* SOLR-1770: Move the default core instance directory into a collection1 folder.(Mark Miller)++* SOLR-3355: Add shard and collection to SolrCore statistics. (Michael Garski, Mark Miller)================== 4.0.0-ALPHA ==================More information about this release, including any errata related to thediff --git a/solr/core/src/java/org/apache/solr/core/SolrCore.java b/solr/core/src/java/org/apache/solr/core/SolrCore.javaindex 70d4c6cb82d..834be655407 100644--- a/solr/core/src/java/org/apache/solr/core/SolrCore.java+++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java@@ -25,6 +25,7 @@ import org.apache.lucene.index.IndexWriter;import org.apache.lucene.search.BooleanQuery;import org.apache.lucene.store.Directory;import org.apache.lucene.store.LockObtainFailedException;+import org.apache.solr.cloud.CloudDescriptor;import org.apache.solr.common.SolrException;import org.apache.solr.common.params.CommonParams;import org.apache.solr.common.params.CommonParams.EchoParamStyle;@@ -1980,9 +1981,18 @@ public final class SolrCore implements SolrInfoMBean {lst.add("startTime", new Date(startTime));lst.add("refCount", getOpenCount());- if (null != getCoreDescriptor() && null != getCoreDescriptor().getCoreContainer()) {- lst.add("aliases", getCoreDescriptor().getCoreContainer().getCoreNames(this));+ CoreDescriptor cd = getCoreDescriptor();+ if (cd != null) {+ if (null != cd && cd.getCoreContainer() != null) {+ lst.add("aliases", getCoreDescriptor().getCoreContainer().getCoreNames(this));+ }+ CloudDescriptor cloudDesc = cd.getCloudDescriptor();+ if (cloudDesc != null) {+ lst.add("collection", cloudDesc.getCollectionName());+ lst.add("shard", cloudDesc.getShardId());+ }}+return lst;}diff --git a/solr/core/src/test/org/apache/solr/BasicFunctionalityTest.java b/solr/core/src/test/org/apache/solr/BasicFunctionalityTest.javaindex 297a2496b46..9f682883210 100644--- a/solr/core/src/test/org/apache/solr/BasicFunctionalityTest.java+++ b/solr/core/src/test/org/apache/solr/BasicFunctionalityTest.java@@ -128,6 +128,11 @@ public class BasicFunctionalityTest extends SolrTestCaseJ4 {IndexWriter writer = ((DirectUpdateHandler2)core.getUpdateHandler()).getSolrCoreState().getIndexWriter(core);assertEquals("Mergefactor was not picked up", 8, ((LogMergePolicy)writer.getConfig().getMergePolicy()).getMergeFactor());+ // test stats call+ NamedList stats = core.getStatistics();+ assertEquals("collection1", stats.get("coreName"));+ assertTrue(stats.get("refCount") != null);+lrf.args.put(CommonParams.VERSION,"2.2");assertQ("test query on empty index",req("qlkciyopsbgzyvkylsjhchghjrdf")diff --git a/solr/core/src/test/org/apache/solr/cloud/BasicZkTest.java b/solr/core/src/test/org/apache/solr/cloud/BasicZkTest.javaindex 58dd4a128a1..ea82db41d86 100644--- a/solr/core/src/test/org/apache/solr/cloud/BasicZkTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/BasicZkTest.java@@ -23,6 +23,7 @@ import org.apache.lucene.util.LuceneTestCase.Slow;import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.common.params.CommonParams;import org.apache.solr.common.params.ModifiableSolrParams;+import org.apache.solr.common.util.NamedList;import org.apache.solr.core.SolrCore;import org.apache.solr.request.LocalSolrQueryRequest;import org.apache.solr.request.SolrQueryRequest;@@ -160,6 +161,13 @@ public class BasicZkTest extends AbstractZkTestCase {}+ // test stats call+ NamedList stats = core.getStatistics();+ assertEquals("collection1", stats.get("coreName"));+ assertEquals("collection1", stats.get("collection"));+ assertEquals("shard1", stats.get("shard"));+ assertTrue(stats.get("refCount") != null);+//zkController.getZkClient().printLayoutToStdOut();}