Search in sources :

Example 1 with RUNNING

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."));
                }
            }
        }
    }
}
Also used : Plan(io.prestosql.sql.planner.Plan) Duration(io.airlift.units.Duration) PreDestroy(javax.annotation.PreDestroy) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) Locale(java.util.Locale) Map(java.util.Map) QueryMonitor(io.prestosql.event.QueryMonitor) StateCacheStore(io.prestosql.statestore.StateCacheStore) ClusterMemoryManager(io.prestosql.memory.ClusterMemoryManager) PrestoException(io.prestosql.spi.PrestoException) SharedQueryState(io.prestosql.statestore.SharedQueryState) StateMap(io.prestosql.spi.statestore.StateMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ErrorType(io.prestosql.spi.ErrorType) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) ExceededCpuLimitException(io.prestosql.ExceededCpuLimitException) Threads.threadsNamed(io.airlift.concurrent.Threads.threadsNamed) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) String.format(java.lang.String.format) Objects(java.util.Objects) List(java.util.List) SessionPropertyManager(io.prestosql.metadata.SessionPropertyManager) PostConstruct(javax.annotation.PostConstruct) GENERIC_INTERNAL_ERROR(io.prestosql.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR) SystemSessionProperties.getQueryMaxCpuTime(io.prestosql.SystemSessionProperties.getQueryMaxCpuTime) QueryEditorUIModule(io.prestosql.queryeditorui.QueryEditorUIModule) Nested(org.weakref.jmx.Nested) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) StateChangeListener(io.prestosql.execution.StateMachine.StateChangeListener) Logger(io.airlift.log.Logger) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ThreadPoolExecutorMBean(io.airlift.concurrent.ThreadPoolExecutorMBean) EmbedVersion(io.prestosql.version.EmbedVersion) Flatten(org.weakref.jmx.Flatten) QUERY_EXPIRE(io.prestosql.spi.StandardErrorCode.QUERY_EXPIRE) Supplier(java.util.function.Supplier) Inject(javax.inject.Inject) Managed(org.weakref.jmx.Managed) BasicQueryInfo(io.prestosql.server.BasicQueryInfo) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) RUNNING(io.prestosql.execution.QueryState.RUNNING) QueryId(io.prestosql.spi.QueryId) NoSuchElementException(java.util.NoSuchElementException) ExecutorService(java.util.concurrent.ExecutorService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) QuerySnapshotManager(io.prestosql.snapshot.QuerySnapshotManager) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) StateUtils.isMultiCoordinatorEnabled(io.prestosql.utils.StateUtils.isMultiCoordinatorEnabled) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Ordering(com.google.common.collect.Ordering) QueryOutputInfo(io.prestosql.execution.QueryExecution.QueryOutputInfo) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) StateStoreProvider(io.prestosql.statestore.StateStoreProvider) Futures.immediateFailedFuture(com.google.common.util.concurrent.Futures.immediateFailedFuture) StateStoreConstants(io.prestosql.statestore.StateStoreConstants) SharedQueryState(io.prestosql.statestore.SharedQueryState) PrestoException(io.prestosql.spi.PrestoException)

