use of org.apache.accumulo.core.client.admin.compaction.CompactionSelector.Selection 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());
}
Aggregations