Search in sources :

Example 6 with TaskInfo

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

the class QueryMonitor method computeCpuDistribution.

private static StageCpuDistribution computeCpuDistribution(StageInfo stageInfo) {
    Distribution cpuDistribution = new Distribution();
    for (TaskInfo taskInfo : stageInfo.getTasks()) {
        cpuDistribution.add(taskInfo.getStats().getTotalCpuTime().toMillis());
    }
    DistributionSnapshot snapshot = cpuDistribution.snapshot();
    return new StageCpuDistribution(stageInfo.getStageId().getId(), stageInfo.getTasks().size(), (long) snapshot.getP25(), (long) snapshot.getP50(), (long) snapshot.getP75(), (long) snapshot.getP90(), (long) snapshot.getP95(), (long) snapshot.getP99(), (long) snapshot.getMin(), (long) snapshot.getMax(), (long) snapshot.getTotal(), snapshot.getTotal() / snapshot.getCount());
}
Also used : TaskInfo(io.trino.execution.TaskInfo) DistributionSnapshot(io.airlift.stats.Distribution.DistributionSnapshot) StageCpuDistribution(io.trino.spi.eventlistener.StageCpuDistribution) Distribution(io.airlift.stats.Distribution) StageCpuDistribution(io.trino.spi.eventlistener.StageCpuDistribution)

Example 7 with TaskInfo

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

the class TestHttpRemoteTask method createHttpRemoteTaskFactory.

private static HttpRemoteTaskFactory createHttpRemoteTaskFactory(TestingTaskResource testingTaskResource, DynamicFilterService dynamicFilterService) {
    Bootstrap app = new Bootstrap(new JsonModule(), new HandleJsonModule(), new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bind(JsonMapper.class).in(SINGLETON);
            binder.bind(Metadata.class).toInstance(createTestMetadataManager());
            jsonBinder(binder).addDeserializerBinding(Type.class).to(TypeDeserializer.class);
            jsonCodecBinder(binder).bindJsonCodec(TaskStatus.class);
            jsonCodecBinder(binder).bindJsonCodec(VersionedDynamicFilterDomains.class);
            jsonBinder(binder).addSerializerBinding(Block.class).to(BlockJsonSerde.Serializer.class);
            jsonBinder(binder).addDeserializerBinding(Block.class).to(BlockJsonSerde.Deserializer.class);
            jsonCodecBinder(binder).bindJsonCodec(TaskInfo.class);
            jsonCodecBinder(binder).bindJsonCodec(TaskUpdateRequest.class);
            jsonCodecBinder(binder).bindJsonCodec(FailTaskRequest.class);
            binder.bind(TypeManager.class).toInstance(TESTING_TYPE_MANAGER);
            binder.bind(BlockEncodingManager.class).in(SINGLETON);
            binder.bind(BlockEncodingSerde.class).to(InternalBlockEncodingSerde.class).in(SINGLETON);
        }

        @Provides
        private HttpRemoteTaskFactory createHttpRemoteTaskFactory(JsonMapper jsonMapper, JsonCodec<TaskStatus> taskStatusCodec, JsonCodec<VersionedDynamicFilterDomains> dynamicFilterDomainsCodec, JsonCodec<TaskInfo> taskInfoCodec, JsonCodec<TaskUpdateRequest> taskUpdateRequestCodec, JsonCodec<FailTaskRequest> failTaskRequestCodec) {
            JaxrsTestingHttpProcessor jaxrsTestingHttpProcessor = new JaxrsTestingHttpProcessor(URI.create("http://fake.invalid/"), testingTaskResource, jsonMapper);
            TestingHttpClient testingHttpClient = new TestingHttpClient(jaxrsTestingHttpProcessor.setTrace(TRACE_HTTP));
            testingTaskResource.setHttpClient(testingHttpClient);
            return new HttpRemoteTaskFactory(new QueryManagerConfig(), TASK_MANAGER_CONFIG, testingHttpClient, new TestSqlTaskManager.MockLocationFactory(), taskStatusCodec, dynamicFilterDomainsCodec, taskInfoCodec, taskUpdateRequestCodec, failTaskRequestCodec, new RemoteTaskStats(), dynamicFilterService);
        }
    });
    Injector injector = app.doNotInitializeLogging().quiet().initialize();
    return injector.getInstance(HttpRemoteTaskFactory.class);
}
Also used : VersionedDynamicFilterDomains(io.trino.execution.DynamicFiltersCollector.VersionedDynamicFilterDomains) TaskInfo(io.trino.execution.TaskInfo) JsonMapper(io.airlift.jaxrs.JsonMapper) JsonCodecBinder.jsonCodecBinder(io.airlift.json.JsonCodecBinder.jsonCodecBinder) Binder(com.google.inject.Binder) JsonBinder.jsonBinder(io.airlift.json.JsonBinder.jsonBinder) FailTaskRequest(io.trino.server.FailTaskRequest) JaxrsTestingHttpProcessor(io.airlift.jaxrs.testing.JaxrsTestingHttpProcessor) HandleJsonModule(io.trino.metadata.HandleJsonModule) Injector(com.google.inject.Injector) HttpRemoteTaskFactory(io.trino.server.HttpRemoteTaskFactory) TestingHttpClient(io.airlift.http.client.testing.TestingHttpClient) Bootstrap(io.airlift.bootstrap.Bootstrap) TypeDeserializer(io.trino.type.TypeDeserializer) TaskUpdateRequest(io.trino.server.TaskUpdateRequest) InternalBlockEncodingSerde(io.trino.metadata.InternalBlockEncodingSerde) BlockEncodingSerde(io.trino.spi.block.BlockEncodingSerde) TaskStatus(io.trino.execution.TaskStatus) Provides(com.google.inject.Provides) JsonModule(io.airlift.json.JsonModule) HandleJsonModule(io.trino.metadata.HandleJsonModule) TypeDeserializer(io.trino.type.TypeDeserializer) QueryManagerConfig(io.trino.execution.QueryManagerConfig) JsonModule(io.airlift.json.JsonModule) Module(com.google.inject.Module) HandleJsonModule(io.trino.metadata.HandleJsonModule)

