Search in sources :

Example 1 with SingleLogicalSlot

use of org.apache.flink.runtime.jobmaster.slotpool.SingleLogicalSlot in project flink by apache.

the class SharedSlot method allocateLogicalSlot.

/**
 * Registers an allocation request for a logical slot.
 *
 * @return the logical slot
 */
public LogicalSlot allocateLogicalSlot() {
    LOG.debug("Allocating logical slot from shared slot ({})", physicalSlotRequestId);
    Preconditions.checkState(state == State.ALLOCATED, "The shared slot has already been released.");
    final LogicalSlot slot = new SingleLogicalSlot(new SlotRequestId(), physicalSlot, Locality.UNKNOWN, this, slotWillBeOccupiedIndefinitely);
    allocatedLogicalSlots.put(slot.getSlotRequestId(), slot);
    return slot;
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) SingleLogicalSlot(org.apache.flink.runtime.jobmaster.slotpool.SingleLogicalSlot) SingleLogicalSlot(org.apache.flink.runtime.jobmaster.slotpool.SingleLogicalSlot)

Example 2 with SingleLogicalSlot

use of org.apache.flink.runtime.jobmaster.slotpool.SingleLogicalSlot in project flink by apache.

the class SharedSlot method allocateNonExistentLogicalSlot.

private CompletableFuture<SingleLogicalSlot> allocateNonExistentLogicalSlot(ExecutionVertexID executionVertexId) {
    CompletableFuture<SingleLogicalSlot> logicalSlotFuture;
    SlotRequestId logicalSlotRequestId = new SlotRequestId();
    String logMessageBase = getLogicalSlotString(logicalSlotRequestId, executionVertexId);
    LOG.debug("Request a {}", logMessageBase);
    logicalSlotFuture = slotContextFuture.thenApply(physicalSlot -> {
        LOG.debug("Allocated {}", logMessageBase);
        return createLogicalSlot(physicalSlot, logicalSlotRequestId);
    });
    requestedLogicalSlots.put(executionVertexId, logicalSlotRequestId, logicalSlotFuture);
    // If the physical slot request fails (slotContextFuture), it will also fail the
    // logicalSlotFuture.
    // Therefore, the next `exceptionally` callback will call removeLogicalSlotRequest and do
    // the cleanup
    // in requestedLogicalSlots and eventually in sharedSlots
    logicalSlotFuture.exceptionally(cause -> {
        LOG.debug("Failed {}", logMessageBase, cause);
        removeLogicalSlotRequest(logicalSlotRequestId);
        return null;
    });
    return logicalSlotFuture;
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) DualKeyLinkedMap(org.apache.flink.runtime.util.DualKeyLinkedMap) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Locality(org.apache.flink.runtime.jobmanager.scheduler.Locality) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) SlotOwner(org.apache.flink.runtime.jobmaster.SlotOwner) CompletableFuture(java.util.concurrent.CompletableFuture) SingleLogicalSlot(org.apache.flink.runtime.jobmaster.slotpool.SingleLogicalSlot) ExecutionVertexID(org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID) Preconditions(org.apache.flink.util.Preconditions) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) Execution(org.apache.flink.runtime.executiongraph.Execution) Consumer(java.util.function.Consumer) PhysicalSlot(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlot) Map(java.util.Map) SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) Nullable(javax.annotation.Nullable) SingleLogicalSlot(org.apache.flink.runtime.jobmaster.slotpool.SingleLogicalSlot)

Example 3 with SingleLogicalSlot

use of org.apache.flink.runtime.jobmaster.slotpool.SingleLogicalSlot in project flink by apache.

the class SharedSlot method cancelLogicalSlotRequest.

/**
 * Cancels a logical slot request.
 *
 * <p>If the logical slot request is already complete, nothing happens because the logical slot
 * is already given to the execution and it the responsibility of the execution to call {@link
 * #returnLogicalSlot(LogicalSlot)}.
 *
 * <p>If the logical slot request is not complete yet, its future gets cancelled or failed.
 *
 * @param executionVertexID {@link ExecutionVertexID} of the execution for which to cancel the
 *     logical slot
 * @param cause the reason of cancellation or null if it is not available
 */
void cancelLogicalSlotRequest(ExecutionVertexID executionVertexID, @Nullable Throwable cause) {
    Preconditions.checkState(state == State.ALLOCATED, "SharedSlot (physical request %s) has been released", physicalSlotRequestId);
    CompletableFuture<SingleLogicalSlot> logicalSlotFuture = requestedLogicalSlots.getValueByKeyA(executionVertexID);
    SlotRequestId logicalSlotRequestId = requestedLogicalSlots.getKeyBByKeyA(executionVertexID);
    if (logicalSlotFuture != null) {
        LOG.debug("Cancel {} from {}", getLogicalSlotString(logicalSlotRequestId), executionVertexID);
        // callback will also call removeLogicalSlotRequest
        if (cause == null) {
            logicalSlotFuture.cancel(false);
        } else {
            logicalSlotFuture.completeExceptionally(cause);
        }
    } else {
        LOG.debug("No SlotExecutionVertexAssignment for logical {} from physical {}}", logicalSlotRequestId, physicalSlotRequestId);
    }
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) SingleLogicalSlot(org.apache.flink.runtime.jobmaster.slotpool.SingleLogicalSlot)

Aggregations

SlotRequestId (org.apache.flink.runtime.jobmaster.SlotRequestId)3 SingleLogicalSlot (org.apache.flink.runtime.jobmaster.slotpool.SingleLogicalSlot)3 LogicalSlot (org.apache.flink.runtime.jobmaster.LogicalSlot)2 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 ResourceProfile (org.apache.flink.runtime.clusterframework.types.ResourceProfile)1 Execution (org.apache.flink.runtime.executiongraph.Execution)1 Locality (org.apache.flink.runtime.jobmanager.scheduler.Locality)1 SlotOwner (org.apache.flink.runtime.jobmaster.SlotOwner)1 PhysicalSlot (org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlot)1 ExecutionVertexID (org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID)1 DualKeyLinkedMap (org.apache.flink.runtime.util.DualKeyLinkedMap)1 Preconditions (org.apache.flink.util.Preconditions)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1