Search in sources :

Example 1 with ServiceEnvironmentImpl

use of org.apache.accumulo.server.ServiceEnvironmentImpl 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 ServiceEnvironmentImpl

use of org.apache.accumulo.server.ServiceEnvironmentImpl in project accumulo by apache.

the class CompactableUtils method selectFiles.

static Set<StoredTabletFile> selectFiles(Tablet tablet, SortedMap<StoredTabletFile, DataFileValue> datafiles, PluginConfig selectorConfig) {
    CompactionSelector selector = newInstance(tablet.getTableConfiguration(), selectorConfig.getClassName(), CompactionSelector.class);
    final ServiceEnvironment senv = new ServiceEnvironmentImpl(tablet.getContext());
    selector.init(new CompactionSelector.InitParameters() {

        @Override
        public Map<String, String> getOptions() {
            return selectorConfig.getOptions();
        }

        @Override
        public PluginEnvironment getEnvironment() {
            return senv;
        }

        @Override
        public TableId getTableId() {
            return tablet.getExtent().tableId();
        }
    });
    Selection selection = selector.select(new CompactionSelector.SelectionParameters() {

        @Override
        public PluginEnvironment getEnvironment() {
            return senv;
        }

        @Override
        public Collection<CompactableFile> getAvailableFiles() {
            return Collections2.transform(datafiles.entrySet(), e -> new CompactableFileImpl(e.getKey(), e.getValue()));
        }

        @Override
        public Collection<Summary> getSummaries(Collection<CompactableFile> files, Predicate<SummarizerConfiguration> summarySelector) {
            var context = tablet.getContext();
            var tsrm = tablet.getTabletResources().getTabletServerResourceManager();
            SummaryCollection sc = new SummaryCollection();
            SummarizerFactory factory = new SummarizerFactory(tablet.getTableConfiguration());
            for (CompactableFile cf : files) {
                var file = CompactableFileImpl.toStoredTabletFile(cf);
                FileSystem fs = context.getVolumeManager().getFileSystemByPath(file.getPath());
                Configuration conf = context.getHadoopConf();
                SummaryCollection fsc = SummaryReader.load(fs, conf, factory, file.getPath(), summarySelector, tsrm.getSummaryCache(), tsrm.getIndexCache(), tsrm.getFileLenCache(), context.getCryptoService()).getSummaries(Collections.singletonList(new Gatherer.RowRange(tablet.getExtent())));
                sc.merge(fsc, factory);
            }
            return sc.getSummaries();
        }

        @Override
        public TableId getTableId() {
            return tablet.getExtent().tableId();
        }

        @Override
        public Optional<SortedKeyValueIterator<Key, Value>> getSample(CompactableFile file, SamplerConfiguration sc) {
            try {
                FileOperations fileFactory = FileOperations.getInstance();
                Path path = new Path(file.getUri());
                FileSystem ns = tablet.getTabletServer().getVolumeManager().getFileSystemByPath(path);
                var fiter = fileFactory.newReaderBuilder().forFile(path.toString(), ns, ns.getConf(), tablet.getContext().getCryptoService()).withTableConfiguration(tablet.getTableConfiguration()).seekToBeginning().build();
                return Optional.ofNullable(fiter.getSample(new SamplerConfigurationImpl(sc)));
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }
    });
    return selection.getFilesToCompact().stream().map(CompactableFileImpl::toStoredTabletFile).collect(Collectors.toSet());
}
Also used : PluginEnvironment(org.apache.accumulo.core.client.PluginEnvironment) TableId(org.apache.accumulo.core.data.TableId) TableId(org.apache.accumulo.core.data.TableId) FileCompactor(org.apache.accumulo.server.compaction.FileCompactor) FileSystem(org.apache.hadoop.fs.FileSystem) LoggerFactory(org.slf4j.LoggerFactory) Collections2(com.google.common.collect.Collections2) MetadataTableUtil(org.apache.accumulo.server.util.MetadataTableUtil) Selection(org.apache.accumulo.core.client.admin.compaction.CompactionSelector.Selection) PluginConfig(org.apache.accumulo.core.client.admin.PluginConfig) CompactableFile(org.apache.accumulo.core.client.admin.compaction.CompactableFile) BlockCache(org.apache.accumulo.core.spi.cache.BlockCache) ConfigurationTypeHelper(org.apache.accumulo.core.conf.ConfigurationTypeHelper) ClassLoaderUtil(org.apache.accumulo.core.classloader.ClassLoaderUtil) FileOperations(org.apache.accumulo.core.file.FileOperations) Map(java.util.Map) Configuration(org.apache.hadoop.conf.Configuration) Path(org.apache.hadoop.fs.Path) CompactionStrategyConfigUtil(org.apache.accumulo.core.clientImpl.CompactionStrategyConfigUtil) Value(org.apache.accumulo.core.data.Value) SamplerConfiguration(org.apache.accumulo.core.client.sample.SamplerConfiguration) Property(org.apache.accumulo.core.conf.Property) CompactionEnv(org.apache.accumulo.server.compaction.FileCompactor.CompactionEnv) VolumeManager(org.apache.accumulo.server.fs.VolumeManager) Predicate(java.util.function.Predicate) Collection(java.util.Collection) MajorCompactionReason(org.apache.accumulo.tserver.compaction.MajorCompactionReason) FileSKVIterator(org.apache.accumulo.core.file.FileSKVIterator) Set(java.util.Set) SummaryReader(org.apache.accumulo.core.summary.SummaryReader) Collectors(java.util.stream.Collectors) UncheckedIOException(java.io.UncheckedIOException) CompactionStrategyConfig(org.apache.accumulo.core.client.admin.CompactionStrategyConfig) TableConfiguration(org.apache.accumulo.server.conf.TableConfiguration) CompactionSelector(org.apache.accumulo.core.client.admin.compaction.CompactionSelector) Pair(org.apache.accumulo.core.util.Pair) ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) Optional(java.util.Optional) ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) CacheBuilder(com.google.common.cache.CacheBuilder) SortedMap(java.util.SortedMap) SummarizerFactory(org.apache.accumulo.core.summary.SummarizerFactory) CompactionPlan(org.apache.accumulo.tserver.compaction.CompactionPlan) DataFileValue(org.apache.accumulo.core.metadata.schema.DataFileValue) SamplerConfigurationImpl(org.apache.accumulo.core.sample.impl.SamplerConfigurationImpl) CompactionHelper(org.apache.accumulo.tserver.tablet.CompactableImpl.CompactionHelper) SummarizerConfiguration(org.apache.accumulo.core.client.summary.SummarizerConfiguration) SummaryCollection(org.apache.accumulo.core.summary.SummaryCollection) HashMap(java.util.HashMap) CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig) SortedKeyValueIterator(org.apache.accumulo.core.iterators.SortedKeyValueIterator) PluginEnvironment(org.apache.accumulo.core.client.PluginEnvironment) HashSet(java.util.HashSet) StoredTabletFile(org.apache.accumulo.core.metadata.StoredTabletFile) Gatherer(org.apache.accumulo.core.summary.Gatherer) CompactionKind(org.apache.accumulo.core.spi.compaction.CompactionKind) Key(org.apache.accumulo.core.data.Key) ServiceEnvironmentImpl(org.apache.accumulo.server.ServiceEnvironmentImpl) TabletFile(org.apache.accumulo.core.metadata.TabletFile) CompactionStats(org.apache.accumulo.server.compaction.CompactionStats) Summary(org.apache.accumulo.core.client.summary.Summary) CompactionCanceledException(org.apache.accumulo.server.compaction.FileCompactor.CompactionCanceledException) Logger(org.slf4j.Logger) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) MajorCompactionRequest(org.apache.accumulo.tserver.compaction.MajorCompactionRequest) IOException(java.io.IOException) CompactionConfigurer(org.apache.accumulo.core.client.admin.compaction.CompactionConfigurer) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) WriteParameters(org.apache.accumulo.tserver.compaction.WriteParameters) ExecutionException(java.util.concurrent.ExecutionException) CompactionJob(org.apache.accumulo.core.spi.compaction.CompactionJob) Preconditions(com.google.common.base.Preconditions) CompactionStrategy(org.apache.accumulo.tserver.compaction.CompactionStrategy) Cache(com.google.common.cache.Cache) Collections(java.util.Collections) UserCompactionUtils(org.apache.accumulo.core.clientImpl.UserCompactionUtils) CompactableFileImpl(org.apache.accumulo.core.metadata.CompactableFileImpl) Gatherer(org.apache.accumulo.core.summary.Gatherer) Configuration(org.apache.hadoop.conf.Configuration) SamplerConfiguration(org.apache.accumulo.core.client.sample.SamplerConfiguration) TableConfiguration(org.apache.accumulo.server.conf.TableConfiguration) SummarizerConfiguration(org.apache.accumulo.core.client.summary.SummarizerConfiguration) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) Selection(org.apache.accumulo.core.client.admin.compaction.CompactionSelector.Selection) SamplerConfigurationImpl(org.apache.accumulo.core.sample.impl.SamplerConfigurationImpl) SamplerConfiguration(org.apache.accumulo.core.client.sample.SamplerConfiguration) FileOperations(org.apache.accumulo.core.file.FileOperations) SummarizerFactory(org.apache.accumulo.core.summary.SummarizerFactory) UncheckedIOException(java.io.UncheckedIOException) ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) FileSystem(org.apache.hadoop.fs.FileSystem) SummarizerConfiguration(org.apache.accumulo.core.client.summary.SummarizerConfiguration) Path(org.apache.hadoop.fs.Path) CompactableFileImpl(org.apache.accumulo.core.metadata.CompactableFileImpl) CompactableFile(org.apache.accumulo.core.client.admin.compaction.CompactableFile) Optional(java.util.Optional) ServiceEnvironmentImpl(org.apache.accumulo.server.ServiceEnvironmentImpl) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) CompactionSelector(org.apache.accumulo.core.client.admin.compaction.CompactionSelector) Value(org.apache.accumulo.core.data.Value) DataFileValue(org.apache.accumulo.core.metadata.schema.DataFileValue) Collection(java.util.Collection) SummaryCollection(org.apache.accumulo.core.summary.SummaryCollection) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) SummaryCollection(org.apache.accumulo.core.summary.SummaryCollection) Key(org.apache.accumulo.core.data.Key)

