Search in sources :

Example 11 with TaskInfo

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

the class TaskInfoFetcher method addFinalTaskInfoListener.

/**
 * Add a listener for the final task info.  This notification is guaranteed to be fired only once.
 * Listener is always notified asynchronously using a dedicated notification thread pool so, care should
 * be taken to avoid leaking {@code this} when adding a listener in a constructor. Additionally, it is
 * possible notifications are observed out of order due to the asynchronous execution.
 */
public void addFinalTaskInfoListener(StateChangeListener<TaskInfo> stateChangeListener) {
    AtomicBoolean done = new AtomicBoolean();
    StateChangeListener<Optional<TaskInfo>> fireOnceStateChangeListener = finalTaskInfo -> {
        if (finalTaskInfo.isPresent() && done.compareAndSet(false, true)) {
            stateChangeListener.stateChanged(finalTaskInfo.get());
        }
    };
    finalTaskInfo.addStateChangeListener(fireOnceStateChangeListener);
    fireOnceStateChangeListener.stateChanged(finalTaskInfo.get());
}
Also used : HttpClient(io.airlift.http.client.HttpClient) StateMachine(io.trino.execution.StateMachine) ScheduledFuture(java.util.concurrent.ScheduledFuture) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) StateChangeListener(io.trino.execution.StateMachine.StateChangeListener) FullJsonResponseHandler.createFullJsonResponseHandler(io.airlift.http.client.FullJsonResponseHandler.createFullJsonResponseHandler) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CONTENT_TYPE(com.google.common.net.HttpHeaders.CONTENT_TYPE) JSON_UTF_8(com.google.common.net.MediaType.JSON_UTF_8) Duration(io.airlift.units.Duration) Duration.nanosSince(io.airlift.units.Duration.nanosSince) Objects.requireNonNull(java.util.Objects.requireNonNull) Request(io.airlift.http.client.Request) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) URI(java.net.URI) HttpUriBuilder(io.airlift.http.client.HttpUriBuilder) Builder.prepareGet(io.airlift.http.client.Request.Builder.prepareGet) Executor(java.util.concurrent.Executor) FullJsonResponseHandler(io.airlift.http.client.FullJsonResponseHandler) TaskStatus(io.trino.execution.TaskStatus) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) GuardedBy(javax.annotation.concurrent.GuardedBy) TaskId(io.trino.execution.TaskId) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) Futures(com.google.common.util.concurrent.Futures) TaskInfo(io.trino.execution.TaskInfo) HttpUriBuilder.uriBuilderFrom(io.airlift.http.client.HttpUriBuilder.uriBuilderFrom) Optional(java.util.Optional) SetThreadName(io.airlift.concurrent.SetThreadName) JsonCodec(io.airlift.json.JsonCodec) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Optional(java.util.Optional)

Example 12 with TaskInfo

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

the class Query method toStageStats.

private static StageStats toStageStats(StageInfo stageInfo) {
    if (stageInfo == null) {
        return null;
    }
    io.trino.execution.StageStats stageStats = stageInfo.getStageStats();
    ImmutableList.Builder<StageStats> subStages = ImmutableList.builder();
    for (StageInfo subStage : stageInfo.getSubStages()) {
        subStages.add(toStageStats(subStage));
    }
    Set<String> uniqueNodes = new HashSet<>();
    for (TaskInfo task : stageInfo.getTasks()) {
        // todo add nodeId to TaskInfo
        URI uri = task.getTaskStatus().getSelf();
        uniqueNodes.add(uri.getHost() + ":" + uri.getPort());
    }
    return StageStats.builder().setStageId(String.valueOf(stageInfo.getStageId().getId())).setState(stageInfo.getState().toString()).setDone(stageInfo.getState().isDone()).setNodes(uniqueNodes.size()).setTotalSplits(stageStats.getTotalDrivers()).setQueuedSplits(stageStats.getQueuedDrivers()).setRunningSplits(stageStats.getRunningDrivers() + stageStats.getBlockedDrivers()).setCompletedSplits(stageStats.getCompletedDrivers()).setCpuTimeMillis(stageStats.getTotalCpuTime().toMillis()).setWallTimeMillis(stageStats.getTotalScheduledTime().toMillis()).setProcessedRows(stageStats.getRawInputPositions()).setProcessedBytes(stageStats.getRawInputDataSize().toBytes()).setPhysicalInputBytes(stageStats.getPhysicalInputDataSize().toBytes()).setFailedTasks(stageStats.getFailedTasks()).setCoordinatorOnly(stageInfo.isCoordinatorOnly()).setSubStages(subStages.build()).build();
}
Also used : TaskInfo(io.trino.execution.TaskInfo) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) StageStats(io.trino.client.StageStats) StageInfo(io.trino.execution.StageInfo) URI(java.net.URI) HashSet(java.util.HashSet)

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