Search in sources :

Example 26 with BasicQueryInfo

use of com.facebook.presto.server.BasicQueryInfo in project presto by prestodb.

the class TestGracefulShutdown method testShutdown.

@Test(timeOut = SHUTDOWN_TIMEOUT_MILLIS, dataProvider = "testServerInfo")
public void testShutdown(String serverInstanceType, Map<String, String> properties) 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")));
        }
        boolean isCoordinatorInstance = serverInstanceType.equals(COORDINATOR);
        TestingPrestoServer testServer = queryRunner.getServers().stream().filter(server -> server.isCoordinator() == isCoordinatorInstance).findFirst().get();
        if (!isCoordinatorInstance) {
            TaskManager taskManager = testServer.getTaskManager();
            while (taskManager.getAllTaskInfo().isEmpty()) {
                MILLISECONDS.sleep(500);
            }
        }
        testServer.getGracefulShutdownHandler().requestShutdown();
        Futures.allAsList(queryFutures).get();
        List<BasicQueryInfo> queryInfos = queryRunner.getCoordinator().getQueryManager().getQueries();
        for (BasicQueryInfo info : queryInfos) {
            assertEquals(info.getState(), FINISHED);
        }
        TestShutdownAction shutdownAction = (TestShutdownAction) testServer.getShutdownAction();
        shutdownAction.waitForShutdownComplete(SHUTDOWN_TIMEOUT_MILLIS);
        assertTrue(shutdownAction.isShutdown());
    }
}
Also used : TaskManager(com.facebook.presto.execution.TaskManager) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) ArrayList(java.util.ArrayList) TestingPrestoServer(com.facebook.presto.server.testing.TestingPrestoServer) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) TestShutdownAction(com.facebook.presto.server.testing.TestingPrestoServer.TestShutdownAction) Test(org.testng.annotations.Test)

Example 27 with BasicQueryInfo

use of com.facebook.presto.server.BasicQueryInfo in project presto by prestodb.

the class TestMetadataManager method testMetadataIsClearedAfterQueryCanceled.

@Test
public void testMetadataIsClearedAfterQueryCanceled() throws Exception {
    DispatchManager dispatchManager = queryRunner.getCoordinator().getDispatchManager();
    QueryId queryId = dispatchManager.createQueryId();
    dispatchManager.createQuery(queryId, "slug", 0, 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.getCatalogsByQueryId().size(), 0);
}
Also used : DispatchManager(com.facebook.presto.dispatcher.DispatchManager) TestingSessionContext(com.facebook.presto.execution.TestingSessionContext) QueryId(com.facebook.presto.spi.QueryId) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) Test(org.testng.annotations.Test)

Example 28 with BasicQueryInfo

use of com.facebook.presto.server.BasicQueryInfo in project presto by prestodb.

the class TestQueryTaskLimit 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(), QUERY_HAS_TOO_MANY_STAGES.toErrorCode().getCode());
                MILLISECONDS.sleep(100);
                return;
            }
        }
        MILLISECONDS.sleep(10);
    }
}
Also used : BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo)

Example 29 with BasicQueryInfo

use of com.facebook.presto.server.BasicQueryInfo in project presto by prestodb.

the class TestQueryManager method testQueryCpuLimit.

@Test(timeOut = 60_000L)
public void testQueryCpuLimit() throws Exception {
    try (DistributedQueryRunner queryRunner = builder().setSingleExtraProperty("query.max-cpu-time", "1ms").build()) {
        QueryId queryId = createQuery(queryRunner, TEST_SESSION, "SELECT COUNT(*) FROM lineitem");
        waitForQueryState(queryRunner, queryId, FAILED);
        QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
        BasicQueryInfo queryInfo = queryManager.getQueryInfo(queryId);
        assertEquals(queryInfo.getState(), FAILED);
        assertEquals(queryInfo.getErrorCode(), EXCEEDED_CPU_LIMIT.toErrorCode());
    }
}
Also used : QueryId(com.facebook.presto.spi.QueryId) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) QueryManager(com.facebook.presto.execution.QueryManager) Test(org.testng.annotations.Test)

