Search in sources :

Example 11 with QueryId

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

the class QueryResultHandler method resultArrived.

/**
   * Maps internal low-level API protocol to {@link UserResultsListener}-level API protocol.
   * handles data result messages
   */
public void resultArrived(ByteBuf pBody) throws RpcException {
    final QueryResult queryResult = RpcBus.get(pBody, QueryResult.PARSER);
    final QueryId queryId = queryResult.getQueryId();
    final QueryState queryState = queryResult.getQueryState();
    if (logger.isDebugEnabled()) {
        logger.debug("resultArrived: queryState: {}, queryId = {}", queryState, QueryIdHelper.getQueryId(queryId));
    }
    assert queryResult.hasQueryState() : "received query result without QueryState";
    final boolean isFailureResult = QueryState.FAILED == queryState;
    // CANCELED queries are handled the same way as COMPLETED
    final boolean isTerminalResult;
    switch(queryState) {
        case FAILED:
        case CANCELED:
        case COMPLETED:
            isTerminalResult = true;
            break;
        default:
            logger.error("Unexpected/unhandled QueryState " + queryState + " (for query " + queryId + ")");
            isTerminalResult = false;
            break;
    }
    assert isFailureResult || queryResult.getErrorCount() == 0 : "Error count for the query batch is non-zero but QueryState != FAILED";
    UserResultsListener resultsListener = newUserResultsListener(queryId);
    try {
        if (isFailureResult) {
            // Failure case--pass on via submissionFailed(...).
            resultsListener.submissionFailed(new UserRemoteException(queryResult.getError(0)));
        // Note: Listener is removed in finally below.
        } else if (isTerminalResult) {
            try {
                resultsListener.queryCompleted(queryState);
            } catch (Exception e) {
                resultsListener.submissionFailed(UserException.systemError(e).build(logger));
            }
        } else {
            logger.warn("queryState {} was ignored", queryState);
        }
    } finally {
        if (isTerminalResult) {
            // for it?
            if ((!(resultsListener instanceof BufferingResultsListener) || ((BufferingResultsListener) resultsListener).output != null)) {
                queryIdToResultsListenersMap.remove(queryId, resultsListener);
            }
        }
    }
}
Also used : QueryResult(org.apache.drill.exec.proto.UserBitShared.QueryResult) UserRemoteException(org.apache.drill.common.exceptions.UserRemoteException) QueryId(org.apache.drill.exec.proto.UserBitShared.QueryId) QueryState(org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState) UserException(org.apache.drill.common.exceptions.UserException) RpcException(org.apache.drill.exec.rpc.RpcException) UserRemoteException(org.apache.drill.common.exceptions.UserRemoteException)

Example 12 with QueryId

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

the class ProfileResources method cancelQuery.

