Search in sources :

Example 1 with DataTunnel

use of org.apache.drill.exec.rpc.data.DataTunnel in project drill by axbaretto.

the class TestBitRpc method testConnectionBackpressure.

@Test
public void testConnectionBackpressure(@Injectable WorkerBee bee, @Injectable final WorkEventBus workBus) throws Exception {
    DrillConfig config1 = DrillConfig.create();
    final BootStrapContext c = new BootStrapContext(config1, ClassPathScanner.fromPrescan(config1));
    DrillConfig config2 = DrillConfig.create();
    BootStrapContext c2 = new BootStrapContext(config2, ClassPathScanner.fromPrescan(config2));
    final FragmentContext fcon = new MockUp<FragmentContext>() {

        BufferAllocator getAllocator() {
            return c.getAllocator();
        }
    }.getMockInstance();
    final FragmentManager fman = new MockUp<FragmentManager>() {

        int v = 0;

        @Mock
        boolean handle(IncomingDataBatch batch) throws FragmentSetupException, IOException {
            try {
                v++;
                if (v % 10 == 0) {
                    System.out.println("sleeping.");
                    Thread.sleep(3000);
                }
            } catch (InterruptedException e) {
            }
            RawFragmentBatch rfb = batch.newRawFragmentBatch(c.getAllocator());
            rfb.sendOk();
            rfb.release();
            return true;
        }

        public FragmentContext getFragmentContext() {
            return fcon;
        }
    }.getMockInstance();
    new NonStrictExpectations() {

        {
            workBus.getFragmentManagerIfExists((FragmentHandle) any);
            result = fman;
            workBus.getFragmentManager((FragmentHandle) any);
            result = fman;
        }
    };
    int port = 1234;
    DataServer server = new DataServer(c, c.getAllocator(), workBus, null);
    port = server.bind(port, true);
    DrillbitEndpoint ep = DrillbitEndpoint.newBuilder().setAddress("localhost").setDataPort(port).build();
    DataConnectionManager manager = new DataConnectionManager(ep, c2);
    DataTunnel tunnel = new DataTunnel(manager);
    AtomicLong max = new AtomicLong(0);
    for (int i = 0; i < 40; i++) {
        long t1 = System.currentTimeMillis();
        tunnel.sendRecordBatch(new TimingOutcome(max), new FragmentWritableBatch(false, QueryId.getDefaultInstance(), 1, 1, 1, 1, getRandomBatch(c.getAllocator(), 5000)));
        System.out.println(System.currentTimeMillis() - t1);
    // System.out.println("sent.");
    }
    System.out.println(String.format("Max time: %d", max.get()));
    assertTrue(max.get() > 2700);
    Thread.sleep(5000);
}
Also used : RawFragmentBatch(org.apache.drill.exec.record.RawFragmentBatch) DataTunnel(org.apache.drill.exec.rpc.data.DataTunnel) FragmentContext(org.apache.drill.exec.ops.FragmentContext) FragmentWritableBatch(org.apache.drill.exec.record.FragmentWritableBatch) IncomingDataBatch(org.apache.drill.exec.rpc.data.IncomingDataBatch) FragmentSetupException(org.apache.drill.exec.exception.FragmentSetupException) IOException(java.io.IOException) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) Mock(mockit.Mock) BufferAllocator(org.apache.drill.exec.memory.BufferAllocator) DataConnectionManager(org.apache.drill.exec.rpc.data.DataConnectionManager) FragmentManager(org.apache.drill.exec.work.fragment.FragmentManager) AtomicLong(java.util.concurrent.atomic.AtomicLong) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) DrillConfig(org.apache.drill.common.config.DrillConfig) DataServer(org.apache.drill.exec.rpc.data.DataServer) NonStrictExpectations(mockit.NonStrictExpectations) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Example 2 with DataTunnel

use of org.apache.drill.exec.rpc.data.DataTunnel in project drill by apache.

the class RuntimeFilterSink method route.

