use of org.apache.flink.runtime.clusterframework.types.ResourceSlot in project flink by apache.
the class SlotManager method notifySlotAvailable.
/**
* Notifies the SlotManager that a slot is available again after being allocated.
* @param slotID slot id of available slot
*/
public void notifySlotAvailable(ResourceID resourceID, SlotID slotID) {
if (!allocationMap.isAllocated(slotID)) {
throw new IllegalStateException("Slot was not previously allocated but " + "TaskManager reports it as available again");
}
allocationMap.removeAllocation(slotID);
final Map<SlotID, ResourceSlot> slots = registeredSlots.get(resourceID);
ResourceSlot freeSlot = slots.get(slotID);
if (freeSlot == null) {
throw new IllegalStateException("Slot was not registered with SlotManager but " + "TaskManager reported it to be available.");
}
handleFreeSlot(freeSlot);
}
use of org.apache.flink.runtime.clusterframework.types.ResourceSlot in project flink by apache.
the class SlotManager method notifyTaskManagerFailure.
/**
* Callback for TaskManager failures. In case that a TaskManager fails, we have to clean up all its slots.
*
* @param resourceId The ResourceID of the TaskManager
*/
public void notifyTaskManagerFailure(final ResourceID resourceId) {
LOG.info("Resource:{} been notified failure", resourceId);
taskManagers.remove(resourceId);
final Map<SlotID, ResourceSlot> slotIdsToRemove = registeredSlots.remove(resourceId);
if (slotIdsToRemove != null) {
for (SlotID slotId : slotIdsToRemove.keySet()) {
LOG.info("Removing Slot: {} upon resource failure", slotId);
if (freeSlots.containsKey(slotId)) {
freeSlots.remove(slotId);
} else if (allocationMap.isAllocated(slotId)) {
allocationMap.removeAllocation(slotId);
} else {
LOG.error("BUG! {} is neither in free pool nor in allocated pool", slotId);
}
}
}
}
use of org.apache.flink.runtime.clusterframework.types.ResourceSlot in project flink by apache.
the class SlotManager method addFreeSlot.
/**
* Add free slots directly to the free pool, this will not trigger pending requests allocation
*
* @param slot The resource slot
*/
@VisibleForTesting
void addFreeSlot(final ResourceSlot slot) {
final ResourceID resourceId = slot.getResourceID();
final SlotID slotId = slot.getSlotId();
if (!registeredSlots.containsKey(resourceId)) {
registeredSlots.put(resourceId, new HashMap<SlotID, ResourceSlot>());
}
registeredSlots.get(resourceId).put(slot.getSlotId(), slot);
freeSlots.put(slotId, slot);
}
use of org.apache.flink.runtime.clusterframework.types.ResourceSlot in project flink by apache.
the class SlotManager method registerNewSlot.
/**
* Registers a new slot with the SlotManager.
*
* @param slot The ResourceSlot which will be registered
*/
private void registerNewSlot(final ResourceSlot slot) {
final SlotID slotId = slot.getSlotId();
final ResourceID resourceId = slotId.getResourceID();
if (!registeredSlots.containsKey(resourceId)) {
registeredSlots.put(resourceId, new HashMap<SlotID, ResourceSlot>());
}
registeredSlots.get(resourceId).put(slotId, slot);
}
use of org.apache.flink.runtime.clusterframework.types.ResourceSlot in project flink by apache.
the class SlotManagerTest method testSlotAllocationFailedAtTaskManager.
/**
* Tests that we did some allocation but failed / rejected by TaskManager, request will retry
*/
@Test
public void testSlotAllocationFailedAtTaskManager() {
TestingSlotManager slotManager = new TestingSlotManager();
ResourceSlot slot = new ResourceSlot(SlotID.generate(), DEFAULT_TESTING_PROFILE, taskExecutorRegistration);
slotManager.addFreeSlot(slot);
SlotRequest request = new SlotRequest(new JobID(), new AllocationID(), DEFAULT_TESTING_PROFILE);
slotManager.requestSlot(request);
assertEquals(1, slotManager.getAllocatedSlotCount());
assertEquals(0, slotManager.getFreeSlotCount());
assertEquals(0, slotManager.getPendingRequestCount());
assertTrue(slotManager.isAllocated(slot.getSlotId()));
slotManager.handleSlotRequestFailedAtTaskManager(request, slot.getSlotId());
assertEquals(1, slotManager.getAllocatedSlotCount());
assertEquals(0, slotManager.getFreeSlotCount());
assertEquals(0, slotManager.getPendingRequestCount());
}
Aggregations