Class ConcurrentMergeScheduler

  • All Implemented Interfaces:
    Closeable, AutoCloseable, Cloneable

    public class ConcurrentMergeScheduler
    extends MergeScheduler
    A 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.

    • Constructor Detail

      • ConcurrentMergeScheduler

        public ConcurrentMergeScheduler()
        Sole constructor, with all settings set to default values.
    • Method Detail

      • setMaxMergesAndThreads

        public void setMaxMergesAndThreads​(int maxMergeCount,
                                           int maxThreadCount)
        Sets the maximum number of merge threads and simultaneous merges allowed.
        Parameters:
        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
      • 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 with message(String), like that:
         if (verbose()) {
           message("your message");
         }
         
      • message

        protected void message​(String message)
        Outputs the given message - this method assumes verbose() was called and returned true.
      • sync

        public void sync()
        Wait for any running merge threads to finish. This call is not interruptible as used by close().
      • mergeThreadCount

        protected int mergeThreadCount()
        Returns the number of merge threads that are alive. Note that this number is ≤ mergeThreads size.
      • handleMergeException

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