Search in sources :

Example 1 with EXCEEDED_TIME_LIMIT

use of io.trino.spi.StandardErrorCode.EXCEEDED_TIME_LIMIT in project trino by trinodb.

the class QueryTracker method enforceTimeLimits.

/**
 * Enforce query max runtime/execution time limits
 */
private void enforceTimeLimits() {
    for (T query : queries.values()) {
        if (query.isDone()) {
            continue;
        }
        Duration queryMaxRunTime = getQueryMaxRunTime(query.getSession());
        Duration queryMaxExecutionTime = getQueryMaxExecutionTime(query.getSession());
        Duration queryMaxPlanningTime = getQueryMaxPlanningTime(query.getSession());
        Optional<DateTime> executionStartTime = query.getExecutionStartTime();
        Optional<Duration> planningTime = query.getPlanningTime();
        DateTime createTime = query.getCreateTime();
        if (executionStartTime.isPresent() && executionStartTime.get().plus(queryMaxExecutionTime.toMillis()).isBeforeNow()) {
            query.fail(new TrinoException(EXCEEDED_TIME_LIMIT, "Query exceeded the maximum execution time limit of " + queryMaxExecutionTime));
        }
        planningTime.filter(duration -> duration.compareTo(queryMaxPlanningTime) > 0).ifPresent(ignored -> query.fail(new TrinoException(EXCEEDED_TIME_LIMIT, "Query exceeded the maximum planning time limit of " + queryMaxPlanningTime)));
        if (createTime.plus(queryMaxRunTime.toMillis()).isBeforeNow()) {
            query.fail(new TrinoException(EXCEEDED_TIME_LIMIT, "Query exceeded maximum time limit of " + queryMaxRunTime));
        }
    }
}
Also used : QueryId(io.trino.spi.QueryId) ScheduledFuture(java.util.concurrent.ScheduledFuture) Logger(io.airlift.log.Logger) Duration(io.airlift.units.Duration) ConcurrentMap(java.util.concurrent.ConcurrentMap) SystemSessionProperties.getQueryMaxPlanningTime(io.trino.SystemSessionProperties.getQueryMaxPlanningTime) TrackedQuery(io.trino.execution.QueryTracker.TrackedQuery) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NoSuchElementException(java.util.NoSuchElementException) ABANDONED_QUERY(io.trino.spi.StandardErrorCode.ABANDONED_QUERY) Collection(java.util.Collection) DateTime(org.joda.time.DateTime) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TrinoException(io.trino.spi.TrinoException) ThreadSafe(javax.annotation.concurrent.ThreadSafe) GuardedBy(javax.annotation.concurrent.GuardedBy) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) EXCEEDED_TIME_LIMIT(io.trino.spi.StandardErrorCode.EXCEEDED_TIME_LIMIT) TimeUnit(java.util.concurrent.TimeUnit) SystemSessionProperties.getQueryMaxRunTime(io.trino.SystemSessionProperties.getQueryMaxRunTime) SERVER_SHUTTING_DOWN(io.trino.spi.StandardErrorCode.SERVER_SHUTTING_DOWN) Optional(java.util.Optional) SystemSessionProperties.getQueryMaxExecutionTime(io.trino.SystemSessionProperties.getQueryMaxExecutionTime) Queue(java.util.Queue) Session(io.trino.Session) EXCEEDED_TIME_LIMIT(io.trino.spi.StandardErrorCode.EXCEEDED_TIME_LIMIT) TrinoException(io.trino.spi.TrinoException) Duration(io.airlift.units.Duration) DateTime(org.joda.time.DateTime)

Aggregations

Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList (com.google.common.collect.ImmutableList)1 Logger (io.airlift.log.Logger)1 Duration (io.airlift.units.Duration)1 Session (io.trino.Session)1 SystemSessionProperties.getQueryMaxExecutionTime (io.trino.SystemSessionProperties.getQueryMaxExecutionTime)1 SystemSessionProperties.getQueryMaxPlanningTime (io.trino.SystemSessionProperties.getQueryMaxPlanningTime)1 SystemSessionProperties.getQueryMaxRunTime (io.trino.SystemSessionProperties.getQueryMaxRunTime)1 TrackedQuery (io.trino.execution.QueryTracker.TrackedQuery)1 QueryId (io.trino.spi.QueryId)1 ABANDONED_QUERY (io.trino.spi.StandardErrorCode.ABANDONED_QUERY)1 EXCEEDED_TIME_LIMIT (io.trino.spi.StandardErrorCode.EXCEEDED_TIME_LIMIT)1 SERVER_SHUTTING_DOWN (io.trino.spi.StandardErrorCode.SERVER_SHUTTING_DOWN)1 TrinoException (io.trino.spi.TrinoException)1 String.format (java.lang.String.format)1 Collection (java.util.Collection)1 NoSuchElementException (java.util.NoSuchElementException)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Optional (java.util.Optional)1 Queue (java.util.Queue)1