Search in sources :

Example 6 with QueryManager

use of io.trino.execution.QueryManager in project trino by trinodb.

the class TestQueuesDb method testQueryExecutionTimeLimit.

@Test(timeOut = 60_000)
public void testQueryExecutionTimeLimit() throws Exception {
    QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
    InternalResourceGroupManager<?> manager = queryRunner.getCoordinator().getResourceGroupManager().get();
    DbResourceGroupConfigurationManager dbConfigurationManager = (DbResourceGroupConfigurationManager) manager.getConfigurationManager();
    QueryId firstQuery = createQuery(queryRunner, testSessionBuilder().setCatalog("tpch").setSchema("sf100000").setSource("dashboard").setSystemProperty(QUERY_MAX_EXECUTION_TIME, "1ms").build(), LONG_LASTING_QUERY);
    waitForQueryState(queryRunner, firstQuery, FAILED);
    assertEquals(queryManager.getFullQueryInfo(firstQuery).getErrorCode(), EXCEEDED_TIME_LIMIT.toErrorCode());
    assertContains(queryManager.getFullQueryInfo(firstQuery).getFailureInfo().getMessage(), "Query exceeded the maximum execution time limit of 1.00ms");
    // set max running queries to 0 for the dashboard resource group so that new queries get queued immediately
    dao.updateResourceGroup(5, "dashboard-${USER}", "1MB", 1, null, 0, null, null, null, null, null, 3L, TEST_ENVIRONMENT);
    dbConfigurationManager.load();
    QueryId secondQuery = createQuery(queryRunner, testSessionBuilder().setCatalog("tpch").setSchema("sf100000").setSource("dashboard").setSystemProperty(QUERY_MAX_EXECUTION_TIME, "1ms").build(), LONG_LASTING_QUERY);
    // this query should immediately get queued
    waitForQueryState(queryRunner, secondQuery, QUEUED);
    // after a 5s wait this query should still be QUEUED, not FAILED as the max execution time should be enforced after the query starts running
    Thread.sleep(5_000);
    DispatchManager dispatchManager = queryRunner.getCoordinator().getDispatchManager();
    assertEquals(dispatchManager.getQueryInfo(secondQuery).getState(), QUEUED);
    // reconfigure the resource group to run the second query
    dao.updateResourceGroup(5, "dashboard-${USER}", "1MB", 1, null, 1, null, null, null, null, null, 3L, TEST_ENVIRONMENT);
    dbConfigurationManager.load();
    // cancel the first one and let the second one start
    dispatchManager.cancelQuery(firstQuery);
    // wait until the second one is FAILED
    waitForQueryState(queryRunner, secondQuery, FAILED);
}
Also used : DbResourceGroupConfigurationManager(io.trino.plugin.resourcegroups.db.DbResourceGroupConfigurationManager) DispatchManager(io.trino.dispatcher.DispatchManager) QueryId(io.trino.spi.QueryId) QueryManager(io.trino.execution.QueryManager) Test(org.testng.annotations.Test)

Example 7 with QueryManager

use of io.trino.execution.QueryManager in project trino by trinodb.

the class AbstractDistributedEngineOnlyQueries method testQueryTransitionsToRunningState.

@Test(timeOut = 10_000)
public void testQueryTransitionsToRunningState() {
    String query = format(// use random marker in query for unique matching below
    "SELECT count(*) c_%s FROM lineitem CROSS JOIN lineitem CROSS JOIN lineitem", randomTableSuffix());
    DistributedQueryRunner queryRunner = getDistributedQueryRunner();
    ListenableFuture<?> queryFuture = Futures.submit(() -> queryRunner.execute(getSession(), query), executorService);
    QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
    assertEventually(() -> {
        List<BasicQueryInfo> queryInfos = queryManager.getQueries().stream().filter(q -> q.getQuery().equals(query)).collect(toImmutableList());
        assertThat(queryInfos).hasSize(1);
        assertThat(queryInfos.get(0).getState()).isEqualTo(RUNNING);
        // we are good. Let's kill the query
        queryManager.cancelQuery(queryInfos.get(0).getQueryId());
    });
    assertThatThrownBy(queryFuture::get).hasMessageContaining("Query was canceled");
}
Also used : AfterClass(org.testng.annotations.AfterClass) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Language(org.intellij.lang.annotations.Language) QueryManager(io.trino.execution.QueryManager) BasicQueryInfo(io.trino.server.BasicQueryInfo) BeforeClass(org.testng.annotations.BeforeClass) ZonedDateTime(java.time.ZonedDateTime) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RUNNING(io.trino.execution.QueryState.RUNNING) Test(org.testng.annotations.Test) String.format(java.lang.String.format) BROADCAST(io.trino.sql.planner.OptimizerConfig.JoinDistributionType.BROADCAST) ENABLE_DYNAMIC_FILTERING(io.trino.SystemSessionProperties.ENABLE_DYNAMIC_FILTERING) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) Assert.assertEventually(io.trino.testing.assertions.Assert.assertEventually) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) Pattern(java.util.regex.Pattern) ExecutorService(java.util.concurrent.ExecutorService) TestTable.randomTableSuffix(io.trino.testing.sql.TestTable.randomTableSuffix) Session(io.trino.Session) BasicQueryInfo(io.trino.server.BasicQueryInfo) QueryManager(io.trino.execution.QueryManager) Test(org.testng.annotations.Test)

