Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scheduler support for custom partitioning across nodes
- Loading branch information
Showing
12 changed files
with
278 additions
and
42 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...in/src/main/java/com/facebook/presto/execution/scheduler/DynamicSplitPlacementPolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.facebook.presto.execution.scheduler; | ||
|
||
import com.facebook.presto.execution.RemoteTask; | ||
import com.facebook.presto.metadata.Split; | ||
import com.facebook.presto.spi.Node; | ||
import com.google.common.collect.Multimap; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.function.Supplier; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
public class DynamicSplitPlacementPolicy | ||
implements SplitPlacementPolicy | ||
{ | ||
private final NodeSelector nodeSelector; | ||
private final Supplier<? extends List<RemoteTask>> remoteTasks; | ||
|
||
public DynamicSplitPlacementPolicy(NodeSelector nodeSelector, Supplier<? extends List<RemoteTask>> remoteTasks) | ||
{ | ||
this.nodeSelector = requireNonNull(nodeSelector, "nodeSelector is null"); | ||
this.remoteTasks = requireNonNull(remoteTasks, "remoteTasks is null"); | ||
} | ||
|
||
@Override | ||
public Multimap<Node, Split> computeAssignments(Set<Split> splits) | ||
{ | ||
return nodeSelector.computeAssignments(splits, remoteTasks.get()); | ||
} | ||
|
||
@Override | ||
public void lockDownNodes() | ||
{ | ||
nodeSelector.lockDownNodes(); | ||
} | ||
|
||
@Override | ||
public List<Node> allNodes() | ||
{ | ||
return nodeSelector.allNodes(); | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
...rc/main/java/com/facebook/presto/execution/scheduler/FixedSourcePartitionedScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.facebook.presto.execution.scheduler; | ||
|
||
import com.facebook.presto.execution.RemoteTask; | ||
import com.facebook.presto.execution.SqlStageExecution; | ||
import com.facebook.presto.metadata.Split; | ||
import com.facebook.presto.spi.Node; | ||
import com.facebook.presto.split.SplitSource; | ||
import com.facebook.presto.sql.planner.NodePartitionMap; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.Multimap; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.function.Supplier; | ||
|
||
import static com.facebook.presto.util.ImmutableCollectors.toImmutableList; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
public class FixedSourcePartitionedScheduler | ||
implements StageScheduler | ||
{ | ||
private final SqlStageExecution stage; | ||
private final NodePartitionMap partitioning; | ||
private final SourcePartitionedScheduler sourcePartitionedScheduler; | ||
private boolean scheduledTasks; | ||
|
||
public FixedSourcePartitionedScheduler( | ||
SqlStageExecution stage, | ||
SplitSource splitSource, | ||
NodePartitionMap partitioning, | ||
int splitBatchSize, | ||
NodeSelector nodeSelector) | ||
{ | ||
requireNonNull(stage, "stage is null"); | ||
requireNonNull(splitSource, "splitSource is null"); | ||
requireNonNull(partitioning, "partitioning is null"); | ||
|
||
this.stage = stage; | ||
this.partitioning = partitioning; | ||
|
||
FixedSplitPlacementPolicy splitPlacementPolicy = new FixedSplitPlacementPolicy(nodeSelector, partitioning, stage::getAllTasks); | ||
sourcePartitionedScheduler = new SourcePartitionedScheduler(stage, splitSource, splitPlacementPolicy, splitBatchSize); | ||
} | ||
|
||
@Override | ||
public ScheduleResult schedule() | ||
{ | ||
// schedule a task on every node in the distribution | ||
List<RemoteTask> newTasks = ImmutableList.of(); | ||
if (!scheduledTasks) { | ||
newTasks = partitioning.getPartitionToNode().entrySet().stream() | ||
.map(entry -> stage.scheduleTask(entry.getValue(), entry.getKey())) | ||
.collect(toImmutableList()); | ||
scheduledTasks = true; | ||
} | ||
|
||
ScheduleResult schedule = sourcePartitionedScheduler.schedule(); | ||
return new ScheduleResult(schedule.isFinished(), newTasks, schedule.getBlocked()); | ||
} | ||
|
||
@Override | ||
public void close() | ||
{ | ||
sourcePartitionedScheduler.close(); | ||
} | ||
|
||
private static class FixedSplitPlacementPolicy | ||
implements SplitPlacementPolicy | ||
{ | ||
private final NodeSelector nodeSelector; | ||
private final NodePartitionMap partitioning; | ||
private final Supplier<? extends List<RemoteTask>> remoteTasks; | ||
|
||
public FixedSplitPlacementPolicy(NodeSelector nodeSelector, | ||
NodePartitionMap partitioning, | ||
Supplier<? extends List<RemoteTask>> remoteTasks) | ||
{ | ||
this.nodeSelector = nodeSelector; | ||
this.partitioning = partitioning; | ||
this.remoteTasks = remoteTasks; | ||
} | ||
|
||
@Override | ||
public Multimap<Node, Split> computeAssignments(Set<Split> splits) | ||
{ | ||
return nodeSelector.computeAssignments(splits, remoteTasks.get(), partitioning); | ||
} | ||
|
||
@Override | ||
public void lockDownNodes() | ||
{ | ||
} | ||
|
||
@Override | ||
public List<Node> allNodes() | ||
{ | ||
return ImmutableList.copyOf(partitioning.getPartitionToNode().values()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.