mirror of https://github.com/apache/lucene.git
add fun test case for reindexing using ParallelLeafReader
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1641795 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3f4a3c393b
commit
efb848f9e3
|
@ -19,7 +19,7 @@ package org.apache.lucene.index;
|
|||
|
||||
import org.apache.lucene.document.DocumentStoredFieldVisitor;
|
||||
import org.apache.lucene.store.AlreadyClosedException;
|
||||
import org.apache.lucene.util.Bits;
|
||||
import org.apache.lucene.util.Bits; // javadocs
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
|
||||
import java.io.Closeable;
|
||||
|
@ -30,7 +30,6 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
// javadocs
|
||||
|
||||
/**
|
||||
IndexReader is an abstract class, providing an interface for accessing a
|
||||
|
@ -99,7 +98,7 @@ public abstract class IndexReader implements Closeable {
|
|||
*/
|
||||
public static interface ReaderClosedListener {
|
||||
/** Invoked when the {@link IndexReader} is closed. */
|
||||
public void onClose(IndexReader reader);
|
||||
public void onClose(IndexReader reader) throws IOException;
|
||||
}
|
||||
|
||||
private final Set<ReaderClosedListener> readerClosedListeners =
|
||||
|
@ -191,7 +190,7 @@ public abstract class IndexReader implements Closeable {
|
|||
*/
|
||||
public final void incRef() {
|
||||
if (!tryIncRef()) {
|
||||
ensureOpen();
|
||||
ensureOpen();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3831,6 +3831,14 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {
|
|||
merge.readers.set(i, null);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
merge.mergeFinished();
|
||||
} catch (Throwable t) {
|
||||
if (th == null) {
|
||||
th = t;
|
||||
}
|
||||
}
|
||||
|
||||
// If any error occured, throw it.
|
||||
if (!suppressExceptions) {
|
||||
|
|
|
@ -80,7 +80,7 @@ public abstract class LeafReader extends IndexReader {
|
|||
public static interface CoreClosedListener {
|
||||
/** Invoked when the shared core of the original {@code
|
||||
* SegmentReader} has closed. */
|
||||
public void onClose(Object ownerCoreCacheKey);
|
||||
public void onClose(Object ownerCoreCacheKey) throws IOException;
|
||||
}
|
||||
|
||||
private static class CoreClosedListenerWrapper implements ReaderClosedListener {
|
||||
|
@ -92,7 +92,7 @@ public abstract class LeafReader extends IndexReader {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onClose(IndexReader reader) {
|
||||
public void onClose(IndexReader reader) throws IOException {
|
||||
listener.onClose(reader.getCoreCacheKey());
|
||||
}
|
||||
|
||||
|
|
|
@ -66,4 +66,9 @@ public final class LeafReaderContext extends IndexReaderContext {
|
|||
public LeafReader reader() {
|
||||
return reader;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LeafReaderContext(" + reader + " docBase=" + docBase + " ord=" + ord + ")";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,6 +129,10 @@ public abstract class MergePolicy {
|
|||
totalDocCount = count;
|
||||
}
|
||||
|
||||
/** Called by {@link IndexWriter} after the merge is done and all readers have been closed. */
|
||||
public void mergeFinished() throws IOException {
|
||||
}
|
||||
|
||||
/** Expert: Get the list of readers to merge. Note that this list does not
|
||||
* necessarily match the list of segments to merge and should only be used
|
||||
* to feed SegmentMerger to initialize a merge. When a {@link OneMerge}
|
||||
|
|
|
@ -28,7 +28,6 @@ import java.util.TreeMap;
|
|||
|
||||
import org.apache.lucene.util.Bits;
|
||||
|
||||
|
||||
/** An {@link LeafReader} which reads multiple, parallel indexes. Each index
|
||||
* added must have the same number of documents, but typically each contains
|
||||
* different fields. Deletions are taken from the first reader.
|
||||
|
@ -322,4 +321,10 @@ public class ParallelLeafReader extends LeafReader {
|
|||
reader.checkIntegrity();
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the {@link LeafReader}s that were passed on init. */
|
||||
public LeafReader[] getParallelReaders() {
|
||||
ensureOpen();
|
||||
return parallelReaders;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,6 +67,19 @@ public final class ReaderManager extends ReferenceManager<DirectoryReader> {
|
|||
current = DirectoryReader.open(dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a new ReaderManager from the given
|
||||
* already-opened {@link DirectoryReader}, stealing
|
||||
* the incoming reference.
|
||||
*
|
||||
* @param reader the directoryReader to use for future reopens
|
||||
*
|
||||
* @throws IOException If there is a low-level I/O error
|
||||
*/
|
||||
public ReaderManager(DirectoryReader reader) throws IOException {
|
||||
current = reader;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decRef(DirectoryReader reference) throws IOException {
|
||||
reference.decRef();
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -56,8 +56,10 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||
import java.util.logging.Logger;
|
||||
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.analysis.MockAnalyzer;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field.Store;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.document.StringField;
|
||||
import org.apache.lucene.document.TextField;
|
||||
|
@ -76,8 +78,8 @@ import org.apache.lucene.index.FieldInfo;
|
|||
import org.apache.lucene.index.FieldInfos;
|
||||
import org.apache.lucene.index.Fields;
|
||||
import org.apache.lucene.index.IndexOptions;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.IndexReader.ReaderClosedListener;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.IndexWriterConfig;
|
||||
import org.apache.lucene.index.LeafReader;
|
||||
|
@ -104,8 +106,8 @@ import org.apache.lucene.index.SortedSetDocValues;
|
|||
import org.apache.lucene.index.StorableField;
|
||||
import org.apache.lucene.index.StoredDocument;
|
||||
import org.apache.lucene.index.Terms;
|
||||
import org.apache.lucene.index.TermsEnum;
|
||||
import org.apache.lucene.index.TermsEnum.SeekStatus;
|
||||
import org.apache.lucene.index.TermsEnum;
|
||||
import org.apache.lucene.index.TieredMergePolicy;
|
||||
import org.apache.lucene.search.AssertingIndexSearcher;
|
||||
import org.apache.lucene.search.DocIdSetIterator;
|
||||
|
@ -116,12 +118,12 @@ import org.apache.lucene.store.Directory;
|
|||
import org.apache.lucene.store.FSDirectory;
|
||||
import org.apache.lucene.store.FSLockFactory;
|
||||
import org.apache.lucene.store.FlushInfo;
|
||||
import org.apache.lucene.store.IOContext;
|
||||
import org.apache.lucene.store.IOContext.Context;
|
||||
import org.apache.lucene.store.IOContext;
|
||||
import org.apache.lucene.store.LockFactory;
|
||||
import org.apache.lucene.store.MergeInfo;
|
||||
import org.apache.lucene.store.MockDirectoryWrapper;
|
||||
import org.apache.lucene.store.MockDirectoryWrapper.Throttling;
|
||||
import org.apache.lucene.store.MockDirectoryWrapper;
|
||||
import org.apache.lucene.store.NRTCachingDirectory;
|
||||
import org.apache.lucene.store.RateLimitedDirectoryWrapper;
|
||||
import org.apache.lucene.util.automaton.AutomatonTestUtil;
|
||||
|
@ -138,7 +140,6 @@ import org.junit.Test;
|
|||
import org.junit.rules.RuleChain;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import com.carrotsearch.randomizedtesting.JUnit4MethodProvider;
|
||||
import com.carrotsearch.randomizedtesting.LifecycleScope;
|
||||
import com.carrotsearch.randomizedtesting.MixWithSuiteName;
|
||||
|
@ -149,16 +150,16 @@ import com.carrotsearch.randomizedtesting.annotations.Listeners;
|
|||
import com.carrotsearch.randomizedtesting.annotations.SeedDecorators;
|
||||
import com.carrotsearch.randomizedtesting.annotations.TestGroup;
|
||||
import com.carrotsearch.randomizedtesting.annotations.TestMethodProviders;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction.Action;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakGroup;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakGroup.Group;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakGroup;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies.Consequence;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies;
|
||||
import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite;
|
||||
import com.carrotsearch.randomizedtesting.generators.RandomPicks;
|
||||
import com.carrotsearch.randomizedtesting.rules.NoClassHooksShadowingRule;
|
||||
|
@ -862,6 +863,11 @@ public abstract class LuceneTestCase extends Assert {
|
|||
dumpIterator(label, iter, stream);
|
||||
}
|
||||
|
||||
/** create a new index writer config with random defaults */
|
||||
public static IndexWriterConfig newIndexWriterConfig() {
|
||||
return newIndexWriterConfig(new MockAnalyzer(random()));
|
||||
}
|
||||
|
||||
/** create a new index writer config with random defaults */
|
||||
public static IndexWriterConfig newIndexWriterConfig(Analyzer a) {
|
||||
return newIndexWriterConfig(random(), a);
|
||||
|
|
Loading…
Reference in New Issue