Search in sources :

Example 6 with QueryId

use of com.facebook.presto.spi.QueryId 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 7 with QueryId

use of com.facebook.presto.spi.QueryId 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 8 with QueryId

use of com.facebook.presto.spi.QueryId 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 9 with QueryId

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

the class TestMemoryManager method testClusterPools.

@Test(timeOut = 240_000)
public void testClusterPools() throws Exception {
    Map<String, String> properties = ImmutableMap.<String, String>builder().put("task.verbose-stats", "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")));
        }
        ClusterMemoryManager memoryManager = queryRunner.getCoordinator().getClusterMemoryManager();
        ClusterMemoryPool reservedPool;
        while ((reservedPool = memoryManager.getPools().get(RESERVED_POOL)) == null) {
            MILLISECONDS.sleep(10);
        }
        ClusterMemoryPool generalPool = memoryManager.getPools().get(GENERAL_POOL);
        assertNotNull(generalPool);
        // Wait for the queries to start running and get assigned to the expected pools
        while (generalPool.getAssignedQueries() != 1 || reservedPool.getAssignedQueries() != 1 || generalPool.getBlockedNodes() != 2 || reservedPool.getBlockedNodes() != 2) {
            MILLISECONDS.sleep(10);
        }
        // Make sure the queries are blocked
        List<QueryInfo> currentQueryInfos = queryRunner.getCoordinator().getQueryManager().getAllQueryInfo();
        for (QueryInfo info : currentQueryInfos) {
            assertFalse(info.getState().isDone());
        }
        assertEquals(currentQueryInfos.size(), 2);
        // Check that the pool information propagated to the query objects
        assertNotEquals(currentQueryInfos.get(0).getMemoryPool(), currentQueryInfos.get(1).getMemoryPool());
        while (!allQueriesBlocked(currentQueryInfos)) {
            MILLISECONDS.sleep(10);
            currentQueryInfos = queryRunner.getCoordinator().getQueryManager().getAllQueryInfo();
            for (QueryInfo info : currentQueryInfos) {
                assertFalse(info.getState().isDone());
            }
        }
        // Release the memory in the reserved pool and the system 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);
            MemoryPool system = server.getLocalMemoryManager().getPool(SYSTEM_POOL);
            // Free up the entire pool
            system.free(fakeQueryId, system.getMaxBytes());
            assertTrue(system.getFreeBytes() > 0);
        }
        // This also checks that the query in the general pool is successfully moved to the reserved pool.
        for (Future<?> query : queryFutures) {
            query.get();
        }
        List<QueryInfo> queryInfos = queryRunner.getCoordinator().getQueryManager().getAllQueryInfo();
        for (QueryInfo info : queryInfos) {
            assertEquals(info.getState(), FINISHED);
        }
        // Make sure we didn't leak any memory on the workers
        for (TestingPrestoServer worker : queryRunner.getServers()) {
            MemoryPool reserved = worker.getLocalMemoryManager().getPool(RESERVED_POOL);
            assertEquals(reserved.getMaxBytes(), reserved.getFreeBytes());
            MemoryPool general = worker.getLocalMemoryManager().getPool(GENERAL_POOL);
            // Free up the memory we reserved earlier
            general.free(fakeQueryId, general.getMaxBytes());
            assertEquals(general.getMaxBytes(), general.getFreeBytes());
            MemoryPool system = worker.getLocalMemoryManager().getPool(SYSTEM_POOL);
            assertEquals(system.getMaxBytes(), system.getFreeBytes());
        }
    }
}
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 10 with QueryId

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

the class InformationSchemaPageSourceProvider method getInternalTable.

private InternalTable getInternalTable(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, ConnectorSplit connectorSplit, List<ColumnHandle> columns) {
    InformationSchemaTransactionHandle transaction = (InformationSchemaTransactionHandle) transactionHandle;
    InformationSchemaSplit split = (InformationSchemaSplit) connectorSplit;
    requireNonNull(columns, "columns is null");
    InformationSchemaTableHandle handle = split.getTableHandle();
    Map<String, NullableValue> filters = split.getFilters();
    Session session = Session.builder(metadata.getSessionPropertyManager()).setTransactionId(transaction.getTransactionId()).setQueryId(new QueryId(connectorSession.getQueryId())).setIdentity(connectorSession.getIdentity()).setSource("information_schema").setCatalog(// default catalog is not be used
    "").setSchema(// default schema is not be used
    "").setTimeZoneKey(connectorSession.getTimeZoneKey()).setLocale(connectorSession.getLocale()).setStartTime(connectorSession.getStartTime()).build();
    return getInformationSchemaTable(session, handle.getCatalogName(), handle.getSchemaTableName(), filters);
}
Also used : QueryId(com.facebook.presto.spi.QueryId) NullableValue(com.facebook.presto.spi.predicate.NullableValue) ConnectorSession(com.facebook.presto.spi.ConnectorSession) Session(com.facebook.presto.Session)

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