Search in sources :

Example 1 with ScanInfo

use of org.apache.accumulo.core.spi.scan.ScanInfo in project accumulo by apache.

the class TabletServerResourceManager method executeReadAhead.

public void executeReadAhead(KeyExtent tablet, ScanDispatcher dispatcher, ScanSession scanInfo, Runnable task) {
    task = ScanSession.wrap(scanInfo, task);
    if (tablet.isRootTablet()) {
        // TODO make meta dispatch??
        scanInfo.scanParams.setScanDispatch(ScanDispatch.builder().build());
        task.run();
    } else if (tablet.isMeta()) {
        // TODO make meta dispatch??
        scanInfo.scanParams.setScanDispatch(ScanDispatch.builder().build());
        scanExecutors.get("meta").execute(task);
    } else {
        DispatchParameters params = new DispatchParamsImpl() {

            // in scan critical path so only create ServiceEnv if needed
            private final Supplier<ServiceEnvironment> senvSupplier = Suppliers.memoize(() -> new ServiceEnvironmentImpl(context));

            @Override
            public ScanInfo getScanInfo() {
                return scanInfo;
            }

            @Override
            public Map<String, ScanExecutor> getScanExecutors() {
                return scanExecutorChoices;
            }

            @Override
            public ServiceEnvironment getServiceEnv() {
                return senvSupplier.get();
            }
        };
        ScanDispatch prefs = dispatcher.dispatch(params);
        scanInfo.scanParams.setScanDispatch(prefs);
        ThreadPoolExecutor executor = scanExecutors.get(prefs.getExecutorName());
        if (executor == null) {
            log.warn("For table id {}, {} dispatched to non-existent executor {} Using default executor.", tablet.tableId(), dispatcher.getClass().getName(), prefs.getExecutorName());
            executor = scanExecutors.get(SimpleScanDispatcher.DEFAULT_SCAN_EXECUTOR_NAME);
        } else if ("meta".equals(prefs.getExecutorName())) {
            log.warn("For table id {}, {} dispatched to meta executor. Using default executor.", tablet.tableId(), dispatcher.getClass().getName());
            executor = scanExecutors.get(SimpleScanDispatcher.DEFAULT_SCAN_EXECUTOR_NAME);
        }
        executor.execute(task);
    }
}
Also used : ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) ServiceEnvironmentImpl(org.apache.accumulo.server.ServiceEnvironmentImpl) DispatchParameters(org.apache.accumulo.core.spi.scan.ScanDispatcher.DispatchParameters) ScanInfo(org.apache.accumulo.core.spi.scan.ScanInfo) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Collectors.toUnmodifiableMap(java.util.stream.Collectors.toUnmodifiableMap) ScanDispatch(org.apache.accumulo.core.spi.scan.ScanDispatch)

Example 2 with ScanInfo

use of org.apache.accumulo.core.spi.scan.ScanInfo 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)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 Collectors.toUnmodifiableMap (java.util.stream.Collectors.toUnmodifiableMap)2 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 List (java.util.List)1 Entry (java.util.Map.Entry)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Optional (java.util.Optional)1 OptionalInt (java.util.OptionalInt)1