Example 3 with ServiceEnvironmentImpl

use of org.apache.accumulo.server.ServiceEnvironmentImpl in project accumulo by apache.

the class TableConfiguration method createCompactionDispatcher.

private static CompactionDispatcher createCompactionDispatcher(AccumuloConfiguration conf, ServerContext context, TableId tableId) {
    CompactionDispatcher newDispatcher = Property.createTableInstanceFromPropertyName(conf, Property.TABLE_COMPACTION_DISPATCHER, CompactionDispatcher.class, null);
    Map<String, String> opts = conf.getAllPropertiesWithPrefixStripped(Property.TABLE_COMPACTION_DISPATCHER_OPTS);
    newDispatcher.init(new CompactionDispatcher.InitParameters() {

        private final ServiceEnvironment senv = new ServiceEnvironmentImpl(context);

        @Override
        public TableId getTableId() {
            return tableId;
        }

        @Override
        public Map<String, String> getOptions() {
            return opts;
        }

        @Override
        public ServiceEnvironment getServiceEnv() {
            return senv;
        }
    });
    return newDispatcher;
}
Also used : TableId(org.apache.accumulo.core.data.TableId) CompactionDispatcher(org.apache.accumulo.core.spi.compaction.CompactionDispatcher) ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) ServiceEnvironmentImpl(org.apache.accumulo.server.ServiceEnvironmentImpl) HashMap(java.util.HashMap) Map(java.util.Map) EnumMap(java.util.EnumMap)

