Search in sources :

Example 1 with ScanPrioritizer

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;
}
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

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Suppliers (com.google.common.base.Suppliers)1 Cache (com.google.common.cache.Cache)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Optional (java.util.Optional)1 OptionalInt (java.util.OptionalInt)1 Queue (java.util.Queue)1 BlockingQueue (java.util.concurrent.BlockingQueue)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1