lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1503329 - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/facet/ lucene/facet/src/java/org/apache/lucene/facet/sortedset/ lucene/facet/src/test/org/apache/lucene/facet/sortedset/
Date Mon, 15 Jul 2013 16:48:18 GMT
Author: mikemccand
Date: Mon Jul 15 16:48:17 2013
New Revision: 1503329

URL: http://svn.apache.org/r1503329
Log:
LUCENE-5090: catch mismatched readers in SortedSetDocValuesAccumulator/ReaderState

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/lucene/   (props changed)
    lucene/dev/branches/branch_4x/lucene/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_4x/lucene/facet/   (props changed)
    lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/sortedset/SortedSetDocValuesAccumulator.java
    lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/sortedset/SortedSetDocValuesReaderState.java
    lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/sortedset/TestSortedSetDocValuesFacets.java

Modified: lucene/dev/branches/branch_4x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/CHANGES.txt?rev=1503329&r1=1503328&r2=1503329&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/lucene/CHANGES.txt Mon Jul 15 16:48:17 2013
@@ -178,6 +178,10 @@ Bug Fixes
 * LUCENE-5103: A join on A single-valued field with deleted docs scored too few
   docs. (David Smiley)
 
+* LUCENE-5090: Detect mismatched readers passed to
+  SortedSetDocValuesReaderState and SortedSetDocValuesAccumulator.
+  (Robert Muir, Mike McCandless)
+
 Optimizations
 
 * LUCENE-4936: Improve numeric doc values compression in case all values share

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/sortedset/SortedSetDocValuesAccumulator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/sortedset/SortedSetDocValuesAccumulator.java?rev=1503329&r1=1503328&r2=1503329&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/sortedset/SortedSetDocValuesAccumulator.java
(original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/sortedset/SortedSetDocValuesAccumulator.java
Mon Jul 15 16:48:17 2013
@@ -35,9 +35,11 @@ import org.apache.lucene.facet.search.Fa
 import org.apache.lucene.facet.search.FacetsAggregator;
 import org.apache.lucene.facet.search.FacetsCollector.MatchingDocs;
 import org.apache.lucene.facet.taxonomy.CategoryPath;
+import org.apache.lucene.index.AtomicReader;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.MultiDocValues.MultiSortedSetDocValues;
 import org.apache.lucene.index.MultiDocValues;
+import org.apache.lucene.index.ReaderUtil;
 import org.apache.lucene.index.SortedSetDocValues;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.PriorityQueue;
@@ -57,7 +59,7 @@ public class SortedSetDocValuesAccumulat
   final String field;
 
   public SortedSetDocValuesAccumulator(FacetSearchParams fsp, SortedSetDocValuesReaderState
state) throws IOException {
-    super(fsp, null, null, new FacetArrays((int) state.getDocValues().getValueCount()));
+    super(fsp, null, null, new FacetArrays(state.getSize()));
     this.state = state;
     this.field = state.getField();
     dv = state.getDocValues();
@@ -90,13 +92,23 @@ public class SortedSetDocValuesAccumulat
       @Override
       public void aggregate(MatchingDocs matchingDocs, CategoryListParams clp, FacetArrays
facetArrays) throws IOException {
 
-        SortedSetDocValues segValues = matchingDocs.context.reader().getSortedSetDocValues(field);
+        AtomicReader reader = matchingDocs.context.reader();
+
+        // LUCENE-5090: make sure the provided reader context "matches"
+        // the top-level reader passed to the
+        // SortedSetDocValuesReaderState, else cryptic
+        // AIOOBE can happen:
+        if (ReaderUtil.getTopLevelContext(matchingDocs.context).reader() != state.origReader)
{
+          throw new IllegalStateException("the SortedSetDocValuesReaderState provided to
this class does not match the reader being searched; you must create a new SortedSetDocValuesReaderState
every time you open a new IndexReader");
+        }
+        
+        SortedSetDocValues segValues = reader.getSortedSetDocValues(field);
         if (segValues == null) {
           return;
         }
 
         final int[] counts = facetArrays.getIntArray();
-        final int maxDoc = matchingDocs.context.reader().maxDoc();
+        final int maxDoc = reader.maxDoc();
         assert maxDoc == matchingDocs.bits.length();
 
         if (dv instanceof MultiSortedSetDocValues) {

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/sortedset/SortedSetDocValuesReaderState.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/sortedset/SortedSetDocValuesReaderState.java?rev=1503329&r1=1503328&r2=1503329&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/sortedset/SortedSetDocValuesReaderState.java
(original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/sortedset/SortedSetDocValuesReaderState.java
Mon Jul 15 16:48:17 2013
@@ -51,6 +51,7 @@ public final class SortedSetDocValuesRea
   private final String field;
   private final AtomicReader topReader;
   private final int valueCount;
+  final IndexReader origReader;
   final char separator;
   final String separatorRegex;
 
@@ -91,6 +92,7 @@ public final class SortedSetDocValuesRea
     this.field = fip.getCategoryListParams(null).field + FACET_FIELD_EXTENSION;
     this.separator = fip.getFacetDelimChar();
     this.separatorRegex = Pattern.quote(Character.toString(separator));
+    this.origReader = reader;
 
     // We need this to create thread-safe MultiSortedSetDV
     // per collector:

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/sortedset/TestSortedSetDocValuesFacets.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/sortedset/TestSortedSetDocValuesFacets.java?rev=1503329&r1=1503328&r2=1503329&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/sortedset/TestSortedSetDocValuesFacets.java
(original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/sortedset/TestSortedSetDocValuesFacets.java
Mon Jul 15 16:48:17 2013
@@ -33,6 +33,7 @@ import org.apache.lucene.facet.search.Fa
 import org.apache.lucene.facet.search.FacetResult;
 import org.apache.lucene.facet.search.FacetsCollector;
 import org.apache.lucene.facet.taxonomy.CategoryPath;
+import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.MatchAllDocsQuery;
@@ -145,4 +146,51 @@ public class TestSortedSetDocValuesFacet
     searcher.getIndexReader().close();
     dir.close();
   }
+
+  // LUCENE-5090
+  public void testStaleState() throws Exception {
+    assumeTrue("Test requires SortedSetDV support", defaultCodecSupportsSortedSet());
+    Directory dir = newDirectory();
+    RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
+
+    SortedSetDocValuesFacetFields dvFields = new SortedSetDocValuesFacetFields();
+
+    Document doc = new Document();
+    dvFields.addFields(doc, Collections.singletonList(new CategoryPath("a", "foo")));
+    writer.addDocument(doc);
+
+    IndexReader r = writer.getReader();
+    SortedSetDocValuesReaderState state = new SortedSetDocValuesReaderState(r);
+
+    doc = new Document();
+    dvFields.addFields(doc, Collections.singletonList(new CategoryPath("a", "bar")));
+    writer.addDocument(doc);
+
+    doc = new Document();
+    dvFields.addFields(doc, Collections.singletonList(new CategoryPath("a", "baz")));
+    writer.addDocument(doc);
+
+    IndexSearcher searcher = newSearcher(writer.getReader());
+
+    List<FacetRequest> requests = new ArrayList<FacetRequest>();
+    requests.add(new CountFacetRequest(new CategoryPath("a"), 10));
+
+    FacetSearchParams fsp = new FacetSearchParams(requests);
+    
+    FacetsCollector c = FacetsCollector.create(new SortedSetDocValuesAccumulator(fsp, state));
+
+    searcher.search(new MatchAllDocsQuery(), c);
+
+    try {
+      c.getFacetResults();
+      fail("did not hit expected exception");
+    } catch (IllegalStateException ise) {
+      // expected
+    }
+
+    r.close();
+    writer.close();
+    searcher.getIndexReader().close();
+    dir.close();
+  }
 }



Mime
View raw message