@GET
@Path("/profiles/cancel/{queryid}")
@Produces(MediaType.TEXT_PLAIN)
public String cancelQuery(@PathParam("queryid") String queryId) {
    QueryId id = QueryIdHelper.getQueryIdFromString(queryId);
    // first check local running
    Foreman f = work.getBee().getForemanForQueryId(id);
    if (f != null) {
        checkOrThrowQueryCancelAuthorization(f.getQueryContext().getQueryUserName(), queryId);
        f.cancel();
        return String.format("Cancelled query %s on locally running node.", queryId);
    }
    // then check remote running
    try {
        final TransientStore<QueryInfo> running = work.getContext().getProfileStoreContext().getRunningProfileStore();
        final QueryInfo info = running.get(queryId);
        checkOrThrowQueryCancelAuthorization(info.getUser(), queryId);
        Ack a = work.getContext().getController().getTunnel(info.getForeman()).requestCancelQuery(id).checkedGet(2, TimeUnit.SECONDS);
        if (a.getOk()) {
            return String.format("Query %s canceled on node %s.", queryId, info.getForeman().getAddress());
        } else {
            return String.format("Attempted to cancel query %s on %s but the query is no longer active on that node.", queryId, info.getForeman().getAddress());
        }
    } catch (Exception e) {
        logger.debug("Failure to find query as running profile.", e);
        return String.format("Failure attempting to cancel query %s.  Unable to find information about where query is actively running.", queryId);
    }
}
Also used : QueryId(org.apache.drill.exec.proto.UserBitShared.QueryId) Ack(org.apache.drill.exec.proto.GeneralRPCProtos.Ack) Foreman(org.apache.drill.exec.work.foreman.Foreman) QueryInfo(org.apache.drill.exec.proto.UserBitShared.QueryInfo) UserException(org.apache.drill.common.exceptions.UserException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 13 with QueryId

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

the class TestCustomTunnel method ensureRoundTrip.

@Test
public void ensureRoundTrip() throws Exception {
    final DrillbitContext context = getDrillbitContext();
    final TestCustomMessageHandler handler = new TestCustomMessageHandler(context.getEndpoint(), false);
    context.getController().registerCustomHandler(1001, handler, DrillbitEndpoint.PARSER);
    final ControlTunnel loopbackTunnel = context.getController().getTunnel(context.getEndpoint());
    final CustomTunnel<DrillbitEndpoint, QueryId> tunnel = loopbackTunnel.getCustomTunnel(1001, DrillbitEndpoint.class, QueryId.PARSER);
    CustomFuture<QueryId> future = tunnel.send(context.getEndpoint());
    assertEquals(expectedId, future.get());
}
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 14 with QueryId

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

the class QueryBuilder method produceSummary.

private QuerySummary produceSummary(BufferingQueryEventListener listener) throws Exception {
    long start = System.currentTimeMillis();
    int recordCount = 0;
    int batchCount = 0;
    QueryId queryId = null;
    QueryState state = null;
    loop: for (; ; ) {
        QueryEvent event = listener.get();
        switch(event.type) {
            case BATCH:
                batchCount++;
                recordCount += event.batch.getHeader().getRowCount();
                event.batch.release();
                break;
            case EOF:
                state = event.state;
                break loop;
            case ERROR:
                throw event.error;
            case QUERY_ID:
                queryId = event.queryId;
                break;
            default:
                throw new IllegalStateException("Unexpected event: " + event.type);
        }
    }
    long end = System.currentTimeMillis();
    long elapsed = end - start;
    return new QuerySummary(queryId, recordCount, batchCount, elapsed, state);
}
Also used : QueryId(org.apache.drill.exec.proto.UserBitShared.QueryId) QueryState(org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState) QueryEvent(org.apache.drill.test.BufferingQueryEventListener.QueryEvent)

Example 15 with QueryId

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

the class TestDrillbitResilience method passThrough.

// To test pause and resume. Test hangs and times out if resume did not happen.
@Test
public void passThrough() {
    final long before = countAllocatedMemory();
    final WaitUntilCompleteListener listener = new WaitUntilCompleteListener() {

        @Override
        public void queryIdArrived(final QueryId queryId) {
            super.queryIdArrived(queryId);
            final ExtendedLatch trigger = new ExtendedLatch(1);
            (new ResumingThread(queryId, ex, trigger)).start();
            trigger.countDown();
        }
    };
    final String controls = Controls.newBuilder().addPause(PojoRecordReader.class, "read-next").build();
    setControls(controls);
    QueryTestUtil.testWithListener(drillClient, QueryType.SQL, TEST_QUERY, listener);
    final Pair<QueryState, Exception> result = listener.waitForCompletion();
    assertStateCompleted(result, QueryState.COMPLETED);
    final long after = countAllocatedMemory();
    assertEquals(String.format("We are leaking %d bytes", after - before), before, after);
}
Also used : QueryId(org.apache.drill.exec.proto.UserBitShared.QueryId) PojoRecordReader(org.apache.drill.exec.store.pojo.PojoRecordReader) QueryState(org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState) UserException(org.apache.drill.common.exceptions.UserException) RpcException(org.apache.drill.exec.rpc.RpcException) ForemanSetupException(org.apache.drill.exec.work.foreman.ForemanSetupException) DrillbitStartupException(org.apache.drill.exec.exception.DrillbitStartupException) ForemanException(org.apache.drill.exec.work.foreman.ForemanException) IOException(java.io.IOException) SchemaChangeException(org.apache.drill.exec.exception.SchemaChangeException) ExtendedLatch(org.apache.drill.common.concurrent.ExtendedLatch) DrillTest(org.apache.drill.test.DrillTest) Test(org.junit.Test)

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