Search in sources :

Example 21 with PlanFragment

use of org.apache.drill.exec.proto.BitControl.PlanFragment in project drill by axbaretto.

the class FragmentsRunner method sendRemoteFragments.

/**
 * Send all the remote fragments belonging to a single target drillbit in one request.
 *
 * @param assignment the drillbit assigned to these fragments
 * @param fragments the set of fragments
 * @param latch the countdown latch used to track the requests to all endpoints
 * @param fragmentSubmitFailures the submission failure counter used to track the requests to all endpoints
 */
private void sendRemoteFragments(final DrillbitEndpoint assignment, final Collection<PlanFragment> fragments, final CountDownLatch latch, final FragmentSubmitFailures fragmentSubmitFailures) {
    @SuppressWarnings("resource") final Controller controller = drillbitContext.getController();
    final InitializeFragments.Builder fb = InitializeFragments.newBuilder();
    for (final PlanFragment planFragment : fragments) {
        fb.addFragment(planFragment);
    }
    final InitializeFragments initFrags = fb.build();
    logger.debug("Sending remote fragments to node: {}\nData: {}", assignment, initFrags);
    final FragmentSubmitListener listener = new FragmentSubmitListener(assignment, initFrags, latch, fragmentSubmitFailures);
    controller.getTunnel(assignment).sendFragments(listener, initFrags);
}
Also used : InitializeFragments(org.apache.drill.exec.proto.BitControl.InitializeFragments) Controller(org.apache.drill.exec.rpc.control.Controller) PlanFragment(org.apache.drill.exec.proto.BitControl.PlanFragment)

Example 22 with PlanFragment

use of org.apache.drill.exec.proto.BitControl.PlanFragment in project drill by axbaretto.

the class QueryWorkUnit method stringifyFragments.

/**
 * Converts list of stored fragments into their string representation,
 * in case of exception returns text indicating that string was malformed.
 * Is used for debugging purposes.
 *
 * @return fragments information
 */
