use of io.trino.execution.scheduler.ScheduleResult.BlockedReason in project trino by trinodb.
the class FixedSourcePartitionedScheduler method schedule.
@Override
public ScheduleResult schedule() {
// schedule a task on every node in the distribution
List<RemoteTask> newTasks = ImmutableList.of();
if (scheduledTasks.isEmpty()) {
ImmutableList.Builder<RemoteTask> newTasksBuilder = ImmutableList.builder();
for (InternalNode node : nodes) {
Optional<RemoteTask> task = stageExecution.scheduleTask(node, partitionIdAllocator.getNextId(), ImmutableMultimap.of(), ImmutableMultimap.of());
if (task.isPresent()) {
scheduledTasks.put(node, task.get());
newTasksBuilder.add(task.get());
}
}
newTasks = newTasksBuilder.build();
}
boolean allBlocked = true;
List<ListenableFuture<Void>> blocked = new ArrayList<>();
BlockedReason blockedReason = BlockedReason.NO_ACTIVE_DRIVER_GROUP;
if (groupedLifespanScheduler.isPresent()) {
// Start new driver groups on the first scheduler if necessary,
// i.e. when previous ones have finished execution (not finished scheduling).
//
// Invoke schedule method to get a new SettableFuture every time.
// Reusing previously returned SettableFuture could lead to the ListenableFuture retaining too many listeners.
blocked.add(groupedLifespanScheduler.get().schedule(sourceSchedulers.get(0)));
}
int splitsScheduled = 0;
Iterator<SourceScheduler> schedulerIterator = sourceSchedulers.iterator();
List<Lifespan> driverGroupsToStart = ImmutableList.of();
boolean shouldInvokeNoMoreDriverGroups = false;
while (schedulerIterator.hasNext()) {
SourceScheduler sourceScheduler = schedulerIterator.next();
for (Lifespan lifespan : driverGroupsToStart) {
sourceScheduler.startLifespan(lifespan, partitionHandleFor(lifespan));
}
if (shouldInvokeNoMoreDriverGroups) {
sourceScheduler.noMoreLifespans();
}
ScheduleResult schedule = sourceScheduler.schedule();
splitsScheduled += schedule.getSplitsScheduled();
if (schedule.getBlockedReason().isPresent()) {
blocked.add(schedule.getBlocked());
blockedReason = blockedReason.combineWith(schedule.getBlockedReason().get());
} else {
verify(schedule.getBlocked().isDone(), "blockedReason not provided when scheduler is blocked");
allBlocked = false;
}
driverGroupsToStart = sourceScheduler.drainCompletedLifespans();
if (schedule.isFinished()) {
stageExecution.schedulingComplete(sourceScheduler.getPlanNodeId());
schedulerIterator.remove();
sourceScheduler.close();
shouldInvokeNoMoreDriverGroups = true;
} else {
shouldInvokeNoMoreDriverGroups = false;
}
}
if (allBlocked) {
return new ScheduleResult(sourceSchedulers.isEmpty(), newTasks, whenAnyComplete(blocked), blockedReason, splitsScheduled);
} else {
return new ScheduleResult(sourceSchedulers.isEmpty(), newTasks, splitsScheduled);
}
}
Aggregations