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);
}
}
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());
}
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;
}
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;
}
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;
}
}
Aggregations