use of io.prestosql.execution.QueryState.RUNNING in project hetu-core by openlookeng.
the class SqlQueryManager method killExpiredQuery.
/**
* Kill query when expired, state has already been updated in StateFetcher.
*/
private void killExpiredQuery() {
if (!isMultiCoordinatorEnabled()) {
return;
}
List<QueryExecution> localRunningQueries = queryTracker.getAllQueries().stream().filter(query -> query.getState() == RUNNING).collect(toImmutableList());
Map<String, SharedQueryState> queries = StateCacheStore.get().getCachedStates(StateStoreConstants.FINISHED_QUERY_STATE_COLLECTION_NAME);
if (queries != null) {
Set<String> expiredQueryIds = queries.entrySet().stream().filter(entry -> isQueryExpired(entry.getValue())).map(entry -> entry.getKey()).collect(Collectors.toSet());
if (!expiredQueryIds.isEmpty()) {
for (QueryExecution localQuery : localRunningQueries) {
if (expiredQueryIds.contains(localQuery.getQueryId().getId())) {
localQuery.fail(new PrestoException(QUERY_EXPIRE, "Query killed because the query has expired. Please try again in a few minutes."));
}
}
}
}
}
use of io.prestosql.execution.QueryState.RUNNING in project hetu-core by openlookeng.
the class TestQueryStateInfoResource method setup.
@BeforeClass
public void setup() {
Request request1 = preparePost().setUri(uriBuilderFrom(server.getBaseUrl()).replacePath("/v1/statement").build()).setBodyGenerator(createStaticBodyGenerator(LONG_LASTING_QUERY, UTF_8)).setHeader(PRESTO_USER, "user1").build();
queryResults = client.execute(request1, createJsonResponseHandler(QUERY_RESULTS_JSON_CODEC));
client.execute(prepareGet().setUri(queryResults.getNextUri()).build(), createJsonResponseHandler(QUERY_RESULTS_JSON_CODEC));
Request request2 = preparePost().setUri(uriBuilderFrom(server.getBaseUrl()).replacePath("/v1/statement").build()).setBodyGenerator(createStaticBodyGenerator(LONG_LASTING_QUERY, UTF_8)).setHeader(PRESTO_USER, "user2").build();
QueryResults queryResults2 = client.execute(request2, createJsonResponseHandler(jsonCodec(QueryResults.class)));
client.execute(prepareGet().setUri(queryResults2.getNextUri()).build(), createJsonResponseHandler(QUERY_RESULTS_JSON_CODEC));
// queries are started in the background, so they may not all be immediately visible
while (true) {
List<BasicQueryInfo> queryInfos1 = client.execute(prepareGet().setUri(uriBuilderFrom(server.getBaseUrl()).replacePath("/v1/query").build()).setHeader(PRESTO_USER, "user1").build(), createJsonResponseHandler(listJsonCodec(BasicQueryInfo.class)));
List<BasicQueryInfo> queryInfos2 = client.execute(prepareGet().setUri(uriBuilderFrom(server.getBaseUrl()).replacePath("/v1/query").build()).setHeader(PRESTO_USER, "user2").build(), createJsonResponseHandler(listJsonCodec(BasicQueryInfo.class)));
if ((queryInfos1.size() == 1) && queryInfos1.stream().allMatch(info -> info.getState() == RUNNING) && (queryInfos2.size() == 1) && queryInfos2.stream().allMatch(info -> info.getState() == RUNNING)) {
break;
}
}
}
use of io.prestosql.execution.QueryState.RUNNING in project hetu-core by openlookeng.
the class SqlQueryManager method killBlockingQuery.
/**
* Kill query when cluster is in OOM state
*/
private void killBlockingQuery() {
if (isMultiCoordinatorEnabled()) {
return;
}
List<QueryExecution> localRunningQueries = queryTracker.getAllQueries().stream().filter(query -> query.getState() == RUNNING).collect(toImmutableList());
Map<String, SharedQueryState> queries = StateCacheStore.get().getCachedStates(StateStoreConstants.OOM_QUERY_STATE_COLLECTION_NAME);
if (queries != null) {
for (SharedQueryState query : queries.values()) {
for (QueryExecution localQuery : localRunningQueries) {
if (query.getBasicQueryInfo().getQueryId().equals(localQuery.getQueryId())) {
memoryManager.killLocalQuery(localQuery);
}
}
}
}
}
Aggregations