Search in sources :

Example 16 with BasicQueryInfo

use of io.prestosql.server.BasicQueryInfo in project hetu-core by openlookeng.

the class QuerySystemTable method cursor.

@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession session, TupleDomain<Integer> constraint) {
    Builder table = InMemoryRecordSet.builder(QUERY_TABLE);
    List<QueryInfo> queryInfos = queryManager.getQueries().stream().map(BasicQueryInfo::getQueryId).map(queryId -> {
        try {
            return queryManager.getFullQueryInfo(queryId);
        } catch (NoSuchElementException e) {
            return null;
        }
    }).filter(Objects::nonNull).collect(toImmutableList());
    for (QueryInfo queryInfo : queryInfos) {
        QueryStats queryStats = queryInfo.getQueryStats();
        table.addRow(queryInfo.getQueryId().toString(), queryInfo.getState().toString(), queryInfo.getSession().getUser(), queryInfo.getSession().getSource().orElse(null), queryInfo.getQuery(), queryInfo.getResourceGroupId().map(QuerySystemTable::resourceGroupIdToBlock).orElse(null), toMillis(queryStats.getQueuedTime()), toMillis(queryStats.getAnalysisTime()), toMillis(queryStats.getDistributedPlanningTime()), toTimeStamp(queryStats.getCreateTime()), toTimeStamp(queryStats.getExecutionStartTime()), toTimeStamp(queryStats.getLastHeartbeat()), toTimeStamp(queryStats.getEndTime()));
    }
    return table.build().cursor();
}
Also used : QueryStats(io.prestosql.execution.QueryStats) Builder(io.prestosql.spi.connector.InMemoryRecordSet.Builder) TableMetadataBuilder.tableMetadataBuilder(io.prestosql.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) BlockBuilder(io.prestosql.spi.block.BlockBuilder) QueryInfo(io.prestosql.execution.QueryInfo) BasicQueryInfo(io.prestosql.server.BasicQueryInfo) NoSuchElementException(java.util.NoSuchElementException)

Example 17 with BasicQueryInfo

use of io.prestosql.server.BasicQueryInfo in project hetu-core by openlookeng.

the class TestMetadataManager method testMetadataIsClearedAfterQueryCanceled.

@Test
public void testMetadataIsClearedAfterQueryCanceled() throws Exception {
    DispatchManager dispatchManager = queryRunner.getCoordinator().getDispatchManager();
    QueryId queryId = dispatchManager.createQueryId();
    dispatchManager.createQuery(queryId, "slug", new TestingSessionContext(TEST_SESSION), "SELECT * FROM lineitem").get();
    // wait until query starts running
    while (true) {
        BasicQueryInfo queryInfo = dispatchManager.getQueryInfo(queryId);
        if (queryInfo.getState().isDone()) {
            assertEquals(queryInfo.getState(), FAILED);
            throw dispatchManager.getDispatchInfo(queryId).get().getFailureInfo().get().toException();
        }
        if (queryInfo.getState() == RUNNING) {
            break;
        }
        Thread.sleep(100);
    }
    // cancel query
    dispatchManager.cancelQuery(queryId);
    assertEquals(metadataManager.getActiveQueryIds().size(), 0);
}
Also used : DispatchManager(io.prestosql.dispatcher.DispatchManager) TestingSessionContext(io.prestosql.execution.TestingSessionContext) QueryId(io.prestosql.spi.QueryId) BasicQueryInfo(io.prestosql.server.BasicQueryInfo) Test(org.testng.annotations.Test)

Example 18 with BasicQueryInfo

use of io.prestosql.server.BasicQueryInfo in project hetu-core by openlookeng.

the class TestNodeStateChange method testWorkerShutdown.