private void route(RuntimeFilterWritable srcRuntimeFilterWritable) {
    BitData.RuntimeFilterBDef runtimeFilterB = srcRuntimeFilterWritable.getRuntimeFilterBDef();
    int joinMajorId = runtimeFilterB.getMajorFragmentId();
    UserBitShared.QueryId queryId = runtimeFilterB.getQueryId();
    List<String> probeFields = runtimeFilterB.getProbeFieldsList();
    List<Integer> sizeInBytes = runtimeFilterB.getBloomFilterSizeInBytesList();
    long rfIdentifier = runtimeFilterB.getRfIdentifier();
    DrillBuf[] data = srcRuntimeFilterWritable.getData();
    List<CoordinationProtos.DrillbitEndpoint> scanNodeEps = joinMjId2probeScanEps.get(joinMajorId);
    int scanNodeSize = scanNodeEps.size();
    srcRuntimeFilterWritable.retainBuffers(scanNodeSize - 1);
    int scanNodeMjId = joinMjId2ScanMjId.get(joinMajorId);
    for (int minorId = 0; minorId < scanNodeEps.size(); minorId++) {
        BitData.RuntimeFilterBDef.Builder builder = BitData.RuntimeFilterBDef.newBuilder();
        for (String probeField : probeFields) {
            builder.addProbeFields(probeField);
        }
        BitData.RuntimeFilterBDef runtimeFilterBDef = builder.setQueryId(queryId).setMajorFragmentId(scanNodeMjId).setMinorFragmentId(minorId).setToForeman(false).setRfIdentifier(rfIdentifier).addAllBloomFilterSizeInBytes(sizeInBytes).build();
        RuntimeFilterWritable runtimeFilterWritable = new RuntimeFilterWritable(runtimeFilterBDef, data);
        CoordinationProtos.DrillbitEndpoint drillbitEndpoint = scanNodeEps.get(minorId);
        DataTunnel dataTunnel = drillbitContext.getDataConnectionsPool().getTunnel(drillbitEndpoint);
        Consumer<RpcException> exceptionConsumer = new Consumer<RpcException>() {

            @Override
            public void accept(final RpcException e) {
                logger.warn("fail to broadcast a runtime filter to the probe side scan node", e);
            }

            @Override
            public void interrupt(final InterruptedException e) {
                logger.warn("fail to broadcast a runtime filter to the probe side scan node", e);
            }
        };
        RpcOutcomeListener<BitData.AckWithCredit> statusHandler = new DataTunnelStatusHandler(exceptionConsumer, sendingAccountor);
        AccountingDataTunnel accountingDataTunnel = new AccountingDataTunnel(dataTunnel, sendingAccountor, statusHandler);
        accountingDataTunnel.sendRuntimeFilter(runtimeFilterWritable);
    }
}
Also used : AccountingDataTunnel(org.apache.drill.exec.ops.AccountingDataTunnel) Consumer(org.apache.drill.exec.ops.Consumer) RpcException(org.apache.drill.exec.rpc.RpcException) DrillBuf(io.netty.buffer.DrillBuf) AccountingDataTunnel(org.apache.drill.exec.ops.AccountingDataTunnel) DataTunnel(org.apache.drill.exec.rpc.data.DataTunnel) CoordinationProtos(org.apache.drill.exec.proto.CoordinationProtos) DataTunnelStatusHandler(org.apache.drill.exec.ops.DataTunnelStatusHandler) BitData(org.apache.drill.exec.proto.BitData) UserBitShared(org.apache.drill.exec.proto.UserBitShared)

Aggregations

DataTunnel (org.apache.drill.exec.rpc.data.DataTunnel)2 DrillBuf (io.netty.buffer.DrillBuf)1 IOException (java.io.IOException)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Mock (mockit.Mock)1 NonStrictExpectations (mockit.NonStrictExpectations)1 DrillConfig (org.apache.drill.common.config.DrillConfig)1 ExecTest (org.apache.drill.exec.ExecTest)1 FragmentSetupException (org.apache.drill.exec.exception.FragmentSetupException)1 BufferAllocator (org.apache.drill.exec.memory.BufferAllocator)1 AccountingDataTunnel (org.apache.drill.exec.ops.AccountingDataTunnel)1 Consumer (org.apache.drill.exec.ops.Consumer)1 DataTunnelStatusHandler (org.apache.drill.exec.ops.DataTunnelStatusHandler)1 FragmentContext (org.apache.drill.exec.ops.FragmentContext)1 BitData (org.apache.drill.exec.proto.BitData)1 CoordinationProtos (org.apache.drill.exec.proto.CoordinationProtos)1 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)1 UserBitShared (org.apache.drill.exec.proto.UserBitShared)1 FragmentWritableBatch (org.apache.drill.exec.record.FragmentWritableBatch)1 RawFragmentBatch (org.apache.drill.exec.record.RawFragmentBatch)1