Search in sources :

Example 1 with ResourceSlot

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);
}
Also used : SlotID(org.apache.flink.runtime.clusterframework.types.SlotID) ResourceSlot(org.apache.flink.runtime.clusterframework.types.ResourceSlot)

Example 2 with ResourceSlot

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);
            }
        }
    }
}
Also used : SlotID(org.apache.flink.runtime.clusterframework.types.SlotID) ResourceSlot(org.apache.flink.runtime.clusterframework.types.ResourceSlot)

Example 3 with ResourceSlot

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);
}
Also used : SlotID(org.apache.flink.runtime.clusterframework.types.SlotID) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) ResourceSlot(org.apache.flink.runtime.clusterframework.types.ResourceSlot) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting)

Example 4 with ResourceSlot

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);
}
Also used : SlotID(org.apache.flink.runtime.clusterframework.types.SlotID) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) ResourceSlot(org.apache.flink.runtime.clusterframework.types.ResourceSlot)

Example 5 with ResourceSlot

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());
}
Also used : AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) SlotRequest(org.apache.flink.runtime.resourcemanager.SlotRequest) ResourceSlot(org.apache.flink.runtime.clusterframework.types.ResourceSlot) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Aggregations

ResourceSlot (org.apache.flink.runtime.clusterframework.types.ResourceSlot)9 SlotID (org.apache.flink.runtime.clusterframework.types.SlotID)6 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)4 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)3 JobID (org.apache.flink.api.common.JobID)2 SlotRequest (org.apache.flink.runtime.resourcemanager.SlotRequest)2 Test (org.junit.Test)2 VisibleForTesting (org.apache.flink.annotation.VisibleForTesting)1 RMSlotRequestRegistered (org.apache.flink.runtime.resourcemanager.messages.jobmanager.RMSlotRequestRegistered)1 TaskExecutorRegistration (org.apache.flink.runtime.resourcemanager.registration.TaskExecutorRegistration)1 SlotStatus (org.apache.flink.runtime.taskexecutor.SlotStatus)1