Search in sources :

Example 1 with SlotID

use of org.apache.flink.runtime.clusterframework.types.SlotID in project flink by apache.

the class TaskExecutor method freeSlot.

private void freeSlot(AllocationID allocationId, Throwable cause) {
    Preconditions.checkNotNull(allocationId);
    try {
        int freedSlotIndex = taskSlotTable.freeSlot(allocationId, cause);
        if (freedSlotIndex != -1 && isConnectedToResourceManager()) {
            // the slot was freed. Tell the RM about it
            ResourceManagerGateway resourceManagerGateway = resourceManagerConnection.getTargetGateway();
            resourceManagerGateway.notifySlotAvailable(resourceManagerConnection.getTargetLeaderId(), resourceManagerConnection.getRegistrationId(), new SlotID(getResourceID(), freedSlotIndex));
        }
    } catch (SlotNotFoundException e) {
        log.debug("Could not free slot for allocation id {}.", allocationId, e);
    }
}
Also used : SlotNotFoundException(org.apache.flink.runtime.taskexecutor.slot.SlotNotFoundException) SlotID(org.apache.flink.runtime.clusterframework.types.SlotID) RpcEndpoint(org.apache.flink.runtime.rpc.RpcEndpoint) ResourceManagerGateway(org.apache.flink.runtime.resourcemanager.ResourceManagerGateway)

Example 2 with SlotID

use of org.apache.flink.runtime.clusterframework.types.SlotID 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 3 with SlotID

use of org.apache.flink.runtime.clusterframework.types.SlotID 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 4 with SlotID

use of org.apache.flink.runtime.clusterframework.types.SlotID 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 5 with SlotID

use of org.apache.flink.runtime.clusterframework.types.SlotID 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)

Aggregations

SlotID (org.apache.flink.runtime.clusterframework.types.SlotID)75 Test (org.junit.Test)62 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)46 JobID (org.apache.flink.api.common.JobID)45 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)40 SlotReport (org.apache.flink.runtime.taskexecutor.SlotReport)36 CompletableFuture (java.util.concurrent.CompletableFuture)31 SlotStatus (org.apache.flink.runtime.taskexecutor.SlotStatus)31 ResourceProfile (org.apache.flink.runtime.clusterframework.types.ResourceProfile)25 TaskExecutorConnection (org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection)23 Acknowledge (org.apache.flink.runtime.messages.Acknowledge)22 InstanceID (org.apache.flink.runtime.instance.InstanceID)21 ResourceManagerId (org.apache.flink.runtime.resourcemanager.ResourceManagerId)20 Assert.assertThat (org.junit.Assert.assertThat)19 ArrayList (java.util.ArrayList)18 Collection (java.util.Collection)17 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)17 Time (org.apache.flink.api.common.time.Time)17 TestingTaskExecutorGatewayBuilder (org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder)17 Matchers.empty (org.hamcrest.Matchers.empty)17