Example 8 with QueryManager

use of io.trino.execution.QueryManager in project trino by trinodb.

the class TestQueryManager method testFailQuery.

@Test(timeOut = 60_000L)
public void testFailQuery() throws Exception {
    DispatchManager dispatchManager = queryRunner.getCoordinator().getDispatchManager();
    QueryId queryId = dispatchManager.createQueryId();
    dispatchManager.createQuery(queryId, Slug.createNew(), TestingSessionContext.fromSession(TEST_SESSION), "SELECT * FROM lineitem").get();
    // wait until query starts running
    while (true) {
        QueryState state = dispatchManager.getQueryInfo(queryId).getState();
        if (state.isDone()) {
            fail("unexpected query state: " + state);
        }
        if (state == RUNNING) {
            break;
        }
        Thread.sleep(100);
    }
    // cancel query
    QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
    queryManager.failQuery(queryId, new TrinoException(GENERIC_INTERNAL_ERROR, "mock exception"));
    QueryInfo queryInfo = queryManager.getFullQueryInfo(queryId);
    assertEquals(queryInfo.getState(), FAILED);
    assertEquals(queryInfo.getErrorCode(), GENERIC_INTERNAL_ERROR.toErrorCode());
    assertNotNull(queryInfo.getFailureInfo());
    assertEquals(queryInfo.getFailureInfo().getMessage(), "mock exception");
}
Also used : DispatchManager(io.trino.dispatcher.DispatchManager) QueryId(io.trino.spi.QueryId) QueryManager(io.trino.execution.QueryManager) TrinoException(io.trino.spi.TrinoException) QueryState(io.trino.execution.QueryState) TestQueryRunnerUtil.waitForQueryState(io.trino.execution.TestQueryRunnerUtil.waitForQueryState) BasicQueryInfo(io.trino.server.BasicQueryInfo) QueryInfo(io.trino.execution.QueryInfo) Test(org.testng.annotations.Test)

Example 9 with QueryManager

use of io.trino.execution.QueryManager in project trino by trinodb.

the class TestQueryManager method testQueryCpuLimit.

@Test(timeOut = 60_000L)
public void testQueryCpuLimit() throws Exception {
    try (DistributedQueryRunner queryRunner = TpchQueryRunnerBuilder.builder().addExtraProperty("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 : DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) QueryId(io.trino.spi.QueryId) BasicQueryInfo(io.trino.server.BasicQueryInfo) QueryManager(io.trino.execution.QueryManager) Test(org.testng.annotations.Test)

Example 10 with QueryManager

use of io.trino.execution.QueryManager in project trino by trinodb.

the class TestQueryManager method testQueryScanExceededSession.

@Test(timeOut = 60_000L)
public void testQueryScanExceededSession() throws Exception {
    try (DistributedQueryRunner queryRunner = TpchQueryRunnerBuilder.builder().build()) {
        Session session = testSessionBuilder().setCatalog("tpch").setSchema(TINY_SCHEMA_NAME).setClientCapabilities(stream(ClientCapabilities.values()).map(ClientCapabilities::toString).collect(toImmutableSet())).setSystemProperty("query_max_scan_physical_bytes", "0B").build();
        QueryId queryId = createQuery(queryRunner, session, "SELECT * FROM system.runtime.nodes");
        waitForQueryState(queryRunner, queryId, FAILED);
        QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
        BasicQueryInfo queryInfo = queryManager.getQueryInfo(queryId);
        assertEquals(queryInfo.getState(), FAILED);
        assertEquals(queryInfo.getErrorCode(), EXCEEDED_SCAN_LIMIT.toErrorCode());
    }
}
Also used : DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) QueryId(io.trino.spi.QueryId) BasicQueryInfo(io.trino.server.BasicQueryInfo) QueryManager(io.trino.execution.QueryManager) ClientCapabilities(io.trino.client.ClientCapabilities) Session(io.trino.Session) Test(org.testng.annotations.Test)

Aggregations

QueryManager (io.trino.execution.QueryManager)12 Test (org.testng.annotations.Test)10 BasicQueryInfo (io.trino.server.BasicQueryInfo)7 QueryId (io.trino.spi.QueryId)7 Session (io.trino.Session)5 DistributedQueryRunner (io.trino.testing.DistributedQueryRunner)5 DispatchManager (io.trino.dispatcher.DispatchManager)4 QueryInfo (io.trino.execution.QueryInfo)4 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 Futures (com.google.common.util.concurrent.Futures)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 Duration (io.airlift.units.Duration)2 DbResourceGroupConfigurationManager (io.trino.plugin.resourcegroups.db.DbResourceGroupConfigurationManager)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Stopwatch (com.google.common.base.Stopwatch)1 Verify.verifyNotNull (com.google.common.base.Verify.verifyNotNull)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)1 Ordering (com.google.common.collect.Ordering)1