diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index de95cdd99c5..d755a87e872 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -97,6 +97,8 @@ Bug Fixes * SOLR-13141: CDCR bootstrap does not replicate index to the replicas of target cluster. (Krzysztof Watral, Amrit Sarkar, Tim, Tdspringsteen, shalin) +* SOLR-13694: IndexSizeEstimator NullPointerException. (ab, hossman) + Other Changes ---------------------- diff --git a/solr/core/src/java/org/apache/solr/handler/admin/IndexSizeEstimator.java b/solr/core/src/java/org/apache/solr/handler/admin/IndexSizeEstimator.java index 35b8de027db..ca54ae4f628 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/IndexSizeEstimator.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/IndexSizeEstimator.java @@ -504,14 +504,16 @@ public class IndexSizeEstimator { CodecReader codecReader = (CodecReader)leafReader; StoredFieldsReader storedFieldsReader = codecReader.getFieldsReader(); // this instance may be faster for a full sequential pass - storedFieldsReader = storedFieldsReader.getMergeInstance(); + StoredFieldsReader mergeInstance = storedFieldsReader.getMergeInstance(); for (int docId = 0; docId < leafReader.maxDoc(); docId += samplingStep) { if (liveDocs != null && !liveDocs.get(docId)) { continue; } - storedFieldsReader.visitDocument(docId, visitor); + mergeInstance.visitDocument(docId, visitor); + } + if (mergeInstance != storedFieldsReader) { + mergeInstance.close(); } - storedFieldsReader.close(); } else { for (int docId = 0; docId < leafReader.maxDoc(); docId += samplingStep) { if (liveDocs != null && !liveDocs.get(docId)) { diff --git a/solr/core/src/test/org/apache/solr/handler/admin/IndexSizeEstimatorTest.java b/solr/core/src/test/org/apache/solr/handler/admin/IndexSizeEstimatorTest.java index 16cf270bb1a..2ad9b87c9d2 100644 --- a/solr/core/src/test/org/apache/solr/handler/admin/IndexSizeEstimatorTest.java +++ b/solr/core/src/test/org/apache/solr/handler/admin/IndexSizeEstimatorTest.java @@ -23,6 +23,14 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; +import org.apache.lucene.codecs.StoredFieldsReader; +import org.apache.lucene.document.DocumentStoredFieldVisitor; +import org.apache.lucene.index.CodecReader; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.LeafReader; +import org.apache.lucene.index.LeafReaderContext; +import org.apache.lucene.index.StoredFieldVisitor; +import org.apache.lucene.util.Bits; import org.apache.lucene.util.RamUsageEstimator; import org.apache.lucene.util.TestUtil; import org.apache.solr.client.solrj.embedded.JettySolrRunner; @@ -124,6 +132,23 @@ public class IndexSizeEstimatorTest extends SolrCloudTestCase { double delta = (double) size * 0.5; assertEquals("sampled size of " + field + " is wildly off", (double)size, (double)sampledSize, delta); }); + // verify the reader is still usable - SOLR-13694 + IndexReader reader = searcher.getRawReader(); + for (LeafReaderContext context : reader.leaves()) { + LeafReader leafReader = context.reader(); + assertTrue("unexpected LeafReader class: " + leafReader.getClass().getName(), leafReader instanceof CodecReader); + Bits liveDocs = leafReader.getLiveDocs(); + CodecReader codecReader = (CodecReader) leafReader; + StoredFieldsReader storedFieldsReader = codecReader.getFieldsReader(); + StoredFieldVisitor visitor = new DocumentStoredFieldVisitor(); + assertNotNull(storedFieldsReader); + for (int docId = 0; docId < leafReader.maxDoc(); docId++) { + if (liveDocs != null && !liveDocs.get(docId)) { + continue; + } + storedFieldsReader.visitDocument(docId, visitor); + } + } } finally { searcherRef.decref(); core.close();