/** * Creates a new sub slot if the slot is not dead, yet. This method should only be called from * the assignment group instance to guarantee synchronization. * * NOTE: This method should only be called from the slot's assignment group. * * @param groupId The ID to identify tasks which can be deployed in this sub slot. * @return The new sub slot if the shared slot is still alive, otherwise null. */ SharedSlot allocateSharedSlot(AbstractID groupId){ if (isAlive()) { SharedSlot slot = new SharedSlot( getJobID(), getOwner(), getTaskManagerLocation(), subSlots.size(), getTaskManagerGateway(), assignmentGroup, this, groupId); subSlots.add(slot); return slot; } else { return null; } }
/** * Checks whether this slot is a root slot that has not yet added any child slots. * * @return True, if this slot is a root slot and has not yet added any children, false otherwise. */ public boolean isRootAndEmpty() { return getParent() == null && subSlots.isEmpty(); }
/** * Gets the root slot of the tree containing this slot. If this slot is the root, * the method returns this slot directly, otherwise it recursively goes to the parent until * it reaches the root. * * @return The root slot of the tree containing this slot */ public Slot getRoot() { if (parent == null) { return this; } else { return parent.getRoot(); } }
if (sharedSlot.isAlive() || !sharedSlot.getSubSlots().isEmpty()) { throw new IllegalArgumentException(); final SharedSlot parent = sharedSlot.getParent(); final AbstractID groupID = sharedSlot.getGroupID(); sharedSlot.getOwner().returnAllocatedSlot(sharedSlot); if (sharedSlot.markReleased()) { LOG.debug("Internally dispose empty shared slot {}.", sharedSlot); int parentRemaining = parent.removeDisposedChildSlot(sharedSlot); putIntoMultiMap(slotsForGroup, parent.getTaskManagerID(), parent); parent.markCancelled(); internalDisposeEmptySharedSlot(parent);
if (!sharedSlot.isRootAndEmpty()) { throw new IllegalArgumentException("The given slot is not an empty root slot."); final ResourceID location = sharedSlot.getTaskManagerID(); if (!sharedSlot.isAlive()) { return null; subSlot = sharedSlot.allocateSubSlot(groupId); groupIdForMap = groupId; SharedSlot constraintGroupSlot = sharedSlot.allocateSharedSlot(constraint.getGroupId()); groupIdForMap = constraint.getGroupId(); subSlot = constraintGroupSlot.allocateSubSlot(null); if (subSlot != null) { constraintGroupSlot.releaseSlot();
/** * Called from {@link org.apache.flink.runtime.instance.SharedSlot#releaseSlot()}. * * @param sharedSlot The slot to be released. */ void releaseSharedSlot(SharedSlot sharedSlot) { synchronized (lock) { if (sharedSlot.markCancelled()) { // we are releasing this slot if (sharedSlot.hasChildren()) { // by simply releasing all children, we should eventually release this slot. Set<Slot> children = sharedSlot.getSubSlots(); while (children.size() > 0) { children.iterator().next().releaseSlot(); } } else { // if there are no children that trigger the release, we trigger it directly internalDisposeEmptySharedSlot(sharedSlot); } } } }
SimpleSlot subslot = shared.allocateSubSlot(null); subslot.setLocality(Locality.LOCAL); return subslot; TaskManagerLocation location = previous.getTaskManagerLocation(); Tuple2<SharedSlot, Locality> p = getSlotForTaskInternal( constraint.getGroupId(), Collections.singleton(location), true); SharedSlot constraintGroupSlot = newSharedSlot.allocateSharedSlot(constraint.getGroupId()); if (constraintGroupSlot != null) { constraint.setSharedSlot(constraintGroupSlot); SimpleSlot subSlot = constraintGroupSlot.allocateSubSlot(null); subSlot.setLocality(Locality.LOCAL); return subSlot; SharedSlot constraintGroupSlot = availableShared.allocateSharedSlot(constraint.getGroupId()); SimpleSlot sub = constraintGroupSlot.allocateSubSlot(null); sub.setLocality(l); return sub;
@Override public int getPhysicalSlotNumber() { return getRootSlotNumber(); }
/** * */ SimpleSlot getSlotForTask(JobVertexID vertexID, Iterable<TaskManagerLocation> locationPreferences) { synchronized (lock) { Tuple2<SharedSlot, Locality> p = getSlotForTaskInternal(vertexID, locationPreferences, false); if (p != null) { SharedSlot ss = p.f0; SimpleSlot slot = ss.allocateSubSlot(vertexID); slot.setLocality(p.f1); return slot; } else { return null; } } }
SharedSlot slot = new SharedSlot( this, location,
if (sharedSlot.isAlive() || !sharedSlot.getSubSlots().isEmpty()) { throw new IllegalArgumentException(); final SharedSlot parent = sharedSlot.getParent(); final AbstractID groupID = sharedSlot.getGroupID(); sharedSlot.getOwner().returnAllocatedSlot(sharedSlot); if (sharedSlot.markReleased()) { LOG.debug("Internally dispose empty shared slot {}.", sharedSlot); int parentRemaining = parent.removeDisposedChildSlot(sharedSlot); putIntoMultiMap(slotsForGroup, parent.getTaskManagerID(), parent); parent.markCancelled(); internalDisposeEmptySharedSlot(parent);
if (!sharedSlot.isRootAndEmpty()) { throw new IllegalArgumentException("The given slot is not an empty root slot."); final ResourceID location = sharedSlot.getTaskManagerID(); if (!sharedSlot.isAlive()) { return null; subSlot = sharedSlot.allocateSubSlot(groupId); groupIdForMap = groupId; SharedSlot constraintGroupSlot = sharedSlot.allocateSharedSlot(constraint.getGroupId()); groupIdForMap = constraint.getGroupId(); subSlot = constraintGroupSlot.allocateSubSlot(null); if (subSlot != null) { constraintGroupSlot.releaseSlot(new FlinkException("Could not create a sub slot in this shared slot."));
/** * Called from {@link org.apache.flink.runtime.instance.SharedSlot#releaseSlot(Throwable)}. * * @param sharedSlot The slot to be released. */ void releaseSharedSlot(SharedSlot sharedSlot) { synchronized (lock) { if (sharedSlot.markCancelled()) { // we are releasing this slot if (sharedSlot.hasChildren()) { final FlinkException cause = new FlinkException("Releasing shared slot parent."); // by simply releasing all children, we should eventually release this slot. Set<Slot> children = sharedSlot.getSubSlots(); while (children.size() > 0) { children.iterator().next().releaseSlot(cause); } } else { // if there are no children that trigger the release, we trigger it directly internalDisposeEmptySharedSlot(sharedSlot); } } } }
SimpleSlot subslot = shared.allocateSubSlot(null); subslot.setLocality(Locality.LOCAL); return subslot; TaskManagerLocation location = previous.getTaskManagerLocation(); Tuple2<SharedSlot, Locality> p = getSharedSlotForTask( constraint.getGroupId(), Collections.singleton(location), true); SharedSlot constraintGroupSlot = newSharedSlot.allocateSharedSlot(constraint.getGroupId()); if (constraintGroupSlot != null) { constraint.setSharedSlot(constraintGroupSlot); SimpleSlot subSlot = constraintGroupSlot.allocateSubSlot(null); subSlot.setLocality(Locality.LOCAL); return subSlot; SharedSlot constraintGroupSlot = availableShared.allocateSharedSlot(constraint.getGroupId()); SimpleSlot sub = constraintGroupSlot.allocateSubSlot(null); sub.setLocality(l); return sub;
/** * Gets the number of the root slot. This code behaves equal to {@code getRoot().getSlotNumber()}. * If this slot is the root of the tree of shared slots, then this method returns the same * value as {@link #getSlotNumber()}. * * @return The slot number of the root slot. */ public int getRootSlotNumber() { if (parent == null) { return slotNumber; } else { return parent.getRootSlotNumber(); } }
/** * Gets a slot suitable for the given task vertex. This method will prefer slots that are local * (with respect to {@link ExecutionVertex#getPreferredLocationsBasedOnInputs()}), but will return non local * slots if no local slot is available. The method returns null, when this sharing group has * no slot is available for the given JobVertexID. * * @param vertexID the vertex id * @param locationPreferences location preferences * * @return A slot to execute the given ExecutionVertex in, or null, if none is available. */ public SimpleSlot getSlotForTask(JobVertexID vertexID, Iterable<TaskManagerLocation> locationPreferences) { synchronized (lock) { Tuple2<SharedSlot, Locality> p = getSharedSlotForTask(vertexID, locationPreferences, false); if (p != null) { SharedSlot ss = p.f0; SimpleSlot slot = ss.allocateSubSlot(vertexID); slot.setLocality(p.f1); return slot; } else { return null; } } }
SharedSlot slot = new SharedSlot( jobID, this, location, nextSlot, taskManagerGateway, sharingGroupAssignment); allocatedSlots.add(slot);
if (sharedSlot.isAlive() | !sharedSlot.getSubSlots().isEmpty()) { throw new IllegalArgumentException(); final SharedSlot parent = sharedSlot.getParent(); final AbstractID groupID = sharedSlot.getGroupID(); sharedSlot.getOwner().returnAllocatedSlot(sharedSlot); if (sharedSlot.markReleased()) { LOG.debug("Internally dispose empty shared slot {}.", sharedSlot); int parentRemaining = parent.removeDisposedChildSlot(sharedSlot); putIntoMultiMap(slotsForGroup, parent.getTaskManagerID(), parent); parent.markCancelled(); internalDisposeEmptySharedSlot(parent);
/** * Creates a new sub slot if the slot is not dead, yet. This method should only be called from * the assignment group instance to guarantee synchronization. * * NOTE: This method should only be called from the slot's assignment group. * * @param groupId The ID to identify tasks which can be deployed in this sub slot. * @return The new sub slot if the shared slot is still alive, otherwise null. */ SharedSlot allocateSharedSlot(AbstractID groupId){ if (isAlive()) { SharedSlot slot = new SharedSlot( getOwner(), getTaskManagerLocation(), subSlots.size(), getTaskManagerGateway(), assignmentGroup, this, groupId); subSlots.add(slot); return slot; } else { return null; } }
if (!sharedSlot.isRootAndEmpty()) { throw new IllegalArgumentException("The given slot is not an empty root slot."); final ResourceID location = sharedSlot.getTaskManagerID(); if (!sharedSlot.isAlive()) { return null; subSlot = sharedSlot.allocateSubSlot(groupId); groupIdForMap = groupId; SharedSlot constraintGroupSlot = sharedSlot.allocateSharedSlot(constraint.getGroupId()); groupIdForMap = constraint.getGroupId(); subSlot = constraintGroupSlot.allocateSubSlot(null); if (subSlot != null) { constraintGroupSlot.releaseSlot(new FlinkException("Could not create a sub slot in this shared slot."));