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, and the maximum number of simultaneous merges
with setMaxMergesAndThreads(int, 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
Runs a merge thread, which may run one or more merges
in sequence.
|
Modifier and Type | Field and Description |
---|---|
protected static Comparator<ConcurrentMergeScheduler.MergeThread> |
compareByMergeDocCount
Sorts
ConcurrentMergeScheduler.MergeThread s; larger merges come first. |
static int |
DEFAULT_MAX_MERGE_COUNT
Default
maxMergeCount . |
static int |
DEFAULT_MAX_THREAD_COUNT
Default
maxThreadCount . |
protected Directory |
dir
Directory that holds the index. |
protected int |
mergeThreadCount
How many
ConcurrentMergeScheduler.MergeThread s have kicked off (this is use
to name them). |
protected List<ConcurrentMergeScheduler.MergeThread> |
mergeThreads
List of currently active
ConcurrentMergeScheduler.MergeThread s. |
protected IndexWriter |
writer
IndexWriter that owns this instance. |
Constructor and Description |
---|
ConcurrentMergeScheduler()
Sole constructor, with all settings set to default
values.
|
Modifier and Type | Method and Description |
---|---|
MergeScheduler |
clone() |
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()
Returns
maxThreadCount . |
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 |
setMaxMergesAndThreads(int maxMergeCount,
int maxThreadCount)
Sets the maximum number of merge threads and simultaneous merges allowed.
|
void |
setMergeThreadPriority(int pri)
Set the base priority that merge threads run at.
|
void |
sync()
Wait for any running merge threads to finish.
|
String |
toString() |
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
ConcurrentMergeScheduler.MergeThread
s.public static final int DEFAULT_MAX_THREAD_COUNT
maxThreadCount
.
We default to 1: tests on spinning-magnet drives showed slower
indexing performance if more than one merge thread runs at
once (though on an SSD it was faster)public static final int DEFAULT_MAX_MERGE_COUNT
maxMergeCount
.protected IndexWriter writer
IndexWriter
that owns this instance.protected int mergeThreadCount
ConcurrentMergeScheduler.MergeThread
s have kicked off (this is use
to name them).protected static final Comparator<ConcurrentMergeScheduler.MergeThread> compareByMergeDocCount
ConcurrentMergeScheduler.MergeThread
s; larger merges come first.public ConcurrentMergeScheduler()
public void setMaxMergesAndThreads(int maxMergeCount, int maxThreadCount)
maxMergeCount
- 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
smallest maxThreadCount
merges at a time.maxThreadCount
- the max # simultaneous merge threads that should
be running at once. This must be <= maxMergeCount
public int getMaxThreadCount()
maxThreadCount
.setMaxMergesAndThreads(int, int)
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 interface Closeable
close
in class MergeScheduler
public void sync()
close()
.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 MergeScheduler clone()
clone
in class MergeScheduler
Copyright © 2000-2014 Apache Software Foundation. All Rights Reserved.