private Response failQuery(QueryId queryId, PrestoException queryException) { requireNonNull(queryId, "queryId is null"); try { QueryState state = queryManager.getQueryState(queryId); // check before killing to provide the proper error code (this is racy) if (state.isDone()) { return Response.status(Status.CONFLICT).build(); } queryManager.failQuery(queryId, queryException); // verify if the query was failed (if not, we lost the race) if (!queryException.getErrorCode().equals(queryManager.getQueryInfo(queryId).getErrorCode())) { return Response.status(Status.CONFLICT).build(); } return Response.status(Status.OK).build(); } catch (NoSuchElementException e) { return Response.status(Status.GONE).build(); } }
private Response failQuery(QueryId queryId, PrestoException queryException) { requireNonNull(queryId, "queryId is null"); try { QueryState state = queryManager.getQueryState(queryId); // check before killing to provide the proper error code (this is racy) if (state.isDone()) { return Response.status(Status.CONFLICT).build(); } queryManager.failQuery(queryId, queryException); // verify if the query was failed (if not, we lost the race) if (!queryException.getErrorCode().equals(queryManager.getQueryInfo(queryId).getErrorCode())) { return Response.status(Status.CONFLICT).build(); } return Response.status(Status.OK).build(); } catch (NoSuchElementException e) { return Response.status(Status.GONE).build(); } }
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(), CLUSTER_OUT_OF_MEMORY.toErrorCode().getCode()); return; } } MILLISECONDS.sleep(10); } }
@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()); } } }
private void testRejection() throws Exception { try (DistributedQueryRunner queryRunner = createQueryRunner()) { queryRunner.installPlugin(new ResourceGroupManagerPlugin()); queryRunner.getCoordinator().getResourceGroupManager().get().setConfigurationManager("file", ImmutableMap.of("resource-groups.config-file", getResourceFilePath("resource_groups_config_dashboard.json"))); 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()); } }
@UsedByGeneratedCode public void killQuery(String queryId, String message) { QueryId query = parseQueryId(queryId); try { QueryState state = queryManager.getQueryState(query); // check before killing to provide the proper error message (this is racy) if (state.isDone()) { throw new PrestoException(NOT_SUPPORTED, "Target query is not running: " + queryId); } queryManager.failQuery(query, createKillQueryException(message)); // verify if the query was killed (if not, we lost the race) if (!ADMINISTRATIVELY_KILLED.toErrorCode().equals(queryManager.getQueryInfo(query).getErrorCode())) { throw new PrestoException(NOT_SUPPORTED, "Target query is not running: " + queryId); } } catch (NoSuchElementException e) { throw new PrestoException(NOT_FOUND, "Target query not found: " + queryId); } }
@UsedByGeneratedCode public void killQuery(String queryId, String message) { QueryId query = parseQueryId(queryId); try { QueryState state = queryManager.getQueryState(query); // check before killing to provide the proper error message (this is racy) if (state.isDone()) { throw new PrestoException(NOT_SUPPORTED, "Target query is not running: " + queryId); } queryManager.failQuery(query, createKillQueryException(message)); // verify if the query was killed (if not, we lost the race) if (!ADMINISTRATIVELY_KILLED.toErrorCode().equals(queryManager.getQueryInfo(query).getErrorCode())) { throw new PrestoException(NOT_SUPPORTED, "Target query is not running: " + queryId); } } catch (NoSuchElementException e) { throw new PrestoException(NOT_FOUND, "Target query not found: " + queryId); } }
assertEquals(basicInfo.getErrorCode(), StandardErrorCode.ABANDONED_QUERY.toErrorCode()); assertEquals(basicInfo.getErrorType(), StandardErrorCode.ABANDONED_QUERY.toErrorCode().getType());
assertEquals(basicInfo.getErrorCode(), StandardErrorCode.ABANDONED_QUERY.toErrorCode()); assertEquals(basicInfo.getErrorType(), StandardErrorCode.ABANDONED_QUERY.toErrorCode().getType());