use of org.apache.accumulo.server.ServiceEnvironmentImpl in project accumulo by apache.
the class CompactableUtils method computeOverrides.
static Map<String, String> computeOverrides(Tablet tablet, Set<CompactableFile> files, PluginConfig cfg) {
CompactionConfigurer configurer = CompactableUtils.newInstance(tablet.getTableConfiguration(), cfg.getClassName(), CompactionConfigurer.class);
final ServiceEnvironment senv = new ServiceEnvironmentImpl(tablet.getContext());
configurer.init(new CompactionConfigurer.InitParameters() {
@Override
public Map<String, String> getOptions() {
return cfg.getOptions();
}
@Override
public PluginEnvironment getEnvironment() {
return senv;
}
@Override
public TableId getTableId() {
return tablet.getExtent().tableId();
}
});
var overrides = configurer.override(new CompactionConfigurer.InputParameters() {
@Override
public Collection<CompactableFile> getInputFiles() {
return files;
}
@Override
public PluginEnvironment getEnvironment() {
return senv;
}
@Override
public TableId getTableId() {
return tablet.getExtent().tableId();
}
});
if (overrides.getOverrides().isEmpty()) {
return null;
}
return overrides.getOverrides();
}
use of org.apache.accumulo.server.ServiceEnvironmentImpl in project accumulo by apache.
the class CompactionService method configurationChanged.
public void configurationChanged(String plannerClassName, Long maxRate, Map<String, String> plannerOptions) {
Preconditions.checkArgument(maxRate >= 0);
var old = this.rateLimit.getAndSet(maxRate);
if (old != maxRate)
log.debug("Updated compaction service id:{} rate limit:{}", myId, maxRate);
if (this.plannerClassName.equals(plannerClassName) && this.plannerOpts.equals(plannerOptions))
return;
var initParams = new CompactionPlannerInitParams(myId, plannerOptions, new ServiceEnvironmentImpl(context));
var tmpPlanner = createPlanner(plannerClassName);
tmpPlanner.init(initParams);
Map<CompactionExecutorId, CompactionExecutor> tmpExecutors = new HashMap<>();
initParams.getRequestedExecutors().forEach((ceid, numThreads) -> {
InternalCompactionExecutor executor = (InternalCompactionExecutor) executors.get(ceid);
if (executor == null) {
executor = new InternalCompactionExecutor(ceid, numThreads, ceMetrics, readLimiter, writeLimiter);
} else {
executor.setThreads(numThreads);
}
tmpExecutors.put(ceid, executor);
});
initParams.getRequestedExternalExecutors().forEach(ceid -> {
ExternalCompactionExecutor executor = (ExternalCompactionExecutor) executors.get(ceid);
if (executor == null) {
executor = externExecutorSupplier.apply(ceid);
}
tmpExecutors.put(ceid, executor);
});
Sets.difference(executors.keySet(), tmpExecutors.keySet()).forEach(ceid -> {
executors.get(ceid).stop();
});
this.plannerClassName = plannerClassName;
this.plannerOpts = plannerOptions;
this.executors = Map.copyOf(tmpExecutors);
this.planner = tmpPlanner;
log.debug("Updated compaction service id:{} planner:{} options:{}", myId, plannerClassName, plannerOptions);
}
use of org.apache.accumulo.server.ServiceEnvironmentImpl 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