@Test(timeOut = SHUTDOWN_TIMEOUT_MILLIS2)
public void testWorkerShutdown() throws Exception {
    try (DistributedQueryRunner queryRunner = createQueryRunner(TINY_SESSION, properties)) {
        List<ListenableFuture<?>> queryFutures = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            queryFutures.add(executor.submit(() -> queryRunner.execute("SELECT COUNT(*), clerk FROM orders GROUP BY clerk")));
        }
        TestingPrestoServer worker = queryRunner.getServers().stream().filter(server -> !server.isCoordinator()).findFirst().get();
        TaskManager taskManager = worker.getTaskManager();
        // wait until tasks show up on the worker
        while (taskManager.getAllTaskInfo().isEmpty()) {
            MILLISECONDS.sleep(500);
        }
        worker.getNodeStateChangeHandler().doStateTransition(NodeState.SHUTTING_DOWN);
        Futures.allAsList(queryFutures).get();
        List<BasicQueryInfo> queryInfos = queryRunner.getCoordinator().getQueryManager().getQueries();
        for (BasicQueryInfo info : queryInfos) {
            assertEquals(info.getState(), FINISHED);
        }
        TestingPrestoServer.TestShutdownAction shutdownAction = (TestingPrestoServer.TestShutdownAction) worker.getShutdownAction();
        shutdownAction.waitForShutdownComplete(SHUTDOWN_TIMEOUT_MILLIS2);
        assertTrue(shutdownAction.isShutdown());
    }
}
Also used : TaskManager(io.prestosql.execution.TaskManager) BasicQueryInfo(io.prestosql.server.BasicQueryInfo) ArrayList(java.util.ArrayList) TestingPrestoServer(io.prestosql.server.testing.TestingPrestoServer) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Test(org.testng.annotations.Test)

Example 19 with BasicQueryInfo

use of io.prestosql.server.BasicQueryInfo in project hetu-core by openlookeng.

the class TestNodeStateChange method testCoordinatorIsolation.

@Test(timeOut = 30_000)
public void testCoordinatorIsolation() throws Exception {
    try (DistributedQueryRunner queryRunner = createQueryRunner(TINY_SESSION, defaultProperties)) {
        List<ListenableFuture<?>> queryFutures = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            queryFutures.add(executor.submit(() -> queryRunner.execute("SELECT COUNT(*), clerk FROM orders GROUP BY clerk")));
        }
        TestingPrestoServer coordinator = queryRunner.getServers().stream().filter(TestingPrestoServer::isCoordinator).findFirst().get();
        QueryManager queryManager = coordinator.getQueryManager();
        // wait until queries show up on the coordinator
        while (queryManager.getQueries().isEmpty()) {
            MILLISECONDS.sleep(500);
        }
        assertEquals(coordinator.getNodeStateChangeHandler().getState(), NodeState.ACTIVE);
        coordinator.getNodeStateChangeHandler().doStateTransition(NodeState.ISOLATING);
        Futures.allAsList(queryFutures).get();
        List<BasicQueryInfo> queryInfos = queryRunner.getCoordinator().getQueryManager().getQueries();
        for (BasicQueryInfo info : queryInfos) {
            assertEquals(info.getState(), FINISHED);
        }
        while (!coordinator.getNodeStateChangeHandler().getState().equals(NodeState.ISOLATED)) {
            Thread.sleep(1000);
        }
    }
}
Also used : BasicQueryInfo(io.prestosql.server.BasicQueryInfo) ArrayList(java.util.ArrayList) TestingPrestoServer(io.prestosql.server.testing.TestingPrestoServer) QueryManager(io.prestosql.execution.QueryManager) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Test(org.testng.annotations.Test)

Example 20 with BasicQueryInfo

use of io.prestosql.server.BasicQueryInfo in project hetu-core by openlookeng.

the class TestMemoryManager method waitForQueryToBeKilled.

private void waitForQueryToBeKilled(DistributedQueryRunner queryRunner) throws InterruptedException {
    while (true) {
        for (BasicQueryInfo info : queryRunner.getCoordinator().getQueryManager().getQueries()) {
            if (info.getState().isDone()) {
                assertNotNull(info.getErrorCode());
                assertEquals(info.getErrorCode().getCode(), CLUSTER_OUT_OF_MEMORY.toErrorCode().getCode());
                return;
            }
        }
        MILLISECONDS.sleep(10);
    }
}
Also used : BasicQueryInfo(io.prestosql.server.BasicQueryInfo)

Aggregations

BasicQueryInfo (io.prestosql.server.BasicQueryInfo)20 Test (org.testng.annotations.Test)9 QueryManager (io.prestosql.execution.QueryManager)6 TestingPrestoServer (io.prestosql.server.testing.TestingPrestoServer)5 QueryId (io.prestosql.spi.QueryId)5 Duration (io.airlift.units.Duration)4 DispatchManager (io.prestosql.dispatcher.DispatchManager)4 QueryInfo (io.prestosql.execution.QueryInfo)4 ArrayList (java.util.ArrayList)4 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)3 ErrorCode (io.prestosql.spi.ErrorCode)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)2 UncheckedTimeoutException (com.google.common.util.concurrent.UncheckedTimeoutException)2 Uninterruptibles.sleepUninterruptibly (com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly)2 Assertions (io.airlift.testing.Assertions)2 Duration.nanosSince (io.airlift.units.Duration.nanosSince)2 Session (io.prestosql.Session)2