Search in sources :

Example 31 with SlotRequestId

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));
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) PhysicalSlotRequest(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequest)

Example 32 with SlotRequestId

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;
}
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 33 with SlotRequestId

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);
    }
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) SingleLogicalSlot(org.apache.flink.runtime.jobmaster.slotpool.SingleLogicalSlot)

Example 34 with SlotRequestId

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));
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) CompletableFuture(java.util.concurrent.CompletableFuture) SlotProfile(org.apache.flink.runtime.clusterframework.types.SlotProfile)

Example 35 with SlotRequestId

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);
        }
    }
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) ComponentMainThreadExecutorServiceAdapter(org.apache.flink.runtime.concurrent.ComponentMainThreadExecutorServiceAdapter) IntStream(java.util.stream.IntStream) FlinkException(org.apache.flink.util.FlinkException) LocalTaskManagerLocation(org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation) Matchers.not(org.hamcrest.Matchers.not) CompletableFuture(java.util.concurrent.CompletableFuture) Supplier(java.util.function.Supplier) Matchers.nullValue(org.hamcrest.Matchers.nullValue) TestLogger(org.apache.flink.util.TestLogger) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) CheckedSupplier(org.apache.flink.util.function.CheckedSupplier) Before(org.junit.Before) Collection(java.util.Collection) Test(org.junit.Test) Collectors(java.util.stream.Collectors) SimpleAckingTaskManagerGateway(org.apache.flink.runtime.executiongraph.utils.SimpleAckingTaskManagerGateway) ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) SlotOffer(org.apache.flink.runtime.taskexecutor.slot.SlotOffer) Consumer(java.util.function.Consumer) TestingResourceManagerGateway(org.apache.flink.runtime.resourcemanager.utils.TestingResourceManagerGateway) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.is(org.hamcrest.Matchers.is) Collections(java.util.Collections) Time(org.apache.flink.api.common.time.Time) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) SlotOffer(org.apache.flink.runtime.taskexecutor.slot.SlotOffer) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) FlinkException(org.apache.flink.util.FlinkException) SimpleAckingTaskManagerGateway(org.apache.flink.runtime.executiongraph.utils.SimpleAckingTaskManagerGateway) CompletableFuture(java.util.concurrent.CompletableFuture) LocalTaskManagerLocation(org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation)

Aggregations

SlotRequestId (org.apache.flink.runtime.jobmaster.SlotRequestId)51 Test (org.junit.Test)40 TestingPhysicalSlot (org.apache.flink.runtime.scheduler.TestingPhysicalSlot)15 LogicalSlot (org.apache.flink.runtime.jobmaster.LogicalSlot)12 CompletableFuture (java.util.concurrent.CompletableFuture)11 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)11 ResourceProfile (org.apache.flink.runtime.clusterframework.types.ResourceProfile)8 TestLogger (org.apache.flink.util.TestLogger)6 Collectors (java.util.stream.Collectors)5 CoreMatchers.is (org.hamcrest.CoreMatchers.is)5 Assert.fail (org.junit.Assert.fail)5 Collection (java.util.Collection)4 Collections (java.util.Collections)4 List (java.util.List)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Consumer (java.util.function.Consumer)4 Time (org.apache.flink.api.common.time.Time)4 Arrays (java.util.Arrays)3 ExecutionException (java.util.concurrent.ExecutionException)3 SlotProfile (org.apache.flink.runtime.clusterframework.types.SlotProfile)3