Search in sources :

Example 21 with LogicalSlot

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

the class SlotSharingExecutionSlotAllocatorTest method testPhysicalSlotReleaseLogicalSlots.

@Test
public void testPhysicalSlotReleaseLogicalSlots() throws ExecutionException, InterruptedException {
    AllocationContext context = AllocationContext.newBuilder().addGroup(EV1, EV2).build();
    List<SlotExecutionVertexAssignment> assignments = context.allocateSlotsFor(EV1, EV2);
    List<TestingPayload> payloads = assignments.stream().map(assignment -> {
        TestingPayload payload = new TestingPayload();
        assignment.getLogicalSlotFuture().thenAccept(logicalSlot -> logicalSlot.tryAssignPayload(payload));
        return payload;
    }).collect(Collectors.toList());
    SlotRequestId slotRequestId = context.getSlotProvider().getFirstRequestOrFail().getSlotRequestId();
    TestingPhysicalSlot physicalSlot = context.getSlotProvider().getFirstResponseOrFail().get();
    assertThat(payloads.stream().allMatch(payload -> payload.getTerminalStateFuture().isDone()), is(false));
    assertThat(physicalSlot.getPayload(), notNullValue());
    physicalSlot.getPayload().release(new Throwable());
    assertThat(payloads.stream().allMatch(payload -> payload.getTerminalStateFuture().isDone()), is(true));
    assertThat(context.getSlotProvider().getCancellations().containsKey(slotRequestId), is(true));
    context.allocateSlotsFor(EV1, EV2);
    // there should be one more physical slot allocation, as the first allocation should be
    // removed after releasing all logical slots
    assertThat(context.getSlotProvider().getRequests().keySet(), hasSize(2));
}
Also used : DummyPayload(org.apache.flink.runtime.jobmaster.slotpool.DummyPayload) CoreMatchers.is(org.hamcrest.CoreMatchers.is) FlinkException(org.apache.flink.util.FlinkException) BiConsumerWithException(org.apache.flink.util.function.BiConsumerWithException) Arrays(java.util.Arrays) PhysicalSlotRequest(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequest) PhysicalSlotRequestBulk(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequestBulk) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) SlotProfile(org.apache.flink.runtime.clusterframework.types.SlotProfile) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Assert.assertThat(org.junit.Assert.assertThat) SharedSlotProfileRetrieverFactory(org.apache.flink.runtime.scheduler.SharedSlotProfileRetriever.SharedSlotProfileRetrieverFactory) Map(java.util.Map) PhysicalSlotRequestBulkChecker(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequestBulkChecker) TestLogger(org.apache.flink.util.TestLogger) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Assert.fail(org.junit.Assert.fail) SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) ExecutionGraphTestUtils.createRandomExecutionVertexId(org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.createRandomExecutionVertexId) Matchers.empty(org.hamcrest.Matchers.empty) CancellationException(java.util.concurrent.CancellationException) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Collection(java.util.Collection) TestingPayload(org.apache.flink.runtime.jobmaster.TestingPayload) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) Test(org.junit.Test) ExecutionVertexID(org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID) Collectors(java.util.stream.Collectors) ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) ExecutionException(java.util.concurrent.ExecutionException) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) List(java.util.List) SlotProfileTestingUtils(org.apache.flink.runtime.clusterframework.types.SlotProfileTestingUtils) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Optional(java.util.Optional) Collections(java.util.Collections) Time(org.apache.flink.api.common.time.Time) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) TestingPayload(org.apache.flink.runtime.jobmaster.TestingPayload) Test(org.junit.Test)

Example 22 with LogicalSlot

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

the class SharedSlotTest method testReleaseEmptyDoesNotCallAllocatorReleaseBack.

