Search in sources :

Example 1 with FragmentRecordBatch

use of org.apache.drill.exec.proto.BitData.FragmentRecordBatch in project drill by apache.

the class DataServerRequestHandler method handle.

@Override
public void handle(DataServerConnection connection, int rpcType, ByteBuf pBody, ByteBuf dBody, ResponseSender sender) throws RpcException {
    assert rpcType == BitData.RpcType.REQ_RECORD_BATCH_VALUE;
    final FragmentRecordBatch fragmentBatch = RpcBus.get(pBody, FragmentRecordBatch.PARSER);
    final AckSender ack = new AckSender(sender);
    // increment so we don't get false returns.
    ack.increment();
    try {
        final IncomingDataBatch batch = new IncomingDataBatch(fragmentBatch, (DrillBuf) dBody, ack);
        final int targetCount = fragmentBatch.getReceivingMinorFragmentIdCount();
        // randomize who gets first transfer (and thus ownership) so memory usage is balanced when we're sharing amongst
        // multiple fragments.
        final int firstOwner = ThreadLocalRandom.current().nextInt(targetCount);
        submit(batch, firstOwner, targetCount);
        submit(batch, 0, firstOwner);
    } catch (IOException | FragmentSetupException e) {
        logger.error("Failure while getting fragment manager. {}", QueryIdHelper.getQueryIdentifiers(fragmentBatch.getQueryId(), fragmentBatch.getReceivingMajorFragmentId(), fragmentBatch.getReceivingMinorFragmentIdList()), e);
        ack.clear();
        sender.send(new Response(BitData.RpcType.ACK, Acks.FAIL));
    } finally {
        // decrement the extra reference we grabbed at the top.
        ack.sendOk();
    }
}
Also used : Response(org.apache.drill.exec.rpc.Response) FragmentSetupException(org.apache.drill.exec.exception.FragmentSetupException) FragmentRecordBatch(org.apache.drill.exec.proto.BitData.FragmentRecordBatch) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 FragmentSetupException (org.apache.drill.exec.exception.FragmentSetupException)1 FragmentRecordBatch (org.apache.drill.exec.proto.BitData.FragmentRecordBatch)1 Response (org.apache.drill.exec.rpc.Response)1