Search in sources :

Example 41 with LogicalSlot

use of org.apache.flink.runtime.jobmaster.LogicalSlot in project flink by apache.

the class SharedSlotTest method tesDuplicatedReturnLogicalSlotFails.

@Test
public void tesDuplicatedReturnLogicalSlotFails() {
    CompletableFuture<PhysicalSlot> slotContextFuture = CompletableFuture.completedFuture(new TestingPhysicalSlot(RP, new AllocationID()));
    AtomicInteger released = new AtomicInteger(0);
    SharedSlot sharedSlot = SharedSlotBuilder.newBuilder().withSlotContextFuture(slotContextFuture).withExternalReleaseCallback(g -> released.incrementAndGet()).build();
    LogicalSlot logicalSlot = sharedSlot.allocateLogicalSlot(EV1).join();
    sharedSlot.returnLogicalSlot(logicalSlot);
    try {
        sharedSlot.returnLogicalSlot(logicalSlot);
        fail("Duplicated 'returnLogicalSlot' call should fail with IllegalStateException");
    } catch (IllegalStateException e) {
    // expected
    }
}
Also used : DummyPayload(org.apache.flink.runtime.jobmaster.slotpool.DummyPayload) CoreMatchers.is(org.hamcrest.CoreMatchers.is) LocalTaskManagerLocation(org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation) Locality(org.apache.flink.runtime.jobmanager.scheduler.Locality) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) ExecutionVertexID(org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID) SharedSlotTestingUtils.createExecutionSlotSharingGroup(org.apache.flink.runtime.scheduler.SharedSlotTestingUtils.createExecutionSlotSharingGroup) SimpleAckingTaskManagerGateway(org.apache.flink.runtime.executiongraph.utils.SimpleAckingTaskManagerGateway) ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) Assert.assertThat(org.junit.Assert.assertThat) PhysicalSlot(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlot) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestLogger(org.apache.flink.util.TestLogger) Assert.fail(org.junit.Assert.fail) SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) ExecutionGraphTestUtils.createRandomExecutionVertexId(org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.createRandomExecutionVertexId) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) PhysicalSlot(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlot) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) Test(org.junit.Test)

Example 42 with LogicalSlot

use of org.apache.flink.runtime.jobmaster.LogicalSlot in project flink by apache.

the class SlotSharingExecutionSlotAllocatorTest method testFailedPhysicalSlotRequestFailsLogicalSlotFuturesAndRemovesSharedSlot.

@Test
public void testFailedPhysicalSlotRequestFailsLogicalSlotFuturesAndRemovesSharedSlot() {
    AllocationContext context = AllocationContext.newBuilder().addGroup(EV1).withPhysicalSlotProvider(TestingPhysicalSlotProvider.createWithoutImmediatePhysicalSlotCreation()).build();
    CompletableFuture<LogicalSlot> logicalSlotFuture = context.allocateSlotsFor(EV1).get(0).getLogicalSlotFuture();
    SlotRequestId slotRequestId = context.getSlotProvider().getFirstRequestOrFail().getSlotRequestId();
    assertThat(logicalSlotFuture.isDone(), is(false));
    context.getSlotProvider().getResponses().get(slotRequestId).completeExceptionally(new Throwable());
    assertThat(logicalSlotFuture.isCompletedExceptionally(), is(true));
    // next allocation allocates new shared slot
    context.allocateSlotsFor(EV1);
    assertThat(context.getSlotProvider().getRequests().keySet(), hasSize(2));
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) Test(org.junit.Test)

Example 43 with LogicalSlot

use of org.apache.flink.runtime.jobmaster.LogicalSlot in project flink by apache.

the class SlotSharingExecutionSlotAllocatorTest method testRequestBulkCancel.

