Package org.apache.lucene.index
Class ConcurrentMergeScheduler
- java.lang.Object
-
- org.apache.lucene.index.MergeScheduler
-
- org.apache.lucene.index.ConcurrentMergeScheduler
-
public class ConcurrentMergeScheduler extends MergeScheduler
AMergeSchedulerthat runs each merge using a separate thread.Specify the max number of threads that may run at once with
setMaxThreadCount(int).Separately specify the maximum number of simultaneous merges with
setMaxMergeCount(int). If the number of merges exceeds the max number of threads then the largest merges are paused until one of the smaller merges completes.If more than
getMaxMergeCount()merges are requested then this class will forcefully throttle the incoming threads by pausing until one more more merges complete.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classConcurrentMergeScheduler.MergeThread
-
Field Summary
Fields Modifier and Type Field Description protected static Comparator<ConcurrentMergeScheduler.MergeThread>compareByMergeDocCountprotected Directorydirprotected intmergeThreadCountprotected List<ConcurrentMergeScheduler.MergeThread>mergeThreadsprotected IndexWriterwriter
-
Constructor Summary
Constructors Constructor Description ConcurrentMergeScheduler()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static booleananyUnhandledExceptions()Used for testingstatic voidclearUnhandledExceptions()voidclose()Close this MergeScheduler.protected voiddoMerge(MergePolicy.OneMerge merge)Does the actual merge, by callingIndexWriter.merge(org.apache.lucene.index.MergePolicy.OneMerge)intgetMaxMergeCount()intgetMaxThreadCount()protected ConcurrentMergeScheduler.MergeThreadgetMergeThread(IndexWriter writer, MergePolicy.OneMerge merge)Create and return a new MergeThreadintgetMergeThreadPriority()Return the priority that merge threads run at.protected voidhandleMergeException(Throwable exc)Called when an exception is hit in a background merge threadvoidmerge(IndexWriter writer)Run the merges provided byIndexWriter.getNextMerge().protected intmergeThreadCount()Returns the number of merge threads that are alive.protected voidmessage(String message)Outputs the given message - this method assumesverbose()was called and returned true.voidsetMaxMergeCount(int count)Sets the max # simultaneous merges that are allowed.voidsetMaxThreadCount(int count)Sets the max # simultaneous merge threads that should be running at once.voidsetMergeThreadPriority(int pri)Set the base priority that merge threads run at.static voidsetTestMode()Deprecated.this test mode code will be removed in a future releasevoidsync()Wait for any running merge threads to finishprotected voidupdateMergeThreads()Called whenever the running merges have changed, to pause & unpause threads.protected booleanverbose()Returns true if verbosing is enabled.
-
-
-
Field Detail
-
mergeThreads
protected List<ConcurrentMergeScheduler.MergeThread> mergeThreads
-
dir
protected Directory dir
-
writer
protected IndexWriter writer
-
mergeThreadCount
protected int mergeThreadCount
-
compareByMergeDocCount
protected static final Comparator<ConcurrentMergeScheduler.MergeThread> compareByMergeDocCount
-
-
Method Detail
-
setMaxThreadCount
public void setMaxThreadCount(int count)
Sets the max # simultaneous merge threads that should be running at once. This must be <=setMaxMergeCount(int).
-
getMaxThreadCount
public int getMaxThreadCount()
- See Also:
setMaxThreadCount(int)
-
setMaxMergeCount
public void setMaxMergeCount(int count)
Sets the max # simultaneous merges that are allowed. 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. Note that we will only run the smallestsetMaxThreadCount(int)merges at a time.
-
getMaxMergeCount
public int getMaxMergeCount()
-
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 base priority that merge threads run at. Note that CMS may increase priority of some merge threads beyond this base priority. It's best not to set this any higher than Thread.MAX_PRIORITY-maxThreadCount, so that CMS has room to set relative priority among threads.
-
updateMergeThreads
protected void updateMergeThreads()
Called whenever the running merges have changed, to pause & unpause threads. This method sorts the merge threads by their merge size in descending order and then pauses/unpauses threads from first to last -- that way, smaller merges are guaranteed to run before larger ones.
-
verbose
protected boolean verbose()
Returns true if verbosing is enabled. This method is usually used in conjunction withmessage(String), like that:if (verbose()) { message("your message"); }
-
message
protected void message(String message)
Outputs the given message - this method assumesverbose()was called and returned true.
-
close
public void close()
Description copied from class:MergeSchedulerClose this MergeScheduler.- Specified by:
closein classMergeScheduler
-
sync
public void sync()
Wait for any running merge threads to finish
-
mergeThreadCount
protected int mergeThreadCount()
Returns the number of merge threads that are alive. Note that this number is ≤mergeThreadssize.
-
merge
public void merge(IndexWriter writer) throws IOException
Description copied from class:MergeSchedulerRun the merges provided byIndexWriter.getNextMerge().- Specified by:
mergein classMergeScheduler- Throws:
IOException
-
doMerge
protected void doMerge(MergePolicy.OneMerge merge) throws IOException
Does the actual merge, by callingIndexWriter.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
@Deprecated public static void setTestMode()
Deprecated.this test mode code will be removed in a future release
-
-