Search in sources :

Example 1 with TaskInfo

use of io.trino.execution.TaskInfo in project trino by trinodb.

the class TaskSystemTable method cursor.

@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession session, TupleDomain<Integer> constraint) {
    Builder table = InMemoryRecordSet.builder(TASK_TABLE);
    for (TaskInfo taskInfo : taskManager.getAllTaskInfo()) {
        TaskStats stats = taskInfo.getStats();
        TaskStatus taskStatus = taskInfo.getTaskStatus();
        table.addRow(nodeId, taskStatus.getTaskId().toString(), taskStatus.getTaskId().getStageId().toString(), taskStatus.getTaskId().getQueryId().toString(), taskStatus.getState().toString(), (long) stats.getTotalDrivers(), (long) stats.getQueuedDrivers(), (long) stats.getRunningDrivers(), (long) stats.getCompletedDrivers(), toMillis(stats.getTotalScheduledTime()), toMillis(stats.getTotalCpuTime()), toMillis(stats.getTotalBlockedTime()), toBytes(stats.getRawInputDataSize()), stats.getRawInputPositions(), toBytes(stats.getProcessedInputDataSize()), stats.getProcessedInputPositions(), toBytes(stats.getOutputDataSize()), stats.getOutputPositions(), toBytes(stats.getPhysicalInputDataSize()), toBytes(stats.getPhysicalWrittenDataSize()), toTimestampWithTimeZoneMillis(stats.getCreateTime()), toTimestampWithTimeZoneMillis(stats.getFirstStartTime()), toTimestampWithTimeZoneMillis(taskInfo.getLastHeartbeat()), toTimestampWithTimeZoneMillis(stats.getEndTime()));
    }
    return table.build().cursor();
}
Also used : TaskInfo(io.trino.execution.TaskInfo) TableMetadataBuilder.tableMetadataBuilder(io.trino.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) Builder(io.trino.spi.connector.InMemoryRecordSet.Builder) TaskStats(io.trino.operator.TaskStats) TaskStatus(io.trino.execution.TaskStatus)

Example 2 with TaskInfo

use of io.trino.execution.TaskInfo in project trino by trinodb.

the class Query method globalUniqueNodes.

private static Set<String> globalUniqueNodes(StageInfo stageInfo) {
    if (stageInfo == null) {
        return ImmutableSet.of();
    }
    ImmutableSet.Builder<String> nodes = ImmutableSet.builder();
    for (TaskInfo task : stageInfo.getTasks()) {
        // todo add nodeId to TaskInfo
        URI uri = task.getTaskStatus().getSelf();
        nodes.add(uri.getHost() + ":" + uri.getPort());
    }
    for (StageInfo subStage : stageInfo.getSubStages()) {
        nodes.addAll(globalUniqueNodes(subStage));
    }
    return nodes.build();
}
Also used : TaskInfo(io.trino.execution.TaskInfo) ImmutableSet(com.google.common.collect.ImmutableSet) StageInfo(io.trino.execution.StageInfo) URI(java.net.URI)

Example 3 with TaskInfo

use of io.trino.execution.TaskInfo in project trino by trinodb.

the class TaskResource method createOrUpdateTask.

@ResourceSecurity(INTERNAL_ONLY)
@POST
@Path("{taskId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public void createOrUpdateTask(@PathParam("taskId") TaskId taskId, TaskUpdateRequest taskUpdateRequest, @Context UriInfo uriInfo, @Suspended AsyncResponse asyncResponse) {
    requireNonNull(taskUpdateRequest, "taskUpdateRequest is null");
    Session session = taskUpdateRequest.getSession().toSession(sessionPropertyManager, taskUpdateRequest.getExtraCredentials());
    if (injectFailure(session.getTraceToken(), taskId, RequestType.CREATE_OR_UPDATE_TASK, asyncResponse)) {
        return;
    }
    TaskInfo taskInfo = taskManager.updateTask(session, taskId, taskUpdateRequest.getFragment(), taskUpdateRequest.getSplitAssignments(), taskUpdateRequest.getOutputIds(), taskUpdateRequest.getDynamicFilterDomains());
    if (shouldSummarize(uriInfo)) {
        taskInfo = taskInfo.summarize();
    }
    asyncResponse.resume(Response.ok().entity(taskInfo).build());
}
Also used : TaskInfo(io.trino.execution.TaskInfo) Session(io.trino.Session) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ResourceSecurity(io.trino.server.security.ResourceSecurity)

Example 4 with TaskInfo

use of io.trino.execution.TaskInfo in project trino by trinodb.

the class GracefulShutdownHandler method shutdown.

