org.apache.lucene.index
Class ConcurrentMergeScheduler

java.lang.Object
  extended by org.apache.lucene.index.MergeScheduler
      extended by org.apache.lucene.index.ConcurrentMergeScheduler

public class ConcurrentMergeScheduler
extends MergeScheduler

A MergeScheduler that runs each merge using a separate thread, up until a maximum number of threads (setMaxThreadCount(int)) at which when a merge is needed, the thread(s) that are updating the index will pause until one or more merges completes. This is a simple way to use concurrency in the indexing process without having to create and manage application level threads.


Nested Class Summary
protected  class ConcurrentMergeScheduler.MergeThread
           
 
Field Summary
protected  Directory dir
           
protected  int mergeThreadCount
           
protected  List<ConcurrentMergeScheduler.MergeThread> mergeThreads
           
protected  IndexWriter writer
           
 
Constructor Summary
ConcurrentMergeScheduler()
           
 
Method Summary
static boolean anyUnhandledExceptions()
          Used for testing
static void clearUnhandledExceptions()
           
 void close()
          Close this MergeScheduler.
protected  void doMerge(MergePolicy.OneMerge merge)
          Does the actual merge, by calling IndexWriter.merge(org.apache.lucene.index.MergePolicy.OneMerge)
 int getMaxThreadCount()
          Get the max # simultaneous threads that may be running.
protected  ConcurrentMergeScheduler.MergeThread getMergeThread(IndexWriter writer, MergePolicy.OneMerge merge)
          Create and return a new MergeThread
 int getMergeThreadPriority()
          Return the priority that merge threads run at.
protected  void handleMergeException(Throwable exc)
          Called when an exception is hit in a background merge thread
 void merge(IndexWriter writer)
          Run the merges provided by IndexWriter.getNextMerge().
 void setMaxThreadCount(int count)
          Sets the max # simultaneous threads that may be running.
 void setMergeThreadPriority(int pri)
          Set the priority that merge threads run at.
static void setTestMode()
           
 void sync()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mergeThreads

protected List<ConcurrentMergeScheduler.MergeThread> mergeThreads

dir

protected Directory dir

writer

protected IndexWriter writer

mergeThreadCount

protected int mergeThreadCount
Constructor Detail

ConcurrentMergeScheduler

public ConcurrentMergeScheduler()
Method Detail

setMaxThreadCount

public void setMaxThreadCount(int count)
Sets the max # simultaneous threads that may be running. If a merge is necessary yet we already have this many threads running, the incoming thread (that is calling add/updateDocument) will block until a merge thread has completed.


getMaxThreadCount

public int getMaxThreadCount()
Get the max # simultaneous threads that may be running. @see #setMaxThreadCount.


getMergeThreadPriority

public int getMergeThreadPriority()
Return the priority that merge threads run at. By default the priority is 1 plus the priority of (ie, slightly higher priority than) the first thread that calls merge.


setMergeThreadPriority

public void setMergeThreadPriority(int pri)
Set the priority that merge threads run at.


close

public void close()
Description copied from class: MergeScheduler
Close this MergeScheduler.


sync

public void sync()

merge

public void merge(IndexWriter writer)
           throws CorruptIndexException,
                  IOException
Description copied from class: MergeScheduler
Run the merges provided by IndexWriter.getNextMerge().

Throws:
CorruptIndexException
IOException

doMerge

protected void doMerge(MergePolicy.OneMerge merge)
                throws IOException
Does the actual merge, by calling IndexWriter.merge(org.apache.lucene.index.MergePolicy.OneMerge)

Throws:
IOException

getMergeThread

protected ConcurrentMergeScheduler.MergeThread getMergeThread(IndexWriter writer,
                                                              MergePolicy.OneMerge merge)
                                                       throws IOException
Create and return a new MergeThread

Throws:
IOException

handleMergeException

protected void handleMergeException(Throwable exc)
Called when an exception is hit in a background merge thread


anyUnhandledExceptions

public static boolean anyUnhandledExceptions()
Used for testing


clearUnhandledExceptions

public static void clearUnhandledExceptions()

setTestMode

public static void setTestMode()


Copyright © 2000-2010 Apache Software Foundation. All Rights Reserved.