@Test
public void testReleaseEmptyDoesNotCallAllocatorReleaseBack() {
    CompletableFuture<PhysicalSlot> slotContextFuture = CompletableFuture.completedFuture(new TestingPhysicalSlot(RP, new AllocationID()));
    CompletableFuture<SharedSlot> sharedSlotReleaseFuture = new CompletableFuture<>();
    AtomicInteger released = new AtomicInteger(0);
    SharedSlot sharedSlot = SharedSlotBuilder.newBuilder().withSlotContextFuture(slotContextFuture).withExternalReleaseCallback(g -> {
        // checks that release -> externalReleaseCallback -> release
        // does not lead to infinite recursion
        // due to SharedSlot.state.RELEASED check
        sharedSlotReleaseFuture.join().release(new Throwable());
        released.incrementAndGet();
    }).build();
    sharedSlotReleaseFuture.complete(sharedSlot);
    LogicalSlot logicalSlot = sharedSlot.allocateLogicalSlot(EV1).join();
    assertThat(released.get(), is(0));
    // returns the only and last slot, calling the external release callback
    sharedSlot.returnLogicalSlot(logicalSlot);
    assertThat(released.get(), is(1));
    // slot is already released, it should not get released again
    sharedSlot.release(new Throwable());
    assertThat(released.get(), is(1));
}
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) CompletableFuture(java.util.concurrent.CompletableFuture) 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 23 with LogicalSlot

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

the class SharedSlotTest method testLogicalSlotAllocation.

@Test
public void testLogicalSlotAllocation() {
    CompletableFuture<PhysicalSlot> slotContextFuture = new CompletableFuture<>();
    CompletableFuture<ExecutionSlotSharingGroup> released = new CompletableFuture<>();
    SharedSlot sharedSlot = SharedSlotBuilder.newBuilder().withSlotContextFuture(slotContextFuture).slotWillBeOccupiedIndefinitely().withExternalReleaseCallback(released::complete).build();
    CompletableFuture<LogicalSlot> logicalSlotFuture = sharedSlot.allocateLogicalSlot(EV1);
    assertThat(logicalSlotFuture.isDone(), is(false));
    AllocationID allocationId = new AllocationID();
    LocalTaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation();
    SimpleAckingTaskManagerGateway taskManagerGateway = new SimpleAckingTaskManagerGateway();
    slotContextFuture.complete(new TestingPhysicalSlot(allocationId, taskManagerLocation, 3, taskManagerGateway, RP));
    assertThat(sharedSlot.isEmpty(), is(false));
    assertThat(released.isDone(), is(false));
    assertThat(logicalSlotFuture.isDone(), is(true));
    LogicalSlot logicalSlot = logicalSlotFuture.join();
    assertThat(logicalSlot.getAllocationId(), is(allocationId));
    assertThat(logicalSlot.getTaskManagerLocation(), is(taskManagerLocation));
    assertThat(logicalSlot.getTaskManagerGateway(), is(taskManagerGateway));
    assertThat(logicalSlot.getLocality(), is(Locality.UNKNOWN));
}
Also used : PhysicalSlot(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlot) SimpleAckingTaskManagerGateway(org.apache.flink.runtime.executiongraph.utils.SimpleAckingTaskManagerGateway) CompletableFuture(java.util.concurrent.CompletableFuture) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) LocalTaskManagerLocation(org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation) SharedSlotTestingUtils.createExecutionSlotSharingGroup(org.apache.flink.runtime.scheduler.SharedSlotTestingUtils.createExecutionSlotSharingGroup) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) Test(org.junit.Test)

Example 24 with LogicalSlot

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

the class TestExecutionSlotAllocator method createSlotVertexAssignments.

private List<SlotExecutionVertexAssignment> createSlotVertexAssignments(final Collection<ExecutionVertexID> executionVertexIds) {
    final List<SlotExecutionVertexAssignment> result = new ArrayList<>();
    for (ExecutionVertexID executionVertexId : executionVertexIds) {
        final CompletableFuture<LogicalSlot> logicalSlotFuture = new CompletableFuture<>();
        result.add(new SlotExecutionVertexAssignment(executionVertexId, logicalSlotFuture));
    }
    return result;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ExecutionVertexID(org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID) ArrayList(java.util.ArrayList) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot)

Example 25 with LogicalSlot

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

the class TestExecutionSlotAllocator method returnLogicalSlot.

@Override
public void returnLogicalSlot(final LogicalSlot logicalSlot) {
    returnedSlots.add(logicalSlot);
    if (completePendingRequestsWithReturnedSlots) {
        if (pendingRequests.size() > 0) {
            // logical slots are not re-usable, creating a new one instead.
            final LogicalSlot slot = logicalSlotBuilder.setSlotOwner(this).createTestingLogicalSlot();
            final SlotExecutionVertexAssignment slotVertexAssignment = pendingRequests.remove(pendingRequests.keySet().stream().findAny().get());
            slotVertexAssignment.getLogicalSlotFuture().complete(slot);
        }
    }
}
Also used : LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot)

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