Search in sources :

Example 1 with QueryManager

use of com.facebook.presto.execution.QueryManager in project presto by prestodb.

the class TestQueues method testRejection.

@Test(timeOut = 240_000)
public void testRejection() throws Exception {
    String dbConfigUrl = getDbConfigUrl();
    H2ResourceGroupsDao dao = getDao(dbConfigUrl);
    try (DistributedQueryRunner queryRunner = createQueryRunner(dbConfigUrl, dao)) {
        // Verify the query cannot be submitted
        QueryId queryId = createQuery(queryRunner, newRejectionSession(), LONG_LASTING_QUERY);
        waitForQueryState(queryRunner, queryId, FAILED);
        QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
        assertEquals(queryManager.getQueryInfo(queryId).getErrorCode(), QUERY_REJECTED.toErrorCode());
        int selectorCount = getSelectors(queryRunner).size();
        dao.insertSelector(4, "user.*", "(?i).*reject.*");
        assertEquals(dao.getSelectors().size(), selectorCount + 1);
        //MILLISECONDS.sleep(2000);
        do {
            MILLISECONDS.sleep(500);
        } while (getSelectors(queryRunner).size() == selectorCount);
        // Verify the query can be submitted
        queryId = createQuery(queryRunner, newRejectionSession(), LONG_LASTING_QUERY);
        waitForQueryState(queryRunner, queryId, RUNNING);
        dao.deleteSelector(4, "user.*", "(?i).*reject.*");
        do {
            MILLISECONDS.sleep(500);
        } while (getSelectors(queryRunner).size() != selectorCount);
        // Verify the query cannot be submitted
        queryId = createQuery(queryRunner, newRejectionSession(), LONG_LASTING_QUERY);
        waitForQueryState(queryRunner, queryId, FAILED);
    }
}
Also used : DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) QueryId(com.facebook.presto.spi.QueryId) QueryManager(com.facebook.presto.execution.QueryManager) H2ResourceGroupsDao(com.facebook.presto.resourceGroups.db.H2ResourceGroupsDao) Test(org.testng.annotations.Test)

Example 2 with QueryManager

use of com.facebook.presto.execution.QueryManager in project presto by prestodb.

the class TestResourceGroupPerQueryLimitEnforcement method testQueryMemoryLimit.

