Search in sources :

Example 1 with RawFragmentBatch

use of org.apache.drill.exec.record.RawFragmentBatch in project drill by apache.

the class BaseRawBatchBuffer method clearBufferWithBody.

/**
   * Helper method to clear buffer with request bodies release also flushes ack queue - in case there are still
   * responses pending
   */
private void clearBufferWithBody() {
    while (!bufferQueue.isEmpty()) {
        final RawFragmentBatch batch;
        try {
            batch = bufferQueue.poll();
            assertAckSent(batch);
        } catch (IOException e) {
            context.fail(e);
            continue;
        }
        if (batch.getBody() != null) {
            batch.getBody().release();
        }
    }
}
Also used : RawFragmentBatch(org.apache.drill.exec.record.RawFragmentBatch) IOException(java.io.IOException)

Example 2 with RawFragmentBatch

use of org.apache.drill.exec.record.RawFragmentBatch in project drill by apache.

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;
    DataConnectionConfig config = new DataConnectionConfig(c.getAllocator(), c, new DataServerRequestHandler(workBus, bee));
    DataServer server = new DataServer(config);
    port = server.bind(port, true);
    DrillbitEndpoint ep = DrillbitEndpoint.newBuilder().setAddress("localhost").setDataPort(port).build();
    DataConnectionManager manager = new DataConnectionManager(ep, config);
    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 : FragmentContext(org.apache.drill.exec.ops.FragmentContext) FragmentWritableBatch(org.apache.drill.exec.record.FragmentWritableBatch) Mock(mockit.Mock) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) DrillConfig(org.apache.drill.common.config.DrillConfig) RawFragmentBatch(org.apache.drill.exec.record.RawFragmentBatch) FragmentSetupException(org.apache.drill.exec.exception.FragmentSetupException) IOException(java.io.IOException) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) BufferAllocator(org.apache.drill.exec.memory.BufferAllocator) FragmentManager(org.apache.drill.exec.work.fragment.FragmentManager) AtomicLong(java.util.concurrent.atomic.AtomicLong) BootStrapContext(org.apache.drill.exec.server.BootStrapContext) NonStrictExpectations(mockit.NonStrictExpectations) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Example 3 with RawFragmentBatch

use of org.apache.drill.exec.record.RawFragmentBatch in project drill by apache.

the class UnorderedReceiverBatch method next.

@Override
public IterOutcome next() {
    batchLoader.resetRecordCount();
    stats.startProcessing();
    try {
        RawFragmentBatch batch;
        try {
            stats.startWait();
            batch = getNextBatch();
            // skip over empty batches. we do this since these are basically control messages.
            while (batch != null && batch.getHeader().getDef().getRecordCount() == 0 && (!first || batch.getHeader().getDef().getFieldCount() == 0)) {
                batch = getNextBatch();
            }
        } finally {
            stats.stopWait();
        }
        first = false;
        if (batch == null) {
            batchLoader.clear();
            if (!context.shouldContinue()) {
                return IterOutcome.STOP;
            }
            return IterOutcome.NONE;
        }
        if (context.isOverMemoryLimit()) {
            return IterOutcome.OUT_OF_MEMORY;
        }
        //      logger.debug("Next received batch {}", batch);
        final RecordBatchDef rbd = batch.getHeader().getDef();
        final boolean schemaChanged = batchLoader.load(rbd, batch.getBody());
        // TODO:  Clean:  DRILL-2933:  That load(...) no longer throws
        // SchemaChangeException, so check/clean catch clause below.
        stats.addLongStat(Metric.BYTES_RECEIVED, batch.getByteCount());
        batch.release();
        if (schemaChanged) {
            this.schema = batchLoader.getSchema();
            stats.batchReceived(0, rbd.getRecordCount(), true);
            return IterOutcome.OK_NEW_SCHEMA;
        } else {
            stats.batchReceived(0, rbd.getRecordCount(), false);
            return IterOutcome.OK;
        }
    } catch (SchemaChangeException | IOException ex) {
        context.fail(ex);
        return IterOutcome.STOP;
    } finally {
        stats.stopProcessing();
    }
}
Also used : RawFragmentBatch(org.apache.drill.exec.record.RawFragmentBatch) SchemaChangeException(org.apache.drill.exec.exception.SchemaChangeException) RecordBatchDef(org.apache.drill.exec.proto.UserBitShared.RecordBatchDef) IOException(java.io.IOException)