public String stringifyFragments() {
    StringBuilder stringBuilder = new StringBuilder();
    final int fragmentCount = fragments.size();
    int fragmentIndex = 0;
    for (final PlanFragment planFragment : fragments) {
        final ExecProtos.FragmentHandle fragmentHandle = planFragment.getHandle();
        stringBuilder.append("PlanFragment(");
        stringBuilder.append(++fragmentIndex);
        stringBuilder.append('/');
        stringBuilder.append(fragmentCount);
        stringBuilder.append(") major_fragment_id ");
        stringBuilder.append(fragmentHandle.getMajorFragmentId());
        stringBuilder.append(" minor_fragment_id ");
        stringBuilder.append(fragmentHandle.getMinorFragmentId());
        stringBuilder.append('\n');
        final CoordinationProtos.DrillbitEndpoint endpointAssignment = planFragment.getAssignment();
        stringBuilder.append("  DrillbitEndpoint address ");
        stringBuilder.append(endpointAssignment.getAddress());
        stringBuilder.append('\n');
        String jsonString = "<<malformed JSON>>";
        stringBuilder.append("  fragment_json: ");
        final ObjectMapper objectMapper = new ObjectMapper();
        try {
            final Object json = objectMapper.readValue(planFragment.getFragmentJson(), Object.class);
            jsonString = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(json);
        } catch (final Exception e) {
        // we've already set jsonString to a fallback value
        }
        stringBuilder.append(jsonString);
    }
    return stringBuilder.toString();
}
Also used : ExecProtos(org.apache.drill.exec.proto.ExecProtos) CoordinationProtos(org.apache.drill.exec.proto.CoordinationProtos) PlanFragment(org.apache.drill.exec.proto.BitControl.PlanFragment) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) ForemanSetupException(org.apache.drill.exec.work.foreman.ForemanSetupException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 23 with PlanFragment

use of org.apache.drill.exec.proto.BitControl.PlanFragment in project drill by axbaretto.

the class TestPartitionSender method testThreadsHelper.

/**
 * Core of the testing
 * @param hashToRandomExchange
 * @param drillbitContext
 * @param options
 * @param incoming
 * @param registry
 * @param planReader
 * @param planningSet
 * @param rootFragment
 * @param expectedThreadsCount
 * @throws Exception
 */
private void testThreadsHelper(HashToRandomExchange hashToRandomExchange, DrillbitContext drillbitContext, OptionList options, RecordBatch incoming, FunctionImplementationRegistry registry, PhysicalPlanReader planReader, PlanningSet planningSet, Fragment rootFragment, int expectedThreadsCount) throws Exception {
    final QueryContextInformation queryContextInfo = Utilities.createQueryContextInfo("dummySchemaName", "938ea2d9-7cb9-4baf-9414-a5a0b7777e8e");
    final QueryWorkUnit qwu = PARALLELIZER.getFragments(options, drillbitContext.getEndpoint(), QueryId.getDefaultInstance(), drillbitContext.getBits(), rootFragment, USER_SESSION, queryContextInfo);
    qwu.applyPlan(planReader);
    final List<MinorFragmentEndpoint> mfEndPoints = PhysicalOperatorUtil.getIndexOrderedEndpoints(Lists.newArrayList(drillbitContext.getBits()));
    for (PlanFragment planFragment : qwu.getFragments()) {
        if (!planFragment.getFragmentJson().contains("hash-partition-sender")) {
            continue;
        }
        MockPartitionSenderRootExec partionSenderRootExec = null;
        FragmentContextImpl context = null;
        try {
            context = new FragmentContextImpl(drillbitContext, planFragment, null, registry);
            final int majorFragmentId = planFragment.getHandle().getMajorFragmentId();
            final HashPartitionSender partSender = new HashPartitionSender(majorFragmentId, hashToRandomExchange, hashToRandomExchange.getExpression(), mfEndPoints);
            partionSenderRootExec = new MockPartitionSenderRootExec(context, incoming, partSender);
            assertEquals("Number of threads calculated", expectedThreadsCount, partionSenderRootExec.getNumberPartitions());
            partionSenderRootExec.createPartitioner();
            final PartitionerDecorator partDecor = partionSenderRootExec.getPartitioner();
            assertNotNull(partDecor);
            List<Partitioner> partitioners = partDecor.getPartitioners();
            assertNotNull(partitioners);
            final int actualThreads = DRILLBITS_COUNT > expectedThreadsCount ? expectedThreadsCount : DRILLBITS_COUNT;
            assertEquals("Number of partitioners", actualThreads, partitioners.size());
            for (int i = 0; i < mfEndPoints.size(); i++) {
                assertNotNull("PartitionOutgoingBatch", partDecor.getOutgoingBatches(i));
            }
            // check distribution of PartitionOutgoingBatch - should be even distribution
            boolean isFirst = true;
            int prevBatchCountSize = 0;
            int batchCountSize = 0;
            for (Partitioner part : partitioners) {
                final List<PartitionOutgoingBatch> outBatch = (List<PartitionOutgoingBatch>) part.getOutgoingBatches();
                batchCountSize = outBatch.size();
                if (!isFirst) {
                    assertTrue(Math.abs(batchCountSize - prevBatchCountSize) <= 1);
                } else {
                    isFirst = false;
                }
                prevBatchCountSize = batchCountSize;
            }
            partionSenderRootExec.getStats().startProcessing();
            try {
                partDecor.partitionBatch(incoming);
            } finally {
                partionSenderRootExec.getStats().stopProcessing();
            }
            if (actualThreads == 1) {
                assertEquals("With single thread parent and child waitNanos should match", partitioners.get(0).getStats().getWaitNanos(), partionSenderRootExec.getStats().getWaitNanos());
            }
            // testing values distribution
            partitioners = partDecor.getPartitioners();
            isFirst = true;
            // since we have fake Nullvector distribution is skewed
            for (Partitioner part : partitioners) {
                final List<PartitionOutgoingBatch> outBatches = (List<PartitionOutgoingBatch>) part.getOutgoingBatches();
                for (PartitionOutgoingBatch partOutBatch : outBatches) {
                    final int recordCount = ((VectorAccessible) partOutBatch).getRecordCount();
                    if (isFirst) {
                        assertEquals("RecordCount", 100, recordCount);
                        isFirst = false;
                    } else {
                        assertEquals("RecordCount", 0, recordCount);
                    }
                }
            }
            // test exceptions within threads
            // test stats merging
            partionSenderRootExec.getStats().startProcessing();
            try {
                partDecor.executeMethodLogic(new InjectExceptionTest());
                fail("Should throw IOException here");
            } catch (IOException ioe) {
                final OperatorProfile.Builder oPBuilder = OperatorProfile.newBuilder();
                partionSenderRootExec.getStats().addAllMetrics(oPBuilder);
                final List<MetricValue> metrics = oPBuilder.getMetricList();
                for (MetricValue metric : metrics) {
                    if (Metric.BYTES_SENT.metricId() == metric.getMetricId()) {
                        assertEquals("Should add metricValue irrespective of exception", 5 * actualThreads, metric.getLongValue());
                    }
                    if (Metric.SENDING_THREADS_COUNT.metricId() == metric.getMetricId()) {
                        assertEquals(actualThreads, metric.getLongValue());
                    }
                }
                assertEquals(actualThreads - 1, ioe.getSuppressed().length);
            } finally {
                partionSenderRootExec.getStats().stopProcessing();
            }
        } finally {
            // cleanup
            partionSenderRootExec.close();
            context.close();
        }
    }
}
Also used : HashPartitionSender(org.apache.drill.exec.physical.config.HashPartitionSender) VectorAccessible(org.apache.drill.exec.record.VectorAccessible) QueryWorkUnit(org.apache.drill.exec.work.QueryWorkUnit) FragmentContextImpl(org.apache.drill.exec.ops.FragmentContextImpl) IOException(java.io.IOException) PlanFragment(org.apache.drill.exec.proto.BitControl.PlanFragment) MinorFragmentEndpoint(org.apache.drill.exec.physical.MinorFragmentEndpoint) MinorFragmentEndpoint(org.apache.drill.exec.physical.MinorFragmentEndpoint) MetricValue(org.apache.drill.exec.proto.UserBitShared.MetricValue) List(java.util.List) OptionList(org.apache.drill.exec.server.options.OptionList) QueryContextInformation(org.apache.drill.exec.proto.BitControl.QueryContextInformation)

Example 24 with PlanFragment

use of org.apache.drill.exec.proto.BitControl.PlanFragment in project drill by axbaretto.

the class DrillClient method runQuery.

/**
 * Run query based on list of fragments that were supposedly produced during query planning phase. Supported
 * query type is {@link QueryType#EXECUTION}
 * @param type
 * @param planFragments
 * @param resultsListener
 * @throws RpcException
 */
public void runQuery(QueryType type, List<PlanFragment> planFragments, UserResultsListener resultsListener) throws RpcException {
    // QueryType can be only executional
    checkArgument((QueryType.EXECUTION == type), "Only EXECUTION type query is supported with PlanFragments");
    // setting Plan on RunQuery will be used for logging purposes and therefore can not be null
    // since there is no Plan string provided we will create a JsonArray out of individual fragment Plans
    ArrayNode jsonArray = objectMapper.createArrayNode();
    for (PlanFragment fragment : planFragments) {
        try {
            jsonArray.add(objectMapper.readTree(fragment.getFragmentJson()));
        } catch (IOException e) {
            logger.error("Exception while trying to read PlanFragment JSON for %s", fragment.getHandle().getQueryId(), e);
            throw new RpcException(e);
        }
    }
    final String fragmentsToJsonString;
    try {
        fragmentsToJsonString = objectMapper.writeValueAsString(jsonArray);
    } catch (JsonProcessingException e) {
        logger.error("Exception while trying to get JSONString from Array of individual Fragments Json for %s", e);
        throw new RpcException(e);
    }
    final UserProtos.RunQuery query = newBuilder().setType(type).addAllFragments(planFragments).setPlan(fragmentsToJsonString).setResultsMode(STREAM_FULL).build();
    client.submitQuery(resultsListener, query);
}
Also used : RunQuery(org.apache.drill.exec.proto.UserProtos.RunQuery) RpcException(org.apache.drill.exec.rpc.RpcException) NonTransientRpcException(org.apache.drill.exec.rpc.NonTransientRpcException) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) UserProtos(org.apache.drill.exec.proto.UserProtos) PlanFragment(org.apache.drill.exec.proto.BitControl.PlanFragment)