@Test(timeOut = 60_000L)
public void testQueryMemoryLimit() throws Exception {
    QueryId queryId = createQuery(queryRunner, testSessionBuilder().setCatalog("tpch").setSchema(TINY_SCHEMA_NAME).setSource("per_query_memory_limit_test").build(), "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_GLOBAL_MEMORY_LIMIT.toErrorCode());
    assertTrue(queryInfo.getFailureInfo().getMessage().contains(RESOURCE_GROUP.name()));
}
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 3 with QueryManager

use of com.facebook.presto.execution.QueryManager in project presto by prestodb.

the class TestResourceGroupPerQueryLimitEnforcement method testQueryCpuLimit.

@Test(timeOut = 60_000L)
public void testQueryCpuLimit() throws Exception {
    QueryId queryId = createQuery(queryRunner, testSessionBuilder().setCatalog("tpch").setSchema(TINY_SCHEMA_NAME).setSource("per_query_cpu_limit_test").build(), "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());
    assertTrue(queryInfo.getFailureInfo().getMessage().contains(RESOURCE_GROUP.name()));
}
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 4 with QueryManager

use of com.facebook.presto.execution.QueryManager in project presto by prestodb.

the class TestResourceGroupPerQueryLimitEnforcement method testQueryExecutionTimeLimit.

@Test(timeOut = 60_000L)
public void testQueryExecutionTimeLimit() throws Exception {
    QueryId queryId = createQuery(queryRunner, testSessionBuilder().setCatalog("tpch").setSchema(TINY_SCHEMA_NAME).setSource("per_query_execution_time_limit_test").build(), "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_TIME_LIMIT.toErrorCode());
    assertTrue(queryInfo.getFailureInfo().getMessage().contains(RESOURCE_GROUP.name()));
}
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 5 with QueryManager

use of com.facebook.presto.execution.QueryManager in project presto by prestodb.

the class TestQueuesDb method testSelectorPriority.

@Test(timeOut = 60_000)
public void testSelectorPriority() throws Exception {
    InternalResourceGroupManager manager = queryRunner.getCoordinator().getResourceGroupManager().get();
    QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
    ReloadingResourceGroupConfigurationManager reloadingConfigurationManager = (ReloadingResourceGroupConfigurationManager) manager.getConfigurationManager();
    QueryId firstQuery = createQuery(queryRunner, dashboardSession(), LONG_LASTING_QUERY);
    waitForQueryState(queryRunner, firstQuery, RUNNING);
    Optional<ResourceGroupId> resourceGroup = queryManager.getFullQueryInfo(firstQuery).getResourceGroupId();
    assertTrue(resourceGroup.isPresent());
    assertEquals(resourceGroup.get().toString(), "global.user-user.dashboard-user");
    // create a new resource group that rejects all queries submitted to it
    dao.insertResourceGroup(10, "reject-all-queries", "1MB", 0, 0, 0, null, null, null, null, null, null, null, null, 3L, TEST_ENVIRONMENT);
    // add a new selector that has a higher priority than the existing dashboard selector and that routes queries to the "reject-all-queries" resource group
    dao.insertSelector(10, 200, "user.*", "(?i).*dashboard.*", null, null, null);
    // reload the configuration
    reloadingConfigurationManager.load();
    QueryId secondQuery = createQuery(queryRunner, dashboardSession(), LONG_LASTING_QUERY);
    waitForQueryState(queryRunner, secondQuery, FAILED);
    DispatchManager dispatchManager = queryRunner.getCoordinator().getDispatchManager();
    BasicQueryInfo basicQueryInfo = dispatchManager.getQueryInfo(secondQuery);
    assertEquals(basicQueryInfo.getErrorCode(), QUERY_QUEUE_FULL.toErrorCode());
}
Also used : ReloadingResourceGroupConfigurationManager(com.facebook.presto.resourceGroups.reloading.ReloadingResourceGroupConfigurationManager) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) TestQueues.createResourceGroupId(com.facebook.presto.execution.TestQueues.createResourceGroupId) DispatchManager(com.facebook.presto.dispatcher.DispatchManager) QueryId(com.facebook.presto.spi.QueryId) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) QueryManager(com.facebook.presto.execution.QueryManager) InternalResourceGroupManager(com.facebook.presto.execution.resourceGroups.InternalResourceGroupManager) Test(org.testng.annotations.Test)

Aggregations

QueryManager (com.facebook.presto.execution.QueryManager)16 QueryId (com.facebook.presto.spi.QueryId)15 Test (org.testng.annotations.Test)15 BasicQueryInfo (com.facebook.presto.server.BasicQueryInfo)10 DispatchManager (com.facebook.presto.dispatcher.DispatchManager)5 Session (com.facebook.presto.Session)3 InternalResourceGroupManager (com.facebook.presto.execution.resourceGroups.InternalResourceGroupManager)3 ReloadingResourceGroupConfigurationManager (com.facebook.presto.resourceGroups.reloading.ReloadingResourceGroupConfigurationManager)3 QueryInfo (com.facebook.presto.execution.QueryInfo)2 QueryState (com.facebook.presto.execution.QueryState)2 TestQueryRunnerUtil.waitForQueryState (com.facebook.presto.execution.TestQueryRunnerUtil.waitForQueryState)2 TestingSessionContext (com.facebook.presto.execution.TestingSessionContext)2 H2ResourceGroupsDao (com.facebook.presto.resourceGroups.db.H2ResourceGroupsDao)2 PrestoException (com.facebook.presto.spi.PrestoException)2 DistributedQueryRunner (com.facebook.presto.tests.DistributedQueryRunner)2 BoundedExecutor (com.facebook.airlift.concurrent.BoundedExecutor)1 Threads.threadsNamed (com.facebook.airlift.concurrent.Threads.threadsNamed)1 Logger (com.facebook.airlift.log.Logger)1 Assertions (com.facebook.airlift.testing.Assertions)1 SystemSessionProperties (com.facebook.presto.SystemSessionProperties)1