Search in sources :

Example 1 with DriverStats

use of io.trino.operator.DriverStats in project trino by trinodb.

the class SqlTaskExecution method enqueueDriverSplitRunner.

private synchronized void enqueueDriverSplitRunner(boolean forceRunSplit, List<DriverSplitRunner> runners) {
    // schedule driver to be executed
    List<ListenableFuture<Void>> finishedFutures = taskExecutor.enqueueSplits(taskHandle, forceRunSplit, runners);
    checkState(finishedFutures.size() == runners.size(), "Expected %s futures but got %s", runners.size(), finishedFutures.size());
    // when driver completes, update state and fire events
    for (int i = 0; i < finishedFutures.size(); i++) {
        ListenableFuture<Void> finishedFuture = finishedFutures.get(i);
        DriverSplitRunner splitRunner = runners.get(i);
        // record new driver
        status.incrementRemainingDriver(splitRunner.getLifespan());
        Futures.addCallback(finishedFuture, new FutureCallback<Object>() {

            @Override
            public void onSuccess(Object result) {
                try (SetThreadName ignored = new SetThreadName("Task-%s", taskId)) {
                    // record driver is finished
                    status.decrementRemainingDriver(splitRunner.getLifespan());
                    checkTaskCompletion();
                    splitMonitor.splitCompletedEvent(taskId, getDriverStats());
                }
            }

            @Override
            public void onFailure(Throwable cause) {
                try (SetThreadName ignored = new SetThreadName("Task-%s", taskId)) {
                    taskStateMachine.failed(cause);
                    // record driver is finished
                    status.decrementRemainingDriver(splitRunner.getLifespan());
                    // fire failed event with cause
                    splitMonitor.splitFailedEvent(taskId, getDriverStats(), cause);
                }
            }

            private DriverStats getDriverStats() {
                DriverContext driverContext = splitRunner.getDriverContext();
                DriverStats driverStats;
                if (driverContext != null) {
                    driverStats = driverContext.getDriverStats();
                } else {
                    // split runner did not start successfully
                    driverStats = new DriverStats();
                }
                return driverStats;
            }
        }, notificationExecutor);
    }
}
Also used : DriverContext(io.trino.operator.DriverContext) DriverStats(io.trino.operator.DriverStats) SetThreadName(io.airlift.concurrent.SetThreadName) ListenableFuture(com.google.common.util.concurrent.ListenableFuture)

Example 2 with DriverStats

use of io.trino.operator.DriverStats in project trino by trinodb.

the class SplitMonitor method splitCompletedEvent.

private void splitCompletedEvent(TaskId taskId, DriverStats driverStats, @Nullable String failureType, @Nullable String failureMessage) {
    Duration queuedTime = ofMillis(driverStats.getQueuedTime().toMillis());
    Optional<Duration> queuedTimeIfSplitRan = Optional.empty();
    if (driverStats.getStartTime() != null) {
        queuedTimeIfSplitRan = Optional.of(queuedTime);
    }
    Duration elapsedTime = ofMillis(driverStats.getElapsedTime().toMillis());
    Optional<Duration> elapsedTimeIfSplitRan = Optional.empty();
    if (driverStats.getEndTime() != null) {
        elapsedTimeIfSplitRan = Optional.of(elapsedTime);
    }
    Optional<SplitFailureInfo> splitFailureMetadata = Optional.empty();
    if (failureType != null) {
        splitFailureMetadata = Optional.of(new SplitFailureInfo(failureType, failureMessage != null ? failureMessage : ""));
    }
    Optional<String> splitCatalog = driverStats.getOperatorStats().stream().map(OperatorStats::getInfo).filter(SplitOperatorInfo.class::isInstance).map(SplitOperatorInfo.class::cast).map(info -> info.getCatalogName().getCatalogName()).findFirst();
    try {
        eventListenerManager.splitCompleted(new SplitCompletedEvent(taskId.getQueryId().toString(), taskId.getStageId().toString(), taskId.toString(), splitCatalog, driverStats.getCreateTime().toDate().toInstant(), Optional.ofNullable(driverStats.getStartTime()).map(startTime -> startTime.toDate().toInstant()), Optional.ofNullable(driverStats.getEndTime()).map(endTime -> endTime.toDate().toInstant()), new SplitStatistics(ofMillis(driverStats.getTotalCpuTime().toMillis()), elapsedTime, queuedTime, ofMillis(driverStats.getRawInputReadTime().toMillis()), driverStats.getRawInputPositions(), driverStats.getRawInputDataSize().toBytes(), queuedTimeIfSplitRan, elapsedTimeIfSplitRan), splitFailureMetadata, objectMapper.writeValueAsString(driverStats)));
    } catch (JsonProcessingException e) {
        log.error(e, "Error processing split completion event for task %s", taskId);
    }
}
Also used : SplitCompletedEvent(io.trino.spi.eventlistener.SplitCompletedEvent) SplitFailureInfo(io.trino.spi.eventlistener.SplitFailureInfo) Logger(io.airlift.log.Logger) OperatorStats(io.trino.operator.OperatorStats) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DriverStats(io.trino.operator.DriverStats) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TaskId(io.trino.execution.TaskId) SplitStatistics(io.trino.spi.eventlistener.SplitStatistics) Inject(javax.inject.Inject) EventListenerManager(io.trino.eventlistener.EventListenerManager) Duration(java.time.Duration) Objects.requireNonNull(java.util.Objects.requireNonNull) SplitOperatorInfo(io.trino.operator.SplitOperatorInfo) Optional(java.util.Optional) Duration.ofMillis(java.time.Duration.ofMillis) Nullable(javax.annotation.Nullable) SplitCompletedEvent(io.trino.spi.eventlistener.SplitCompletedEvent) SplitStatistics(io.trino.spi.eventlistener.SplitStatistics) SplitFailureInfo(io.trino.spi.eventlistener.SplitFailureInfo) Duration(java.time.Duration) SplitOperatorInfo(io.trino.operator.SplitOperatorInfo) OperatorStats(io.trino.operator.OperatorStats) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

DriverStats (io.trino.operator.DriverStats)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 SetThreadName (io.airlift.concurrent.SetThreadName)1 Logger (io.airlift.log.Logger)1 EventListenerManager (io.trino.eventlistener.EventListenerManager)1 TaskId (io.trino.execution.TaskId)1 DriverContext (io.trino.operator.DriverContext)1 OperatorStats (io.trino.operator.OperatorStats)1 SplitOperatorInfo (io.trino.operator.SplitOperatorInfo)1 SplitCompletedEvent (io.trino.spi.eventlistener.SplitCompletedEvent)1 SplitFailureInfo (io.trino.spi.eventlistener.SplitFailureInfo)1 SplitStatistics (io.trino.spi.eventlistener.SplitStatistics)1 Duration (java.time.Duration)1 Duration.ofMillis (java.time.Duration.ofMillis)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Optional (java.util.Optional)1 Nullable (javax.annotation.Nullable)1 Inject (javax.inject.Inject)1