public class ConcurrentMergeScheduler extends MergeScheduler
MergeScheduler
that 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.
Modifier and Type | Class and Description |
---|---|
protected class |
ConcurrentMergeScheduler.MergeThread |
Modifier and Type | Field and Description |
---|---|
protected static Comparator<ConcurrentMergeScheduler.MergeThread> |
compareByMergeDocCount |
protected Directory |
dir |
protected int |
mergeThreadCount |
protected List<ConcurrentMergeScheduler.MergeThread> |
mergeThreads |
protected IndexWriter |
writer |
Constructor and Description |
---|
ConcurrentMergeScheduler() |
Modifier and Type | Method and Description |
---|---|
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 |
getMaxMergeCount()
|
int |
getMaxThreadCount() |
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() . |
protected int |
mergeThreadCount()
Returns the number of merge threads that are alive.
|
protected void |
message(String message)
Outputs the given message - this method assumes
verbose() was
called and returned true. |
void |
setMaxMergeCount(int count)
Sets the max # simultaneous merges that are allowed.
|
void |
setMaxThreadCount(int count)
Sets the max # simultaneous merge threads that should
be running at once.
|
void |
setMergeThreadPriority(int pri)
Set the base priority that merge threads run at.
|
static void |
setTestMode()
Deprecated.
this test mode code will be removed in a future release
|
void |
sync()
Wait for any running merge threads to finish
|
protected void |
updateMergeThreads()
Called whenever the running merges have changed, to pause & unpause
threads.
|
protected boolean |
verbose()
Returns true if verbosing is enabled.
|
protected List<ConcurrentMergeScheduler.MergeThread> mergeThreads
protected Directory dir
protected IndexWriter writer
protected int mergeThreadCount
protected static final Comparator<ConcurrentMergeScheduler.MergeThread> compareByMergeDocCount
public void setMaxThreadCount(int count)
setMaxMergeCount(int)
.public int getMaxThreadCount()
setMaxThreadCount(int)
public void setMaxMergeCount(int count)
setMaxThreadCount(int)
merges at a time.public int getMaxMergeCount()
public int getMergeThreadPriority()
public void setMergeThreadPriority(int pri)
protected void updateMergeThreads()
protected boolean verbose()
message(String)
, like that:
if (verbose()) { message("your message"); }
protected void message(String message)
verbose()
was
called and returned true.public void close()
MergeScheduler
close
in class MergeScheduler
public void sync()
protected int mergeThreadCount()
mergeThreads
size.public void merge(IndexWriter writer) throws IOException
MergeScheduler
IndexWriter.getNextMerge()
.merge
in class MergeScheduler
IOException
protected void doMerge(MergePolicy.OneMerge merge) throws IOException
IndexWriter.merge(org.apache.lucene.index.MergePolicy.OneMerge)
IOException
protected ConcurrentMergeScheduler.MergeThread getMergeThread(IndexWriter writer, MergePolicy.OneMerge merge) throws IOException
IOException
protected void handleMergeException(Throwable exc)
public static boolean anyUnhandledExceptions()
public static void clearUnhandledExceptions()
@Deprecated public static void setTestMode()