Search in sources :

Example 11 with QueryManager

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

the class TestQueryManager method testQueryScanExceeded.

@Test(timeOut = 60_000L)
public void testQueryScanExceeded() throws Exception {
    try (DistributedQueryRunner queryRunner = TpchQueryRunnerBuilder.builder().addExtraProperty("query.max-scan-physical-bytes", "0B").build()) {
        QueryId queryId = createQuery(queryRunner, TEST_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) Test(org.testng.annotations.Test)

Example 12 with QueryManager

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

the class TestMinWorkerRequirement method testMultipleRequiredWorkerNodesSessionOverride.

@Test
public void testMultipleRequiredWorkerNodesSessionOverride() throws Exception {
    ListeningExecutorService service = MoreExecutors.listeningDecorator(newFixedThreadPool(3));
    try (DistributedQueryRunner queryRunner = TpchQueryRunnerBuilder.builder().setNodeCount(1).build()) {
        Session session1 = testSessionBuilder().setSystemProperty(REQUIRED_WORKERS_COUNT, "2").setCatalog("tpch").setSchema("tiny").build();
        ListenableFuture<ResultWithQueryId<MaterializedResult>> queryFuture1 = service.submit(() -> queryRunner.executeWithQueryId(session1, "SELECT COUNT(*) from lineitem"));
        Session session2 = Session.builder(session1).setSystemProperty(REQUIRED_WORKERS_COUNT, "3").build();
        ListenableFuture<ResultWithQueryId<MaterializedResult>> queryFuture2 = service.submit(() -> queryRunner.executeWithQueryId(session2, "SELECT COUNT(*) from lineitem"));
        Session session3 = Session.builder(session1).setSystemProperty(REQUIRED_WORKERS_COUNT, "4").build();
        ListenableFuture<ResultWithQueryId<MaterializedResult>> queryFuture3 = service.submit(() -> queryRunner.executeWithQueryId(session3, "SELECT COUNT(*) from lineitem"));
        MILLISECONDS.sleep(1000);
        // None of the queries should run
        assertFalse(queryFuture1.isDone());
        assertFalse(queryFuture2.isDone());
        assertFalse(queryFuture3.isDone());
        queryRunner.addServers(1);
        assertEquals(queryRunner.getCoordinator().refreshNodes().getActiveNodes().size(), 2);
        // After adding 1 node, only 1st query should run
        MILLISECONDS.sleep(1000);
        assertTrue(queryFuture1.get().getResult().getRowCount() > 0);
        QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
        QueryInfo completedQueryInfo = queryManager.getFullQueryInfo(queryFuture1.get().getQueryId());
        assertTrue(completedQueryInfo.getQueryStats().getResourceWaitingTime().roundTo(SECONDS) >= 1);
        assertFalse(queryFuture2.isDone());
        assertFalse(queryFuture3.isDone());
        // After adding 2 nodes, 2nd and 3rd query should also run
        queryRunner.addServers(2);
        assertEquals(queryRunner.getCoordinator().refreshNodes().getActiveNodes().size(), 4);
        assertTrue(queryFuture2.get().getResult().getRowCount() > 0);
        completedQueryInfo = queryManager.getFullQueryInfo(queryFuture2.get().getQueryId());
        assertTrue(completedQueryInfo.getQueryStats().getResourceWaitingTime().roundTo(SECONDS) >= 2);
        assertTrue(queryFuture3.get().getResult().getRowCount() > 0);
        completedQueryInfo = queryManager.getFullQueryInfo(queryFuture3.get().getQueryId());
        assertTrue(completedQueryInfo.getQueryStats().getResourceWaitingTime().roundTo(SECONDS) >= 2);
    } finally {
        service.shutdown();
    }
}
Also used : DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) ResultWithQueryId(io.trino.testing.ResultWithQueryId) QueryManager(io.trino.execution.QueryManager) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) QueryInfo(io.trino.execution.QueryInfo) 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