Example 4 with RawFragmentBatch

use of org.apache.drill.exec.record.RawFragmentBatch in project drill by apache.

the class MergingRecordBatch method getNext.

@SuppressWarnings("resource")
private RawFragmentBatch getNext(final int providerIndex) throws IOException {
    stats.startWait();
    final RawFragmentBatchProvider provider = fragProviders[providerIndex];
    try {
        injector.injectInterruptiblePause(context.getExecutionControls(), "waiting-for-data", logger);
        final RawFragmentBatch b = provider.getNext();
        if (b != null) {
            stats.addLongStat(Metric.BYTES_RECEIVED, b.getByteCount());
            stats.batchReceived(0, b.getHeader().getDef().getRecordCount(), false);
            inputCounts[providerIndex] += b.getHeader().getDef().getRecordCount();
        }
        return b;
    } catch (final InterruptedException 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();
        return null;
    } finally {
        stats.stopWait();
    }
}
Also used : RawFragmentBatch(org.apache.drill.exec.record.RawFragmentBatch) RawFragmentBatchProvider(org.apache.drill.exec.record.RawFragmentBatchProvider)

Example 5 with RawFragmentBatch

use of org.apache.drill.exec.record.RawFragmentBatch in project drill by apache.

the class IncomingBuffers method batchArrived.

public boolean batchArrived(final IncomingDataBatch incomingBatch) throws FragmentSetupException, IOException {
    // Otherwise we would leak memory.
    try (AutoCloseableLock lock = sharedIncomingBatchLock.open()) {
        if (closed) {
            return false;
        }
        if (incomingBatch.getHeader().getIsLastBatch()) {
            streamsRemaining.decrementAndGet();
        }
        final int sendMajorFragmentId = incomingBatch.getHeader().getSendingMajorFragmentId();
        DataCollector collector = collectorMap.get(sendMajorFragmentId);
        if (collector == null) {
            throw new FragmentSetupException(String.format("We received a major fragment id that we were not expecting.  The id was %d. %s", sendMajorFragmentId, Arrays.toString(collectorMap.values().toArray())));
        }
        synchronized (collector) {
            final RawFragmentBatch newRawFragmentBatch = incomingBatch.newRawFragmentBatch(context.getAllocator());
            boolean decrementedToZero = collector.batchArrived(incomingBatch.getHeader().getSendingMinorFragmentId(), newRawFragmentBatch);
            newRawFragmentBatch.release();
            // we should only return true if remaining required has been decremented and is currently equal to zero.
            return decrementedToZero;
        }
    }
}
Also used : RawFragmentBatch(org.apache.drill.exec.record.RawFragmentBatch) AutoCloseableLock(org.apache.drill.common.concurrent.AutoCloseableLock) FragmentSetupException(org.apache.drill.exec.exception.FragmentSetupException)

Aggregations

RawFragmentBatch (org.apache.drill.exec.record.RawFragmentBatch)10 IOException (java.io.IOException)5 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)2 FragmentSetupException (org.apache.drill.exec.exception.FragmentSetupException)2 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)2 BufferAllocator (org.apache.drill.exec.memory.BufferAllocator)2 FragmentContext (org.apache.drill.exec.ops.FragmentContext)2 MinorFragmentEndpoint (org.apache.drill.exec.physical.MinorFragmentEndpoint)2 RawFragmentBatchProvider (org.apache.drill.exec.record.RawFragmentBatchProvider)2 DrillBuf (io.netty.buffer.DrillBuf)1 Comparator (java.util.Comparator)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Mock (mockit.Mock)1 MockUp (mockit.MockUp)1 NonStrictExpectations (mockit.NonStrictExpectations)1 AutoCloseableLock (org.apache.drill.common.concurrent.AutoCloseableLock)1 DrillConfig (org.apache.drill.common.config.DrillConfig)1 ExecTest (org.apache.drill.exec.ExecTest)1 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)1 UserBitShared (org.apache.drill.exec.proto.UserBitShared)1