All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.trino.memory.LowMemoryKiller Maven / Gradle / Ivy

There is a newer version: 465
Show newest version
/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.trino.memory;

import com.google.common.collect.ImmutableMap;
import com.google.inject.BindingAnnotation;
import io.trino.execution.TaskId;
import io.trino.execution.TaskInfo;
import io.trino.operator.RetryPolicy;
import io.trino.spi.QueryId;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import static com.google.common.base.MoreObjects.toStringHelper;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static java.util.Objects.requireNonNull;

public interface LowMemoryKiller
{
    Optional chooseTargetToKill(List runningQueries, List nodes);

    class RunningQueryInfo
    {
        private final QueryId queryId;
        private final long memoryReservation;
        private final Map taskInfos;
        private final RetryPolicy retryPolicy;

        public RunningQueryInfo(
                QueryId queryId,
                long memoryReservation,
                Map taskInfos,
                RetryPolicy retryPolicy)
        {
            this.queryId = requireNonNull(queryId, "queryId is null");
            this.memoryReservation = memoryReservation;
            requireNonNull(taskInfos, "taskInfos is null");
            this.taskInfos = ImmutableMap.copyOf(taskInfos);
            this.retryPolicy = requireNonNull(retryPolicy, "retryPolicy is null");
        }

        public QueryId getQueryId()
        {
            return queryId;
        }

        public long getMemoryReservation()
        {
            return memoryReservation;
        }

        public Map getTaskInfos()
        {
            return taskInfos;
        }

        public RetryPolicy getRetryPolicy()
        {
            return retryPolicy;
        }

        @Override
        public String toString()
        {
            return toStringHelper(this)
                    .add("queryId", queryId)
                    .add("memoryReservation", memoryReservation)
                    .add("taskStats", taskInfos)
                    .add("retryPolicy", retryPolicy)
                    .toString();
        }
    }

    @Retention(RUNTIME)
    @Target({FIELD, PARAMETER, METHOD})
    @BindingAnnotation
    @interface ForQueryLowMemoryKiller {}

    @Retention(RUNTIME)
    @Target({FIELD, PARAMETER, METHOD})
    @BindingAnnotation
    @interface ForTaskLowMemoryKiller {}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy