use of com.facebook.airlift.concurrent.SetThreadName in project presto by prestodb.
the class SqlTaskExecution method createSqlTaskExecution.
static SqlTaskExecution createSqlTaskExecution(TaskStateMachine taskStateMachine, TaskContext taskContext, OutputBuffer outputBuffer, List<TaskSource> sources, LocalExecutionPlan localExecutionPlan, TaskExecutor taskExecutor, Executor notificationExecutor, SplitMonitor queryMonitor) {
SqlTaskExecution task = new SqlTaskExecution(taskStateMachine, taskContext, outputBuffer, localExecutionPlan, taskExecutor, queryMonitor, notificationExecutor);
try (SetThreadName ignored = new SetThreadName("Task-%s", task.getTaskId())) {
// The scheduleDriversForTaskLifeCycle method calls enqueueDriverSplitRunner, which registers a callback with access to this object.
// The call back is accessed from another thread, so this code can not be placed in the constructor.
task.scheduleDriversForTaskLifeCycle();
task.addSources(sources);
return task;
}
}
use of com.facebook.airlift.concurrent.SetThreadName in project presto by prestodb.
the class SqlTaskExecution method enqueueDriverSplitRunner.
private synchronized void enqueueDriverSplitRunner(boolean forceRunSplit, List<DriverSplitRunner> runners) {
// schedule driver to be executed
List<ListenableFuture<?>> 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<?> finishedFuture = finishedFutures.get(i);
final 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 com.facebook.airlift.concurrent.SetThreadName in project presto by prestodb.
the class SqlTaskExecution method addSources.
public void addSources(List<TaskSource> sources) {
requireNonNull(sources, "sources is null");
checkState(!Thread.holdsLock(this), "Can not add sources while holding a lock on the %s", getClass().getSimpleName());
try (SetThreadName ignored = new SetThreadName("Task-%s", taskId)) {
// update our record of sources and schedule drivers for new partitioned splits
Map<PlanNodeId, TaskSource> updatedRemoteSources = updateSources(sources);
// the unpartitioned splits
for (WeakReference<Driver> driverReference : drivers) {
Driver driver = driverReference.get();
// the driver can be GCed due to a failure or a limit
if (driver == null) {
// remove the weak reference from the list to avoid a memory leak
// NOTE: this is a concurrent safe operation on a CopyOnWriteArrayList
drivers.remove(driverReference);
continue;
}
Optional<PlanNodeId> sourceId = driver.getSourceId();
if (!sourceId.isPresent()) {
continue;
}
TaskSource sourceUpdate = updatedRemoteSources.get(sourceId.get());
if (sourceUpdate == null) {
continue;
}
driver.updateSource(sourceUpdate);
}
// we may have transitioned to no more splits, so check for completion
checkTaskCompletion();
}
}
use of com.facebook.airlift.concurrent.SetThreadName in project presto by prestodb.
the class SqlTaskExecutionFactory method create.
public SqlTaskExecution create(Session session, QueryContext queryContext, TaskStateMachine taskStateMachine, OutputBuffer outputBuffer, TaskExchangeClientManager taskExchangeClientManager, PlanFragment fragment, List<TaskSource> sources, TableWriteInfo tableWriteInfo) {
TaskContext taskContext = queryContext.addTaskContext(taskStateMachine, session, // Plan has to be retained only if verbose memory exceeded errors are requested
isVerboseExceededMemoryLimitErrorsEnabled(session) ? Optional.of(fragment.getRoot()) : Optional.empty(), perOperatorCpuTimerEnabled, cpuTimerEnabled, perOperatorAllocationTrackingEnabled, allocationTrackingEnabled, legacyLifespanCompletionCondition);
LocalExecutionPlan localExecutionPlan;
try (SetThreadName ignored = new SetThreadName("Task-%s", taskStateMachine.getTaskId())) {
try {
localExecutionPlan = planner.plan(taskContext, fragment.getRoot(), fragment.getPartitioningScheme(), fragment.getStageExecutionDescriptor(), fragment.getTableScanSchedulingOrder(), outputBuffer, new HttpRemoteSourceFactory(blockEncodingSerde, taskExchangeClientManager, orderingCompiler), tableWriteInfo);
} catch (Throwable e) {
// planning failed
taskStateMachine.failed(e);
throwIfUnchecked(e);
throw new RuntimeException(e);
}
}
return createSqlTaskExecution(taskStateMachine, taskContext, outputBuffer, sources, localExecutionPlan, taskExecutor, taskNotificationExecutor, splitMonitor);
}
use of com.facebook.airlift.concurrent.SetThreadName in project presto by prestodb.
the class SqlQueryExecution method start.
@Override
public void start() {
try (SetThreadName ignored = new SetThreadName("Query-%s", stateMachine.getQueryId())) {
try {
// transition to planning
if (!stateMachine.transitionToPlanning()) {
// query already started or finished
return;
}
// analyze query
PlanRoot plan = analyzeQuery();
metadata.beginQuery(getSession(), plan.getConnectors());
// plan distribution of query
planDistribution(plan);
// transition to starting
if (!stateMachine.transitionToStarting()) {
// query already started or finished
return;
}
// if query is not finished, start the scheduler, otherwise cancel it
SqlQuerySchedulerInterface scheduler = queryScheduler.get();
if (!stateMachine.isDone()) {
scheduler.start();
}
} catch (Throwable e) {
fail(e);
throwIfInstanceOf(e, Error.class);
}
}
}
Aggregations