LUCENE-5242: DirectoryTaxonomyWriter.replaceTaxonomy did not fully reset its state

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1525894 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shai Erera 2013-09-24 14:20:47 +00:00
parent 89eb9397c7
commit 84f6e500b3
3 changed files with 29 additions and 0 deletions

View File

@ -85,6 +85,10 @@ Bug Fixes
* LUCENE-4998: Fixed a few places to pass IOContext.READONCE instead * LUCENE-4998: Fixed a few places to pass IOContext.READONCE instead
of IOContext.READ (Shikhar Bhushan via Mike McCandless) 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: API Changes:
* LUCENE-5222: Add SortField.needsScores(). Previously it was not possible * LUCENE-5222: Add SortField.needsScores(). Previously it was not possible

View File

@ -981,12 +981,14 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
initReaderManager(); // ensure that it's initialized initReaderManager(); // ensure that it's initialized
refreshReaderManager(); refreshReaderManager();
nextID = indexWriter.maxDoc(); 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 // need to clear the cache, so that addCategory won't accidentally return
// old categories that are in the cache. // old categories that are in the cache.
cache.clear(); cache.clear();
cacheIsComplete = false; cacheIsComplete = false;
shouldFillCache = true; shouldFillCache = true;
cacheMisses.set(0);
// update indexEpoch as a taxonomy replace is just like it has be recreated // update indexEpoch as a taxonomy replace is just like it has be recreated
++indexEpoch; ++indexEpoch;

View File

@ -469,4 +469,27 @@ public class TestDirectoryTaxonomyWriter extends FacetTestCase {
IOUtils.close(indexDir, taxoDir); IOUtils.close(indexDir, taxoDir);
} }
@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();
}
} }