Search in sources :

Example 1 with SlotAllocationSnapshot

use of org.apache.flink.runtime.taskexecutor.slot.SlotAllocationSnapshot in project flink by apache.

the class TaskExecutor method tryLoadLocalAllocationSnapshots.

/**
 * This method tries to repopulate the {@link JobTable} and {@link TaskSlotTable} from the local
 * filesystem in a best-effort manner.
 */
private void tryLoadLocalAllocationSnapshots() {
    Collection<SlotAllocationSnapshot> slotAllocationSnapshots = slotAllocationSnapshotPersistenceService.loadAllocationSnapshots();
    log.debug("Recovered slot allocation snapshots {}.", slotAllocationSnapshots);
    final Set<AllocationID> allocatedSlots = new HashSet<>();
    for (SlotAllocationSnapshot slotAllocationSnapshot : slotAllocationSnapshots) {
        try {
            allocateSlotForJob(slotAllocationSnapshot.getJobId(), slotAllocationSnapshot.getSlotID(), slotAllocationSnapshot.getAllocationId(), slotAllocationSnapshot.getResourceProfile(), slotAllocationSnapshot.getJobTargetAddress());
        } catch (SlotAllocationException e) {
            log.debug("Cannot reallocate restored slot {}.", slotAllocationSnapshot, e);
        }
        allocatedSlots.add(slotAllocationSnapshot.getAllocationId());
    }
    localStateStoresManager.retainLocalStateForAllocations(allocatedSlots);
}
Also used : SlotAllocationException(org.apache.flink.runtime.taskexecutor.exceptions.SlotAllocationException) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) SlotAllocationSnapshot(org.apache.flink.runtime.taskexecutor.slot.SlotAllocationSnapshot) HashSet(java.util.HashSet)

Example 2 with SlotAllocationSnapshot

use of org.apache.flink.runtime.taskexecutor.slot.SlotAllocationSnapshot in project flink by apache.

the class TaskExecutor method requestSlot.

// ----------------------------------------------------------------------
// Slot allocation RPCs
// ----------------------------------------------------------------------
@Override
public CompletableFuture<Acknowledge> requestSlot(final SlotID slotId, final JobID jobId, final AllocationID allocationId, final ResourceProfile resourceProfile, final String targetAddress, final ResourceManagerId resourceManagerId, final Time timeout) {
    // TODO: Filter invalid requests from the resource manager by using the
    // instance/registration Id
    log.info("Receive slot request {} for job {} from resource manager with leader id {}.", allocationId, jobId, resourceManagerId);
    if (!isConnectedToResourceManager(resourceManagerId)) {
        final String message = String.format("TaskManager is not connected to the resource manager %s.", resourceManagerId);
        log.debug(message);
        return FutureUtils.completedExceptionally(new TaskManagerException(message));
    }
    tryPersistAllocationSnapshot(new SlotAllocationSnapshot(slotId, jobId, targetAddress, allocationId, resourceProfile));
    try {
        final boolean isConnected = allocateSlotForJob(jobId, slotId, allocationId, resourceProfile, targetAddress);
        if (isConnected) {
            offerSlotsToJobManager(jobId);
        }
        return CompletableFuture.completedFuture(Acknowledge.get());
    } catch (SlotAllocationException e) {
        log.debug("Could not allocate slot for allocation id {}.", allocationId, e);
        return FutureUtils.completedExceptionally(e);
    }
}
Also used : TaskManagerException(org.apache.flink.runtime.taskexecutor.exceptions.TaskManagerException) SlotAllocationException(org.apache.flink.runtime.taskexecutor.exceptions.SlotAllocationException) SlotAllocationSnapshot(org.apache.flink.runtime.taskexecutor.slot.SlotAllocationSnapshot)

Aggregations

SlotAllocationException (org.apache.flink.runtime.taskexecutor.exceptions.SlotAllocationException)2 SlotAllocationSnapshot (org.apache.flink.runtime.taskexecutor.slot.SlotAllocationSnapshot)2 HashSet (java.util.HashSet)1 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)1 TaskManagerException (org.apache.flink.runtime.taskexecutor.exceptions.TaskManagerException)1