ConcurrentMergeScheduler

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.

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 merges complete.

This class sets defaults based on Java's view of the cpu count, and it assumes a solid state disk (or similar). If you have a spinning disk and want to maximize performance, use .setDefaultMaxMergesAndThreads.

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
inner class CachedExecutor : Executor

This executor provides intra-merge threads for parallel execution of merge tasks. It provides a limited number of threads to execute merge tasks. In particular, if the number of mergeThreads is equal to maxThreadCount, then the executor will execute the merge task in the calling thread.

Link copied to clipboard
object Companion
Link copied to clipboard

Runs a merge thread to execute a single merge, then exits.

Properties

Link copied to clipboard

true if we should rate-limit writes for each merge

Link copied to clipboard
Link copied to clipboard

See .setMaxMergesAndThreads.

Link copied to clipboard

Returns maxThreadCount.

Functions

Link copied to clipboard

Used for testing

Link copied to clipboard
open override fun close()

Close this MergeScheduler.

Link copied to clipboard

Turn off auto IO throttling.

Link copied to clipboard

Turn on dynamic IO throttling, to adaptively rate limit writes bytes/sec to the minimal rate necessary so merges do not fall behind. By default this is disabled and writes are not rate-limited.

Link copied to clipboard

Get the per-merge IO throttle rate for forced merges.

Link copied to clipboard

Provides an executor for parallelism during a single merge operation. By default, the method returns a SameThreadExecutorService where all intra-merge actions occur in their calling thread.

Link copied to clipboard
open override fun initialize(infoStream: InfoStream, directory: Directory)

IndexWriter calls this on init.

Link copied to clipboard
open suspend override fun merge(mergeSource: MergeScheduler.MergeSource, trigger: MergeTrigger)

Run the merges provided by MergeSource.getNextMerge.

Link copied to clipboard

Returns the number of merge threads that are alive, ignoring the calling thread if it is a merge thread. Note that this number is .mergeThreads size.

Link copied to clipboard
fun message(message: String)

Outputs the given message - this method assumes .verbose was called and returned true.

Link copied to clipboard
fun removeMergeThread(currentJob: Job?)

Removes the calling thread from the active merge threads.

Link copied to clipboard
Link copied to clipboard

Sets max merges and threads to proper defaults for rotational or non-rotational storage.

Link copied to clipboard

Set the per-merge IO throttle rate for forced merges (default: Double.POSITIVE_INFINITY).

Link copied to clipboard
fun setMaxMergesAndThreads(maxMergeCount: Int, maxThreadCount: Int)

Expert: directly set the maximum number of merge threads and simultaneous merges allowed.

Link copied to clipboard

Used for testing

Link copied to clipboard
suspend fun sync()

Wait for any running merge threads to finish. This call is not interruptible as used by .close.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard

Returns true if infoStream messages are enabled. This method is usually used in conjunction with .message:

Link copied to clipboard
open override fun wrapForMerge(merge: MergePolicy.OneMerge, in: Directory): Directory

Wraps the incoming Directory so that we can merge-throttle it using [ ].