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());
}
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);
}
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;
}
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);
}
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();
}
}
Aggregations