@Test
public void testRequestBulkCancel() {
    TestingPhysicalSlotRequestBulkChecker bulkChecker = new TestingPhysicalSlotRequestBulkChecker();
    AllocationContext context = createBulkCheckerContextWithEv12GroupAndEv3Group(bulkChecker);
    // allocate 2 physical slots for 2 groups
    List<SlotExecutionVertexAssignment> assignments1 = context.allocateSlotsFor(EV1, EV3);
    fulfilOneOfTwoSlotRequestsAndGetPendingProfile(context, new AllocationID());
    PhysicalSlotRequestBulk bulk1 = bulkChecker.getBulk();
    List<SlotExecutionVertexAssignment> assignments2 = context.allocateSlotsFor(EV2);
    // cancelling of (EV1, EV3) releases assignments1 and only one physical slot for EV3
    // the second physical slot is held by sharing EV2 from the next bulk
    bulk1.cancel(new Throwable());
    // return completed logical slot to clear shared slot and release physical slot
    CompletableFuture<LogicalSlot> ev1slot = assignments1.get(0).getLogicalSlotFuture();
    boolean ev1failed = ev1slot.isCompletedExceptionally();
    CompletableFuture<LogicalSlot> ev3slot = assignments1.get(1).getLogicalSlotFuture();
    boolean ev3failed = ev3slot.isCompletedExceptionally();
    LogicalSlot slot = ev1failed ? ev3slot.join() : ev1slot.join();
    releaseLogicalSlot(slot);
    // EV3 needs again a physical slot, therefore there are 3 requests overall
    context.allocateSlotsFor(EV1, EV3);
    assertThat(context.getSlotProvider().getRequests().values(), hasSize(3));
    // either EV1 or EV3 logical slot future is fulfilled before cancellation
    assertThat(ev1failed != ev3failed, is(true));
    assertThat(assignments2.get(0).getLogicalSlotFuture().isCompletedExceptionally(), is(false));
}
Also used : PhysicalSlotRequestBulk(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequestBulk) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) Test(org.junit.Test)

Example 44 with LogicalSlot

use of org.apache.flink.runtime.jobmaster.LogicalSlot in project flink by apache.

the class TestExecutionSlotAllocator method completePendingRequest.

public LogicalSlot completePendingRequest(final ExecutionVertexID executionVertexId) {
    final LogicalSlot slot = logicalSlotBuilder.setSlotOwner(this).createTestingLogicalSlot();
    final SlotExecutionVertexAssignment slotVertexAssignment = removePendingRequest(executionVertexId);
    checkState(slotVertexAssignment != null);
    slotVertexAssignment.getLogicalSlotFuture().complete(slot);
    return slot;
}
Also used : LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot)

Example 45 with LogicalSlot

use of org.apache.flink.runtime.jobmaster.LogicalSlot in project flink by apache.

the class AdaptiveScheduler method assignSlotsToExecutionGraph.

@Nonnull
private ExecutionGraph assignSlotsToExecutionGraph(ExecutionGraph executionGraph, ReservedSlots reservedSlots) {
    for (ExecutionVertex executionVertex : executionGraph.getAllExecutionVertices()) {
        final LogicalSlot assignedSlot = reservedSlots.getSlotFor(executionVertex.getID());
        final CompletableFuture<Void> registrationFuture = executionVertex.getCurrentExecutionAttempt().registerProducedPartitions(assignedSlot.getTaskManagerLocation(), false);
        Preconditions.checkState(registrationFuture.isDone(), "Partition registration must be completed immediately for reactive mode");
        executionVertex.tryAssignResource(assignedSlot);
    }
    return executionGraph;
}
Also used : ExecutionVertex(org.apache.flink.runtime.executiongraph.ExecutionVertex) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) Nonnull(javax.annotation.Nonnull)

Aggregations

LogicalSlot (org.apache.flink.runtime.jobmaster.LogicalSlot)57 Test (org.junit.Test)34 TestingLogicalSlotBuilder (org.apache.flink.runtime.jobmaster.TestingLogicalSlotBuilder)18 CompletableFuture (java.util.concurrent.CompletableFuture)13 SlotRequestId (org.apache.flink.runtime.jobmaster.SlotRequestId)13 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)9 ExecutionGraphTestUtils.getExecutionVertex (org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.getExecutionVertex)9 TestingPhysicalSlot (org.apache.flink.runtime.scheduler.TestingPhysicalSlot)9 ExecutionVertexID (org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID)8 ExecutionVertex (org.apache.flink.runtime.executiongraph.ExecutionVertex)7 SimpleAckingTaskManagerGateway (org.apache.flink.runtime.executiongraph.utils.SimpleAckingTaskManagerGateway)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 TaskManagerGateway (org.apache.flink.runtime.jobmanager.slots.TaskManagerGateway)6 FlinkException (org.apache.flink.util.FlinkException)6 TestLogger (org.apache.flink.util.TestLogger)6 IOException (java.io.IOException)5 List (java.util.List)5 Map (java.util.Map)5 Consumer (java.util.function.Consumer)5