Search in sources :

Example 1 with CoLocationGroupImpl

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);
        }
    }
}
Also used : CoLocationGroupImpl(org.apache.flink.runtime.jobmanager.scheduler.CoLocationGroupImpl)

Example 2 with CoLocationGroupImpl

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);
        }
    }
}
Also used : IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) Tuple2(org.apache.flink.api.java.tuple.Tuple2) CoLocationGroupImpl(org.apache.flink.runtime.jobmanager.scheduler.CoLocationGroupImpl) SlotSharingGroup(org.apache.flink.runtime.jobmanager.scheduler.SlotSharingGroup) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap)

Aggregations

CoLocationGroupImpl (org.apache.flink.runtime.jobmanager.scheduler.CoLocationGroupImpl)2 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)1 SlotSharingGroup (org.apache.flink.runtime.jobmanager.scheduler.SlotSharingGroup)1