Search in sources :

Example 6 with QueryId

use of org.apache.drill.exec.proto.UserBitShared.QueryId in project drill by apache.

the class TestCustomTunnel method ensureRoundTripBytes.

@Test
public void ensureRoundTripBytes() throws Exception {
    final DrillbitContext context = getDrillbitContext();
    final TestCustomMessageHandler handler = new TestCustomMessageHandler(context.getEndpoint(), true);
    context.getController().registerCustomHandler(1002, handler, DrillbitEndpoint.PARSER);
    final ControlTunnel loopbackTunnel = context.getController().getTunnel(context.getEndpoint());
    final CustomTunnel<DrillbitEndpoint, QueryId> tunnel = loopbackTunnel.getCustomTunnel(1002, DrillbitEndpoint.class, QueryId.PARSER);
    buf1.retain();
    CustomFuture<QueryId> future = tunnel.send(context.getEndpoint(), buf1);
    assertEquals(expectedId, future.get());
    byte[] actual = new byte[1024];
    future.getBuffer().getBytes(0, actual);
    future.getBuffer().release();
    assertTrue(Arrays.equals(expected, actual));
}
Also used : DrillbitContext(org.apache.drill.exec.server.DrillbitContext) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) QueryId(org.apache.drill.exec.proto.UserBitShared.QueryId) Test(org.junit.Test)

Example 7 with QueryId

use of org.apache.drill.exec.proto.UserBitShared.QueryId in project drill by apache.

the class UserWorker method queryIdGenerator.

/**
   * Helper method to generate QueryId
   * @return generated QueryId
   */
private static QueryId queryIdGenerator() {
    ThreadLocalRandom r = ThreadLocalRandom.current();
    // create a new queryid where the first four bytes are a growing time (each new value comes earlier in sequence).  Last 12 bytes are random.
    final long time = (int) (System.currentTimeMillis() / 1000);
    final long p1 = ((Integer.MAX_VALUE - time) << 32) + r.nextInt();
    final long p2 = r.nextLong();
    final QueryId id = QueryId.newBuilder().setPart1(p1).setPart2(p2).build();
    return id;
}
Also used : QueryId(org.apache.drill.exec.proto.UserBitShared.QueryId) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom)

Example 8 with QueryId

use of org.apache.drill.exec.proto.UserBitShared.QueryId in project drill by apache.

the class ControlMessageHandler method handle.

@Override
public void handle(ControlConnection connection, int rpcType, ByteBuf pBody, ByteBuf dBody, ResponseSender sender) throws RpcException {
    if (RpcConstants.EXTRA_DEBUGGING) {
        logger.debug("Received bit com message of type {}", rpcType);
    }
    switch(rpcType) {
        case RpcType.REQ_CANCEL_FRAGMENT_VALUE:
            {
                final FragmentHandle handle = get(pBody, FragmentHandle.PARSER);
                cancelFragment(handle);
                sender.send(ControlRpcConfig.OK);
                break;
            }
        case RpcType.REQ_CUSTOM_VALUE:
            {
                final CustomMessage customMessage = get(pBody, CustomMessage.PARSER);
                sender.send(handlerRegistry.handle(customMessage, (DrillBuf) dBody));
                break;
            }
        case RpcType.REQ_RECEIVER_FINISHED_VALUE:
            {
                final FinishedReceiver finishedReceiver = get(pBody, FinishedReceiver.PARSER);
                receivingFragmentFinished(finishedReceiver);
                sender.send(ControlRpcConfig.OK);
                break;
            }
        case RpcType.REQ_FRAGMENT_STATUS_VALUE:
            bee.getContext().getWorkBus().statusUpdate(get(pBody, FragmentStatus.PARSER));
            // TODO: Support a type of message that has no response.
            sender.send(ControlRpcConfig.OK);
            break;
        case RpcType.REQ_QUERY_CANCEL_VALUE:
            {
                final QueryId queryId = get(pBody, QueryId.PARSER);
                final Foreman foreman = bee.getForemanForQueryId(queryId);
                if (foreman != null) {
                    foreman.cancel();
                    sender.send(ControlRpcConfig.OK);
                } else {
                    sender.send(ControlRpcConfig.FAIL);
                }
                break;
            }
        case RpcType.REQ_INITIALIZE_FRAGMENTS_VALUE:
            {
                final InitializeFragments fragments = get(pBody, InitializeFragments.PARSER);
                for (int i = 0; i < fragments.getFragmentCount(); i++) {
                    startNewRemoteFragment(fragments.getFragment(i));
                }
                sender.send(ControlRpcConfig.OK);
                break;
            }
        case RpcType.REQ_QUERY_STATUS_VALUE:
            {
                final QueryId queryId = get(pBody, QueryId.PARSER);
                final Foreman foreman = bee.getForemanForQueryId(queryId);
                if (foreman == null) {
                    throw new RpcException("Query not running on node.");
                }
                final QueryProfile profile = foreman.getQueryManager().getQueryProfile();
                sender.send(new Response(RpcType.RESP_QUERY_STATUS, profile));
                break;
            }
        case RpcType.REQ_UNPAUSE_FRAGMENT_VALUE:
            {
                final FragmentHandle handle = get(pBody, FragmentHandle.PARSER);
                resumeFragment(handle);
                sender.send(ControlRpcConfig.OK);
                break;
            }
        default:
            throw new RpcException("Not yet supported.");
    }
}
Also used : Response(org.apache.drill.exec.rpc.Response) QueryProfile(org.apache.drill.exec.proto.UserBitShared.QueryProfile) InitializeFragments(org.apache.drill.exec.proto.BitControl.InitializeFragments) QueryId(org.apache.drill.exec.proto.UserBitShared.QueryId) UserRpcException(org.apache.drill.exec.rpc.UserRpcException) RpcException(org.apache.drill.exec.rpc.RpcException) CustomMessage(org.apache.drill.exec.proto.BitControl.CustomMessage) FragmentHandle(org.apache.drill.exec.proto.ExecProtos.FragmentHandle) Foreman(org.apache.drill.exec.work.foreman.Foreman) FinishedReceiver(org.apache.drill.exec.proto.BitControl.FinishedReceiver)

