Search in sources :

Example 6 with ServiceEnvironmentImpl

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();
}
Also used : PluginEnvironment(org.apache.accumulo.core.client.PluginEnvironment) TableId(org.apache.accumulo.core.data.TableId) ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) CompactionConfigurer(org.apache.accumulo.core.client.admin.compaction.CompactionConfigurer) ServiceEnvironmentImpl(org.apache.accumulo.server.ServiceEnvironmentImpl) Collection(java.util.Collection) SummaryCollection(org.apache.accumulo.core.summary.SummaryCollection) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap)

Example 7 with ServiceEnvironmentImpl

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);
}
Also used : ServiceEnvironmentImpl(org.apache.accumulo.server.ServiceEnvironmentImpl) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CompactionPlannerInitParams(org.apache.accumulo.core.util.compaction.CompactionPlannerInitParams) CompactionExecutorId(org.apache.accumulo.core.spi.compaction.CompactionExecutorId)

Example 8 with ServiceEnvironmentImpl

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;
}
Also used : BlockCacheManager(org.apache.accumulo.core.spi.cache.BlockCacheManager) LoggerFactory(org.slf4j.LoggerFactory) ScanInfo(org.apache.accumulo.core.spi.scan.ScanInfo) PriorityBlockingQueue(java.util.concurrent.PriorityBlockingQueue) BlockCache(org.apache.accumulo.core.spi.cache.BlockCache) ConfigurationTypeHelper(org.apache.accumulo.core.conf.ConfigurationTypeHelper) Map(java.util.Map) ScanCacheProvider(org.apache.accumulo.core.file.blockfile.impl.ScanCacheProvider) NativeMapLoader(org.apache.accumulo.tserver.memory.NativeMapLoader) Property(org.apache.accumulo.core.conf.Property) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BlockingQueue(java.util.concurrent.BlockingQueue) ScanExecutor(org.apache.accumulo.core.spi.scan.ScanExecutor) ThreadPools(org.apache.accumulo.core.util.threads.ThreadPools) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) SimpleScanDispatcher(org.apache.accumulo.core.spi.scan.SimpleScanDispatcher) List(java.util.List) ScanDispatcher(org.apache.accumulo.core.spi.scan.ScanDispatcher) Entry(java.util.Map.Entry) ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) ScanPrioritizer(org.apache.accumulo.core.spi.scan.ScanPrioritizer) Optional(java.util.Optional) UtilWaitThread.sleepUninterruptibly(org.apache.accumulo.fate.util.UtilWaitThread.sleepUninterruptibly) Queue(java.util.Queue) CacheBuilder(com.google.common.cache.CacheBuilder) TraceUtil(org.apache.accumulo.core.trace.TraceUtil) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) BlockCacheConfiguration(org.apache.accumulo.core.file.blockfile.cache.impl.BlockCacheConfiguration) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LargestFirstMemoryManager(org.apache.accumulo.tserver.memory.LargestFirstMemoryManager) HashMap(java.util.HashMap) ScanExecutorConfig(org.apache.accumulo.core.conf.AccumuloConfiguration.ScanExecutorConfig) FileManager(org.apache.accumulo.server.fs.FileManager) CacheType(org.apache.accumulo.core.spi.cache.CacheType) Threads(org.apache.accumulo.core.util.threads.Threads) OptionalInt(java.util.OptionalInt) Function(java.util.function.Function) Supplier(java.util.function.Supplier) BlockCacheManagerFactory(org.apache.accumulo.core.file.blockfile.cache.impl.BlockCacheManagerFactory) ArrayList(java.util.ArrayList) Collectors.toUnmodifiableMap(java.util.stream.Collectors.toUnmodifiableMap) Objects.requireNonNull(java.util.Objects.requireNonNull) ServiceEnvironmentImpl(org.apache.accumulo.server.ServiceEnvironmentImpl) Suppliers(com.google.common.base.Suppliers) ExecutorService(java.util.concurrent.ExecutorService) IntSupplier(java.util.function.IntSupplier) Logger(org.slf4j.Logger) ScanFileManager(org.apache.accumulo.server.fs.FileManager.ScanFileManager) ScanDispatch(org.apache.accumulo.core.spi.scan.ScanDispatch) ServerContext(org.apache.accumulo.server.ServerContext) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) IOException(java.io.IOException) ScanSession(org.apache.accumulo.tserver.session.ScanSession) DispatchParameters(org.apache.accumulo.core.spi.scan.ScanDispatcher.DispatchParameters) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) TabletMemoryReport(org.apache.accumulo.tserver.memory.TabletMemoryReport) Tablet(org.apache.accumulo.tserver.tablet.Tablet) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) Cache(com.google.common.cache.Cache) Collections(java.util.Collections) ServiceEnvironmentImpl(org.apache.accumulo.server.ServiceEnvironmentImpl) ScanInfo(org.apache.accumulo.core.spi.scan.ScanInfo) IOException(java.io.IOException) ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ScanPrioritizer(org.apache.accumulo.core.spi.scan.ScanPrioritizer) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Collectors.toUnmodifiableMap(java.util.stream.Collectors.toUnmodifiableMap)

Aggregations

HashMap (java.util.HashMap)8 ServiceEnvironmentImpl (org.apache.accumulo.server.ServiceEnvironmentImpl)8 Map (java.util.Map)7 ServiceEnvironment (org.apache.accumulo.core.spi.common.ServiceEnvironment)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 Collection (java.util.Collection)3 SortedMap (java.util.SortedMap)3 TableId (org.apache.accumulo.core.data.TableId)3 Cache (com.google.common.cache.Cache)2 CacheBuilder (com.google.common.cache.CacheBuilder)2 IOException (java.io.IOException)2 Collections (java.util.Collections)2 EnumMap (java.util.EnumMap)2 Optional (java.util.Optional)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 Collectors.toUnmodifiableMap (java.util.stream.Collectors.toUnmodifiableMap)2 PluginEnvironment (org.apache.accumulo.core.client.PluginEnvironment)2 CompactionConfigurer (org.apache.accumulo.core.client.admin.compaction.CompactionConfigurer)2 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)2 ScanDispatcher (org.apache.accumulo.core.spi.scan.ScanDispatcher)2