use of org.apache.accumulo.core.spi.scan.ScanPrioritizer in project accumulo by apache.
the class TabletServerResourceManager method createPriorityExecutor.
private ThreadPoolExecutor createPriorityExecutor(ScanExecutorConfig sec, Map<String, Queue<Runnable>> scanExecQueues) {
BlockingQueue<Runnable> queue;
if (sec.prioritizerClass.orElse("").isEmpty()) {
queue = new LinkedBlockingQueue<>();
} else {
ScanPrioritizer factory = null;
try {
factory = ConfigurationTypeHelper.getClassInstance(null, sec.prioritizerClass.get(), ScanPrioritizer.class);
} catch (Exception e) {
throw new RuntimeException(e);
}
if (factory == null) {
queue = new LinkedBlockingQueue<>();
} else {
Comparator<ScanInfo> comparator = factory.createComparator(new ScanPrioritizer.CreateParameters() {
private final ServiceEnvironment senv = new ServiceEnvironmentImpl(context);
@Override
public Map<String, String> getOptions() {
return sec.prioritizerOpts;
}
@Override
public ServiceEnvironment getServiceEnv() {
return senv;
}
});
// function to extract scan session from runnable
Function<Runnable, ScanInfo> extractor = r -> ((ScanSession.ScanMeasurer) TraceUtil.unwrap(r)).getScanInfo();
queue = new PriorityBlockingQueue<>(sec.maxThreads, Comparator.comparing(extractor, comparator));
}
}
scanExecQueues.put(sec.name, queue);
ThreadPoolExecutor es = ThreadPools.createThreadPool(sec.getCurrentMaxThreads(), sec.getCurrentMaxThreads(), 0L, TimeUnit.MILLISECONDS, "scan-" + sec.name, queue, sec.priority, true);
modifyThreadPoolSizesAtRuntime(sec::getCurrentMaxThreads, "scan-" + sec.name, es);
return es;
}
Aggregations