Apache Lucene open-source search software
SOLR-14657: Improve error handling in IndexReader realted metrics that were causing scary ERROR logging if metrics were requested while Solr was in the process of closing/re-opening a new IndexReader
Chris Hostettera6c058a26094
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex b46ccfea886..1fc5a5f7200 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -156,6 +156,9 @@ Bug Fixes* SOLR-14516: Fix NPE in JSON response writer(wt=json) with /get when writing non-stored, non-indexed docvalue fieldfrom an uncommitted document (noble, Ishan Chattopadhyaya, Munendra S N)+* SOLR-14657: Improve error handling in IndexReader realted metrics that were causing scary ERROR logging+ if metrics were requested while Solr was in the process of closing/re-opening a new IndexReader. (hossman)+Other Changes---------------------diff --git a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.javaindex 4cc97586118..3ebd43c845e 100644--- a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java+++ b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java@@ -35,7 +35,9 @@ import java.util.concurrent.TimeUnit;import java.util.concurrent.atomic.AtomicLong;import java.util.concurrent.atomic.AtomicReference;+import com.codahale.metrics.Gauge;import com.google.common.collect.Iterables;+import org.apache.lucene.document.Document;import org.apache.lucene.index.DirectoryReader;import org.apache.lucene.index.ExitableDirectoryReader;@@ -51,6 +53,7 @@ import org.apache.lucene.index.Terms;import org.apache.lucene.index.TermsEnum;import org.apache.lucene.search.*;import org.apache.lucene.search.TotalHits.Relation;+import org.apache.lucene.store.AlreadyClosedException;import org.apache.lucene.store.Directory;import org.apache.lucene.util.Bits;import org.apache.lucene.util.BytesRef;@@ -2274,12 +2277,12 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable, SolrIparentContext.gauge(() -> warmupTime, true, "warmupTime", Category.SEARCHER.toString(), scope);parentContext.gauge(() -> registerTime, true, "registeredAt", Category.SEARCHER.toString(), scope);// reader stats- parentContext.gauge(() -> reader.numDocs(), true, "numDocs", Category.SEARCHER.toString(), scope);- parentContext.gauge(() -> reader.maxDoc(), true, "maxDoc", Category.SEARCHER.toString(), scope);- parentContext.gauge(() -> reader.maxDoc() - reader.numDocs(), true, "deletedDocs", Category.SEARCHER.toString(), scope);- parentContext.gauge(() -> reader.toString(), true, "reader", Category.SEARCHER.toString(), scope);- parentContext.gauge(() -> reader.directory().toString(), true, "readerDir", Category.SEARCHER.toString(), scope);- parentContext.gauge(() -> reader.getVersion(), true, "indexVersion", Category.SEARCHER.toString(), scope);+ parentContext.gauge(rgauge(-1, () -> reader.numDocs()), true, "numDocs", Category.SEARCHER.toString(), scope);+ parentContext.gauge(rgauge(-1, () -> reader.maxDoc()), true, "maxDoc", Category.SEARCHER.toString(), scope);+ parentContext.gauge(rgauge(-1, () -> reader.maxDoc() - reader.numDocs()), true, "deletedDocs", Category.SEARCHER.toString(), scope);+ parentContext.gauge(rgauge(-1, () -> reader.toString()), true, "reader", Category.SEARCHER.toString(), scope);+ parentContext.gauge(rgauge("", () -> reader.directory().toString()), true, "readerDir", Category.SEARCHER.toString(), scope);+ parentContext.gauge(rgauge(-1, () -> reader.getVersion()), true, "indexVersion", Category.SEARCHER.toString(), scope);// size of the currently opened commitparentContext.gauge(() -> {try {@@ -2301,6 +2304,20 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable, SolrI}), true, "statsCache", Category.CACHE.toString(), scope);}+ /**+ * wraps a gauge (related to an IndexReader) and swallows any {@link AlreadyClosedException} that+ * might be thrown, returning the specified default in it's place.+ */+ private <T> Gauge<T> rgauge(T closedDefault, Gauge<T> g) {+ return () -> {+ try {+ return g.getValue();+ } catch (AlreadyClosedException ignore) {+ return closedDefault;+ }+ };+ }+private static class FilterImpl extends Filter {private final Filter topFilter;private final List<Weight> weights;