Example 25 with PlanFragment

use of org.apache.drill.exec.proto.BitControl.PlanFragment in project drill by axbaretto.

the class SimpleParallelizer method generateWorkUnit.

protected QueryWorkUnit generateWorkUnit(OptionList options, DrillbitEndpoint foremanNode, QueryId queryId, Fragment rootNode, PlanningSet planningSet, UserSession session, QueryContextInformation queryContextInfo) throws ExecutionSetupException {
    List<MinorFragmentDefn> fragmentDefns = new ArrayList<>();
    MinorFragmentDefn rootFragmentDefn = null;
    FragmentRoot rootOperator = null;
    // assigned before we can materialize, so we start a new loop here rather than utilizing the previous one.
    for (Wrapper wrapper : planningSet) {
        Fragment node = wrapper.getNode();
        final PhysicalOperator physicalOperatorRoot = node.getRoot();
        boolean isRootNode = rootNode == node;
        if (isRootNode && wrapper.getWidth() != 1) {
            throw new ForemanSetupException(String.format("Failure while trying to setup fragment. " + "The root fragment must always have parallelization one. In the current case, the width was set to %d.", wrapper.getWidth()));
        }
        // a fragment is self driven if it doesn't rely on any other exchanges.
        boolean isLeafFragment = node.getReceivingExchangePairs().size() == 0;
        // Create a minorFragment for each major fragment.
        for (int minorFragmentId = 0; minorFragmentId < wrapper.getWidth(); minorFragmentId++) {
            IndexedFragmentNode iNode = new IndexedFragmentNode(minorFragmentId, wrapper);
            wrapper.resetAllocation();
            PhysicalOperator op = physicalOperatorRoot.accept(Materializer.INSTANCE, iNode);
            Preconditions.checkArgument(op instanceof FragmentRoot);
            FragmentRoot root = (FragmentRoot) op;
            FragmentHandle handle = // 
            FragmentHandle.newBuilder().setMajorFragmentId(// 
            wrapper.getMajorFragmentId()).setMinorFragmentId(// 
            minorFragmentId).setQueryId(// 
            queryId).build();
            PlanFragment fragment = // 
            PlanFragment.newBuilder().setForeman(// 
            foremanNode).setHandle(// 
            handle).setAssignment(// 
            wrapper.getAssignedEndpoint(minorFragmentId)).setLeafFragment(// 
            isLeafFragment).setContext(queryContextInfo).setMemInitial(// 
            wrapper.getInitialAllocation()).setMemMax(wrapper.getMaxAllocation()).setCredentials(session.getCredentials()).addAllCollector(CountRequiredFragments.getCollectors(root)).build();
            MinorFragmentDefn fragmentDefn = new MinorFragmentDefn(fragment, root, options);
            if (isRootNode) {
                logger.debug("Root fragment:\n {}", DrillStringUtils.unescapeJava(fragment.toString()));
                rootFragmentDefn = fragmentDefn;
                rootOperator = root;
            } else {
                logger.debug("Remote fragment:\n {}", DrillStringUtils.unescapeJava(fragment.toString()));
                fragmentDefns.add(fragmentDefn);
            }
        }
    }
    return new QueryWorkUnit(rootOperator, rootFragmentDefn, fragmentDefns);
}
Also used : MinorFragmentDefn(org.apache.drill.exec.work.QueryWorkUnit.MinorFragmentDefn) QueryWorkUnit(org.apache.drill.exec.work.QueryWorkUnit) ArrayList(java.util.ArrayList) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) FragmentHandle(org.apache.drill.exec.proto.ExecProtos.FragmentHandle) PlanFragment(org.apache.drill.exec.proto.BitControl.PlanFragment) IndexedFragmentNode(org.apache.drill.exec.planner.fragment.Materializer.IndexedFragmentNode) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) MinorFragmentEndpoint(org.apache.drill.exec.physical.MinorFragmentEndpoint) PlanFragment(org.apache.drill.exec.proto.BitControl.PlanFragment) PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) ForemanSetupException(org.apache.drill.exec.work.foreman.ForemanSetupException)