Example 2 with RUNNING

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;
        }
    }
}
Also used : HttpClient(io.airlift.http.client.HttpClient) Test(org.testng.annotations.Test) PRESTO_USER(io.prestosql.client.PrestoHeaders.PRESTO_USER) UnexpectedResponseException(io.airlift.http.client.UnexpectedResponseException) Assert.assertEquals(io.prestosql.testing.assertions.Assert.assertEquals) Request(io.airlift.http.client.Request) RUNNING(io.prestosql.execution.QueryState.RUNNING) AfterClass(org.testng.annotations.AfterClass) Builder.preparePost(io.airlift.http.client.Request.Builder.preparePost) Builder.prepareGet(io.airlift.http.client.Request.Builder.prepareGet) JettyHttpClient(io.airlift.http.client.jetty.JettyHttpClient) QueryResults(io.prestosql.client.QueryResults) Closeables.closeQuietly(io.airlift.testing.Closeables.closeQuietly) UTF_8(java.nio.charset.StandardCharsets.UTF_8) BeforeClass(org.testng.annotations.BeforeClass) TestingPrestoServer(io.prestosql.server.testing.TestingPrestoServer) Assert.assertNotNull(org.testng.Assert.assertNotNull) JsonCodec.jsonCodec(io.airlift.json.JsonCodec.jsonCodec) List(java.util.List) JsonCodec.listJsonCodec(io.airlift.json.JsonCodec.listJsonCodec) HttpUriBuilder.uriBuilderFrom(io.airlift.http.client.HttpUriBuilder.uriBuilderFrom) JsonResponseHandler.createJsonResponseHandler(io.airlift.http.client.JsonResponseHandler.createJsonResponseHandler) Assert.assertTrue(org.testng.Assert.assertTrue) StaticBodyGenerator.createStaticBodyGenerator(io.airlift.http.client.StaticBodyGenerator.createStaticBodyGenerator) JsonCodec(io.airlift.json.JsonCodec) TpchPlugin(io.prestosql.plugin.tpch.TpchPlugin) Request(io.airlift.http.client.Request) QueryResults(io.prestosql.client.QueryResults) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with RUNNING

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);
                }
            }
        }
    }
}
Also used : Plan(io.prestosql.sql.planner.Plan) Duration(io.airlift.units.Duration) PreDestroy(javax.annotation.PreDestroy) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) Locale(java.util.Locale) Map(java.util.Map) QueryMonitor(io.prestosql.event.QueryMonitor) StateCacheStore(io.prestosql.statestore.StateCacheStore) ClusterMemoryManager(io.prestosql.memory.ClusterMemoryManager) PrestoException(io.prestosql.spi.PrestoException) SharedQueryState(io.prestosql.statestore.SharedQueryState) StateMap(io.prestosql.spi.statestore.StateMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ErrorType(io.prestosql.spi.ErrorType) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) ExceededCpuLimitException(io.prestosql.ExceededCpuLimitException) Threads.threadsNamed(io.airlift.concurrent.Threads.threadsNamed) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) String.format(java.lang.String.format) Objects(java.util.Objects) List(java.util.List) SessionPropertyManager(io.prestosql.metadata.SessionPropertyManager) PostConstruct(javax.annotation.PostConstruct) GENERIC_INTERNAL_ERROR(io.prestosql.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR) SystemSessionProperties.getQueryMaxCpuTime(io.prestosql.SystemSessionProperties.getQueryMaxCpuTime) QueryEditorUIModule(io.prestosql.queryeditorui.QueryEditorUIModule) Nested(org.weakref.jmx.Nested) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) StateChangeListener(io.prestosql.execution.StateMachine.StateChangeListener) Logger(io.airlift.log.Logger) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ThreadPoolExecutorMBean(io.airlift.concurrent.ThreadPoolExecutorMBean) EmbedVersion(io.prestosql.version.EmbedVersion) Flatten(org.weakref.jmx.Flatten) QUERY_EXPIRE(io.prestosql.spi.StandardErrorCode.QUERY_EXPIRE) Supplier(java.util.function.Supplier) Inject(javax.inject.Inject) Managed(org.weakref.jmx.Managed) BasicQueryInfo(io.prestosql.server.BasicQueryInfo) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) RUNNING(io.prestosql.execution.QueryState.RUNNING) QueryId(io.prestosql.spi.QueryId) NoSuchElementException(java.util.NoSuchElementException) ExecutorService(java.util.concurrent.ExecutorService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) QuerySnapshotManager(io.prestosql.snapshot.QuerySnapshotManager) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) StateUtils.isMultiCoordinatorEnabled(io.prestosql.utils.StateUtils.isMultiCoordinatorEnabled) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Ordering(com.google.common.collect.Ordering) QueryOutputInfo(io.prestosql.execution.QueryExecution.QueryOutputInfo) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) StateStoreProvider(io.prestosql.statestore.StateStoreProvider) Futures.immediateFailedFuture(com.google.common.util.concurrent.Futures.immediateFailedFuture) StateStoreConstants(io.prestosql.statestore.StateStoreConstants) SharedQueryState(io.prestosql.statestore.SharedQueryState)

Aggregations

RUNNING (io.prestosql.execution.QueryState.RUNNING)3 List (java.util.List)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 Ordering (com.google.common.collect.Ordering)2 Futures.immediateFailedFuture (com.google.common.util.concurrent.Futures.immediateFailedFuture)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ThreadPoolExecutorMBean (io.airlift.concurrent.ThreadPoolExecutorMBean)2 Threads.threadsNamed (io.airlift.concurrent.Threads.threadsNamed)2 ObjectMapperProvider (io.airlift.json.ObjectMapperProvider)2 Logger (io.airlift.log.Logger)2 Duration (io.airlift.units.Duration)2 ExceededCpuLimitException (io.prestosql.ExceededCpuLimitException)2 Session (io.prestosql.Session)2 SystemSessionProperties.getQueryMaxCpuTime (io.prestosql.SystemSessionProperties.getQueryMaxCpuTime)2 QueryMonitor (io.prestosql.event.QueryMonitor)2 QueryOutputInfo (io.prestosql.execution.QueryExecution.QueryOutputInfo)2 StateChangeListener (io.prestosql.execution.StateMachine.StateChangeListener)2 ClusterMemoryManager (io.prestosql.memory.ClusterMemoryManager)2