Search in sources :

Example 91 with QueryId

use of io.trino.spi.QueryId 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 92 with QueryId

use of io.trino.spi.QueryId in project trino by trinodb.

the class TestQueuesDb method testNonLeafGroup.

@Test
public void testNonLeafGroup() throws Exception {
    Session session = testSessionBuilder().setCatalog("tpch").setSchema("sf100000").setSource("non-leaf").build();
    InternalResourceGroupManager<?> manager = queryRunner.getCoordinator().getResourceGroupManager().get();
    DbResourceGroupConfigurationManager dbConfigurationManager = (DbResourceGroupConfigurationManager) manager.getConfigurationManager();
    int originalSize = getSelectors(queryRunner).size();
    // Add a selector for a non leaf group
    dao.insertSelector(3, 100, "user.*", null, "(?i).*non-leaf.*", null, null, null);
    dbConfigurationManager.load();
    while (getSelectors(queryRunner).size() != originalSize + 1) {
        MILLISECONDS.sleep(500);
    }
    // Submit query with side effect of creating resource groups
    QueryId firstDashboardQuery = createQuery(queryRunner, dashboardSession(), LONG_LASTING_QUERY);
    waitForQueryState(queryRunner, firstDashboardQuery, RUNNING);
    cancelQuery(queryRunner, firstDashboardQuery);
    waitForQueryState(queryRunner, firstDashboardQuery, FAILED);
    // Submit a query to a non-leaf resource group
    QueryId invalidResourceGroupQuery = createQuery(queryRunner, session, LONG_LASTING_QUERY);
    waitForQueryState(queryRunner, invalidResourceGroupQuery, FAILED);
    assertEquals(queryRunner.getCoordinator().getDispatchManager().getQueryInfo(invalidResourceGroupQuery).getErrorCode(), INVALID_RESOURCE_GROUP.toErrorCode());
}
Also used : DbResourceGroupConfigurationManager(io.trino.plugin.resourcegroups.db.DbResourceGroupConfigurationManager) QueryId(io.trino.spi.QueryId) H2TestUtil.dashboardSession(io.trino.execution.resourcegroups.db.H2TestUtil.dashboardSession) Session(io.trino.Session) H2TestUtil.adhocSession(io.trino.execution.resourcegroups.db.H2TestUtil.adhocSession) H2TestUtil.rejectingSession(io.trino.execution.resourcegroups.db.H2TestUtil.rejectingSession) Test(org.testng.annotations.Test)

Example 93 with QueryId

use of io.trino.spi.QueryId in project trino by trinodb.

the class TestQueuesDb method testTooManyQueries.

@Test(timeOut = 90_000)
public void testTooManyQueries() throws Exception {
    QueryId firstDashboardQuery = createQuery(queryRunner, dashboardSession(), LONG_LASTING_QUERY);
    waitForQueryState(queryRunner, firstDashboardQuery, RUNNING);
    QueryId secondDashboardQuery = createQuery(queryRunner, dashboardSession(), LONG_LASTING_QUERY);
    waitForQueryState(queryRunner, secondDashboardQuery, QUEUED);
    QueryId thirdDashboardQuery = createQuery(queryRunner, dashboardSession(), LONG_LASTING_QUERY);
    waitForQueryState(queryRunner, thirdDashboardQuery, FAILED);
    // Allow one more query to run and resubmit third query
    dao.updateResourceGroup(3, "user-${USER}", "1MB", 3, 4, 4, null, null, null, null, null, 1L, TEST_ENVIRONMENT);
    dao.updateResourceGroup(5, "dashboard-${USER}", "1MB", 1, 2, 2, null, null, null, null, null, 3L, TEST_ENVIRONMENT);
    InternalResourceGroupManager<?> manager = queryRunner.getCoordinator().getResourceGroupManager().get();
    DbResourceGroupConfigurationManager dbConfigurationManager = (DbResourceGroupConfigurationManager) manager.getConfigurationManager();
    // Trigger reload to make the test more deterministic
    dbConfigurationManager.load();
    waitForQueryState(queryRunner, secondDashboardQuery, RUNNING);
    thirdDashboardQuery = createQuery(queryRunner, dashboardSession(), LONG_LASTING_QUERY);
    waitForQueryState(queryRunner, thirdDashboardQuery, QUEUED);
    // Lower running queries in dashboard resource groups and reload the config
    dao.updateResourceGroup(5, "dashboard-${USER}", "1MB", 1, 1, 1, null, null, null, null, null, 3L, TEST_ENVIRONMENT);
    dbConfigurationManager.load();
    // Cancel query and verify that third query is still queued
    cancelQuery(queryRunner, firstDashboardQuery);
    waitForQueryState(queryRunner, firstDashboardQuery, FAILED);
    MILLISECONDS.sleep(2000);
    waitForQueryState(queryRunner, thirdDashboardQuery, QUEUED);
}
Also used : DbResourceGroupConfigurationManager(io.trino.plugin.resourcegroups.db.DbResourceGroupConfigurationManager) QueryId(io.trino.spi.QueryId) Test(org.testng.annotations.Test)

