Skip to content

Commit a659c3e

Browse files
skrzypo987losipiuk
authored andcommitted
Remove StageExecutionDescriptor class
The class is not useful after removal of grouped execution. Major parts of PlanFragmenter class has been removed in the process, as well as some tests strictly related to grouped execution
1 parent c761977 commit a659c3e

29 files changed

+56
-1765
lines changed

core/trino-main/src/main/java/io/trino/execution/SqlTaskExecution.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import io.trino.operator.DriverStats;
3636
import io.trino.operator.PipelineContext;
3737
import io.trino.operator.PipelineExecutionStrategy;
38-
import io.trino.operator.StageExecutionDescriptor;
3938
import io.trino.operator.TaskContext;
4039
import io.trino.spi.SplitWeight;
4140
import io.trino.spi.TrinoException;
@@ -223,7 +222,7 @@ private SqlTaskExecution(
223222
taskContext,
224223
localExecutionPlan.getDriverFactories().stream()
225224
.collect(toImmutableMap(DriverFactory::getPipelineId, DriverFactory::getPipelineExecutionStrategy)));
226-
this.schedulingLifespanManager = new SchedulingLifespanManager(localExecutionPlan.getPartitionedSourceOrder(), localExecutionPlan.getStageExecutionDescriptor(), this.status);
225+
this.schedulingLifespanManager = new SchedulingLifespanManager(localExecutionPlan.getPartitionedSourceOrder(), this.status);
227226

228227
checkArgument(this.driverRunnerFactoriesWithSplitLifeCycle.keySet().equals(partitionedSources),
229228
"Fragment is partitioned, but not all partitioned drivers were found");
@@ -779,7 +778,6 @@ private static class SchedulingLifespanManager
779778
// Note that different drivers in a task may have different pipelineExecutionStrategy.
780779

781780
private final List<PlanNodeId> sourceStartOrder;
782-
private final StageExecutionDescriptor stageExecutionDescriptor;
783781
private final Status status;
784782

785783
private final Map<Lifespan, SchedulingLifespan> lifespans = new HashMap<>();
@@ -790,10 +788,9 @@ private static class SchedulingLifespanManager
790788

791789
private int maxScheduledPlanNodeOrdinal;
792790

793-
public SchedulingLifespanManager(List<PlanNodeId> sourceStartOrder, StageExecutionDescriptor stageExecutionDescriptor, Status status)
791+
public SchedulingLifespanManager(List<PlanNodeId> sourceStartOrder, Status status)
794792
{
795793
this.sourceStartOrder = ImmutableList.copyOf(sourceStartOrder);
796-
this.stageExecutionDescriptor = stageExecutionDescriptor;
797794
this.status = requireNonNull(status, "status is null");
798795
}
799796