Example 8 with TaskInfo

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

the class TaskResource method deleteTask.

@ResourceSecurity(INTERNAL_ONLY)
@DELETE
@Path("{taskId}")
@Produces(MediaType.APPLICATION_JSON)
public TaskInfo deleteTask(@PathParam("taskId") TaskId taskId, @QueryParam("abort") @DefaultValue("true") boolean abort, @Context UriInfo uriInfo) {
    requireNonNull(taskId, "taskId is null");
    TaskInfo taskInfo;
    if (abort) {
        taskInfo = taskManager.abortTask(taskId);
    } else {
        taskInfo = taskManager.cancelTask(taskId);
    }
    if (shouldSummarize(uriInfo)) {
        taskInfo = taskInfo.summarize();
    }
    return taskInfo;
}
Also used : TaskInfo(io.trino.execution.TaskInfo) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) ResourceSecurity(io.trino.server.security.ResourceSecurity)

Example 9 with TaskInfo

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

the class TaskResource method getTaskInfo.

@ResourceSecurity(INTERNAL_ONLY)
@GET
@Path("{taskId}")
@Produces(MediaType.APPLICATION_JSON)
public void getTaskInfo(@PathParam("taskId") TaskId taskId, @HeaderParam(TRINO_CURRENT_VERSION) Long currentVersion, @HeaderParam(TRINO_MAX_WAIT) Duration maxWait, @Context UriInfo uriInfo, @Suspended AsyncResponse asyncResponse) {
    requireNonNull(taskId, "taskId is null");
    if (injectFailure(taskManager.getTraceToken(taskId), taskId, RequestType.GET_TASK_INFO, asyncResponse)) {
        return;
    }
    if (currentVersion == null || maxWait == null) {
        TaskInfo taskInfo = taskManager.getTaskInfo(taskId);
        if (shouldSummarize(uriInfo)) {
            taskInfo = taskInfo.summarize();
        }
        asyncResponse.resume(taskInfo);
        return;
    }
    Duration waitTime = randomizeWaitTime(maxWait);
    ListenableFuture<TaskInfo> futureTaskInfo = addTimeout(taskManager.getTaskInfo(taskId, currentVersion), () -> taskManager.getTaskInfo(taskId), waitTime, timeoutExecutor);
    if (shouldSummarize(uriInfo)) {
        futureTaskInfo = Futures.transform(futureTaskInfo, TaskInfo::summarize, directExecutor());
    }
    // For hard timeout, add an additional time to max wait for thread scheduling contention and GC
    Duration timeout = new Duration(waitTime.toMillis() + ADDITIONAL_WAIT_TIME.toMillis(), MILLISECONDS);
    bindAsyncResponse(asyncResponse, futureTaskInfo, responseExecutor).withTimeout(timeout);
}
Also used : TaskInfo(io.trino.execution.TaskInfo) Duration(io.airlift.units.Duration) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ResourceSecurity(io.trino.server.security.ResourceSecurity)

Example 10 with TaskInfo

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

the class TaskInfoFetcher method updateTaskInfo.

synchronized void updateTaskInfo(TaskInfo newTaskInfo) {
    TaskStatus localTaskStatus = taskStatusFetcher.getTaskStatus();
    TaskStatus newRemoteTaskStatus = newTaskInfo.getTaskStatus();
    TaskInfo newValue;
    if (localTaskStatus.getState().isDone() && newRemoteTaskStatus.getState().isDone() && localTaskStatus.getState() != newRemoteTaskStatus.getState()) {
        // prefer local
        newValue = newTaskInfo.withTaskStatus(localTaskStatus);
    } else {
        newValue = newTaskInfo;
    }
    boolean updated = taskInfo.setIf(newValue, oldValue -> {
        TaskStatus oldTaskStatus = oldValue.getTaskStatus();
        TaskStatus newTaskStatus = newValue.getTaskStatus();
        if (oldTaskStatus.getState().isDone()) {
            // never update if the task has reached a terminal state
            return false;
        }
        // don't update to an older version (same version is ok)
        return newTaskStatus.getVersion() >= oldTaskStatus.getVersion();
    });
    if (updated && newValue.getTaskStatus().getState().isDone()) {
        finalTaskInfo.compareAndSet(Optional.empty(), Optional.of(newValue));
        stop();
    }
}
Also used : TaskInfo(io.trino.execution.TaskInfo) TaskStatus(io.trino.execution.TaskStatus)

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