Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-8869: Optionally disable printing field cache entries in SolrFieldCacheMBean

Gregory Chanancb1738360e0c
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 8fc2156664b..81e079e68ab 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -83,6 +83,8 @@ Other Changes
* SOLR-5616: Simplifies grouping code to use ResponseBuilder.needDocList() to determine if it needs to
generate a doc list for grouped results. (Steven Bower, Keith Laban, Dennis Gove)
+* SOLR-8869: Optionally disable printing field cache entries in SolrFieldCacheMBean (Gregory Chanan)
+
================== 6.0.0 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release
diff --git a/solr/core/src/java/org/apache/solr/search/SolrFieldCacheMBean.java b/solr/core/src/java/org/apache/solr/search/SolrFieldCacheMBean.java
index 46e35b53201..cfc68c4d687 100644
--- a/solr/core/src/java/org/apache/solr/search/SolrFieldCacheMBean.java
+++ b/solr/core/src/java/org/apache/solr/search/SolrFieldCacheMBean.java
@@ -31,6 +31,8 @@ import org.apache.solr.core.SolrInfoMBean;
*/
public class SolrFieldCacheMBean implements SolrInfoMBean {
+ private boolean disableEntryList = Boolean.getBoolean("disableSolrFieldCacheMBeanEntryList");
+
@Override
public String getName() { return this.getClass().getName(); }
@Override
@@ -52,8 +54,10 @@ public class SolrFieldCacheMBean implements SolrInfoMBean {
NamedList stats = new SimpleOrderedMap();
String[] entries = UninvertingReader.getUninvertedStats();
stats.add("entries_count", entries.length);
- for (int i = 0; i < entries.length; i++) {
- stats.add("entry#" + i, entries[i]);
+ if (!disableEntryList) {
+ for (int i = 0; i < entries.length; i++) {
+ stats.add("entry#" + i, entries[i]);
+ }
}
return stats;
}
diff --git a/solr/core/src/test/org/apache/solr/search/TestSolrFieldCacheMBean.java b/solr/core/src/test/org/apache/solr/search/TestSolrFieldCacheMBean.java
new file mode 100644
index 00000000000..b90430e9ef6
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/search/TestSolrFieldCacheMBean.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.search;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.util.NamedList;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.invoke.MethodHandles;
+
+public class TestSolrFieldCacheMBean extends SolrTestCaseJ4 {
+
+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ initCore("solrconfig.xml","schema-minimal.xml");
+ }
+
+ @Test
+ public void testEntryList() throws Exception {
+ // ensure entries to FieldCache
+ assertU(adoc("id", "id0"));
+ assertU(commit());
+ assertQ(req("q", "*:*", "sort", "id asc"), "//*[@numFound='1']");
+
+ SolrFieldCacheMBean mbean = new SolrFieldCacheMBean();
+ NamedList stats = mbean.getStatistics();
+ assert(new Integer(stats.get("entries_count").toString()) > 0);
+ assertNotNull(stats.get("entry#0"));
+
+ // Test again with entry list disabled
+ System.setProperty("disableSolrFieldCacheMBeanEntryList", "true");
+ try {
+ mbean = new SolrFieldCacheMBean();
+ stats = mbean.getStatistics();
+ assert(new Integer(stats.get("entries_count").toString()) > 0);
+ assertNull(stats.get("entry#0"));
+ } finally {
+ System.clearProperty("disableSolrFieldCacheMBeanEntryList");
+ }
+ }
+}