Search in sources :

Example 6 with QueryManager

use of io.prestosql.execution.QueryManager in project hetu-core by openlookeng.

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
    // Hetu: add parameters softReservedMemory and hardReservedConcurrency
    dao.updateResourceGroup(5, "dashboard-${USER}", "1MB", "1MB", 1, null, 0, 0, null, null, null, null, null, "RECENT_QUERIES", 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
    // Hetu: add parameters softReservedMemory and hardReservedConcurrency
    dao.updateResourceGroup(5, "dashboard-${USER}", "1MB", "1MB", 1, null, 1, 0, null, null, null, null, null, "RECENT_QUERIES", 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.prestosql.plugin.resourcegroups.db.DbResourceGroupConfigurationManager) DispatchManager(io.prestosql.dispatcher.DispatchManager) QueryId(io.prestosql.spi.QueryId) QueryManager(io.prestosql.execution.QueryManager) Test(org.testng.annotations.Test)

Example 7 with QueryManager

use of io.prestosql.execution.QueryManager in project hetu-core by openlookeng.

the class ExecutingStatementResource method getQuery.

protected Query getQuery(QueryId queryId, String slug) {
    Query query = queries.get(queryId);
    if (query != null) {
        if (!query.isSlugValid(slug)) {
            throw badRequest(NOT_FOUND, "Query not found");
        }
        return query;
    }
    // this is the first time the query has been accessed on this coordinator
    Session session;
    try {
        if (!queryManager.isQuerySlugValid(queryId, slug)) {
            throw badRequest(NOT_FOUND, "Query not found");
        }
        session = queryManager.getQuerySession(queryId);
    } catch (NoSuchElementException e) {
        throw badRequest(NOT_FOUND, "Query not found");
    }
    query = queries.computeIfAbsent(queryId, id -> {
        ExchangeClient exchangeClient = exchangeClientSupplier.get(new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), ExecutingStatementResource.class.getSimpleName()));
        if (SystemSessionProperties.isSnapshotEnabled(session)) {
            exchangeClient.setSnapshotEnabled(snapshotUtils.getOrCreateQuerySnapshotManager(queryId, session));
        }
        return Query.create(session, slug, queryManager, exchangeClient, responseExecutor, timeoutExecutor, blockEncodingSerde);
    });
    return query;
}
Also used : Produces(javax.ws.rs.Produces) SystemSessionProperties(io.prestosql.SystemSessionProperties) Path(javax.ws.rs.Path) Duration(io.airlift.units.Duration) QueryManager(io.prestosql.execution.QueryManager) PreDestroy(javax.annotation.PreDestroy) MediaType(javax.ws.rs.core.MediaType) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) QueryParam(javax.ws.rs.QueryParam) BoundedExecutor(io.airlift.concurrent.BoundedExecutor) SimpleLocalMemoryContext(io.prestosql.memory.context.SimpleLocalMemoryContext) SnapshotUtils(io.prestosql.snapshot.SnapshotUtils) HeaderParam(javax.ws.rs.HeaderParam) X_FORWARDED_PROTO(com.google.common.net.HttpHeaders.X_FORWARDED_PROTO) PRESTO_SET_ROLE(io.prestosql.client.PrestoHeaders.PRESTO_SET_ROLE) DELETE(javax.ws.rs.DELETE) Context(javax.ws.rs.core.Context) AsyncResponse(javax.ws.rs.container.AsyncResponse) NOT_FOUND(javax.ws.rs.core.Response.Status.NOT_FOUND) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Threads.threadsNamed(io.airlift.concurrent.Threads.threadsNamed) QueryStatusInfo(io.prestosql.client.QueryStatusInfo) Suspended(javax.ws.rs.container.Suspended) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) DataSize(io.airlift.units.DataSize) Response(javax.ws.rs.core.Response) Entry(java.util.Map.Entry) WebApplicationException(javax.ws.rs.WebApplicationException) UriInfo(javax.ws.rs.core.UriInfo) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AsyncResponseHandler.bindAsyncResponse(io.airlift.jaxrs.AsyncResponseHandler.bindAsyncResponse) AggregatedMemoryContext.newSimpleAggregatedMemoryContext(io.prestosql.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext) PRESTO_CLEAR_TRANSACTION_ID(io.prestosql.client.PrestoHeaders.PRESTO_CLEAR_TRANSACTION_ID) PathParam(javax.ws.rs.PathParam) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Logger(io.airlift.log.Logger) GET(javax.ws.rs.GET) PRESTO_SET_CATALOG(io.prestosql.client.PrestoHeaders.PRESTO_SET_CATALOG) MEGABYTE(io.airlift.units.DataSize.Unit.MEGABYTE) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) BlockEncodingSerde(io.prestosql.spi.block.BlockEncodingSerde) PRESTO_CLEAR_SESSION(io.prestosql.client.PrestoHeaders.PRESTO_CLEAR_SESSION) ExchangeClient(io.prestosql.operator.ExchangeClient) ConcurrentMap(java.util.concurrent.ConcurrentMap) Inject(javax.inject.Inject) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) QueryId(io.prestosql.spi.QueryId) NoSuchElementException(java.util.NoSuchElementException) Status(javax.ws.rs.core.Response.Status) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) QueryResults(io.prestosql.client.QueryResults) ForStatementResource(io.prestosql.server.ForStatementResource) PRESTO_SET_PATH(io.prestosql.client.PrestoHeaders.PRESTO_SET_PATH) PRESTO_STARTED_TRANSACTION_ID(io.prestosql.client.PrestoHeaders.PRESTO_STARTED_TRANSACTION_ID) TEXT_PLAIN_TYPE(javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE) Futures(com.google.common.util.concurrent.Futures) URLEncoder(java.net.URLEncoder) PRESTO_SET_SCHEMA(io.prestosql.client.PrestoHeaders.PRESTO_SET_SCHEMA) PRESTO_ADDED_PREPARE(io.prestosql.client.PrestoHeaders.PRESTO_ADDED_PREPARE) Ordering(com.google.common.collect.Ordering) ExchangeClientSupplier(io.prestosql.operator.ExchangeClientSupplier) PRESTO_DEALLOCATED_PREPARE(io.prestosql.client.PrestoHeaders.PRESTO_DEALLOCATED_PREPARE) PRESTO_SET_SESSION(io.prestosql.client.PrestoHeaders.PRESTO_SET_SESSION) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ExchangeClient(io.prestosql.operator.ExchangeClient) SimpleLocalMemoryContext(io.prestosql.memory.context.SimpleLocalMemoryContext) NoSuchElementException(java.util.NoSuchElementException) Session(io.prestosql.Session)

