Search in sources :

Example 41 with QueryId

use of com.facebook.presto.spi.QueryId in project presto by prestodb.

the class TestMemoryManager method testOutOfMemoryKiller.

@Test(timeOut = 240_000, expectedExceptions = ExecutionException.class, expectedExceptionsMessageRegExp = ".*The cluster is out of memory, and your query was killed. Please try again in a few minutes.")
public void testOutOfMemoryKiller() throws Exception {
    Map<String, String> properties = ImmutableMap.<String, String>builder().put("task.verbose-stats", "true").put("query.low-memory-killer.delay", "5s").put("query.low-memory-killer.enabled", "true").build();
    try (DistributedQueryRunner queryRunner = createQueryRunner(TINY_SESSION, properties)) {
        // Reserve all the memory
        QueryId fakeQueryId = new QueryId("fake");
        for (TestingPrestoServer server : queryRunner.getServers()) {
            for (MemoryPool pool : server.getLocalMemoryManager().getPools()) {
                assertTrue(pool.tryReserve(fakeQueryId, pool.getMaxBytes()));
            }
        }
        List<Future<?>> queryFutures = new ArrayList<>();
        for (int i = 0; i < 2; i++) {
            queryFutures.add(executor.submit(() -> queryRunner.execute("SELECT COUNT(*), clerk FROM orders GROUP BY clerk")));
        }
        // Wait for one of the queries to die
        boolean queryDone = false;
        while (!queryDone) {
            for (QueryInfo info : queryRunner.getCoordinator().getQueryManager().getAllQueryInfo()) {
                if (info.getState().isDone()) {
                    assertEquals(info.getErrorCode().getCode(), CLUSTER_OUT_OF_MEMORY.toErrorCode().getCode());
                    queryDone = true;
                    break;
                }
            }
            MILLISECONDS.sleep(10);
        }
        // Release the memory in the reserved pool
        for (TestingPrestoServer server : queryRunner.getServers()) {
            MemoryPool reserved = server.getLocalMemoryManager().getPool(RESERVED_POOL);
            // Free up the entire pool
            reserved.free(fakeQueryId, reserved.getMaxBytes());
            assertTrue(reserved.getFreeBytes() > 0);
        }
        for (Future<?> query : queryFutures) {
            query.get();
        }
    }
}
Also used : DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) QueryId(com.facebook.presto.spi.QueryId) TestingPrestoServer(com.facebook.presto.server.testing.TestingPrestoServer) ArrayList(java.util.ArrayList) QueryInfo(com.facebook.presto.execution.QueryInfo) Future(java.util.concurrent.Future) Test(org.testng.annotations.Test)

Example 42 with QueryId

use of com.facebook.presto.spi.QueryId in project presto by prestodb.

the class TestQueues method testBasic.

@Test(timeOut = 240_000)
public void testBasic() throws Exception {
    String dbConfigUrl = getDbConfigUrl();
    H2ResourceGroupsDao dao = getDao(dbConfigUrl);
    try (DistributedQueryRunner queryRunner = createQueryRunner(dbConfigUrl, dao)) {
        QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
        // submit first "dashboard" query
        QueryId firstDashboardQuery = createQuery(queryRunner, newDashboardSession(), LONG_LASTING_QUERY);
        // wait for the first "dashboard" query to start
        waitForQueryState(queryRunner, firstDashboardQuery, RUNNING);
        assertEquals(queryManager.getStats().getRunningQueries(), 1);
        // submit second "dashboard" query
        QueryId secondDashboardQuery = createQuery(queryRunner, newDashboardSession(), LONG_LASTING_QUERY);
        MILLISECONDS.sleep(2000);
        // wait for the second "dashboard" query to be queued ("dashboard.${USER}" queue strategy only allows one "dashboard" query to be accepted for execution)
        waitForQueryState(queryRunner, secondDashboardQuery, QUEUED);
        assertEquals(queryManager.getStats().getRunningQueries(), 1);
        // Update db to allow for 1 more running query in dashboard resource group
        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);
        QueryId thirdDashboardQuery = createQuery(queryRunner, newDashboardSession(), LONG_LASTING_QUERY);
        waitForQueryState(queryRunner, thirdDashboardQuery, QUEUED);
        assertEquals(queryManager.getStats().getRunningQueries(), 2);
        // submit first non "dashboard" query
        QueryId firstNonDashboardQuery = createQuery(queryRunner, newSession(), LONG_LASTING_QUERY);
        // wait for the first non "dashboard" query to start
        waitForQueryState(queryRunner, firstNonDashboardQuery, RUNNING);
        assertEquals(queryManager.getStats().getRunningQueries(), 3);
        // submit second non "dashboard" query
        QueryId secondNonDashboardQuery = createQuery(queryRunner, newSession(), LONG_LASTING_QUERY);
        // wait for the second non "dashboard" query to start
        waitForQueryState(queryRunner, secondNonDashboardQuery, RUNNING);
        assertEquals(queryManager.getStats().getRunningQueries(), 4);
        // cancel first "dashboard" query, the second "dashboard" query and second non "dashboard" query should start running
        cancelQuery(queryRunner, firstDashboardQuery);
        waitForQueryState(queryRunner, firstDashboardQuery, FAILED);
        waitForQueryState(queryRunner, thirdDashboardQuery, RUNNING);
        assertEquals(queryManager.getStats().getRunningQueries(), 4);
        assertEquals(queryManager.getStats().getCompletedQueries().getTotalCount(), 1);
    }
}
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)

Aggregations

QueryId (com.facebook.presto.spi.QueryId)42 Test (org.testng.annotations.Test)26 Session (com.facebook.presto.Session)20 AllowAllAccessControl (com.facebook.presto.security.AllowAllAccessControl)17 AccessControl (com.facebook.presto.security.AccessControl)15 AccessControlManager (com.facebook.presto.security.AccessControlManager)15 TransactionManager (com.facebook.presto.transaction.TransactionManager)15 TransactionManager.createTestTransactionManager (com.facebook.presto.transaction.TransactionManager.createTestTransactionManager)15 DistributedQueryRunner (com.facebook.presto.tests.DistributedQueryRunner)10 StartTransaction (com.facebook.presto.sql.tree.StartTransaction)7 CompletionException (java.util.concurrent.CompletionException)7 PrestoException (com.facebook.presto.spi.PrestoException)6 MemoryPoolId (com.facebook.presto.spi.memory.MemoryPoolId)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 DataSize (io.airlift.units.DataSize)5 QueryInfo (com.facebook.presto.execution.QueryInfo)4 MemoryPool (com.facebook.presto.memory.MemoryPool)4 QueryContext (com.facebook.presto.memory.QueryContext)4 ResourceGroupManagerPlugin (com.facebook.presto.resourceGroups.ResourceGroupManagerPlugin)4 H2ResourceGroupsDao (com.facebook.presto.resourceGroups.db.H2ResourceGroupsDao)4