use of org.apache.flink.runtime.jobmanager.scheduler.CoLocationGroupImpl in project flink by apache.
the class JobVertex method setStrictlyCoLocatedWith.
/**
* Tells this vertex to strictly co locate its subtasks with the subtasks of the given vertex.
* Strict co-location implies that the n'th subtask of this vertex will run on the same parallel
* computing instance (TaskManager) as the n'th subtask of the given vertex.
*
* <p>NOTE: Co-location is only possible between vertices in a slot sharing group.
*
* <p>NOTE: This vertex must (transitively) depend on the vertex to be co-located with. That
* means that the respective vertex must be a (transitive) input of this vertex.
*
* @param strictlyCoLocatedWith The vertex whose subtasks to co-locate this vertex's subtasks
* with.
* @throws IllegalArgumentException Thrown, if this vertex and the vertex to co-locate with are
* not in a common slot sharing group.
* @see #setSlotSharingGroup(SlotSharingGroup)
*/
public void setStrictlyCoLocatedWith(JobVertex strictlyCoLocatedWith) {
if (this.slotSharingGroup == null || this.slotSharingGroup != strictlyCoLocatedWith.slotSharingGroup) {
throw new IllegalArgumentException("Strict co-location requires that both vertices are in the same slot sharing group.");
}
CoLocationGroupImpl thisGroup = this.coLocationGroup;
CoLocationGroupImpl otherGroup = strictlyCoLocatedWith.coLocationGroup;
if (otherGroup == null) {
if (thisGroup == null) {
CoLocationGroupImpl group = new CoLocationGroupImpl(this, strictlyCoLocatedWith);
this.coLocationGroup = group;
strictlyCoLocatedWith.coLocationGroup = group;
} else {
thisGroup.addVertex(strictlyCoLocatedWith);
strictlyCoLocatedWith.coLocationGroup = thisGroup;
}
} else {
if (thisGroup == null) {
otherGroup.addVertex(this);
this.coLocationGroup = otherGroup;
} else {
// both had yet distinct groups, we need to merge them
thisGroup.mergeInto(otherGroup);
}
}
}
use of org.apache.flink.runtime.jobmanager.scheduler.CoLocationGroupImpl in project flink by apache.
the class StreamingJobGraphGenerator method setCoLocation.
private void setCoLocation() {
final Map<String, Tuple2<SlotSharingGroup, CoLocationGroupImpl>> coLocationGroups = new HashMap<>();
for (Map.Entry<Integer, JobVertex> entry : jobVertices.entrySet()) {
final StreamNode node = streamGraph.getStreamNode(entry.getKey());
final JobVertex vertex = entry.getValue();
final SlotSharingGroup sharingGroup = vertex.getSlotSharingGroup();
// configure co-location constraint
final String coLocationGroupKey = node.getCoLocationGroup();
if (coLocationGroupKey != null) {
if (sharingGroup == null) {
throw new IllegalStateException("Cannot use a co-location constraint without a slot sharing group");
}
Tuple2<SlotSharingGroup, CoLocationGroupImpl> constraint = coLocationGroups.computeIfAbsent(coLocationGroupKey, k -> new Tuple2<>(sharingGroup, new CoLocationGroupImpl()));
if (constraint.f0 != sharingGroup) {
throw new IllegalStateException("Cannot co-locate operators from different slot sharing groups");
}
vertex.updateCoLocationGroup(constraint.f1);
constraint.f1.addVertex(vertex);
}
}
}
Aggregations