use of com.facebook.presto.server.BasicQueryInfo in project presto by prestodb.
the class TestGracefulShutdown method testShutdown.
@Test(timeOut = SHUTDOWN_TIMEOUT_MILLIS, dataProvider = "testServerInfo")
public void testShutdown(String serverInstanceType, Map<String, String> properties) throws Exception {
try (DistributedQueryRunner queryRunner = createQueryRunner(TINY_SESSION, properties)) {
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")));
}
boolean isCoordinatorInstance = serverInstanceType.equals(COORDINATOR);
TestingPrestoServer testServer = queryRunner.getServers().stream().filter(server -> server.isCoordinator() == isCoordinatorInstance).findFirst().get();
if (!isCoordinatorInstance) {
TaskManager taskManager = testServer.getTaskManager();
while (taskManager.getAllTaskInfo().isEmpty()) {
MILLISECONDS.sleep(500);
}
}
testServer.getGracefulShutdownHandler().requestShutdown();
Futures.allAsList(queryFutures).get();
List<BasicQueryInfo> queryInfos = queryRunner.getCoordinator().getQueryManager().getQueries();
for (BasicQueryInfo info : queryInfos) {
assertEquals(info.getState(), FINISHED);
}
TestShutdownAction shutdownAction = (TestShutdownAction) testServer.getShutdownAction();
shutdownAction.waitForShutdownComplete(SHUTDOWN_TIMEOUT_MILLIS);
assertTrue(shutdownAction.isShutdown());
}
}
use of com.facebook.presto.server.BasicQueryInfo in project presto by prestodb.
the class TestMetadataManager method testMetadataIsClearedAfterQueryCanceled.
@Test
public void testMetadataIsClearedAfterQueryCanceled() throws Exception {
DispatchManager dispatchManager = queryRunner.getCoordinator().getDispatchManager();
QueryId queryId = dispatchManager.createQueryId();
dispatchManager.createQuery(queryId, "slug", 0, new TestingSessionContext(TEST_SESSION), "SELECT * FROM lineitem").get();
// wait until query starts running
while (true) {
BasicQueryInfo queryInfo = dispatchManager.getQueryInfo(queryId);
if (queryInfo.getState().isDone()) {
assertEquals(queryInfo.getState(), FAILED);
throw dispatchManager.getDispatchInfo(queryId).get().getFailureInfo().get().toException();
}
if (queryInfo.getState() == RUNNING) {
break;
}
Thread.sleep(100);
}
// cancel query
dispatchManager.cancelQuery(queryId);
assertEquals(metadataManager.getCatalogsByQueryId().size(), 0);
}
use of com.facebook.presto.server.BasicQueryInfo in project presto by prestodb.
the class TestQueryTaskLimit method waitForQueryToBeKilled.
private void waitForQueryToBeKilled(DistributedQueryRunner queryRunner) throws InterruptedException {
while (true) {
for (BasicQueryInfo info : queryRunner.getCoordinator().getQueryManager().getQueries()) {
if (info.getState().isDone()) {
assertNotNull(info.getErrorCode());
assertEquals(info.getErrorCode().getCode(), QUERY_HAS_TOO_MANY_STAGES.toErrorCode().getCode());
MILLISECONDS.sleep(100);
return;
}
}
MILLISECONDS.sleep(10);
}
}
use of com.facebook.presto.server.BasicQueryInfo in project presto by prestodb.
the class TestQueryManager method testQueryCpuLimit.
@Test(timeOut = 60_000L)
public void testQueryCpuLimit() throws Exception {
try (DistributedQueryRunner queryRunner = builder().setSingleExtraProperty("query.max-cpu-time", "1ms").build()) {
QueryId queryId = createQuery(queryRunner, TEST_SESSION, "SELECT COUNT(*) FROM lineitem");
waitForQueryState(queryRunner, queryId, FAILED);
QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
BasicQueryInfo queryInfo = queryManager.getQueryInfo(queryId);
assertEquals(queryInfo.getState(), FAILED);
assertEquals(queryInfo.getErrorCode(), EXCEEDED_CPU_LIMIT.toErrorCode());
}
}
use of com.facebook.presto.server.BasicQueryInfo in project presto by prestodb.
the class TestQueues method testQueuedQueryInteraction.
@Test(timeOut = 60_000)
public void testQueuedQueryInteraction() throws Exception {
queryRunner.installPlugin(new ResourceGroupManagerPlugin());
queryRunner.getCoordinator().getResourceGroupManager().get().setConfigurationManager("file", ImmutableMap.of("resource-groups.config-file", getResourceFilePath("resource_groups_config_dashboard.json")));
// submit first "dashboard" query
QueryId firstDashboardQuery = createDashboardQuery(queryRunner);
// wait for the first "dashboard" query to start
waitForQueryState(queryRunner, firstDashboardQuery, RUNNING);
// submit second "dashboard" query
QueryId secondDashboardQuery = createDashboardQuery(queryRunner);
// 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);
// Retrieve information for the queued query
BasicQueryInfo queryInfo = getBasicQueryInfo("/v1/query/" + secondDashboardQuery.getId());
assertNotNull(queryInfo);
assertEquals(queryInfo.getState(), QUEUED);
assertEquals(queryInfo.getQuery(), LONG_LASTING_QUERY);
assertNotNull(queryInfo.getQueryStats());
killQuery(format("/v1/query/%s/killed", secondDashboardQuery.getId()));
queryInfo = getBasicQueryInfo("/v1/query/" + secondDashboardQuery.getId());
assertNotNull(queryInfo);
assertEquals(queryInfo.getErrorCode(), ADMINISTRATIVELY_KILLED.toErrorCode());
// submit third "dashboard" query
QueryId thirdDashboardQuery = createDashboardQuery(queryRunner);
waitForQueryState(queryRunner, thirdDashboardQuery, QUEUED);
killQuery(format("/v1/query/%s/preempted", thirdDashboardQuery.getId()));
queryInfo = getBasicQueryInfo("/v1/query/" + thirdDashboardQuery.getId());
assertNotNull(queryInfo);
assertEquals(queryInfo.getErrorCode(), ADMINISTRATIVELY_PREEMPTED.toErrorCode());
}
Aggregations