Example 8 with QueryManager

use of io.prestosql.execution.QueryManager in project hetu-core by openlookeng.

the class TestOracleDistributedQueries method testQueryLoggingCount.

/**
 * testQueryLoggingCount
 */
@Override
public void testQueryLoggingCount() {
    QueryManager queryManager = ((DistributedQueryRunner) getQueryRunner()).getCoordinator().getQueryManager();
    executeExclusively(() -> {
        assertUntilTimeout(() -> assertEquals(queryManager.getQueries().stream().map(BasicQueryInfo::getQueryId).map(queryManager::getFullQueryInfo).filter(info -> !info.isFinalQueryInfo()).collect(toList()), ImmutableList.of()), new Duration(1, MINUTES));
        DispatchManager dispatchManager = ((DistributedQueryRunner) getQueryRunner()).getCoordinator().getDispatchManager();
        long beforeCompletedQueriesCount = waitUntilStable(() -> dispatchManager.getStats().getCompletedQueries().getTotalCount(), new Duration(NUMBER_5, SECONDS));
        long beforeSubmittedQueriesCount = dispatchManager.getStats().getSubmittedQueries().getTotalCount();
        assertUpdate("CREATE TABLE test_query_logging_count AS SELECT 1 foo_1, 2 foo_2_4", 1);
        assertQuery("SELECT foo_1, foo_2_4 FROM test_query_logging_count", "SELECT 1, 2");
        assertUpdate("DROP TABLE test_query_logging_count");
        assertQueryFails("SELECT * FROM test_query_logging_count", ".*Table .* does not exist");
        assertUntilTimeout(() -> assertEquals(dispatchManager.getStats().getCompletedQueries().getTotalCount() - beforeCompletedQueriesCount, NUMBER_4), new Duration(1, MINUTES));
        assertEquals(dispatchManager.getStats().getSubmittedQueries().getTotalCount() - beforeSubmittedQueriesCount, NUMBER_4);
    });
}
Also used : IntStream.range(java.util.stream.IntStream.range) SystemSessionProperties(io.prestosql.SystemSessionProperties) QueryInfo(io.prestosql.execution.QueryInfo) Test(org.testng.annotations.Test) Thread.currentThread(java.lang.Thread.currentThread) INFORMATION_SCHEMA(io.prestosql.connector.informationschema.InformationSchemaMetadata.INFORMATION_SCHEMA) MaterializedResult(io.prestosql.testing.MaterializedResult) Duration(io.airlift.units.Duration) ADD_COLUMN(io.prestosql.testing.TestingAccessControlManager.TestingPrivilegeType.ADD_COLUMN) RENAME_TABLE(io.prestosql.testing.TestingAccessControlManager.TestingPrivilegeType.RENAME_TABLE) SET_SESSION(io.prestosql.testing.TestingAccessControlManager.TestingPrivilegeType.SET_SESSION) Assertions(io.airlift.testing.Assertions) QueryManager(io.prestosql.execution.QueryManager) DistributedQueryRunner(io.prestosql.tests.DistributedQueryRunner) Duration.nanosSince(io.airlift.units.Duration.nanosSince) Assert.assertFalse(org.testng.Assert.assertFalse) CREATE_TABLE(io.prestosql.testing.TestingAccessControlManager.TestingPrivilegeType.CREATE_TABLE) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) AbstractTestDistributedQueries(io.prestosql.tests.AbstractTestDistributedQueries) OracleQueryRunner.createOracleQueryRunner(io.hetu.core.plugin.oracle.OracleQueryRunner.createOracleQueryRunner) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Uninterruptibles.sleepUninterruptibly(com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly) DROP_COLUMN(io.prestosql.testing.TestingAccessControlManager.TestingPrivilegeType.DROP_COLUMN) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) TpchTable(io.airlift.tpch.TpchTable) CREATE_VIEW(io.prestosql.testing.TestingAccessControlManager.TestingPrivilegeType.CREATE_VIEW) SET_USER(io.prestosql.testing.TestingAccessControlManager.TestingPrivilegeType.SET_USER) Assert.assertNull(org.testng.Assert.assertNull) QueryAssertions.assertContains(io.prestosql.tests.QueryAssertions.assertContains) TESTING_CATALOG(io.prestosql.testing.TestingSession.TESTING_CATALOG) Assert.assertEquals(org.testng.Assert.assertEquals) MINUTES(java.util.concurrent.TimeUnit.MINUTES) Supplier(java.util.function.Supplier) TestingAccessControlManager.privilege(io.prestosql.testing.TestingAccessControlManager.privilege) ImmutableList(com.google.common.collect.ImmutableList) BasicQueryInfo(io.prestosql.server.BasicQueryInfo) Session(io.prestosql.Session) UncheckedTimeoutException(com.google.common.util.concurrent.UncheckedTimeoutException) DispatchManager(io.prestosql.dispatcher.DispatchManager) AfterClass(org.testng.annotations.AfterClass) ResultWithQueryId(io.prestosql.tests.ResultWithQueryId) Language(org.intellij.lang.annotations.Language) QUERY_MAX_MEMORY(io.prestosql.SystemSessionProperties.QUERY_MAX_MEMORY) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) Collectors.toList(java.util.stream.Collectors.toList) DROP_TABLE(io.prestosql.testing.TestingAccessControlManager.TestingPrivilegeType.DROP_TABLE) Assert.assertTrue(org.testng.Assert.assertTrue) RENAME_COLUMN(io.prestosql.testing.TestingAccessControlManager.TestingPrivilegeType.RENAME_COLUMN) SECONDS(java.util.concurrent.TimeUnit.SECONDS) DispatchManager(io.prestosql.dispatcher.DispatchManager) QueryManager(io.prestosql.execution.QueryManager) Duration(io.airlift.units.Duration)

