Search in sources :

Example 11 with MinorFragmentEndpoint

use of org.apache.drill.exec.physical.MinorFragmentEndpoint in project drill by apache.

the class AbstractDeMuxExchange method createSenderReceiverMapping.

protected void createSenderReceiverMapping() {
    if (isSenderReceiverMappingCreated) {
        return;
    }
    senderToReceiversMapping = ArrayListMultimap.create();
    receiverToSenderMapping = Maps.newHashMap();
    // Find the list of receiver fragment ids assigned to each Drillbit endpoint
    ArrayListMultimap<DrillbitEndpoint, Integer> endpointReceiverList = ArrayListMultimap.create();
    int receiverFragmentId = 0;
    for (DrillbitEndpoint receiverLocation : receiverLocations) {
        endpointReceiverList.put(receiverLocation, receiverFragmentId);
        receiverFragmentId++;
    }
    int senderFragmentId = 0;
    for (DrillbitEndpoint senderLocation : senderLocations) {
        final List<Integer> receiverMinorFragmentIds = endpointReceiverList.get(senderLocation);
        for (Integer receiverId : receiverMinorFragmentIds) {
            receiverToSenderMapping.put(receiverId, new MinorFragmentEndpoint(senderFragmentId, senderLocation));
            senderToReceiversMapping.put(senderFragmentId, new MinorFragmentEndpoint(receiverId, receiverLocations.get(receiverId)));
        }
        senderFragmentId++;
    }
    isSenderReceiverMappingCreated = true;
}
Also used : MinorFragmentEndpoint(org.apache.drill.exec.physical.MinorFragmentEndpoint) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) MinorFragmentEndpoint(org.apache.drill.exec.physical.MinorFragmentEndpoint)

Example 12 with MinorFragmentEndpoint

use of org.apache.drill.exec.physical.MinorFragmentEndpoint in project drill by apache.

the class AbstractMuxExchange method createSenderReceiverMapping.

protected void createSenderReceiverMapping() {
    if (isSenderReceiverMappingCreated) {
        return;
    }
    senderToReceiverMapping = Maps.newHashMap();
    receiverToSenderMapping = ArrayListMultimap.create();
    // Find the list of sender fragment ids assigned to each Drillbit endpoint.
    ArrayListMultimap<DrillbitEndpoint, Integer> endpointSenderList = ArrayListMultimap.create();
    int senderFragmentId = 0;
    for (DrillbitEndpoint senderLocation : senderLocations) {
        endpointSenderList.put(senderLocation, senderFragmentId);
        senderFragmentId++;
    }
    int receiverFragmentId = 0;
    for (DrillbitEndpoint receiverLocation : receiverLocations) {
        List<Integer> senderFragmentIds = endpointSenderList.get(receiverLocation);
        for (Integer senderId : senderFragmentIds) {
            senderToReceiverMapping.put(senderId, new MinorFragmentEndpoint(receiverFragmentId, receiverLocation));
            receiverToSenderMapping.put(receiverFragmentId, new MinorFragmentEndpoint(senderId, senderLocations.get(senderId)));
        }
        receiverFragmentId++;
    }
    isSenderReceiverMappingCreated = true;
}
Also used : MinorFragmentEndpoint(org.apache.drill.exec.physical.MinorFragmentEndpoint) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) MinorFragmentEndpoint(org.apache.drill.exec.physical.MinorFragmentEndpoint)

Example 13 with MinorFragmentEndpoint

use of org.apache.drill.exec.physical.MinorFragmentEndpoint 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 14 with MinorFragmentEndpoint

use of org.apache.drill.exec.physical.MinorFragmentEndpoint in project drill by axbaretto.

the class UnorderedDeMuxExchange method getReceiver.

@Override
public Receiver getReceiver(int minorFragmentId) {
    createSenderReceiverMapping();
    MinorFragmentEndpoint sender = receiverToSenderMapping.get(minorFragmentId);
    if (sender == null) {
        throw new IllegalStateException(String.format("Failed to find sender for receiver [%d]", minorFragmentId));
    }
    return new UnorderedReceiver(this.senderMajorFragmentId, Collections.singletonList(sender), false);
}
Also used : MinorFragmentEndpoint(org.apache.drill.exec.physical.MinorFragmentEndpoint)

Example 15 with MinorFragmentEndpoint

use of org.apache.drill.exec.physical.MinorFragmentEndpoint in project drill by axbaretto.

the class PhysicalOperatorUtil method getIndexOrderedEndpoints.

/**
 * Helper method to create a list of MinorFragmentEndpoint instances from a given endpoint assignment list.
 *
 * @param endpoints Assigned endpoint list. Index of each endpoint in list indicates the MinorFragmentId of the
 *                  fragment that is assigned to the endpoint.
 * @return
 */
public static List<MinorFragmentEndpoint> getIndexOrderedEndpoints(List<DrillbitEndpoint> endpoints) {
    List<MinorFragmentEndpoint> destinations = Lists.newArrayList();
    int minorFragmentId = 0;
    for (DrillbitEndpoint endpoint : endpoints) {
        destinations.add(new MinorFragmentEndpoint(minorFragmentId, endpoint));
        minorFragmentId++;
    }
    return destinations;
}
Also used : MinorFragmentEndpoint(org.apache.drill.exec.physical.MinorFragmentEndpoint) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) MinorFragmentEndpoint(org.apache.drill.exec.physical.MinorFragmentEndpoint)

Aggregations

MinorFragmentEndpoint (org.apache.drill.exec.physical.MinorFragmentEndpoint)21 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)6 FragmentHandle (org.apache.drill.exec.proto.ExecProtos.FragmentHandle)6 FinishedReceiver (org.apache.drill.exec.proto.BitControl.FinishedReceiver)4 RpcOutcomeListener (org.apache.drill.exec.rpc.RpcOutcomeListener)4 SelectionVectorMode (org.apache.drill.exec.record.BatchSchema.SelectionVectorMode)3 IOException (java.io.IOException)2 List (java.util.List)2 AccountingDataTunnel (org.apache.drill.exec.ops.AccountingDataTunnel)2 FragmentContextImpl (org.apache.drill.exec.ops.FragmentContextImpl)2 HashPartitionSender (org.apache.drill.exec.physical.config.HashPartitionSender)2 PlanFragment (org.apache.drill.exec.proto.BitControl.PlanFragment)2 QueryContextInformation (org.apache.drill.exec.proto.BitControl.QueryContextInformation)2 MetricValue (org.apache.drill.exec.proto.UserBitShared.MetricValue)2 BatchSchema (org.apache.drill.exec.record.BatchSchema)2 FragmentWritableBatch (org.apache.drill.exec.record.FragmentWritableBatch)2 VectorAccessible (org.apache.drill.exec.record.VectorAccessible)2 OptionList (org.apache.drill.exec.server.options.OptionList)2 QueryWorkUnit (org.apache.drill.exec.work.QueryWorkUnit)2 ArrayList (java.util.ArrayList)1