Search in sources :

Example 1 with QUERY_EXPIRE

use of io.prestosql.spi.StandardErrorCode.QUERY_EXPIRE 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)

Aggregations

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