Search in sources :

Example 1 with QueryId

use of io.trino.spi.QueryId in project trino by trinodb.

the class KillQueryProcedure method killQuery.

@UsedByGeneratedCode
public void killQuery(String queryId, String message, ConnectorSession session) {
    QueryId query = parseQueryId(queryId);
    try {
        checkState(dispatchManager.isPresent(), "No dispatch manager is set. kill_query procedure should be executed on coordinator.");
        DispatchQuery dispatchQuery = dispatchManager.get().getQuery(query);
        checkCanKillQueryOwnedBy(((FullConnectorSession) session).getSession().getIdentity(), dispatchQuery.getSession().getIdentity(), accessControl);
        // check before killing to provide the proper error message (this is racy)
        if (dispatchQuery.isDone()) {
            throw new TrinoException(NOT_SUPPORTED, "Target query is not running: " + queryId);
        }
        dispatchQuery.fail(createKillQueryException(message));
        // verify if the query was killed (if not, we lost the race)
        checkState(dispatchQuery.isDone(), "Failure to fail the query: %s", query);
        if (!ADMINISTRATIVELY_KILLED.toErrorCode().equals(dispatchQuery.getErrorCode().orElse(null))) {
            throw new TrinoException(NOT_SUPPORTED, "Target query is not running: " + queryId);
        }
    } catch (NoSuchElementException e) {
        throw new TrinoException(NOT_FOUND, "Target query not found: " + queryId);
    }
}
Also used : DispatchQuery(io.trino.dispatcher.DispatchQuery) QueryId(io.trino.spi.QueryId) TrinoException(io.trino.spi.TrinoException) NoSuchElementException(java.util.NoSuchElementException) FullConnectorSession(io.trino.FullConnectorSession) UsedByGeneratedCode(io.trino.annotation.UsedByGeneratedCode)

Example 2 with QueryId

use of io.trino.spi.QueryId in project trino by trinodb.

the class TotalReservationOnBlockedNodesLowMemoryKiller method chooseWholeQueryToKill.

private Optional<KillTarget> chooseWholeQueryToKill(List<MemoryInfo> nodes) {
    Map<QueryId, Long> memoryReservationOnBlockedNodes = new HashMap<>();
    for (MemoryInfo node : nodes) {
        MemoryPoolInfo memoryPool = node.getPool();
        if (memoryPool == null) {
            continue;
        }
        if (memoryPool.getFreeBytes() + memoryPool.getReservedRevocableBytes() > 0) {
            continue;
        }
        Map<QueryId, Long> queryMemoryReservations = memoryPool.getQueryMemoryReservations();
        queryMemoryReservations.forEach((queryId, memoryReservation) -> {
            memoryReservationOnBlockedNodes.compute(queryId, (id, oldValue) -> oldValue == null ? memoryReservation : oldValue + memoryReservation);
        });
    }
    return memoryReservationOnBlockedNodes.entrySet().stream().max(comparingLong(Map.Entry::getValue)).map(Map.Entry::getKey).map(KillTarget::wholeQuery);
}
Also used : TaskMemoryInfo(io.trino.TaskMemoryInfo) HashMap(java.util.HashMap) QueryId(io.trino.spi.QueryId) Comparator.comparingLong(java.util.Comparator.comparingLong) MemoryPoolInfo(io.trino.spi.memory.MemoryPoolInfo) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with QueryId

use of io.trino.spi.QueryId in project trino by trinodb.

the class WorkerResource method getThreads.

@ResourceSecurity(WEB_UI)
@GET
@Path("{nodeId}/task/{taskId}")
public Response getThreads(@PathParam("taskId") TaskId task, @PathParam("nodeId") String nodeId, @Context HttpServletRequest servletRequest, @Context HttpHeaders httpHeaders) {
    QueryId queryId = task.getQueryId();
    Optional<QueryInfo> queryInfo = dispatchManager.getFullQueryInfo(queryId);
    if (queryInfo.isPresent()) {
        try {
            checkCanViewQueryOwnedBy(sessionContextFactory.extractAuthorizedIdentity(servletRequest, httpHeaders, alternateHeaderName), queryInfo.get().getSession().toIdentity(), accessControl);
            return proxyJsonResponse(nodeId, "v1/task/" + task);
        } catch (AccessDeniedException e) {
            throw new ForbiddenException();
        }
    }
    return Response.status(Status.GONE).build();
}
Also used : AccessDeniedException(io.trino.spi.security.AccessDeniedException) ForbiddenException(javax.ws.rs.ForbiddenException) QueryId(io.trino.spi.QueryId) QueryInfo(io.trino.execution.QueryInfo) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ResourceSecurity(io.trino.server.security.ResourceSecurity)