Example 30 with BasicQueryInfo

use of com.facebook.presto.server.BasicQueryInfo in project presto by prestodb.

the class TestQueues method testQueuedQueryInteraction.

@Test(timeOut = 60_000)
public void testQueuedQueryInteraction() throws Exception {
    queryRunner.installPlugin(new ResourceGroupManagerPlugin());
    queryRunner.getCoordinator().getResourceGroupManager().get().setConfigurationManager("file", ImmutableMap.of("resource-groups.config-file", getResourceFilePath("resource_groups_config_dashboard.json")));
    // submit first "dashboard" query
    QueryId firstDashboardQuery = createDashboardQuery(queryRunner);
    // wait for the first "dashboard" query to start
    waitForQueryState(queryRunner, firstDashboardQuery, RUNNING);
    // submit second "dashboard" query
    QueryId secondDashboardQuery = createDashboardQuery(queryRunner);
    // wait for the second "dashboard" query to be queued ("dashboard.${USER}" queue strategy only allows one "dashboard" query to be accepted for execution)
    waitForQueryState(queryRunner, secondDashboardQuery, QUEUED);
    // Retrieve information for the queued query
    BasicQueryInfo queryInfo = getBasicQueryInfo("/v1/query/" + secondDashboardQuery.getId());
    assertNotNull(queryInfo);
    assertEquals(queryInfo.getState(), QUEUED);
    assertEquals(queryInfo.getQuery(), LONG_LASTING_QUERY);
    assertNotNull(queryInfo.getQueryStats());
    killQuery(format("/v1/query/%s/killed", secondDashboardQuery.getId()));
    queryInfo = getBasicQueryInfo("/v1/query/" + secondDashboardQuery.getId());
    assertNotNull(queryInfo);
    assertEquals(queryInfo.getErrorCode(), ADMINISTRATIVELY_KILLED.toErrorCode());
    // submit third "dashboard" query
    QueryId thirdDashboardQuery = createDashboardQuery(queryRunner);
    waitForQueryState(queryRunner, thirdDashboardQuery, QUEUED);
    killQuery(format("/v1/query/%s/preempted", thirdDashboardQuery.getId()));
    queryInfo = getBasicQueryInfo("/v1/query/" + thirdDashboardQuery.getId());
    assertNotNull(queryInfo);
    assertEquals(queryInfo.getErrorCode(), ADMINISTRATIVELY_PREEMPTED.toErrorCode());
}
Also used : QueryId(com.facebook.presto.spi.QueryId) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) ResourceGroupManagerPlugin(com.facebook.presto.resourceGroups.ResourceGroupManagerPlugin) Test(org.testng.annotations.Test)

Aggregations

BasicQueryInfo (com.facebook.presto.server.BasicQueryInfo)32 Test (org.testng.annotations.Test)19 QueryId (com.facebook.presto.spi.QueryId)12 QueryManager (com.facebook.presto.execution.QueryManager)9 TestingPrestoServer (com.facebook.presto.server.testing.TestingPrestoServer)4 Session (com.facebook.presto.Session)3 DispatchManager (com.facebook.presto.dispatcher.DispatchManager)3 ExecutionFailureInfo (com.facebook.presto.execution.ExecutionFailureInfo)3 QueryInfo (com.facebook.presto.execution.QueryInfo)3 PrestoException (com.facebook.presto.spi.PrestoException)3 DistributedQueryRunner (com.facebook.presto.tests.DistributedQueryRunner)3 ImmutableList (com.google.common.collect.ImmutableList)2 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2 ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 Assertions (com.facebook.airlift.testing.Assertions)1 SystemSessionProperties (com.facebook.presto.SystemSessionProperties)1 QUERY_MAX_MEMORY (com.facebook.presto.SystemSessionProperties.QUERY_MAX_MEMORY)1