Example 9 with QueryManager

use of io.prestosql.execution.QueryManager in project hetu-core by openlookeng.

the class TestNodeStateChange method testCoordinatorIsolation.

@Test(timeOut = 30_000)
public void testCoordinatorIsolation() throws Exception {
    try (DistributedQueryRunner queryRunner = createQueryRunner(TINY_SESSION, defaultProperties)) {
        List<ListenableFuture<?>> queryFutures = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            queryFutures.add(executor.submit(() -> queryRunner.execute("SELECT COUNT(*), clerk FROM orders GROUP BY clerk")));
        }
        TestingPrestoServer coordinator = queryRunner.getServers().stream().filter(TestingPrestoServer::isCoordinator).findFirst().get();
        QueryManager queryManager = coordinator.getQueryManager();
        // wait until queries show up on the coordinator
        while (queryManager.getQueries().isEmpty()) {
            MILLISECONDS.sleep(500);
        }
        assertEquals(coordinator.getNodeStateChangeHandler().getState(), NodeState.ACTIVE);
        coordinator.getNodeStateChangeHandler().doStateTransition(NodeState.ISOLATING);
        Futures.allAsList(queryFutures).get();
        List<BasicQueryInfo> queryInfos = queryRunner.getCoordinator().getQueryManager().getQueries();
        for (BasicQueryInfo info : queryInfos) {
            assertEquals(info.getState(), FINISHED);
        }
        while (!coordinator.getNodeStateChangeHandler().getState().equals(NodeState.ISOLATED)) {
            Thread.sleep(1000);
        }
    }
}
Also used : BasicQueryInfo(io.prestosql.server.BasicQueryInfo) ArrayList(java.util.ArrayList) TestingPrestoServer(io.prestosql.server.testing.TestingPrestoServer) QueryManager(io.prestosql.execution.QueryManager) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Test(org.testng.annotations.Test)

