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;
}
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;
}
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);
}
}
Aggregations