use of org.apache.drill.shaded.guava.com.google.common.base.Stopwatch in project drill by apache.
the class BasicServer method close.
@Override
public void close() throws IOException {
try {
Stopwatch watch = Stopwatch.createStarted();
// this takes 1s to complete
// known issue: https://github.com/netty/netty/issues/2545
eventLoopGroup.shutdownGracefully(0, 0, TimeUnit.SECONDS).get();
long elapsed = watch.elapsed(MILLISECONDS);
if (elapsed > 500) {
logger.info("closed eventLoopGroup " + eventLoopGroup + " in " + elapsed + " ms");
}
if (isSslEnabled()) {
closeSSL();
}
} catch (final InterruptedException | ExecutionException e) {
logger.warn("Failure while shutting down {}. ", this.getClass().getName(), e);
// Preserve evidence that the interruption occurred so that code higher up on the call stack can learn of the
// interruption and respond to it if it wants to.
Thread.currentThread().interrupt();
}
}
use of org.apache.drill.shaded.guava.com.google.common.base.Stopwatch in project drill by apache.
the class FileSelection method minusDirectories.
public FileSelection minusDirectories(DrillFileSystem fs) throws IOException {
if (isExpandedFully()) {
return this;
}
Stopwatch timer = logger.isDebugEnabled() ? Stopwatch.createStarted() : null;
List<FileStatus> statuses = getStatuses(fs);
List<FileStatus> nonDirectories = Lists.newArrayList();
for (FileStatus status : statuses) {
nonDirectories.addAll(DrillFileSystemUtil.listFiles(fs, status.getPath(), true));
}
FileSelection fileSel = create(nonDirectories, null, selectionRoot);
if (timer != null) {
logger.debug("FileSelection.minusDirectories() took {} ms, numFiles: {}", timer.elapsed(TimeUnit.MILLISECONDS), statuses.size());
timer.stop();
}
// fileSel will be null if we query an empty folder
if (fileSel != null) {
fileSel.setExpandedFully();
}
return fileSel;
}
use of org.apache.drill.shaded.guava.com.google.common.base.Stopwatch in project drill by apache.
the class ScanResult method getImplementations.
/**
* Loads all the scanned classes for this parent as a side effect
* @param c the parent
* @return all the classes found
*/
public <T> Set<Class<? extends T>> getImplementations(Class<T> c) {
ParentClassDescriptor p = getImplementations(c.getName());
Stopwatch watch = Stopwatch.createStarted();
Set<Class<? extends T>> result = new HashSet<>();
try {
if (p != null) {
for (ChildClassDescriptor child : p.getChildren()) {
if (!child.isAbstract()) {
try {
result.add(Class.forName(child.getName()).asSubclass(c));
} catch (ClassNotFoundException e) {
throw new DrillRuntimeException("scanned class could not be found: " + child.getName(), e);
}
}
}
}
return result;
} finally {
logger.info(format("loading %d classes for %s took %dms", result.size(), c.getName(), watch.elapsed(MILLISECONDS)));
}
}
use of org.apache.drill.shaded.guava.com.google.common.base.Stopwatch in project drill by apache.
the class MongoRecordReader method next.
@Override
public int next() {
if (cursor == null) {
logger.debug("Filters Applied : " + filters);
logger.debug("Fields Selected :" + fields);
MongoIterable<BsonDocument> projection;
if (CollectionUtils.isNotEmpty(operations)) {
List<Bson> operations = new ArrayList<>(this.operations);
if (!fields.isEmpty()) {
operations.add(Aggregates.project(fields));
}
if (plugin.getConfig().allowDiskUse()) {
projection = collection.aggregate(operations).allowDiskUse(true);
} else {
projection = collection.aggregate(operations);
}
} else {
projection = collection.find(filters).projection(fields);
}
cursor = projection.batchSize(plugin.getConfig().getBatchSize()).iterator();
}
writer.allocate();
writer.reset();
int docCount = 0;
Stopwatch watch = Stopwatch.createStarted();
try {
while (docCount < BaseValueVector.INITIAL_VALUE_ALLOCATION && cursor.hasNext()) {
writer.setPosition(docCount);
if (isBsonRecordReader) {
BsonDocument bsonDocument = cursor.next();
bsonReader.write(writer, new BsonDocumentReader(bsonDocument));
} else {
String doc = cursor.next().toJson();
jsonReader.setSource(doc.getBytes(Charsets.UTF_8));
jsonReader.write(writer);
}
docCount++;
}
if (isBsonRecordReader) {
bsonReader.ensureAtLeastOneField(writer);
} else {
jsonReader.ensureAtLeastOneField(writer);
}
writer.setValueCount(docCount);
logger.debug("Took {} ms to get {} records", watch.elapsed(TimeUnit.MILLISECONDS), docCount);
return docCount;
} catch (IOException e) {
String msg = "Failure while reading document. - Parser was at record: " + (docCount + 1);
logger.error(msg, e);
throw new DrillRuntimeException(msg, e);
}
}
use of org.apache.drill.shaded.guava.com.google.common.base.Stopwatch in project drill by apache.
the class DbScanSortRemovalRule method doOnMatch.
private void doOnMatch(IndexPhysicalPlanCallContext indexContext) {
Stopwatch indexPlanTimer = Stopwatch.createStarted();
final PlannerSettings settings = PrelUtil.getPlannerSettings(indexContext.call.getPlanner());
DbGroupScan groupScan = (DbGroupScan) indexContext.scan.getGroupScan();
boolean isIndexScan = groupScan.isIndexScan();
if (!isIndexScan) {
// This case generates the index scan and removes the sort if possible.
final IndexCollection indexCollection = groupScan.getSecondaryIndexCollection(indexContext.scan);
if (indexCollection == null) {
return;
}
if (settings.isStatisticsEnabled()) {
groupScan.getStatistics().initialize(null, indexContext.scan, indexContext);
}
IndexPlanUtils.updateSortExpression(indexContext, indexContext.getSort() != null ? indexContext.getCollation().getFieldCollations() : null);
IndexSelector selector = new IndexSelector(indexContext);
for (IndexDescriptor indexDesc : indexCollection) {
indexDesc.getIndexGroupScan().setStatistics(groupScan.getStatistics());
FunctionalIndexInfo functionInfo = indexDesc.getFunctionalInfo();
if (IndexPlanUtils.isCoveringIndex(indexContext, functionInfo)) {
selector.addIndex(indexDesc, true, indexContext.lowerProject != null ? indexContext.lowerProject.getRowType().getFieldCount() : indexContext.scan.getRowType().getFieldCount());
}
}
IndexProperties idxProp = selector.getBestIndexNoFilter();
if (idxProp != null) {
try {
// generate a covering plan
CoveringPlanNoFilterGenerator planGen = new CoveringPlanNoFilterGenerator(indexContext, idxProp.getIndexDesc().getFunctionalInfo(), false, settings);
if (planGen.convertChild() != null) {
indexContext.getCall().transformTo(planGen.convertChild());
} else {
logger.debug("Not able to generate index plan in {}", this.getClass().toString());
}
} catch (Exception e) {
logger.warn("Exception while trying to generate indexscan to remove sort", e);
}
}
} else {
Preconditions.checkNotNull(indexContext.getSort());
// This case tries to use the already generated index to see if a sort can be removed.
if (indexContext.scan.getTraitSet().getTrait(RelCollationTraitDef.INSTANCE).getFieldCollations().size() == 0) {
return;
}
try {
RelNode finalRel = indexContext.scan.copy(indexContext.scan.getTraitSet(), indexContext.scan.getInputs());
if (indexContext.lowerProject != null) {
List<RelNode> inputs = Lists.newArrayList();
inputs.add(finalRel);
finalRel = indexContext.lowerProject.copy(indexContext.lowerProject.getTraitSet(), inputs);
}
finalRel = AbstractIndexPlanGenerator.getSortNode(indexContext, finalRel, true, false, indexContext.exch != null);
if (finalRel == null) {
logger.debug("Not able to generate index plan in {}", this.getClass().toString());
return;
}
finalRel = Prule.convert(finalRel, finalRel.getTraitSet().plus(Prel.DRILL_PHYSICAL));
indexContext.getCall().transformTo(finalRel);
} catch (Exception e) {
logger.warn("Exception while trying to use the indexscan to remove the sort", e);
}
}
indexPlanTimer.stop();
logger.debug("Index Planning took {} ms", indexPlanTimer.elapsed(TimeUnit.MILLISECONDS));
}
Aggregations