Example 9 with QueryId

use of org.apache.drill.exec.proto.UserBitShared.QueryId in project drill by apache.

the class UserWorker method getQueryPlan.

public QueryPlanFragments getQueryPlan(UserClientConnection connection, GetQueryPlanFragments req) {
    final QueryId queryId = queryIdGenerator();
    final QueryPlanFragments qPlanFragments = new PlanSplitter().planFragments(bee.getContext(), queryId, req, connection);
    return qPlanFragments;
}
Also used : QueryPlanFragments(org.apache.drill.exec.proto.UserProtos.QueryPlanFragments) GetQueryPlanFragments(org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments) QueryId(org.apache.drill.exec.proto.UserBitShared.QueryId)

Example 10 with QueryId

use of org.apache.drill.exec.proto.UserBitShared.QueryId in project drill by apache.

the class UserWorker method submitWork.

public QueryId submitWork(UserClientConnection connection, RunQuery query) {
    final QueryId id = queryIdGenerator();
    incrementer.increment(connection.getSession());
    Foreman foreman = new Foreman(bee, bee.getContext(), connection, id, query);
    bee.addNewForeman(foreman);
    return id;
}
Also used : QueryId(org.apache.drill.exec.proto.UserBitShared.QueryId) Foreman(org.apache.drill.exec.work.foreman.Foreman)

Aggregations

QueryId (org.apache.drill.exec.proto.UserBitShared.QueryId)15 UserException (org.apache.drill.common.exceptions.UserException)5 RpcException (org.apache.drill.exec.rpc.RpcException)5 QueryState (org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState)4 Foreman (org.apache.drill.exec.work.foreman.Foreman)4 UserRemoteException (org.apache.drill.common.exceptions.UserRemoteException)3 Test (org.junit.Test)3 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)2 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)2 Ack (org.apache.drill.exec.proto.GeneralRPCProtos.Ack)2 QueryInfo (org.apache.drill.exec.proto.UserBitShared.QueryInfo)2 QueryProfile (org.apache.drill.exec.proto.UserBitShared.QueryProfile)2 GetQueryPlanFragments (org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments)2 RunQuery (org.apache.drill.exec.proto.UserProtos.RunQuery)2 Response (org.apache.drill.exec.rpc.Response)2 DrillbitContext (org.apache.drill.exec.server.DrillbitContext)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)1 DrillBuf (io.netty.buffer.DrillBuf)1 IOException (java.io.IOException)1