Search in sources :

Example 1 with H2ResourceGroupsDao

use of com.facebook.presto.resourceGroups.db.H2ResourceGroupsDao in project presto by prestodb.

the class TestQueues method testTooManyQueries.

@Test(timeOut = 240_000)
public void testTooManyQueries() throws Exception {
    String dbConfigUrl = getDbConfigUrl();
    H2ResourceGroupsDao dao = getDao(dbConfigUrl);
    try (DistributedQueryRunner queryRunner = createQueryRunner(dbConfigUrl, dao)) {
        QueryId firstDashboardQuery = createQuery(queryRunner, newDashboardSession(), LONG_LASTING_QUERY);
        waitForQueryState(queryRunner, firstDashboardQuery, RUNNING);
        QueryId secondDashboardQuery = createQuery(queryRunner, newDashboardSession(), LONG_LASTING_QUERY);
        waitForQueryState(queryRunner, secondDashboardQuery, QUEUED);
        QueryId thirdDashboardQuery = createQuery(queryRunner, newDashboardSession(), 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, null, null, null, null, null, 1L);
        dao.updateResourceGroup(5, "dashboard-${USER}", "1MB", 1, 2, null, null, null, null, null, 3L);
        waitForQueryState(queryRunner, secondDashboardQuery, RUNNING);
        thirdDashboardQuery = createQuery(queryRunner, newDashboardSession(), LONG_LASTING_QUERY);
        waitForQueryState(queryRunner, thirdDashboardQuery, QUEUED);
        // Lower running queries in dashboard resource groups and wait until groups are reconfigured
        dao.updateResourceGroup(5, "dashboard-${USER}", "1MB", 1, 1, null, null, null, null, null, 3L);
        ResourceGroupManager manager = queryRunner.getCoordinator().getResourceGroupManager().get();
        do {
            MILLISECONDS.sleep(500);
        } while (manager.getResourceGroupInfo(new ResourceGroupId(new ResourceGroupId(new ResourceGroupId("global"), "user-user"), "dashboard-user")).getMaxRunningQueries() != 1);
        // 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 : DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) QueryId(com.facebook.presto.spi.QueryId) ResourceGroupManager(com.facebook.presto.execution.resourceGroups.ResourceGroupManager) H2ResourceGroupsDao(com.facebook.presto.resourceGroups.db.H2ResourceGroupsDao) Test(org.testng.annotations.Test)

Example 2 with H2ResourceGroupsDao

use of com.facebook.presto.resourceGroups.db.H2ResourceGroupsDao 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 3 with H2ResourceGroupsDao

use of com.facebook.presto.resourceGroups.db.H2ResourceGroupsDao in project presto by prestodb.

the class TestQueues method getSimpleQueryRunner.

static DistributedQueryRunner getSimpleQueryRunner() throws Exception {
    String dbConfigUrl = getDbConfigUrl();
    H2ResourceGroupsDao dao = getDao(dbConfigUrl);
    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
    builder.put("experimental.resource-groups-enabled", "true");
    Map<String, String> properties = builder.build();
    DistributedQueryRunner queryRunner = TpchQueryRunner.createQueryRunner(properties);
    Plugin h2ResourceGroupManagerPlugin = new H2ResourceGroupManagerPlugin();
    queryRunner.installPlugin(h2ResourceGroupManagerPlugin);
    queryRunner.getCoordinator().getResourceGroupManager().get().setConfigurationManager(NAME, ImmutableMap.of("resource-groups.config-db-url", dbConfigUrl));
    setup(queryRunner, dao);
    return queryRunner;
}
Also used : DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) H2ResourceGroupsDao(com.facebook.presto.resourceGroups.db.H2ResourceGroupsDao) ImmutableMap(com.google.common.collect.ImmutableMap) TpchPlugin(com.facebook.presto.tpch.TpchPlugin) Plugin(com.facebook.presto.spi.Plugin)

Example 4 with H2ResourceGroupsDao

use of com.facebook.presto.resourceGroups.db.H2ResourceGroupsDao in project presto by prestodb.

the class TestQueues method testTwoQueriesAtSameTime.

@Test(timeOut = 240_000)
public void testTwoQueriesAtSameTime() throws Exception {
    String dbConfigUrl = getDbConfigUrl();
    H2ResourceGroupsDao dao = getDao(dbConfigUrl);
    try (DistributedQueryRunner queryRunner = createQueryRunner(dbConfigUrl, dao)) {
        QueryId firstDashboardQuery = createQuery(queryRunner, newDashboardSession(), LONG_LASTING_QUERY);
        QueryId secondDashboardQuery = createQuery(queryRunner, newDashboardSession(), LONG_LASTING_QUERY);
        ImmutableSet<QueryState> queuedOrRunning = ImmutableSet.of(QUEUED, RUNNING);
        waitForQueryState(queryRunner, firstDashboardQuery, RUNNING);
        waitForQueryState(queryRunner, secondDashboardQuery, QUEUED);
    }
}
Also used : DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) QueryId(com.facebook.presto.spi.QueryId) H2ResourceGroupsDao(com.facebook.presto.resourceGroups.db.H2ResourceGroupsDao) QueryState(com.facebook.presto.execution.QueryState) Test(org.testng.annotations.Test)

Example 5 with H2ResourceGroupsDao

use of com.facebook.presto.resourceGroups.db.H2ResourceGroupsDao in project presto by prestodb.

the class TestQueues method getDao.

private static H2ResourceGroupsDao getDao(String url) {
    DbResourceGroupConfig dbResourceGroupConfig = new DbResourceGroupConfig().setConfigDbUrl(url);
    H2ResourceGroupsDao dao = new H2DaoProvider(dbResourceGroupConfig).get();
    dao.createResourceGroupsTable();
    dao.createSelectorsTable();
    dao.createResourceGroupsGlobalPropertiesTable();
    return dao;
}
Also used : DbResourceGroupConfig(com.facebook.presto.resourceGroups.db.DbResourceGroupConfig) H2DaoProvider(com.facebook.presto.resourceGroups.db.H2DaoProvider) H2ResourceGroupsDao(com.facebook.presto.resourceGroups.db.H2ResourceGroupsDao)

Aggregations

H2ResourceGroupsDao (com.facebook.presto.resourceGroups.db.H2ResourceGroupsDao)6 DistributedQueryRunner (com.facebook.presto.tests.DistributedQueryRunner)5 QueryId (com.facebook.presto.spi.QueryId)4 Test (org.testng.annotations.Test)4 QueryManager (com.facebook.presto.execution.QueryManager)2 QueryState (com.facebook.presto.execution.QueryState)1 ResourceGroupManager (com.facebook.presto.execution.resourceGroups.ResourceGroupManager)1 DbResourceGroupConfig (com.facebook.presto.resourceGroups.db.DbResourceGroupConfig)1 H2DaoProvider (com.facebook.presto.resourceGroups.db.H2DaoProvider)1 Plugin (com.facebook.presto.spi.Plugin)1 ResourceGroupId (com.facebook.presto.spi.resourceGroups.ResourceGroupId)1 TpchPlugin (com.facebook.presto.tpch.TpchPlugin)1 ImmutableMap (com.google.common.collect.ImmutableMap)1