Search in sources :

Example 1 with TaskStatus

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

the class TaskSystemTable method cursor.

@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession session, TupleDomain<Integer> constraint) {
    Builder table = InMemoryRecordSet.builder(TASK_TABLE);
    for (TaskInfo taskInfo : taskManager.getAllTaskInfo()) {
        TaskStats stats = taskInfo.getStats();
        TaskStatus taskStatus = taskInfo.getTaskStatus();
        table.addRow(nodeId, taskStatus.getTaskId().toString(), taskStatus.getTaskId().getStageId().toString(), taskStatus.getTaskId().getQueryId().toString(), taskStatus.getState().toString(), (long) stats.getTotalDrivers(), (long) stats.getQueuedDrivers(), (long) stats.getRunningDrivers(), (long) stats.getCompletedDrivers(), toMillis(stats.getTotalScheduledTime()), toMillis(stats.getTotalCpuTime()), toMillis(stats.getTotalBlockedTime()), toBytes(stats.getRawInputDataSize()), stats.getRawInputPositions(), toBytes(stats.getProcessedInputDataSize()), stats.getProcessedInputPositions(), toBytes(stats.getOutputDataSize()), stats.getOutputPositions(), toBytes(stats.getPhysicalInputDataSize()), toBytes(stats.getPhysicalWrittenDataSize()), toTimestampWithTimeZoneMillis(stats.getCreateTime()), toTimestampWithTimeZoneMillis(stats.getFirstStartTime()), toTimestampWithTimeZoneMillis(taskInfo.getLastHeartbeat()), toTimestampWithTimeZoneMillis(stats.getEndTime()));
    }
    return table.build().cursor();
}
Also used : TaskInfo(io.trino.execution.TaskInfo) TableMetadataBuilder.tableMetadataBuilder(io.trino.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) Builder(io.trino.spi.connector.InMemoryRecordSet.Builder) TaskStats(io.trino.operator.TaskStats) TaskStatus(io.trino.execution.TaskStatus)

Example 2 with TaskStatus

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

the class ContinuousTaskStatusFetcher method scheduleNextRequest.

private synchronized void scheduleNextRequest() {
    // stopped or done?
    TaskStatus taskStatus = getTaskStatus();
    if (!running || taskStatus.getState().isDone()) {
        return;
    }
    // outstanding request?
    if (future != null && !future.isDone()) {
        // this should never happen
        log.error("Cannot reschedule update because an update is already running");
        return;
    }
    // if throttled due to error, asynchronously wait for timeout and try again
    ListenableFuture<Void> errorRateLimit = errorTracker.acquireRequestPermit();
    if (!errorRateLimit.isDone()) {
        errorRateLimit.addListener(this::scheduleNextRequest, executor);
        return;
    }
    Request request = prepareGet().setUri(uriBuilderFrom(taskStatus.getSelf()).appendPath("status").build()).setHeader(CONTENT_TYPE, JSON_UTF_8.toString()).setHeader(TRINO_CURRENT_VERSION, Long.toString(taskStatus.getVersion())).setHeader(TRINO_MAX_WAIT, refreshMaxWait.toString()).build();
    errorTracker.startRequest();
    future = httpClient.executeAsync(request, createFullJsonResponseHandler(taskStatusCodec));
    Futures.addCallback(future, new SimpleHttpResponseHandler<>(new TaskStatusResponseCallback(), request.getUri(), stats), executor);
}
Also used : Request(io.airlift.http.client.Request) TaskStatus(io.trino.execution.TaskStatus)

Example 3 with TaskStatus

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

the class HttpRemoteTask method getPartitionedSplitsInfo.

@Override
public PartitionedSplitsInfo getPartitionedSplitsInfo() {
    TaskStatus taskStatus = getTaskStatus();
    if (taskStatus.getState().isDone()) {
        return PartitionedSplitsInfo.forZeroSplits();
    }
    PartitionedSplitsInfo unacknowledgedSplitsInfo = getUnacknowledgedPartitionedSplitsInfo();
    int count = unacknowledgedSplitsInfo.getCount() + taskStatus.getQueuedPartitionedDrivers() + taskStatus.getRunningPartitionedDrivers();
    long weight = unacknowledgedSplitsInfo.getWeightSum() + taskStatus.getQueuedPartitionedSplitsWeight() + taskStatus.getRunningPartitionedSplitsWeight();
    return PartitionedSplitsInfo.forSplitCountAndWeightSum(count, weight);
}
Also used : PartitionedSplitsInfo(io.trino.execution.PartitionedSplitsInfo) TaskStatus(io.trino.execution.TaskStatus)

