Search in sources :

Example 16 with Stopwatch

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();
    }
}
Also used : Stopwatch(org.apache.drill.shaded.guava.com.google.common.base.Stopwatch) ExecutionException(java.util.concurrent.ExecutionException)

Example 17 with Stopwatch

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;
}
Also used : FileStatus(org.apache.hadoop.fs.FileStatus) Stopwatch(org.apache.drill.shaded.guava.com.google.common.base.Stopwatch)

Example 18 with Stopwatch

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)));
    }
}
Also used : Stopwatch(org.apache.drill.shaded.guava.com.google.common.base.Stopwatch) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) HashSet(java.util.HashSet)

Example 19 with Stopwatch

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);
    }
}
Also used : BsonDocument(org.bson.BsonDocument) ArrayList(java.util.ArrayList) Stopwatch(org.apache.drill.shaded.guava.com.google.common.base.Stopwatch) BsonDocumentReader(org.bson.BsonDocumentReader) IOException(java.io.IOException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) Bson(org.bson.conversions.Bson)

Example 20 with Stopwatch

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));
}
Also used : PlannerSettings(org.apache.drill.exec.planner.physical.PlannerSettings) IndexSelector(org.apache.drill.exec.planner.index.IndexSelector) Stopwatch(org.apache.drill.shaded.guava.com.google.common.base.Stopwatch) IndexDescriptor(org.apache.drill.exec.planner.index.IndexDescriptor) IndexCollection(org.apache.drill.exec.planner.index.IndexCollection) IndexProperties(org.apache.drill.exec.planner.index.IndexProperties) CoveringPlanNoFilterGenerator(org.apache.drill.exec.planner.index.generators.CoveringPlanNoFilterGenerator) RelNode(org.apache.calcite.rel.RelNode) DbGroupScan(org.apache.drill.exec.physical.base.DbGroupScan) FunctionalIndexInfo(org.apache.drill.exec.planner.index.FunctionalIndexInfo)

Aggregations

Stopwatch (org.apache.drill.shaded.guava.com.google.common.base.Stopwatch)68 IOException (java.io.IOException)13 Path (org.apache.hadoop.fs.Path)12 ArrayList (java.util.ArrayList)8 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)8 FileStatus (org.apache.hadoop.fs.FileStatus)8 DrillBuf (io.netty.buffer.DrillBuf)7 ByteBuffer (java.nio.ByteBuffer)7 SchemaPath (org.apache.drill.common.expression.SchemaPath)7 HashMap (java.util.HashMap)5 RelNode (org.apache.calcite.rel.RelNode)5 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)4 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)4 VectorContainer (org.apache.drill.exec.record.VectorContainer)4 SelectionVector4 (org.apache.drill.exec.record.selection.SelectionVector4)4 ValueVector (org.apache.drill.exec.vector.ValueVector)4 CompressionCodecName (org.apache.parquet.hadoop.metadata.CompressionCodecName)4 File (java.io.File)3 ResultSet (java.sql.ResultSet)3 ResultSetMetaData (java.sql.ResultSetMetaData)3