LUCENE-3641: Fixed MultiReader to correctly propagate readerFinishedListeners to clones/reopened readers

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1213106 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2011-12-11 23:32:13 +00:00
parent 50cbfec8ff
commit 3c00042ca0
2 changed files with 16 additions and 5 deletions

View File

@ -724,6 +724,9 @@ Bug fixes
In ParallelReader the bug was not existent, but the implementation method
was also made private. (Uwe Schindler)
* LUCENE-3641: Fixed MultiReader to correctly propagate readerFinishedListeners
to clones/reopened readers. (Uwe Schindler)
Documentation
* LUCENE-3597: Fixed incorrect grouping documentation. (Martijn van Groningen, Robert Muir)

View File

@ -18,6 +18,7 @@ package org.apache.lucene.index;
*/
import java.io.IOException;
import java.util.Collection;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.lucene.util.Bits;
@ -27,7 +28,7 @@ import org.apache.lucene.util.MapBackedSet;
/** An IndexReader which reads multiple indexes, appending
* their content. */
public class MultiReader extends BaseMultiReader<IndexReader> {
private boolean[] decrefOnClose; // remember which subreaders to decRef on close
private final boolean[] decrefOnClose; // remember which subreaders to decRef on close
/**
* <p>Construct a MultiReader aggregating the named set of (sub)readers.
@ -46,7 +47,7 @@ public class MultiReader extends BaseMultiReader<IndexReader> {
*/
public MultiReader(IndexReader[] subReaders, boolean closeSubReaders) throws IOException {
super(subReaders.clone());
this.readerFinishedListeners = new MapBackedSet<ReaderFinishedListener>(new ConcurrentHashMap<ReaderFinishedListener,Boolean>());
readerFinishedListeners = new MapBackedSet<ReaderFinishedListener>(new ConcurrentHashMap<ReaderFinishedListener,Boolean>());
decrefOnClose = new boolean[subReaders.length];
for (int i = 0; i < subReaders.length; i++) {
if (!closeSubReaders) {
@ -57,6 +58,15 @@ public class MultiReader extends BaseMultiReader<IndexReader> {
}
}
}
// used only by openIfChaged
private MultiReader(IndexReader[] subReaders, boolean[] decrefOnClose,
Collection<ReaderFinishedListener> readerFinishedListeners)
throws IOException {
super(subReaders);
this.decrefOnClose = decrefOnClose;
this.readerFinishedListeners = readerFinishedListeners;
}
@Override
protected synchronized IndexReader doOpenIfChanged() throws CorruptIndexException, IOException {
@ -117,9 +127,7 @@ public class MultiReader extends BaseMultiReader<IndexReader> {
newDecrefOnClose[i] = true;
}
}
MultiReader mr = new MultiReader(newSubReaders);
mr.decrefOnClose = newDecrefOnClose;
return mr;
return new MultiReader(newSubReaders, newDecrefOnClose, readerFinishedListeners);
} else {
return null;
}