use of io.trino.execution.TaskStatus in project trino by trinodb.
the class HttpRemoteTask method abort.
@Override
public synchronized void abort() {
if (getTaskStatus().getState().isDone()) {
return;
}
TaskStatus status = failWith(getTaskStatus(), ABORTED, ImmutableList.of());
try (SetThreadName ignored = new SetThreadName("HttpRemoteTask-%s", taskId)) {
taskStatusFetcher.updateTaskStatus(status);
// send abort to task
scheduleAsyncCleanupRequest(new Backoff(maxErrorDuration), "abort", true);
}
}
use of io.trino.execution.TaskStatus in project trino by trinodb.
the class HttpRemoteTask method getQueuedPartitionedSplitsInfo.
@Override
public PartitionedSplitsInfo getQueuedPartitionedSplitsInfo() {
TaskStatus taskStatus = getTaskStatus();
if (taskStatus.getState().isDone()) {
return PartitionedSplitsInfo.forZeroSplits();
}
PartitionedSplitsInfo unacknowledgedSplitsInfo = getUnacknowledgedPartitionedSplitsInfo();
int count = unacknowledgedSplitsInfo.getCount() + taskStatus.getQueuedPartitionedDrivers();
long weight = unacknowledgedSplitsInfo.getWeightSum() + taskStatus.getQueuedPartitionedSplitsWeight();
return PartitionedSplitsInfo.forSplitCountAndWeightSum(count, weight);
}
use of io.trino.execution.TaskStatus in project trino by trinodb.
the class TaskInfoFetcher method sendNextRequest.
private synchronized void sendNextRequest() {
TaskStatus taskStatus = getTaskInfo().getTaskStatus();
if (!running) {
return;
}
// we already have the final task info
if (isDone(getTaskInfo())) {
stop();
return;
}
// if we have an outstanding request
if (future != null && !future.isDone()) {
return;
}
// if throttled due to error, asynchronously wait for timeout and try again
ListenableFuture<Void> errorRateLimit = errorTracker.acquireRequestPermit();
if (!errorRateLimit.isDone()) {
errorRateLimit.addListener(this::sendNextRequest, executor);
return;
}
HttpUriBuilder httpUriBuilder = uriBuilderFrom(taskStatus.getSelf());
URI uri = summarizeTaskInfo ? httpUriBuilder.addParameter("summarize").build() : httpUriBuilder.build();
Request request = prepareGet().setUri(uri).setHeader(CONTENT_TYPE, JSON_UTF_8.toString()).build();
errorTracker.startRequest();
future = httpClient.executeAsync(request, createFullJsonResponseHandler(taskInfoCodec));
Futures.addCallback(future, new SimpleHttpResponseHandler<>(new TaskInfoResponseCallback(), request.getUri(), stats), executor);
}
use of io.trino.execution.TaskStatus 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();
}
}
use of io.trino.execution.TaskStatus in project trino by trinodb.
the class PipelinedStageExecution method scheduleTask.
@Override
public synchronized Optional<RemoteTask> scheduleTask(InternalNode node, int partition, Multimap<PlanNodeId, Split> initialSplits, Multimap<PlanNodeId, Lifespan> noMoreSplitsForLifespan) {
if (stateMachine.getState().isDone()) {
return Optional.empty();
}
checkArgument(!tasks.containsKey(partition), "A task for partition %s already exists", partition);
OutputBuffers outputBuffers = outputBufferManagers.get(stage.getFragment().getId()).getOutputBuffers();
Optional<RemoteTask> optionalTask = stage.createTask(node, partition, attempt, bucketToPartition, outputBuffers, initialSplits, ImmutableMultimap.of(), ImmutableSet.of());
if (optionalTask.isEmpty()) {
return Optional.empty();
}
RemoteTask task = optionalTask.get();
tasks.put(partition, task);
ImmutableMultimap.Builder<PlanNodeId, Split> exchangeSplits = ImmutableMultimap.builder();
sourceTasks.forEach((fragmentId, sourceTask) -> {
TaskStatus status = sourceTask.getTaskStatus();
if (status.getState() != TaskState.FINISHED) {
PlanNodeId planNodeId = exchangeSources.get(fragmentId).getId();
exchangeSplits.put(planNodeId, createExchangeSplit(sourceTask, task));
}
});
allTasks.add(task.getTaskId());
task.addSplits(exchangeSplits.build());
noMoreSplitsForLifespan.forEach(task::noMoreSplits);
completeSources.forEach(task::noMoreSplits);
task.addStateChangeListener(this::updateTaskStatus);
task.addStateChangeListener(this::updateCompletedDriverGroups);
task.start();
taskLifecycleListener.taskCreated(stage.getFragment().getId(), task);
// update output buffers
OutputBufferId outputBufferId = new OutputBufferId(task.getTaskId().getPartitionId());
updateSourceTasksOutputBuffers(outputBufferManager -> outputBufferManager.addOutputBuffer(outputBufferId));
return Optional.of(task);
}
Aggregations