Aggregations

PlanFragment (org.apache.drill.exec.proto.BitControl.PlanFragment)35 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)18 QueryWorkUnit (org.apache.drill.exec.work.QueryWorkUnit)14 PhysicalOperator (org.apache.drill.exec.physical.base.PhysicalOperator)8 Fragment (org.apache.drill.exec.planner.fragment.Fragment)8 FragmentHandle (org.apache.drill.exec.proto.ExecProtos.FragmentHandle)8 IOException (java.io.IOException)7 FragmentRoot (org.apache.drill.exec.physical.base.FragmentRoot)7 QueryPlanFragments (org.apache.drill.exec.proto.UserProtos.QueryPlanFragments)7 ForemanSetupException (org.apache.drill.exec.work.foreman.ForemanSetupException)7 PlannerTest (org.apache.drill.categories.PlannerTest)6 SlowTest (org.apache.drill.categories.SlowTest)6 ClusterTest (org.apache.drill.test.ClusterTest)6 Test (org.junit.Test)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)5 MinorFragmentEndpoint (org.apache.drill.exec.physical.MinorFragmentEndpoint)5 IndexedFragmentNode (org.apache.drill.exec.planner.fragment.Materializer.IndexedFragmentNode)5 QueryContextInformation (org.apache.drill.exec.proto.BitControl.QueryContextInformation)5 OptionList (org.apache.drill.exec.server.options.OptionList)5 SimpleParallelizer (org.apache.drill.exec.planner.fragment.SimpleParallelizer)4