use of org.apache.flink.runtime.jobmaster.SlotRequestId in project flink by apache.
the class TestingPhysicalSlotProvider method allocatePhysicalSlot.
@Override
public CompletableFuture<PhysicalSlotRequest.Result> allocatePhysicalSlot(PhysicalSlotRequest physicalSlotRequest) {
SlotRequestId slotRequestId = physicalSlotRequest.getSlotRequestId();
requests.put(slotRequestId, physicalSlotRequest);
final CompletableFuture<TestingPhysicalSlot> resultFuture = physicalSlotCreator.apply(physicalSlotRequest.getSlotProfile().getPhysicalSlotResourceProfile());
responses.put(slotRequestId, resultFuture);
return resultFuture.thenApply(physicalSlot -> new PhysicalSlotRequest.Result(slotRequestId, physicalSlot));
}
use of org.apache.flink.runtime.jobmaster.SlotRequestId 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.SlotRequestId 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);
}
}
use of org.apache.flink.runtime.jobmaster.SlotRequestId in project flink by apache.
the class PhysicalSlotProviderImpl method allocatePhysicalSlot.
@Override
public CompletableFuture<PhysicalSlotRequest.Result> allocatePhysicalSlot(PhysicalSlotRequest physicalSlotRequest) {
SlotRequestId slotRequestId = physicalSlotRequest.getSlotRequestId();
SlotProfile slotProfile = physicalSlotRequest.getSlotProfile();
ResourceProfile resourceProfile = slotProfile.getPhysicalSlotResourceProfile();
LOG.debug("Received slot request [{}] with resource requirements: {}", slotRequestId, resourceProfile);
Optional<PhysicalSlot> availablePhysicalSlot = tryAllocateFromAvailable(slotRequestId, slotProfile);
CompletableFuture<PhysicalSlot> slotFuture;
slotFuture = availablePhysicalSlot.map(CompletableFuture::completedFuture).orElseGet(() -> requestNewSlot(slotRequestId, resourceProfile, slotProfile.getPreferredAllocations(), physicalSlotRequest.willSlotBeOccupiedIndefinitely()));
return slotFuture.thenApply(physicalSlot -> new PhysicalSlotRequest.Result(slotRequestId, physicalSlot));
}
use of org.apache.flink.runtime.jobmaster.SlotRequestId in project flink by apache.
the class DeclarativeSlotPoolBridgeRequestCompletionTest method runSlotRequestCompletionTest.
private void runSlotRequestCompletionTest(Supplier<SlotPool> slotPoolSupplier, Consumer<SlotPool> actionAfterSlotRequest) {
try (final SlotPool slotPool = slotPoolSupplier.get()) {
final int requestNum = 10;
final List<SlotRequestId> slotRequestIds = IntStream.range(0, requestNum).mapToObj(ignored -> new SlotRequestId()).collect(Collectors.toList());
final List<CompletableFuture<PhysicalSlot>> slotRequests = slotRequestIds.stream().map(slotRequestId -> slotPool.requestNewAllocatedSlot(slotRequestId, ResourceProfile.UNKNOWN, TIMEOUT)).collect(Collectors.toList());
actionAfterSlotRequest.accept(slotPool);
final LocalTaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation();
slotPool.registerTaskManager(taskManagerLocation.getResourceID());
// create a slot offer that is initiated by the last request
final SlotOffer slotOffer = new SlotOffer(new AllocationID(), 0, ResourceProfile.ANY);
final Collection<SlotOffer> acceptedSlots = slotPool.offerSlots(taskManagerLocation, new SimpleAckingTaskManagerGateway(), Collections.singleton(slotOffer));
assertThat(acceptedSlots, containsInAnyOrder(slotOffer));
final FlinkException testingReleaseException = new FlinkException("Testing release exception");
// check that the slot requests get completed in sequential order
for (int i = 0; i < slotRequestIds.size(); i++) {
final CompletableFuture<PhysicalSlot> slotRequestFuture = slotRequests.get(i);
assertThat(slotRequestFuture.getNow(null), is(not(nullValue())));
slotPool.releaseSlot(slotRequestIds.get(i), testingReleaseException);
}
}
}
Aggregations