Search in sources :

Example 11 with TaskStatus

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);
    }
}
Also used : SetThreadName(io.airlift.concurrent.SetThreadName) TaskStatus(io.trino.execution.TaskStatus)

Example 12 with TaskStatus

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);
}
Also used : PartitionedSplitsInfo(io.trino.execution.PartitionedSplitsInfo) TaskStatus(io.trino.execution.TaskStatus)

Example 13 with TaskStatus

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);
}
Also used : HttpUriBuilder(io.airlift.http.client.HttpUriBuilder) Request(io.airlift.http.client.Request) TaskStatus(io.trino.execution.TaskStatus) URI(java.net.URI)

Example 14 with TaskStatus

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();
    }
}
Also used : TaskInfo(io.trino.execution.TaskInfo) TaskStatus(io.trino.execution.TaskStatus)

Example 15 with TaskStatus

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);
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) OutputBuffers(io.trino.execution.buffer.OutputBuffers) RemoteTask(io.trino.execution.RemoteTask) OutputBufferId(io.trino.execution.buffer.OutputBuffers.OutputBufferId) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Split(io.trino.metadata.Split) RemoteSplit(io.trino.split.RemoteSplit) TaskStatus(io.trino.execution.TaskStatus)

Aggregations

TaskStatus (io.trino.execution.TaskStatus)15 SetThreadName (io.airlift.concurrent.SetThreadName)4 Request (io.airlift.http.client.Request)3 TaskInfo (io.trino.execution.TaskInfo)3 FailTaskRequest (io.trino.server.FailTaskRequest)3 HttpUriBuilder (io.airlift.http.client.HttpUriBuilder)2 VersionedDynamicFilterDomains (io.trino.execution.DynamicFiltersCollector.VersionedDynamicFilterDomains)2 PartitionedSplitsInfo (io.trino.execution.PartitionedSplitsInfo)2 RemoteTask (io.trino.execution.RemoteTask)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Throwables.propagateIfPossible (com.google.common.base.Throwables.propagateIfPossible)1 Verify.verify (com.google.common.base.Verify.verify)1 VerifyException (com.google.common.base.VerifyException)1 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)1 ImmutableListMultimap.flatteningToImmutableListMultimap (com.google.common.collect.ImmutableListMultimap.flatteningToImmutableListMultimap)1 ImmutableListMultimap.toImmutableListMultimap (com.google.common.collect.ImmutableListMultimap.toImmutableListMultimap)1 ImmutableMap (com.google.common.collect.ImmutableMap)1