Search in sources :

Example 1 with RateLimitedIndexOutput

use of org.apache.lucene.store.RateLimitedIndexOutput in project lucene-solr by apache.

the class ConcurrentMergeScheduler method wrapForMerge.

@Override
public Directory wrapForMerge(OneMerge merge, Directory in) {
    Thread mergeThread = Thread.currentThread();
    if (!MergeThread.class.isInstance(mergeThread)) {
        throw new AssertionError("wrapForMerge should be called from MergeThread. Current thread: " + mergeThread);
    }
    // Return a wrapped Directory which has rate-limited output.
    RateLimiter rateLimiter = ((MergeThread) mergeThread).rateLimiter;
    return new FilterDirectory(in) {

        @Override
        public IndexOutput createOutput(String name, IOContext context) throws IOException {
            ensureOpen();
            // somewhere that is failing to pass down the right IOContext:
            assert context.context == IOContext.Context.MERGE : "got context=" + context.context;
            // always be called from that context. Verify this.
            assert mergeThread == Thread.currentThread() : "Not the same merge thread, current=" + Thread.currentThread() + ", expected=" + mergeThread;
            return new RateLimitedIndexOutput(rateLimiter, in.createOutput(name, context));
        }
    };
}
Also used : RateLimitedIndexOutput(org.apache.lucene.store.RateLimitedIndexOutput) FilterDirectory(org.apache.lucene.store.FilterDirectory) IOContext(org.apache.lucene.store.IOContext) RateLimiter(org.apache.lucene.store.RateLimiter)

Aggregations

FilterDirectory (org.apache.lucene.store.FilterDirectory)1 IOContext (org.apache.lucene.store.IOContext)1 RateLimitedIndexOutput (org.apache.lucene.store.RateLimitedIndexOutput)1 RateLimiter (org.apache.lucene.store.RateLimiter)1