Example 10 with QueryManager

use of io.prestosql.execution.QueryManager in project hetu-core by openlookeng.

the class TestQueuesDb method testNonLeafGroup.

@Test
public void testNonLeafGroup() throws Exception {
    Session session = testSessionBuilder().setCatalog("tpch").setSchema("sf100000").setSource("non-leaf").build();
    QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
    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.*", "(?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.prestosql.plugin.resourcegroups.db.DbResourceGroupConfigurationManager) QueryId(io.prestosql.spi.QueryId) QueryManager(io.prestosql.execution.QueryManager) H2TestUtil.adhocSession(io.prestosql.execution.resourcegroups.db.H2TestUtil.adhocSession) H2TestUtil.dashboardSession(io.prestosql.execution.resourcegroups.db.H2TestUtil.dashboardSession) H2TestUtil.rejectingSession(io.prestosql.execution.resourcegroups.db.H2TestUtil.rejectingSession) Session(io.prestosql.Session) Test(org.testng.annotations.Test)

Aggregations

QueryManager (io.prestosql.execution.QueryManager)10 Test (org.testng.annotations.Test)9 BasicQueryInfo (io.prestosql.server.BasicQueryInfo)7 QueryId (io.prestosql.spi.QueryId)6 DispatchManager (io.prestosql.dispatcher.DispatchManager)5 Session (io.prestosql.Session)4 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)3 Duration (io.airlift.units.Duration)3 SystemSessionProperties (io.prestosql.SystemSessionProperties)3 QueryInfo (io.prestosql.execution.QueryInfo)3 DbResourceGroupConfigurationManager (io.prestosql.plugin.resourcegroups.db.DbResourceGroupConfigurationManager)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)2 UncheckedTimeoutException (com.google.common.util.concurrent.UncheckedTimeoutException)2 Uninterruptibles.sleepUninterruptibly (com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly)2 Assertions (io.airlift.testing.Assertions)2 Duration.nanosSince (io.airlift.units.Duration.nanosSince)2 QUERY_MAX_MEMORY (io.prestosql.SystemSessionProperties.QUERY_MAX_MEMORY)2