Search in sources :

Example 16 with QueryInfo

use of io.trino.execution.QueryInfo 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

QueryInfo (io.trino.execution.QueryInfo)16 Test (org.testng.annotations.Test)6 BasicQueryInfo (io.trino.server.BasicQueryInfo)5 QueryManager (io.trino.execution.QueryManager)3 ResourceSecurity (io.trino.server.security.ResourceSecurity)3 QueryId (io.trino.spi.QueryId)3 AccessDeniedException (io.trino.spi.security.AccessDeniedException)3 ForbiddenException (javax.ws.rs.ForbiddenException)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 QueryStats (io.trino.execution.QueryStats)2 BlockBuilder (io.trino.spi.block.BlockBuilder)2 URI (java.net.URI)2 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1 Request (io.airlift.http.client.Request)1 UnexpectedResponseException (io.airlift.http.client.UnexpectedResponseException)1 Duration (io.airlift.units.Duration)1 Session (io.trino.Session)1 QueryResults (io.trino.client.QueryResults)1 DispatchManager (io.trino.dispatcher.DispatchManager)1