Example 4 with ServiceEnvironmentImpl

use of org.apache.accumulo.server.ServiceEnvironmentImpl in project accumulo by apache.

the class TableConfiguration method createScanDispatcher.

private static ScanDispatcher createScanDispatcher(AccumuloConfiguration conf, ServerContext context, TableId tableId) {
    ScanDispatcher newDispatcher = Property.createTableInstanceFromPropertyName(conf, Property.TABLE_SCAN_DISPATCHER, ScanDispatcher.class, null);
    Map<String, String> opts = conf.getAllPropertiesWithPrefixStripped(Property.TABLE_SCAN_DISPATCHER_OPTS);
    newDispatcher.init(new ScanDispatcher.InitParameters() {

        private final ServiceEnvironment senv = new ServiceEnvironmentImpl(context);

        @Override
        public TableId getTableId() {
            return tableId;
        }

        @Override
        public Map<String, String> getOptions() {
            return opts;
        }

        @Override
        public ServiceEnvironment getServiceEnv() {
            return senv;
        }
    });
    return newDispatcher;
}
Also used : ScanDispatcher(org.apache.accumulo.core.spi.scan.ScanDispatcher) TableId(org.apache.accumulo.core.data.TableId) ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) ServiceEnvironmentImpl(org.apache.accumulo.server.ServiceEnvironmentImpl) HashMap(java.util.HashMap) Map(java.util.Map) EnumMap(java.util.EnumMap)

