Skip to content

Commit

Permalink
Fix HttpShardHandlerFactory to use an unbounded queue if the pool siz…
Browse files Browse the repository at this point in the history
…e is limited, to avoid rejected tasks in wide distributed searches
  • Loading branch information
timatbw committed Jan 25, 2018
1 parent f1d6f54 commit ad5ae96
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -194,9 +195,7 @@ public void init(PluginInfo info) {
r.setSeed(Long.parseLong(v));
}

BlockingQueue<Runnable> blockingQueue = (this.queueSize == -1) ?
new SynchronousQueue<Runnable>(this.accessPolicy) :
new ArrayBlockingQueue<Runnable>(this.queueSize, this.accessPolicy);
BlockingQueue<Runnable> blockingQueue = getBlockingQueue();

this.commExecutor = new ExecutorUtil.MDCAwareThreadPoolExecutor(
this.corePoolSize,
Expand Down Expand Up @@ -226,6 +225,21 @@ public void init(PluginInfo info) {
this.loadbalancer = createLoadbalancer(defaultClient);
}

private BlockingQueue<Runnable> getBlockingQueue() {
if (this.queueSize == -1) {
if (this.maximumPoolSize == Integer.MAX_VALUE) {
return new SynchronousQueue<Runnable>(this.accessPolicy);
} else {
// A limited maximumPoolSize would result in new tasks being rejected
// once the pool is full, with SynchronousQueue, so it's better to accept
// as many as we're offered and let the pool work through them
return new LinkedBlockingQueue<>();
}
} else {
return new ArrayBlockingQueue<Runnable>(this.queueSize, this.accessPolicy);
}
}

protected ModifiableSolrParams getClientParams() {
ModifiableSolrParams clientParams = new ModifiableSolrParams();
clientParams.set(HttpClientUtil.PROP_SO_TIMEOUT, soTimeout);
Expand Down

0 comments on commit ad5ae96

Please sign in to comment.