private void shutdown() {
    List<TaskInfo> activeTasks = getActiveTasks();
    // Wait for all remaining tasks to finish.
    while (activeTasks.size() > 0) {
        CountDownLatch countDownLatch = new CountDownLatch(activeTasks.size());
        for (TaskInfo taskInfo : activeTasks) {
            sqlTaskManager.addStateChangeListener(taskInfo.getTaskStatus().getTaskId(), newState -> {
                if (newState.isDone()) {
                    countDownLatch.countDown();
                }
            });
        }
        log.info("Waiting for all tasks to finish");
        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            log.warn("Interrupted while waiting for all tasks to finish");
            currentThread().interrupt();
        }
        activeTasks = getActiveTasks();
    }
    // wait for another grace period for all task states to be observed by the coordinator
    sleepUninterruptibly(gracePeriod.toMillis(), MILLISECONDS);
    Future<?> shutdownFuture = lifeCycleStopper.submit(() -> {
        lifeCycleManager.stop();
        return null;
    });
    // terminate the jvm if life cycle cannot be stopped in a timely manner
    try {
        shutdownFuture.get(LIFECYCLE_STOP_TIMEOUT.toMillis(), MILLISECONDS);
    } catch (TimeoutException e) {
        log.warn(e, "Timed out waiting for the life cycle to stop");
    } catch (InterruptedException e) {
        log.warn(e, "Interrupted while waiting for the life cycle to stop");
        currentThread().interrupt();
    } catch (ExecutionException e) {
        log.warn(e, "Problem stopping the life cycle");
    }
    shutdownAction.onShutdown();
}
Also used : TaskInfo(io.trino.execution.TaskInfo) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 5 with TaskInfo

use of io.trino.execution.TaskInfo in project trino by trinodb.

the class QueryMonitor method logQueryTimeline.

private static void logQueryTimeline(QueryInfo queryInfo) {
    try {
        QueryStats queryStats = queryInfo.getQueryStats();
        DateTime queryStartTime = queryStats.getCreateTime();
        DateTime queryEndTime = queryStats.getEndTime();
        // query didn't finish cleanly
        if (queryStartTime == null || queryEndTime == null) {
            return;
        }
        // planning duration -- start to end of planning
        long planning = queryStats.getPlanningTime().toMillis();
        // Time spent waiting for required no. of worker nodes to be present
        long waiting = queryStats.getResourceWaitingTime().toMillis();
        List<StageInfo> stages = getAllStages(queryInfo.getOutputStage());
        // long lastSchedulingCompletion = 0;
        long firstTaskStartTime = queryEndTime.getMillis();
        long lastTaskStartTime = queryStartTime.getMillis() + planning;
        long lastTaskEndTime = queryStartTime.getMillis() + planning;
        for (StageInfo stage : stages) {
            // only consider leaf stages
            if (!stage.getSubStages().isEmpty()) {
                continue;
            }
            for (TaskInfo taskInfo : stage.getTasks()) {
                TaskStats taskStats = taskInfo.getStats();
                DateTime firstStartTime = taskStats.getFirstStartTime();
                if (firstStartTime != null) {
                    firstTaskStartTime = Math.min(firstStartTime.getMillis(), firstTaskStartTime);
                }
                DateTime lastStartTime = taskStats.getLastStartTime();
                if (lastStartTime != null) {
                    lastTaskStartTime = max(lastStartTime.getMillis(), lastTaskStartTime);
                }
                DateTime endTime = taskStats.getEndTime();
                if (endTime != null) {
                    lastTaskEndTime = max(endTime.getMillis(), lastTaskEndTime);
                }
            }
        }
        long elapsed = max(queryEndTime.getMillis() - queryStartTime.getMillis(), 0);
        long scheduling = max(firstTaskStartTime - queryStartTime.getMillis() - planning, 0);
        long running = max(lastTaskEndTime - firstTaskStartTime, 0);
        long finishing = max(queryEndTime.getMillis() - lastTaskEndTime, 0);
        logQueryTimeline(queryInfo.getQueryId(), queryInfo.getSession().getTransactionId().map(TransactionId::toString).orElse(""), elapsed, planning, waiting, scheduling, running, finishing, queryStartTime, queryEndTime);
    } catch (Exception e) {
        log.error(e, "Error logging query timeline");
    }
}
Also used : TaskInfo(io.trino.execution.TaskInfo) QueryStats(io.trino.execution.QueryStats) StageInfo(io.trino.execution.StageInfo) TaskStats(io.trino.operator.TaskStats) DateTime(org.joda.time.DateTime) TransactionId(io.trino.transaction.TransactionId)

Aggregations

TaskInfo (io.trino.execution.TaskInfo)12 TaskStatus (io.trino.execution.TaskStatus)4 StageInfo (io.trino.execution.StageInfo)3 ResourceSecurity (io.trino.server.security.ResourceSecurity)3 URI (java.net.URI)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 Duration (io.airlift.units.Duration)2 TaskStats (io.trino.operator.TaskStats)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 CONTENT_TYPE (com.google.common.net.HttpHeaders.CONTENT_TYPE)1 JSON_UTF_8 (com.google.common.net.MediaType.JSON_UTF_8)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 Binder (com.google.inject.Binder)1 Injector (com.google.inject.Injector)1 Module (com.google.inject.Module)1 Provides (com.google.inject.Provides)1