You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2013/09/24 16:23:14 UTC

svn commit: r1525896 - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/facet/ lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/ lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/

Author: shaie
Date: Tue Sep 24 14:23:13 2013
New Revision: 1525896

URL: http://svn.apache.org/r1525896
Log:
LUCENE-5242: DirectoryTaxonomyWriter.replaceTaxonomy did not fully reset its state

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/taxonomy/directory/DirectoryTaxonomyWriter.java
    lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.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=1525896&r1=1525895&r2=1525896&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/lucene/CHANGES.txt Tue Sep 24 14:23:13 2013
@@ -38,6 +38,10 @@ Bug Fixes
 * LUCENE-4998: Fixed a few places to pass IOContext.READONCE instead
   of IOContext.READ (Shikhar Bhushan via Mike McCandless)
 
+* LUCENE-5242: DirectoryTaxonomyWriter.replaceTaxonomy did not fully reset
+  its state, which could result in exceptions being thrown, as well as
+  incorrect ordinals returned from getParent. (Shai Erera)
+
 API Changes:
 
 * LUCENE-5222: Add SortField.needsScores(). Previously it was not possible

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java?rev=1525896&r1=1525895&r2=1525896&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java Tue Sep 24 14:23:13 2013
@@ -982,12 +982,14 @@ public class DirectoryTaxonomyWriter imp
     initReaderManager(); // ensure that it's initialized
     refreshReaderManager();
     nextID = indexWriter.maxDoc();
+    taxoArrays = null; // must nullify so that it's re-computed next time it's needed
     
     // need to clear the cache, so that addCategory won't accidentally return
     // old categories that are in the cache.
     cache.clear();
     cacheIsComplete = false;
     shouldFillCache = true;
+    cacheMisses.set(0);
     
     // update indexEpoch as a taxonomy replace is just like it has be recreated
     ++indexEpoch;

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java?rev=1525896&r1=1525895&r2=1525896&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java Tue Sep 24 14:23:13 2013
@@ -413,4 +413,27 @@ public class TestDirectoryTaxonomyWriter
     dir.close();
   }
   
+  
+  @Test
+  public void testReplaceTaxoWithLargeTaxonomy() throws Exception {
+    Directory srcTaxoDir = newDirectory(), targetTaxoDir = newDirectory();
+    
+    // build source, large, taxonomy
+    DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(srcTaxoDir);
+    int ord = taxoWriter.addCategory(new CategoryPath("A/1/1/1/1/1/1", '/'));
+    taxoWriter.close();
+    
+    taxoWriter = new DirectoryTaxonomyWriter(targetTaxoDir);
+    int ordinal = taxoWriter.addCategory(new CategoryPath("B/1", '/'));
+    assertEquals(1, taxoWriter.getParent(ordinal)); // call getParent to initialize taxoArrays
+    taxoWriter.commit();
+    
+    taxoWriter.replaceTaxonomy(srcTaxoDir);
+    assertEquals(ord - 1, taxoWriter.getParent(ord));
+    taxoWriter.close();
+    
+    srcTaxoDir.close();
+    targetTaxoDir.close();
+  }
+  
 }