Example 94 with QueryId

use of io.trino.spi.QueryId in project trino by trinodb.

the class TestQueues method testExceedSoftLimits.

@Test(timeOut = 240_000)
public void testExceedSoftLimits() throws Exception {
    try (DistributedQueryRunner queryRunner = createQueryRunner()) {
        queryRunner.installPlugin(new ResourceGroupManagerPlugin());
        queryRunner.getCoordinator().getResourceGroupManager().get().setConfigurationManager("file", ImmutableMap.of("resource-groups.config-file", getResourceFilePath("resource_groups_config_soft_limits.json")));
        QueryId scheduled1 = createScheduledQuery(queryRunner);
        waitForQueryState(queryRunner, scheduled1, RUNNING);
        QueryId scheduled2 = createScheduledQuery(queryRunner);
        waitForQueryState(queryRunner, scheduled2, RUNNING);
        QueryId scheduled3 = createScheduledQuery(queryRunner);
        waitForQueryState(queryRunner, scheduled3, RUNNING);
        // cluster is now 'at capacity' - scheduled is running 3 (i.e. over soft limit)
        QueryId backfill1 = createBackfill(queryRunner);
        QueryId scheduled4 = createScheduledQuery(queryRunner);
        cancelQuery(queryRunner, scheduled1);
        // backfill should be chosen to run next
        waitForQueryState(queryRunner, backfill1, RUNNING);
        cancelQuery(queryRunner, scheduled2);
        cancelQuery(queryRunner, scheduled3);
        cancelQuery(queryRunner, scheduled4);
        QueryId backfill2 = createBackfill(queryRunner);
        waitForQueryState(queryRunner, backfill2, RUNNING);
        QueryId backfill3 = createBackfill(queryRunner);
        waitForQueryState(queryRunner, backfill3, RUNNING);
        // cluster is now 'at capacity' - backfills is running 3 (i.e. over soft limit)
        QueryId backfill4 = createBackfill(queryRunner);
        QueryId scheduled5 = createScheduledQuery(queryRunner);
        cancelQuery(queryRunner, backfill1);
        // scheduled should be chosen to run next
        waitForQueryState(queryRunner, scheduled5, RUNNING);
        cancelQuery(queryRunner, backfill2);
        cancelQuery(queryRunner, backfill3);
        cancelQuery(queryRunner, backfill4);
        cancelQuery(queryRunner, scheduled5);
        waitForQueryState(queryRunner, scheduled5, FAILED);
    }
}
Also used : DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) QueryId(io.trino.spi.QueryId) ResourceGroupManagerPlugin(io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin) Test(org.testng.annotations.Test)

Example 95 with QueryId

use of io.trino.spi.QueryId in project trino by trinodb.

the class TestQueues method testResourceGroupManagerWithTooManyQueriesScheduled.

@Test(timeOut = 240_000)
public void testResourceGroupManagerWithTooManyQueriesScheduled() throws Exception {
    try (DistributedQueryRunner queryRunner = createQueryRunner()) {
        queryRunner.installPlugin(new ResourceGroupManagerPlugin());
        queryRunner.getCoordinator().getResourceGroupManager().get().setConfigurationManager("file", ImmutableMap.of("resource-groups.config-file", getResourceFilePath("resource_groups_config_dashboard.json")));
        QueryId firstDashboardQuery = createDashboardQuery(queryRunner);
        waitForQueryState(queryRunner, firstDashboardQuery, RUNNING);
        QueryId secondDashboardQuery = createDashboardQuery(queryRunner);
        waitForQueryState(queryRunner, secondDashboardQuery, QUEUED);
        QueryId thirdDashboardQuery = createDashboardQuery(queryRunner);
        waitForQueryState(queryRunner, thirdDashboardQuery, FAILED);
    }
}
Also used : DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) QueryId(io.trino.spi.QueryId) ResourceGroupManagerPlugin(io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin) Test(org.testng.annotations.Test)

Aggregations

QueryId (io.trino.spi.QueryId)103 Test (org.testng.annotations.Test)70 TaskId (io.trino.execution.TaskId)26 StageId (io.trino.execution.StageId)24 Map (java.util.Map)17 ImmutableMap (com.google.common.collect.ImmutableMap)16 DynamicFilterId (io.trino.sql.planner.plan.DynamicFilterId)15 DistributedQueryRunner (io.trino.testing.DistributedQueryRunner)14 Optional (java.util.Optional)13 Duration (io.airlift.units.Duration)12 Session (io.trino.Session)12 DynamicFilter (io.trino.spi.connector.DynamicFilter)12 Symbol (io.trino.sql.planner.Symbol)12 ImmutableSet (com.google.common.collect.ImmutableSet)11 TestingColumnHandle (io.trino.spi.connector.TestingColumnHandle)11 SymbolAllocator (io.trino.sql.planner.SymbolAllocator)11 Set (java.util.Set)10 AccessDeniedException (io.trino.spi.security.AccessDeniedException)9 Assert.assertEquals (org.testng.Assert.assertEquals)9 QualifiedObjectName (io.trino.metadata.QualifiedObjectName)8