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);
}
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;
}
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);
});
}
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);
}
}
}
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());
}
Aggregations