Apache Lucene open-source search software
LUCENE-3023: moved IWC.DEFAULT_MAX_THREAD_STATES into DocumentsWriterPerThreadPool
Simon Willnauer47baa4ba944f
diff --git a/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThreadPool.java b/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThreadPool.javaindex 611f5048283..00be8166075 100644--- a/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThreadPool.java+++ b/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThreadPool.java@@ -41,6 +41,11 @@ import org.apache.lucene.util.SetOnce;* </p>*/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@@ -127,9 +132,17 @@ public abstract class DocumentsWriterPerThreadPool {private CodecProvider codecProvider;private FieldNumberBiMap globalFieldMap;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) {- maxNumPerThreads = (maxNumPerThreads < 1) ? IndexWriterConfig.DEFAULT_MAX_THREAD_STATES : maxNumPerThreads;+ maxNumPerThreads = (maxNumPerThreads < 1) ? DEFAULT_MAX_THREAD_STATES : maxNumPerThreads;perThreads = new ThreadState[maxNumPerThreads];numThreadStatesActive = 0;}diff --git a/lucene/src/java/org/apache/lucene/index/IndexWriterConfig.java b/lucene/src/java/org/apache/lucene/index/IndexWriterConfig.javaindex ef7b27caabf..72002bcd17c 100644--- a/lucene/src/java/org/apache/lucene/index/IndexWriterConfig.java+++ b/lucene/src/java/org/apache/lucene/index/IndexWriterConfig.java@@ -82,12 +82,6 @@ public final class IndexWriterConfig implements Cloneable {*/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}. */public final static boolean DEFAULT_READER_POOLING = false;@@ -162,7 +156,7 @@ public final class IndexWriterConfig implements Cloneable {codecProvider = CodecProvider.getDefault();mergePolicy = new TieredMergePolicy();readerPooling = DEFAULT_READER_POOLING;- indexerThreadPool = new ThreadAffinityDocumentsWriterThreadPool(DEFAULT_MAX_THREAD_STATES);+ indexerThreadPool = new ThreadAffinityDocumentsWriterThreadPool();readerTermsIndexDivisor = DEFAULT_READER_TERMS_INDEX_DIVISOR;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* {@link DocumentsWriterPerThreadPool} is set {@link IndexWriter} will use* {@link ThreadAffinityDocumentsWriterThreadPool} with max number of- * thread-states set to {@value #DEFAULT_MAX_THREAD_STATES} (see- * {@link #DEFAULT_MAX_THREAD_STATES}).+ * thread-states set to {@value DocumentsWriterPerThreadPool#DEFAULT_MAX_THREAD_STATES} (see+ * {@link DocumentsWriterPerThreadPool#DEFAULT_MAX_THREAD_STATES}).* </p>* <p>* NOTE: The given {@link DocumentsWriterPerThreadPool} instance must not be used with@@ -569,18 +563,6 @@ public final class IndexWriterConfig implements Cloneable {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* SegmentReaders it must open for deletions and* 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("mergePolicy=").append(mergePolicy).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("readerTermsIndexDivisor=").append(readerTermsIndexDivisor).append("\n");sb.append("flushPolicy=").append(flushPolicy).append("\n");diff --git a/lucene/src/java/org/apache/lucene/index/ThreadAffinityDocumentsWriterThreadPool.java b/lucene/src/java/org/apache/lucene/index/ThreadAffinityDocumentsWriterThreadPool.javaindex c646ec267c0..9df6b5aebf9 100644--- a/lucene/src/java/org/apache/lucene/index/ThreadAffinityDocumentsWriterThreadPool.java+++ b/lucene/src/java/org/apache/lucene/index/ThreadAffinityDocumentsWriterThreadPool.java@@ -32,7 +32,15 @@ import org.apache.lucene.document.Document;*/public class ThreadAffinityDocumentsWriterThreadPool extends DocumentsWriterPerThreadPool {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) {super(maxNumPerThreads);assert getMaxThreadStates() >= 1;diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexWriterConfig.java b/lucene/src/test/org/apache/lucene/index/TestIndexWriterConfig.javaindex 6dc45249d88..689a6ad0911 100644--- a/lucene/src/test/org/apache/lucene/index/TestIndexWriterConfig.java+++ b/lucene/src/test/org/apache/lucene/index/TestIndexWriterConfig.java@@ -66,7 +66,6 @@ public class TestIndexWriterConfig extends LuceneTestCase {assertEquals(IndexWriterConfig.DEFAULT_READER_POOLING, conf.getReaderPooling());assertTrue(DocumentsWriterPerThread.defaultIndexingChain == conf.getIndexingChain());assertNull(conf.getMergedSegmentWarmer());- assertEquals(IndexWriterConfig.DEFAULT_MAX_THREAD_STATES, conf.getMaxThreadStates());assertEquals(IndexWriterConfig.DEFAULT_READER_TERMS_INDEX_DIVISOR, conf.getReaderTermsIndexDivisor());assertEquals(TieredMergePolicy.class, conf.getMergePolicy().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(16.0, IndexWriterConfig.DEFAULT_RAM_BUFFER_SIZE_MB, 0.0);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);}@@ -262,12 +260,6 @@ public class TestIndexWriterConfig extends LuceneTestCase {// 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 MergePolicyassertEquals(TieredMergePolicy.class, conf.getMergePolicy().getClass());conf.setMergePolicy(new LogDocMergePolicy());