@@ -884,13 +881,6 @@ public Optional<PlanNodeId> getSchedulingPlanNode()
884881
{
885882
checkState(!isDone());
886883
while (!isDone()) {
887-
// Return current plan node if this lifespan is compatible with the plan node.
888-
// i.e. One of the following bullet points is true:
889-
// * The execution strategy of the plan node is grouped. And lifespan represents a driver group.
890-
// * The execution strategy of the plan node is ungrouped. And lifespan is task wide.
891-
if (manager.stageExecutionDescriptor.isScanGroupedExecution(manager.sourceStartOrder.get(schedulingPlanNodeOrdinal)) != lifespan.isTaskWide()) {
892-
return Optional.of(manager.sourceStartOrder.get(schedulingPlanNodeOrdinal));
893-
}
894884
// This lifespan is incompatible with the plan node. As a result, this method should either
895885
// return empty to indicate that scheduling for this lifespan is blocked, or skip the current
896886
// plan node and went on to the next one. Which one of the two happens is dependent on whether

core/trino-main/src/main/java/io/trino/execution/SqlTaskExecutionFactory.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ public SqlTaskExecution create(
8181
fragment.getRoot(),
8282
TypeProvider.copyOf(fragment.getSymbols()),
8383
fragment.getPartitioningScheme(),
84-
fragment.getStageExecutionDescriptor(),
8584
fragment.getPartitionedSources(),
8685
outputBuffer);
8786
}

core/trino-main/src/main/java/io/trino/execution/scheduler/FaultTolerantStageScheduler.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,6 @@ public FaultTolerantStageScheduler(
197197
int taskRetryAttemptsPerTask,
198198
int maxTasksWaitingForNodePerStage)
199199
{
200-
checkArgument(!stage.getFragment().getStageExecutionDescriptor().isStageGroupedExecution(), "grouped execution is expected to be disabled");
201-
202200
this.session = requireNonNull(session, "session is null");
203201
this.stage = requireNonNull(stage, "stage is null");
204202
this.failureDetector = requireNonNull(failureDetector, "failureDetector is null");

core/trino-main/src/main/java/io/trino/execution/scheduler/FixedSourcePartitionedScheduler.java

Lines changed: 3 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,8 @@
2222
import io.trino.execution.RemoteTask;
2323
import io.trino.execution.TableExecuteContextManager;
2424
import io.trino.execution.scheduler.ScheduleResult.BlockedReason;
25-
import io.trino.execution.scheduler.group.DynamicLifespanScheduler;
26-
import io.trino.execution.scheduler.group.FixedLifespanScheduler;
27-
import io.trino.execution.scheduler.group.LifespanScheduler;
2825
import io.trino.metadata.InternalNode;
2926
import io.trino.metadata.Split;
30-
import io.trino.operator.StageExecutionDescriptor;
3127
import io.trino.server.DynamicFilterService;
3228
import io.trino.spi.connector.ConnectorPartitionHandle;
3329
import io.trino.split.SplitSource;
@@ -43,7 +39,6 @@
4339
import java.util.function.Supplier;
4440

4541
import static com.google.common.base.Preconditions.checkArgument;
46-
import static com.google.common.base.Preconditions.checkState;
4742
import static com.google.common.base.Verify.verify;
4843
import static io.airlift.concurrent.MoreFutures.whenAnyComplete;
4944
import static io.trino.execution.scheduler.SourcePartitionedScheduler.newSourcePartitionedSchedulerAsSourceScheduler;
@@ -59,15 +54,13 @@ public class FixedSourcePartitionedScheduler
5954
private final List<InternalNode> nodes;
6055
private final List<SourceScheduler> sourceSchedulers;
6156
private final List<ConnectorPartitionHandle> partitionHandles;
62-
private final Optional<LifespanScheduler> groupedLifespanScheduler;
6357

6458
private final PartitionIdAllocator partitionIdAllocator;
6559
private final Map<InternalNode, RemoteTask> scheduledTasks;
6660

6761
public FixedSourcePartitionedScheduler(
6862
StageExecution stageExecution,
6963
Map<PlanNodeId, SplitSource> splitSources,
70-
StageExecutionDescriptor stageExecutionDescriptor,
7164
List<PlanNodeId> schedulingOrder,
7265
List<InternalNode> nodes,
7366
BucketNodeMap bucketNodeMap,
@@ -93,20 +86,14 @@ public FixedSourcePartitionedScheduler(
9386
BucketedSplitPlacementPolicy splitPlacementPolicy = new BucketedSplitPlacementPolicy(nodeSelector, nodes, bucketNodeMap, stageExecution::getAllTasks);
9487

9588
ArrayList<SourceScheduler> sourceSchedulers = new ArrayList<>();
96-
checkArgument(
97-
partitionHandles.equals(ImmutableList.of(NOT_PARTITIONED)) != stageExecutionDescriptor.isStageGroupedExecution(),
98-
"PartitionHandles should be [NOT_PARTITIONED] if and only if all scan nodes use ungrouped execution strategy");
99-
int nodeCount = nodes.size();
10089
int concurrentLifespans = partitionHandles.size();
10190

10291
boolean firstPlanNode = true;
103-
Optional<LifespanScheduler> groupedLifespanScheduler = Optional.empty();
10492

10593
partitionIdAllocator = new PartitionIdAllocator();
10694
scheduledTasks = new HashMap<>();
10795
for (PlanNodeId planNodeId : schedulingOrder) {
10896
SplitSource splitSource = splitSources.get(planNodeId);
109-
boolean groupedExecutionForScanNode = stageExecutionDescriptor.isScanGroupedExecution(planNodeId);
11097
// TODO : change anySourceTaskBlocked to accommodate the correct blocked status of source tasks
11198
// (ref : https://github.com/trinodb/trino/issues/4713)
11299
SourceScheduler sourceScheduler = newSourcePartitionedSchedulerAsSourceScheduler(
@@ -115,47 +102,21 @@ public FixedSourcePartitionedScheduler(
115102
splitSource,
116103
splitPlacementPolicy,
117104
Math.max(splitBatchSize / concurrentLifespans, 1),
118-
groupedExecutionForScanNode,
105+
false,
119106
dynamicFilterService,
120107
tableExecuteContextManager,
121108
() -> true,
122109
partitionIdAllocator,
123110
scheduledTasks);
124111

125-
if (stageExecutionDescriptor.isStageGroupedExecution() && !groupedExecutionForScanNode) {
126-
sourceScheduler = new AsGroupedSourceScheduler(sourceScheduler);
127-
}
128112
sourceSchedulers.add(sourceScheduler);
129113

130114
if (firstPlanNode) {
131115
firstPlanNode = false;
132-
if (!stageExecutionDescriptor.isStageGroupedExecution()) {
133-
sourceScheduler.startLifespan(Lifespan.taskWide(), NOT_PARTITIONED);
134-
sourceScheduler.noMoreLifespans();
135-
}
136-
else {
137-
LifespanScheduler lifespanScheduler;
138-
if (bucketNodeMap.isDynamic()) {
139-
// Callee of the constructor guarantees dynamic bucket node map will only be
140-
// used when the stage has no remote source.
141-
//
142-
// When the stage has no remote source, any scan is grouped execution guarantees
143-
// all scan is grouped execution.
144-
lifespanScheduler = new DynamicLifespanScheduler(bucketNodeMap, nodes, partitionHandles);
145-
}
146-
else {
147-
lifespanScheduler = new FixedLifespanScheduler(bucketNodeMap, partitionHandles);
148-
}
149-
150-
// Schedule the first few lifespans
151-
lifespanScheduler.scheduleInitial(sourceScheduler);
152-
// Schedule new lifespans for finished ones
153-
stageExecution.addCompletedDriverGroupsChangedListener(lifespanScheduler::onLifespanFinished);
154-
groupedLifespanScheduler = Optional.of(lifespanScheduler);
155-
}
116+
sourceScheduler.startLifespan(Lifespan.taskWide(), NOT_PARTITIONED);
117+
sourceScheduler.noMoreLifespans();
156118
}
157119
}
158-
this.groupedLifespanScheduler = groupedLifespanScheduler;
159120
this.sourceSchedulers = sourceSchedulers;
160121
}
161122

@@ -188,15 +149,6 @@ public ScheduleResult schedule()
188149
List<ListenableFuture<Void>> blocked = new ArrayList<>();
189150
BlockedReason blockedReason = BlockedReason.NO_ACTIVE_DRIVER_GROUP;
190151

191-
if (groupedLifespanScheduler.isPresent()) {
192-
// Start new driver groups on the first scheduler if necessary,
193-
// i.e. when previous ones have finished execution (not finished scheduling).
194-
//
195-
// Invoke schedule method to get a new SettableFuture every time.
196-
// Reusing previously returned SettableFuture could lead to the ListenableFuture retaining too many listeners.
197-
blocked.add(groupedLifespanScheduler.get().schedule(sourceSchedulers.get(0)));
198-
}
199-
200152
int splitsScheduled = 0;
201153
Iterator<SourceScheduler> schedulerIterator = sourceSchedulers.iterator();
202154
List<Lifespan> driverGroupsToStart = ImmutableList.of();
@@ -299,77 +251,4 @@ public InternalNode getNodeForBucket(int bucketId)
299251
return bucketNodeMap.getAssignedNode(bucketId).get();
300252
}
301253
}
302-
303-
private static class AsGroupedSourceScheduler
304-
implements SourceScheduler
305-
{
306-
private final SourceScheduler sourceScheduler;
307-
private boolean started;
308-
private boolean completed;
309-
private final List<Lifespan> pendingCompleted;
310-
311-
public AsGroupedSourceScheduler(SourceScheduler sourceScheduler)
312-
{
313-
this.sourceScheduler = requireNonNull(sourceScheduler, "sourceScheduler is null");
314-
pendingCompleted = new ArrayList<>();
315-
}
316-
317-
@Override
318-
public void start()
319-
{
320-
sourceScheduler.start();
321-
}
322-
323-
@Override
324-
public ScheduleResult schedule()
325-
{
326-
return sourceScheduler.schedule();
327-
}
328-
329-
@Override
330-
public void close()
331-
{
332-
sourceScheduler.close();
333-
}
334-
335-
@Override
336-
public PlanNodeId getPlanNodeId()
337-
{
338-
return sourceScheduler.getPlanNodeId();
339-
}
340-
341-
@Override
342-
public void startLifespan(Lifespan lifespan, ConnectorPartitionHandle partitionHandle)
343-
{
344-
pendingCompleted.add(lifespan);
345-
if (started) {
346-
return;
347-
}
348-
started = true;
349-
sourceScheduler.startLifespan(Lifespan.taskWide(), NOT_PARTITIONED);
350-
sourceScheduler.noMoreLifespans();
351-
}
352-
353-
@Override
354-
public void noMoreLifespans()
355-
{
356-
checkState(started);
357-
}
358-
359-
@Override
360-
public List<Lifespan> drainCompletedLifespans()
361-
{
362-
if (!completed) {
363-
List<Lifespan> lifespans = sourceScheduler.drainCompletedLifespans();
364-
if (lifespans.isEmpty()) {
365-
return ImmutableList.of();
366-
}
367-
checkState(ImmutableList.of(Lifespan.taskWide()).equals(lifespans));
368-
completed = true;
369-
}
370-
List<Lifespan> result = ImmutableList.copyOf(pendingCompleted);
371-
pendingCompleted.clear();
372-
return result;
373-
}
374-
}
375254
}

core/trino-main/src/main/java/io/trino/execution/scheduler/SqlQueryScheduler.java

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,8 +1393,6 @@ public void stateChanged(QueryState newState)
13931393
NodeSelector nodeSelector = nodeScheduler.createNodeSelector(session, catalogName);
13941394
SplitPlacementPolicy placementPolicy = new DynamicSplitPlacementPolicy(nodeSelector, stageExecution::getAllTasks);
13951395

1396-
checkArgument(!fragment.getStageExecutionDescriptor().isStageGroupedExecution());
1397-
13981396
return newSourcePartitionedSchedulerAsStageScheduler(
13991397
stageExecution,
14001398
planNodeId,
@@ -1431,46 +1429,27 @@ else if (partitioningHandle.equals(SCALED_WRITER_DISTRIBUTION)) {
14311429
List<PlanNodeId> schedulingOrder = fragment.getPartitionedSources();
14321430
Optional<CatalogName> catalogName = partitioningHandle.getConnectorId();
14331431
checkArgument(catalogName.isPresent(), "No connector ID for partitioning handle: %s", partitioningHandle);
1434-
List<ConnectorPartitionHandle> connectorPartitionHandles;
1435-
boolean groupedExecutionForStage = fragment.getStageExecutionDescriptor().isStageGroupedExecution();
1436-
if (groupedExecutionForStage) {
1437-
connectorPartitionHandles = nodePartitioningManager.listPartitionHandles(session, partitioningHandle);
1438-
checkState(!ImmutableList.of(NOT_PARTITIONED).equals(connectorPartitionHandles));
1439-
}
1440-
else {
1441-
connectorPartitionHandles = ImmutableList.of(NOT_PARTITIONED);
1442-
}
1432+
List<ConnectorPartitionHandle> connectorPartitionHandles = ImmutableList.of(NOT_PARTITIONED);
14431433

14441434
BucketNodeMap bucketNodeMap;
14451435
List<InternalNode> stageNodeList;
14461436
if (fragment.getRemoteSourceNodes().stream().allMatch(node -> node.getExchangeType() == REPLICATE)) {
14471437
// no remote source
1448-
boolean dynamicLifespanSchedule = fragment.getStageExecutionDescriptor().isDynamicLifespanSchedule();
1449-
bucketNodeMap = nodePartitioningManager.getBucketNodeMap(session, partitioningHandle, dynamicLifespanSchedule);
1450-
1451-
// verify execution is consistent with planner's decision on dynamic lifespan schedule
1452-
verify(bucketNodeMap.isDynamic() == dynamicLifespanSchedule);
1438+
bucketNodeMap = nodePartitioningManager.getBucketNodeMap(session, partitioningHandle, false);
14531439

14541440
stageNodeList = new ArrayList<>(nodeScheduler.createNodeSelector(session, catalogName).allNodes());
14551441
Collections.shuffle(stageNodeList);
14561442
}
14571443
else {
1458-
// cannot use dynamic lifespan schedule
1459-
verify(!fragment.getStageExecutionDescriptor().isDynamicLifespanSchedule());
1460-
14611444
// remote source requires nodePartitionMap
14621445
NodePartitionMap nodePartitionMap = partitioningCache.apply(partitioningHandle);
1463-
if (groupedExecutionForStage) {
1464-
checkState(connectorPartitionHandles.size() == nodePartitionMap.getBucketToPartition().length);
1465-
}
14661446
stageNodeList = nodePartitionMap.getPartitionToNode();
14671447
bucketNodeMap = nodePartitionMap.asBucketNodeMap();
14681448
}
14691449

14701450
return new FixedSourcePartitionedScheduler(
14711451
stageExecution,
14721452
splitSources,
1473-
fragment.getStageExecutionDescriptor(),
14741453
schedulingOrder,
14751454
stageNodeList,
14761455
bucketNodeMap,

0 commit comments

Comments
 (0)