Search in sources :

Example 1 with Lifespan

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

the class HttpRemoteTask method getSplitAssignment.

private synchronized SplitAssignment getSplitAssignment(PlanNodeId planNodeId) {
    Set<ScheduledSplit> splits = pendingSplits.get(planNodeId);
    boolean pendingNoMoreSplits = Boolean.TRUE.equals(this.noMoreSplits.get(planNodeId));
    boolean noMoreSplits = this.noMoreSplits.containsKey(planNodeId);
    Set<Lifespan> noMoreSplitsForLifespan = pendingNoMoreSplitsForLifespan.get(planNodeId);
    SplitAssignment assignment = null;
    if (!splits.isEmpty() || !noMoreSplitsForLifespan.isEmpty() || pendingNoMoreSplits) {
        assignment = new SplitAssignment(planNodeId, splits, noMoreSplitsForLifespan, noMoreSplits);
    }
    return assignment;
}
Also used : ScheduledSplit(io.trino.execution.ScheduledSplit) SplitAssignment(io.trino.execution.SplitAssignment) Lifespan(io.trino.execution.Lifespan)

Example 2 with Lifespan

use of io.trino.execution.Lifespan 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);
    }
}
Also used : BlockedReason(io.trino.execution.scheduler.ScheduleResult.BlockedReason) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) RemoteTask(io.trino.execution.RemoteTask) SourcePartitionedScheduler.newSourcePartitionedSchedulerAsSourceScheduler(io.trino.execution.scheduler.SourcePartitionedScheduler.newSourcePartitionedSchedulerAsSourceScheduler) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) InternalNode(io.trino.metadata.InternalNode) Lifespan(io.trino.execution.Lifespan)

Example 3 with Lifespan

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

the class DynamicLifespanScheduler method onLifespanFinished.

@Override
public void onLifespanFinished(Iterable<Lifespan> newlyCompletedDriverGroups) {
    checkState(initialScheduled);
    SettableFuture<Void> newDriverGroupReady;
    synchronized (this) {
        for (Lifespan newlyCompletedDriverGroup : newlyCompletedDriverGroups) {
            checkArgument(!newlyCompletedDriverGroup.isTaskWide());
            recentlyCompletedDriverGroups.add(newlyCompletedDriverGroup);
        }
        newDriverGroupReady = this.newDriverGroupReady;
    }
    newDriverGroupReady.set(null);
}
Also used : Lifespan(io.trino.execution.Lifespan)

Example 4 with Lifespan

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

the class DynamicLifespanScheduler method schedule.

@Override
public SettableFuture<Void> schedule(SourceScheduler scheduler) {
    // Return a new future even if newDriverGroupReady has not finished.
    // Returning the same SettableFuture instance could lead to ListenableFuture retaining too many listener objects.
    checkState(initialScheduled);
    List<Lifespan> recentlyCompletedDriverGroups;
    synchronized (this) {
        recentlyCompletedDriverGroups = ImmutableList.copyOf(this.recentlyCompletedDriverGroups);
        this.recentlyCompletedDriverGroups.clear();
        newDriverGroupReady = SettableFuture.create();
    }
    for (Lifespan driverGroup : recentlyCompletedDriverGroups) {
        if (!driverGroups.hasNext()) {
            break;
        }
        int driverGroupId = driverGroups.nextInt();
        InternalNode nodeForCompletedDriverGroup = bucketNodeMap.getAssignedNode(driverGroup.getId()).orElseThrow(IllegalStateException::new);
        bucketNodeMap.assignBucketToNode(driverGroupId, nodeForCompletedDriverGroup);
        scheduler.startLifespan(Lifespan.driverGroup(driverGroupId), partitionHandles.get(driverGroupId));
    }
    if (!driverGroups.hasNext()) {
        scheduler.noMoreLifespans();
    }
    return newDriverGroupReady;
}
Also used : InternalNode(io.trino.metadata.InternalNode) Lifespan(io.trino.execution.Lifespan)

Example 5 with Lifespan

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

the class FixedLifespanScheduler method schedule.

@Override
public SettableFuture<Void> schedule(SourceScheduler scheduler) {
    // Return a new future even if newDriverGroupReady has not finished.
    // Returning the same SettableFuture instance could lead to ListenableFuture retaining too many listener objects.
    checkState(initialScheduled);
    List<Lifespan> recentlyCompletedDriverGroups;
    synchronized (this) {
        recentlyCompletedDriverGroups = ImmutableList.copyOf(this.recentlyCompletedDriverGroups);
        this.recentlyCompletedDriverGroups.clear();
        newDriverGroupReady = SettableFuture.create();
    }
    for (Lifespan driverGroup : recentlyCompletedDriverGroups) {
        IntListIterator driverGroupsIterator = nodeToDriverGroupsMap.get(driverGroupToNodeMap.get(driverGroup.getId()));
        if (!driverGroupsIterator.hasNext()) {
            continue;
        }
        int driverGroupId = driverGroupsIterator.nextInt();
        scheduler.startLifespan(Lifespan.driverGroup(driverGroupId), partitionHandles.get(driverGroupId));
        totalDriverGroupsScheduled++;
    }
    verify(totalDriverGroupsScheduled <= driverGroupToNodeMap.size());
    if (totalDriverGroupsScheduled == driverGroupToNodeMap.size()) {
        scheduler.noMoreLifespans();
    }
    return newDriverGroupReady;
}
Also used : IntListIterator(it.unimi.dsi.fastutil.ints.IntListIterator) Lifespan(io.trino.execution.Lifespan)

Aggregations

Lifespan (io.trino.execution.Lifespan)11 RemoteTask (io.trino.execution.RemoteTask)4 InternalNode (io.trino.metadata.InternalNode)4 Split (io.trino.metadata.Split)4 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 CatalogName (io.trino.connector.CatalogName)2 ScheduledSplit (io.trino.execution.ScheduledSplit)2 SplitAssignment (io.trino.execution.SplitAssignment)2 EmptySplit (io.trino.split.EmptySplit)2 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)2 TestingSplit (io.trino.testing.TestingSplit)2 ArrayList (java.util.ArrayList)2 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 TableExecuteContext (io.trino.execution.TableExecuteContext)1 BucketedSplitPlacementPolicy (io.trino.execution.scheduler.FixedSourcePartitionedScheduler.BucketedSplitPlacementPolicy)1 BlockedReason (io.trino.execution.scheduler.ScheduleResult.BlockedReason)1 SourcePartitionedScheduler.newSourcePartitionedSchedulerAsSourceScheduler (io.trino.execution.scheduler.SourcePartitionedScheduler.newSourcePartitionedSchedulerAsSourceScheduler)1