Example 5 with ServiceEnvironmentImpl

use of org.apache.accumulo.server.ServiceEnvironmentImpl in project accumulo by apache.

the class CompactableImpl method getConfiguredService.

@Override
public CompactionServiceId getConfiguredService(CompactionKind kind) {
    Map<String, String> debugHints = null;
    try {
        var dispatcher = tablet.getTableConfiguration().getCompactionDispatcher();
        Map<String, String> tmpHints = Map.of();
        if (kind == CompactionKind.USER) {
            synchronized (this) {
                if (fileMgr.getSelectionStatus() != FileSelectionStatus.NOT_ACTIVE && fileMgr.getSelectionStatus() != FileSelectionStatus.CANCELED && fileMgr.getSelectionKind() == CompactionKind.USER) {
                    tmpHints = compactionConfig.getExecutionHints();
                }
            }
        }
        var hints = tmpHints;
        debugHints = hints;
        var dispatch = dispatcher.dispatch(new DispatchParameters() {

            private final ServiceEnvironment senv = new ServiceEnvironmentImpl(tablet.getContext());

            @Override
            public ServiceEnvironment getServiceEnv() {
                return senv;
            }

            @Override
            public Map<String, String> getExecutionHints() {
                return hints;
            }

            @Override
            public CompactionKind getCompactionKind() {
                return kind;
            }

            @Override
            public CompactionServices getCompactionServices() {
                return manager.getServices();
            }
        });
        return dispatch.getService();
    } catch (RuntimeException e) {
        log.error("Failed to dispatch compaction {} kind:{} hints:{}, falling back to {} service.", getExtent(), kind, debugHints, CompactionServicesConfig.DEFAULT_SERVICE, e);
        return CompactionServicesConfig.DEFAULT_SERVICE;
    }
}
Also used : ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) CompactionKind(org.apache.accumulo.core.spi.compaction.CompactionKind) ServiceEnvironmentImpl(org.apache.accumulo.server.ServiceEnvironmentImpl) DispatchParameters(org.apache.accumulo.core.spi.compaction.CompactionDispatcher.DispatchParameters) CompactionServices(org.apache.accumulo.core.spi.compaction.CompactionServices) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap)

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