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