LUCENE-3023: moved IWC.DEFAULT_MAX_THREAD_STATES into DocumentsWriterPerThreadPool

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/realtime_search@1097534 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Simon Willnauer 2011-04-28 16:22:14 +00:00
parent 870f7e005e
commit 47baa4ba94
4 changed files with 26 additions and 32 deletions

View File

@ -41,6 +41,11 @@ import org.apache.lucene.util.SetOnce;
* </p> * </p>
*/ */
public abstract class DocumentsWriterPerThreadPool { public abstract class DocumentsWriterPerThreadPool {
/** The maximum number of simultaneous threads that may be
* indexing documents at once in IndexWriter; if more
* than this many threads arrive they will wait for
* others to finish. */
public final static int DEFAULT_MAX_THREAD_STATES = 8;
/** /**
* {@link ThreadState} references and guards a * {@link ThreadState} references and guards a
@ -128,8 +133,16 @@ public abstract class DocumentsWriterPerThreadPool {
private FieldNumberBiMap globalFieldMap; private FieldNumberBiMap globalFieldMap;
private final SetOnce<DocumentsWriter> documentsWriter = new SetOnce<DocumentsWriter>(); private final SetOnce<DocumentsWriter> documentsWriter = new SetOnce<DocumentsWriter>();
/**
* Creates a new {@link DocumentsWriterPerThreadPool} with max.
* {@link #DEFAULT_MAX_THREAD_STATES} thread states.
*/
public DocumentsWriterPerThreadPool() {
this(DEFAULT_MAX_THREAD_STATES);
}
public DocumentsWriterPerThreadPool(int maxNumPerThreads) { public DocumentsWriterPerThreadPool(int maxNumPerThreads) {
maxNumPerThreads = (maxNumPerThreads < 1) ? IndexWriterConfig.DEFAULT_MAX_THREAD_STATES : maxNumPerThreads; maxNumPerThreads = (maxNumPerThreads < 1) ? DEFAULT_MAX_THREAD_STATES : maxNumPerThreads;
perThreads = new ThreadState[maxNumPerThreads]; perThreads = new ThreadState[maxNumPerThreads];
numThreadStatesActive = 0; numThreadStatesActive = 0;
} }

View File

@ -82,12 +82,6 @@ public final class IndexWriterConfig implements Cloneable {
*/ */
public static long WRITE_LOCK_TIMEOUT = 1000; public static long WRITE_LOCK_TIMEOUT = 1000;
/** The maximum number of simultaneous threads that may be
* indexing documents at once in IndexWriter; if more
* than this many threads arrive they will wait for
* others to finish. */
public final static int DEFAULT_MAX_THREAD_STATES = 8;
/** Default setting for {@link #setReaderPooling}. */ /** Default setting for {@link #setReaderPooling}. */
public final static boolean DEFAULT_READER_POOLING = false; public final static boolean DEFAULT_READER_POOLING = false;
@ -162,7 +156,7 @@ public final class IndexWriterConfig implements Cloneable {
codecProvider = CodecProvider.getDefault(); codecProvider = CodecProvider.getDefault();
mergePolicy = new TieredMergePolicy(); mergePolicy = new TieredMergePolicy();
readerPooling = DEFAULT_READER_POOLING; readerPooling = DEFAULT_READER_POOLING;
indexerThreadPool = new ThreadAffinityDocumentsWriterThreadPool(DEFAULT_MAX_THREAD_STATES); indexerThreadPool = new ThreadAffinityDocumentsWriterThreadPool();
readerTermsIndexDivisor = DEFAULT_READER_TERMS_INDEX_DIVISOR; readerTermsIndexDivisor = DEFAULT_READER_TERMS_INDEX_DIVISOR;
perThreadHardLimitMB = DEFAULT_RAM_PER_THREAD_HARD_LIMIT_MB; perThreadHardLimitMB = DEFAULT_RAM_PER_THREAD_HARD_LIMIT_MB;
} }
@ -544,8 +538,8 @@ public final class IndexWriterConfig implements Cloneable {
* IndexWriter to assign thread-states to incoming indexing threads. If no * IndexWriter to assign thread-states to incoming indexing threads. If no
* {@link DocumentsWriterPerThreadPool} is set {@link IndexWriter} will use * {@link DocumentsWriterPerThreadPool} is set {@link IndexWriter} will use
* {@link ThreadAffinityDocumentsWriterThreadPool} with max number of * {@link ThreadAffinityDocumentsWriterThreadPool} with max number of
* thread-states set to {@value #DEFAULT_MAX_THREAD_STATES} (see * thread-states set to {@value DocumentsWriterPerThreadPool#DEFAULT_MAX_THREAD_STATES} (see
* {@link #DEFAULT_MAX_THREAD_STATES}). * {@link DocumentsWriterPerThreadPool#DEFAULT_MAX_THREAD_STATES}).
* </p> * </p>
* <p> * <p>
* NOTE: The given {@link DocumentsWriterPerThreadPool} instance must not be used with * NOTE: The given {@link DocumentsWriterPerThreadPool} instance must not be used with
@ -569,18 +563,6 @@ public final class IndexWriterConfig implements Cloneable {
return this.indexerThreadPool; return this.indexerThreadPool;
} }
/** Returns the max number of simultaneous threads that may be indexing
* documents at once in IndexWriter.
* <p>
* To modify the max number of thread-states a new
* {@link DocumentsWriterPerThreadPool} must be set via
* {@link #setIndexerThreadPool(DocumentsWriterPerThreadPool)}.
* </p>
* @see #setIndexerThreadPool(DocumentsWriterPerThreadPool) */
public int getMaxThreadStates() {
return indexerThreadPool.getMaxThreadStates();
}
/** By default, IndexWriter does not pool the /** By default, IndexWriter does not pool the
* SegmentReaders it must open for deletions and * SegmentReaders it must open for deletions and
* merging, unless a near-real-time reader has been * merging, unless a near-real-time reader has been
@ -705,7 +687,6 @@ public final class IndexWriterConfig implements Cloneable {
sb.append("codecProvider=").append(codecProvider).append("\n"); sb.append("codecProvider=").append(codecProvider).append("\n");
sb.append("mergePolicy=").append(mergePolicy).append("\n"); sb.append("mergePolicy=").append(mergePolicy).append("\n");
sb.append("indexerThreadPool=").append(indexerThreadPool).append("\n"); sb.append("indexerThreadPool=").append(indexerThreadPool).append("\n");
sb.append("maxThreadStates=").append(indexerThreadPool.getMaxThreadStates()).append("\n");
sb.append("readerPooling=").append(readerPooling).append("\n"); sb.append("readerPooling=").append(readerPooling).append("\n");
sb.append("readerTermsIndexDivisor=").append(readerTermsIndexDivisor).append("\n"); sb.append("readerTermsIndexDivisor=").append(readerTermsIndexDivisor).append("\n");
sb.append("flushPolicy=").append(flushPolicy).append("\n"); sb.append("flushPolicy=").append(flushPolicy).append("\n");

View File

@ -33,6 +33,14 @@ import org.apache.lucene.document.Document;
public class ThreadAffinityDocumentsWriterThreadPool extends DocumentsWriterPerThreadPool { public class ThreadAffinityDocumentsWriterThreadPool extends DocumentsWriterPerThreadPool {
private Map<Thread, ThreadState> threadBindings = new ConcurrentHashMap<Thread, ThreadState>(); private Map<Thread, ThreadState> threadBindings = new ConcurrentHashMap<Thread, ThreadState>();
/**
* Creates a new {@link DocumentsWriterPerThreadPool} with max.
* {@link #DEFAULT_MAX_THREAD_STATES} thread states.
*/
public ThreadAffinityDocumentsWriterThreadPool() {
this(DEFAULT_MAX_THREAD_STATES);
}
public ThreadAffinityDocumentsWriterThreadPool(int maxNumPerThreads) { public ThreadAffinityDocumentsWriterThreadPool(int maxNumPerThreads) {
super(maxNumPerThreads); super(maxNumPerThreads);
assert getMaxThreadStates() >= 1; assert getMaxThreadStates() >= 1;

View File

@ -66,7 +66,6 @@ public class TestIndexWriterConfig extends LuceneTestCase {
assertEquals(IndexWriterConfig.DEFAULT_READER_POOLING, conf.getReaderPooling()); assertEquals(IndexWriterConfig.DEFAULT_READER_POOLING, conf.getReaderPooling());
assertTrue(DocumentsWriterPerThread.defaultIndexingChain == conf.getIndexingChain()); assertTrue(DocumentsWriterPerThread.defaultIndexingChain == conf.getIndexingChain());
assertNull(conf.getMergedSegmentWarmer()); assertNull(conf.getMergedSegmentWarmer());
assertEquals(IndexWriterConfig.DEFAULT_MAX_THREAD_STATES, conf.getMaxThreadStates());
assertEquals(IndexWriterConfig.DEFAULT_READER_TERMS_INDEX_DIVISOR, conf.getReaderTermsIndexDivisor()); assertEquals(IndexWriterConfig.DEFAULT_READER_TERMS_INDEX_DIVISOR, conf.getReaderTermsIndexDivisor());
assertEquals(TieredMergePolicy.class, conf.getMergePolicy().getClass()); assertEquals(TieredMergePolicy.class, conf.getMergePolicy().getClass());
assertEquals(ThreadAffinityDocumentsWriterThreadPool.class, conf.getIndexerThreadPool().getClass()); assertEquals(ThreadAffinityDocumentsWriterThreadPool.class, conf.getIndexerThreadPool().getClass());
@ -132,7 +131,6 @@ public class TestIndexWriterConfig extends LuceneTestCase {
assertEquals(IndexWriterConfig.DISABLE_AUTO_FLUSH, IndexWriterConfig.DEFAULT_MAX_BUFFERED_DOCS); assertEquals(IndexWriterConfig.DISABLE_AUTO_FLUSH, IndexWriterConfig.DEFAULT_MAX_BUFFERED_DOCS);
assertEquals(16.0, IndexWriterConfig.DEFAULT_RAM_BUFFER_SIZE_MB, 0.0); assertEquals(16.0, IndexWriterConfig.DEFAULT_RAM_BUFFER_SIZE_MB, 0.0);
assertEquals(false, IndexWriterConfig.DEFAULT_READER_POOLING); assertEquals(false, IndexWriterConfig.DEFAULT_READER_POOLING);
assertEquals(8, IndexWriterConfig.DEFAULT_MAX_THREAD_STATES);
assertEquals(IndexReader.DEFAULT_TERMS_INDEX_DIVISOR, IndexWriterConfig.DEFAULT_READER_TERMS_INDEX_DIVISOR); assertEquals(IndexReader.DEFAULT_TERMS_INDEX_DIVISOR, IndexWriterConfig.DEFAULT_READER_TERMS_INDEX_DIVISOR);
} }
@ -262,12 +260,6 @@ public class TestIndexWriterConfig extends LuceneTestCase {
// this is expected // this is expected
} }
assertEquals(IndexWriterConfig.DEFAULT_MAX_THREAD_STATES, conf.getMaxThreadStates());
conf.setIndexerThreadPool(new ThreadAffinityDocumentsWriterThreadPool(5));
assertEquals(5, conf.getMaxThreadStates());
conf.setIndexerThreadPool(new ThreadAffinityDocumentsWriterThreadPool(0));
assertEquals(IndexWriterConfig.DEFAULT_MAX_THREAD_STATES, conf.getMaxThreadStates());
// Test MergePolicy // Test MergePolicy
assertEquals(TieredMergePolicy.class, conf.getMergePolicy().getClass()); assertEquals(TieredMergePolicy.class, conf.getMergePolicy().getClass());
conf.setMergePolicy(new LogDocMergePolicy()); conf.setMergePolicy(new LogDocMergePolicy());