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