Search in sources :

Example 6 with Response

use of org.apache.drill.exec.rpc.Response 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)

Example 7 with Response

use of org.apache.drill.exec.rpc.Response in project drill by apache.

the class CustomHandlerRegistry method handle.

public Response handle(CustomMessage message, DrillBuf dBody) throws RpcException {
    final ParsingHandler<?, ?> handler;
    try (AutoCloseableLock lock = read.open()) {
        handler = handlers.get(message.getType());
    }
    if (handler == null) {
        throw new UserRpcException(endpoint, "Unable to handle message.", new IllegalStateException(String.format("Unable to handle message. The message type provided [%d] did not have a registered handler.", message.getType())));
    }
    final CustomResponse<?> customResponse = handler.onMessage(message.getMessage(), dBody);
    @SuppressWarnings("unchecked") final CustomMessage responseMessage = CustomMessage.newBuilder().setMessage(ByteString.copyFrom(((Controller.CustomSerDe<Object>) handler.getResponseSerDe()).serializeToSend(customResponse.getMessage()))).setType(message.getType()).build();
    // make sure we don't pass in a null array.
    final ByteBuf[] dBodies = customResponse.getBodies() == null ? new DrillBuf[0] : customResponse.getBodies();
    return new Response(RpcType.RESP_CUSTOM, responseMessage, dBodies);
}
Also used : Response(org.apache.drill.exec.rpc.Response) CustomResponse(org.apache.drill.exec.rpc.control.Controller.CustomResponse) UserRpcException(org.apache.drill.exec.rpc.UserRpcException) AutoCloseableLock(org.apache.drill.common.concurrent.AutoCloseableLock) CustomMessage(org.apache.drill.exec.proto.BitControl.CustomMessage) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

Response (org.apache.drill.exec.rpc.Response)7 RpcException (org.apache.drill.exec.rpc.RpcException)4 ByteString (com.google.protobuf.ByteString)2 CustomMessage (org.apache.drill.exec.proto.BitControl.CustomMessage)2 QueryId (org.apache.drill.exec.proto.UserBitShared.QueryId)2 UserRpcException (org.apache.drill.exec.rpc.UserRpcException)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 ByteBuf (io.netty.buffer.ByteBuf)1 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)1 IOException (java.io.IOException)1 SaslException (javax.security.sasl.SaslException)1 AutoCloseableLock (org.apache.drill.common.concurrent.AutoCloseableLock)1 FragmentSetupException (org.apache.drill.exec.exception.FragmentSetupException)1 FinishedReceiver (org.apache.drill.exec.proto.BitControl.FinishedReceiver)1 InitializeFragments (org.apache.drill.exec.proto.BitControl.InitializeFragments)1 FragmentRecordBatch (org.apache.drill.exec.proto.BitData.FragmentRecordBatch)1 FragmentHandle (org.apache.drill.exec.proto.ExecProtos.FragmentHandle)1 Ack (org.apache.drill.exec.proto.GeneralRPCProtos.Ack)1 QueryProfile (org.apache.drill.exec.proto.UserBitShared.QueryProfile)1 CreatePreparedStatementReq (org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementReq)1