Example 4 with QueryId

use of io.trino.spi.QueryId in project trino by trinodb.

the class ClusterMemoryPool method update.

public synchronized void update(List<MemoryInfo> memoryInfos, int assignedQueries) {
    nodes = 0;
    blockedNodes = 0;
    totalDistributedBytes = 0;
    reservedDistributedBytes = 0;
    reservedRevocableDistributedBytes = 0;
    this.assignedQueries = assignedQueries;
    this.queryMemoryReservations.clear();
    this.queryMemoryAllocations.clear();
    this.queryMemoryRevocableReservations.clear();
    for (MemoryInfo info : memoryInfos) {
        MemoryPoolInfo poolInfo = info.getPool();
        nodes++;
        if (poolInfo.getFreeBytes() + poolInfo.getReservedRevocableBytes() <= 0) {
            blockedNodes++;
        }
        totalDistributedBytes += poolInfo.getMaxBytes();
        reservedDistributedBytes += poolInfo.getReservedBytes();
        reservedRevocableDistributedBytes += poolInfo.getReservedRevocableBytes();
        for (Map.Entry<QueryId, Long> entry : poolInfo.getQueryMemoryReservations().entrySet()) {
            queryMemoryReservations.merge(entry.getKey(), entry.getValue(), Long::sum);
        }
        for (Map.Entry<QueryId, List<MemoryAllocation>> entry : poolInfo.getQueryMemoryAllocations().entrySet()) {
            queryMemoryAllocations.merge(entry.getKey(), entry.getValue(), this::mergeQueryAllocations);
        }
        for (Map.Entry<QueryId, Long> entry : poolInfo.getQueryMemoryRevocableReservations().entrySet()) {
            queryMemoryRevocableReservations.merge(entry.getKey(), entry.getValue(), Long::sum);
        }
    }
}
Also used : QueryId(io.trino.spi.QueryId) MemoryPoolInfo(io.trino.spi.memory.MemoryPoolInfo) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with QueryId

use of io.trino.spi.QueryId in project trino by trinodb.

the class PhasedExecutionSchedule method extractDependenciesAndReturnNonLazyFragments.

private Set<PlanFragmentId> extractDependenciesAndReturnNonLazyFragments(Collection<StageExecution> stages) {
    if (stages.isEmpty()) {
        return ImmutableSet.of();
    }
    QueryId queryId = stages.stream().map(stage -> stage.getStageId().getQueryId()).findAny().orElseThrow();
    List<PlanFragment> fragments = stages.stream().map(StageExecution::getFragment).collect(toImmutableList());
    // Build a graph where the plan fragments are vertexes and the edges represent
    // a before -> after relationship. Destination fragment should be started only
    // when source fragment is completed. For example, a join hash build has an edge
    // to the join probe.
    Visitor visitor = new Visitor(queryId, fragments);
    visitor.processAllFragments();
    // Make sure there are no strongly connected components as it would mean circular dependency between stages
    List<Set<PlanFragmentId>> components = new StrongConnectivityInspector<>(fragmentDependency).stronglyConnectedSets();
    verify(components.size() == fragmentDependency.vertexSet().size(), "circular dependency between stages");
    return visitor.getNonLazyFragments();
}
Also used : ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) LinkedHashSet(java.util.LinkedHashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) PlanVisitor(io.trino.sql.planner.plan.PlanVisitor) QueryId(io.trino.spi.QueryId) PlanFragment(io.trino.sql.planner.PlanFragment)

Aggregations

QueryId (io.trino.spi.QueryId)103 Test (org.testng.annotations.Test)70 TaskId (io.trino.execution.TaskId)26 StageId (io.trino.execution.StageId)24 Map (java.util.Map)17 ImmutableMap (com.google.common.collect.ImmutableMap)16 DynamicFilterId (io.trino.sql.planner.plan.DynamicFilterId)15 DistributedQueryRunner (io.trino.testing.DistributedQueryRunner)14 Optional (java.util.Optional)13 Duration (io.airlift.units.Duration)12 Session (io.trino.Session)12 DynamicFilter (io.trino.spi.connector.DynamicFilter)12 Symbol (io.trino.sql.planner.Symbol)12 ImmutableSet (com.google.common.collect.ImmutableSet)11 TestingColumnHandle (io.trino.spi.connector.TestingColumnHandle)11 SymbolAllocator (io.trino.sql.planner.SymbolAllocator)11 Set (java.util.Set)10 AccessDeniedException (io.trino.spi.security.AccessDeniedException)9 Assert.assertEquals (org.testng.Assert.assertEquals)9 QualifiedObjectName (io.trino.metadata.QualifiedObjectName)8