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();
}
}
}
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);
}
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();
}
}
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();
}
}
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;
}
}
}
Aggregations