Example 4 with TaskStatus

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

the class HttpRemoteTask method sendUpdate.

private synchronized void sendUpdate() {
    TaskStatus taskStatus = getTaskStatus();
    // don't update if the task hasn't been started yet or if it is already finished
    if (!started.get() || !needsUpdate.get() || taskStatus.getState().isDone()) {
        return;
    }
    // currentRequest is always cleared when request is complete
    if (currentRequest != null) {
        return;
    }
    // if throttled due to error, asynchronously wait for timeout and try again
    ListenableFuture<Void> errorRateLimit = updateErrorTracker.acquireRequestPermit();
    if (!errorRateLimit.isDone()) {
        errorRateLimit.addListener(this::sendUpdate, executor);
        return;
    }
    List<SplitAssignment> splitAssignments = getSplitAssignments();
    VersionedDynamicFilterDomains dynamicFilterDomains = outboundDynamicFiltersCollector.acknowledgeAndGetNewDomains(sentDynamicFiltersVersion);
    // Workers don't need the embedded JSON representation when the fragment is sent
    Optional<PlanFragment> fragment = sendPlan.get() ? Optional.of(planFragment.withoutEmbeddedJsonRepresentation()) : Optional.empty();
    TaskUpdateRequest updateRequest = new TaskUpdateRequest(session.toSessionRepresentation(), session.getIdentity().getExtraCredentials(), fragment, splitAssignments, outputBuffers.get(), dynamicFilterDomains.getDynamicFilterDomains());
    byte[] taskUpdateRequestJson = taskUpdateRequestCodec.toJsonBytes(updateRequest);
    if (fragment.isPresent()) {
        stats.updateWithPlanBytes(taskUpdateRequestJson.length);
    }
    if (!dynamicFilterDomains.getDynamicFilterDomains().isEmpty()) {
        stats.updateWithDynamicFilterBytes(taskUpdateRequestJson.length);
    }
    HttpUriBuilder uriBuilder = getHttpUriBuilder(taskStatus);
    Request request = preparePost().setUri(uriBuilder.build()).setHeader(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString()).setBodyGenerator(createStaticBodyGenerator(taskUpdateRequestJson)).build();
    updateErrorTracker.startRequest();
    ListenableFuture<JsonResponse<TaskInfo>> future = httpClient.executeAsync(request, createFullJsonResponseHandler(taskInfoCodec));
    currentRequest = future;
    currentRequestStartNanos = System.nanoTime();
    // The needsUpdate flag needs to be set to false BEFORE adding the Future callback since callback might change the flag value
    // and does so without grabbing the instance lock.
    needsUpdate.set(false);
    Futures.addCallback(future, new SimpleHttpResponseHandler<>(new UpdateResponseHandler(splitAssignments, dynamicFilterDomains.getVersion()), request.getUri(), stats), executor);
}
Also used : TaskUpdateRequest(io.trino.server.TaskUpdateRequest) TaskUpdateRequest(io.trino.server.TaskUpdateRequest) FailTaskRequest(io.trino.server.FailTaskRequest) Request(io.airlift.http.client.Request) SplitAssignment(io.trino.execution.SplitAssignment) TaskStatus(io.trino.execution.TaskStatus) PlanFragment(io.trino.sql.planner.PlanFragment) JsonResponse(io.airlift.http.client.FullJsonResponseHandler.JsonResponse) VersionedDynamicFilterDomains(io.trino.execution.DynamicFiltersCollector.VersionedDynamicFilterDomains) HttpUriBuilder(io.airlift.http.client.HttpUriBuilder)

Example 5 with TaskStatus

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

the class HttpRemoteTask method failRemotely.

/**
 * Trigger remote task failure. Task status will be updated only when request sent to remote node returns.
 */
@Override
public synchronized void failRemotely(Throwable cause) {
    try (SetThreadName ignored = new SetThreadName("HttpRemoteTask-%s", taskId)) {
        TaskStatus taskStatus = getTaskStatus();
        if (taskStatus.getState().isDone()) {
            return;
        }
        scheduleAsyncCleanupRequest(new Backoff(maxErrorDuration), "fail", new FailTaskRequest(Failures.toFailure(cause)));
    }
}
Also used : FailTaskRequest(io.trino.server.FailTaskRequest) SetThreadName(io.airlift.concurrent.SetThreadName) 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