diff --git a/lucene/core/src/java/org/apache/lucene/index/SegmentCoreReaders.java b/lucene/core/src/java/org/apache/lucene/index/SegmentCoreReaders.java index e99c1ada266..21ac4a16e98 100644 --- a/lucene/core/src/java/org/apache/lucene/index/SegmentCoreReaders.java +++ b/lucene/core/src/java/org/apache/lucene/index/SegmentCoreReaders.java @@ -56,6 +56,7 @@ final class SegmentCoreReaders { final TermVectorsReader termVectorsReaderOrig; final PointsReader pointsReader; final Directory cfsReader; + final String segment; /** * fieldinfos for this core: means gen=-1. * this is the exact fieldinfos these codec components saw at write. @@ -98,6 +99,8 @@ final class SegmentCoreReaders { cfsDir = dir; } + segment = si.info.name; + coreFieldInfos = codec.fieldInfosFormat().read(cfsDir, si.info, "", context); final SegmentReadState segmentReadState = new SegmentReadState(cfsDir, si.info, coreFieldInfos, context); @@ -192,4 +195,9 @@ final class SegmentCoreReaders { void removeCoreClosedListener(CoreClosedListener listener) { coreClosedListeners.remove(listener); } + + @Override + public String toString() { + return "SegmentCoreReader(" + segment + ")"; + } } diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 78f7f5580f9..37cccaea5db 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -164,6 +164,9 @@ New Features * SOLR-5043: New solr.dns.prevent.reverse.lookup system property that can be used to prevent long core (re)load delays on systems with missconfigured hostname/DNS (hossman) +* SOLR-9844: FieldCache information fetched via the mbeans handler or seen via the UI now displays the total size used. + The individual cache entries in the response are now formatted better as well. (Varun Thacker) + Optimizations ---------------------- * SOLR-9704: Facet Module / JSON Facet API: Optimize blockChildren facets that have 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 62bc4fa1ff2..70781e967f5 100644 --- a/solr/core/src/java/org/apache/solr/search/SolrFieldCacheMBean.java +++ b/solr/core/src/java/org/apache/solr/search/SolrFieldCacheMBean.java @@ -64,11 +64,13 @@ public class SolrFieldCacheMBean implements JmxAugmentedSolrInfoMBean { if (listEntries) { String[] entries = UninvertingReader.getUninvertedStats(); stats.add("entries_count", entries.length); + stats.add("total_size", UninvertingReader.getTotalSize()); for (int i = 0; i < entries.length; i++) { stats.add("entry#" + i, entries[i]); } } else { stats.add("entries_count", UninvertingReader.getUninvertedStatsSize()); + stats.add("total_size", UninvertingReader.getTotalSize()); } return stats; } diff --git a/solr/core/src/java/org/apache/solr/uninverting/FieldCache.java b/solr/core/src/java/org/apache/solr/uninverting/FieldCache.java index 32f56152c8c..544800e3d3b 100644 --- a/solr/core/src/java/org/apache/solr/uninverting/FieldCache.java +++ b/solr/core/src/java/org/apache/solr/uninverting/FieldCache.java @@ -384,7 +384,7 @@ public interface FieldCache { return custom; } - public Object getValue() { + public Accountable getValue() { return value; } @@ -399,15 +399,11 @@ public interface FieldCache { @Override public String toString() { - StringBuilder b = new StringBuilder(250); - b.append("'").append(getReaderKey()).append("'=>"); - b.append("'").append(getFieldName()).append("',"); - b.append(getCacheType()).append(",").append(getCustom()); - b.append("=>").append(getValue().getClass().getName()).append("#"); - b.append(System.identityHashCode(getValue())); - + StringBuilder b = new StringBuilder(100); + b.append("segment='").append(getReaderKey().toString()).append("', "); + b.append("field='").append(getFieldName()).append("', "); String s = getEstimatedSize(); - b.append(" (size =~ ").append(s).append(')'); + b.append("size =~ ").append(s); return b.toString(); } diff --git a/solr/core/src/java/org/apache/solr/uninverting/FieldCacheSanityChecker.java b/solr/core/src/java/org/apache/solr/uninverting/FieldCacheSanityChecker.java index ec398f2174a..3d874ce4bfb 100644 --- a/solr/core/src/java/org/apache/solr/uninverting/FieldCacheSanityChecker.java +++ b/solr/core/src/java/org/apache/solr/uninverting/FieldCacheSanityChecker.java @@ -27,6 +27,7 @@ import java.util.Set; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReaderContext; import org.apache.lucene.store.AlreadyClosedException; +import org.apache.lucene.util.Accountable; import org.apache.lucene.util.MapOfSets; import org.apache.solr.uninverting.FieldCache.CacheEntry; @@ -103,7 +104,7 @@ final class FieldCacheSanityChecker { // iterate over all the cacheEntries to get the mappings we'll need for (int i = 0; i < cacheEntries.length; i++) { final CacheEntry item = cacheEntries[i]; - final Object val = item.getValue(); + final Accountable val = item.getValue(); // It's OK to have dup entries, where one is eg // float[] and the other is the Bits (from diff --git a/solr/core/src/java/org/apache/solr/uninverting/UninvertingReader.java b/solr/core/src/java/org/apache/solr/uninverting/UninvertingReader.java index 78256664dee..87fb7a6bd42 100644 --- a/solr/core/src/java/org/apache/solr/uninverting/UninvertingReader.java +++ b/solr/core/src/java/org/apache/solr/uninverting/UninvertingReader.java @@ -37,6 +37,7 @@ import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.NumericDocValues; import org.apache.lucene.index.SortedDocValues; import org.apache.lucene.index.SortedSetDocValues; +import org.apache.lucene.util.RamUsageEstimator; import org.apache.solr.uninverting.FieldCache.CacheEntry; /** @@ -386,4 +387,13 @@ public class UninvertingReader extends FilterLeafReader { public static int getUninvertedStatsSize() { return FieldCache.DEFAULT.getCacheEntries().length; } + + public static String getTotalSize() { + CacheEntry[] entries = FieldCache.DEFAULT.getCacheEntries(); + long totalBytesUsed = 0; + for (int i = 0; i < entries.length; i++) { + totalBytesUsed += entries[i].getValue().ramBytesUsed(); + } + return RamUsageEstimator.humanReadableUnits(totalBytesUsed); + } } diff --git a/solr/core/src/test/org/apache/solr/search/TestSolrFieldCacheMBean.java b/solr/core/src/test/org/apache/solr/search/TestSolrFieldCacheMBean.java index 5343f7345fb..a705e1ec94a 100644 --- a/solr/core/src/test/org/apache/solr/search/TestSolrFieldCacheMBean.java +++ b/solr/core/src/test/org/apache/solr/search/TestSolrFieldCacheMBean.java @@ -76,6 +76,7 @@ public class TestSolrFieldCacheMBean extends SolrTestCaseJ4 { SolrFieldCacheMBean mbean = new SolrFieldCacheMBean(); NamedList stats = checkJmx ? mbean.getStatisticsForJmx() : mbean.getStatistics(); assert(new Integer(stats.get("entries_count").toString()) > 0); + assertNotNull(stats.get("total_size")); assertNull(stats.get("entry#0")); } }