Search in sources :

Example 1 with PhysicalSlot

use of org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlot in project flink by apache.

the class SlotSharingExecutionSlotAllocator method getOrAllocateSharedSlot.

private SharedSlot getOrAllocateSharedSlot(ExecutionSlotSharingGroup executionSlotSharingGroup, SharedSlotProfileRetriever sharedSlotProfileRetriever) {
    return sharedSlots.computeIfAbsent(executionSlotSharingGroup, group -> {
        SlotRequestId physicalSlotRequestId = new SlotRequestId();
        ResourceProfile physicalSlotResourceProfile = getPhysicalSlotResourceProfile(group);
        SlotProfile slotProfile = sharedSlotProfileRetriever.getSlotProfile(group, physicalSlotResourceProfile);
        PhysicalSlotRequest physicalSlotRequest = new PhysicalSlotRequest(physicalSlotRequestId, slotProfile, slotWillBeOccupiedIndefinitely);
        CompletableFuture<PhysicalSlot> physicalSlotFuture = slotProvider.allocatePhysicalSlot(physicalSlotRequest).thenApply(PhysicalSlotRequest.Result::getPhysicalSlot);
        return new SharedSlot(physicalSlotRequestId, physicalSlotResourceProfile, group, physicalSlotFuture, slotWillBeOccupiedIndefinitely, this::releaseSharedSlot);
    });
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) PhysicalSlotRequest(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequest) PhysicalSlot(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlot) SlotProfile(org.apache.flink.runtime.clusterframework.types.SlotProfile)

Example 2 with PhysicalSlot

use of org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlot 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 3 with PhysicalSlot

use of org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlot 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 4 with PhysicalSlot

use of org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlot in project flink by apache.

the class SharedSlotTest method testReturnLogicalSlotWhileReleasingDoesNotCauseConcurrentModificationException.

@Test
public void testReturnLogicalSlotWhileReleasingDoesNotCauseConcurrentModificationException() {
    CompletableFuture<PhysicalSlot> slotContextFuture = CompletableFuture.completedFuture(new TestingPhysicalSlot(RP, new AllocationID()));
    SharedSlot sharedSlot = SharedSlotBuilder.newBuilder().withSlotContextFuture(slotContextFuture).build();
    LogicalSlot logicalSlot1 = sharedSlot.allocateLogicalSlot(EV1).join();
    LogicalSlot logicalSlot2 = sharedSlot.allocateLogicalSlot(EV2).join();
    logicalSlot1.tryAssignPayload(new LogicalSlot.Payload() {

        @Override
        public void fail(Throwable cause) {
            sharedSlot.returnLogicalSlot(logicalSlot2);
        }

        @Override
        public CompletableFuture<?> getTerminalStateFuture() {
            return CompletableFuture.completedFuture(null);
        }
    });
    sharedSlot.release(new Throwable());
}
Also used : PhysicalSlot(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlot) CompletableFuture(java.util.concurrent.CompletableFuture) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) Test(org.junit.Test)

Example 5 with PhysicalSlot

use of org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlot in project flink by apache.

the class SharedSlotTest method testReleaseIfPhysicalSlotIsAllocated.

@Test
public void testReleaseIfPhysicalSlotIsAllocated() {
    CompletableFuture<PhysicalSlot> slotContextFuture = CompletableFuture.completedFuture(new TestingPhysicalSlot(RP, new AllocationID()));
    CompletableFuture<ExecutionSlotSharingGroup> released = new CompletableFuture<>();
    SharedSlot sharedSlot = SharedSlotBuilder.newBuilder().withSlotContextFuture(slotContextFuture).withExternalReleaseCallback(released::complete).build();
    LogicalSlot logicalSlot = sharedSlot.allocateLogicalSlot(EV1).join();
    CompletableFuture<Object> terminalFuture = new CompletableFuture<>();
    logicalSlot.tryAssignPayload(new DummyPayload(terminalFuture));
    assertThat(terminalFuture.isDone(), is(false));
    sharedSlot.release(new Throwable());
    assertThat(terminalFuture.isDone(), is(true));
    assertThat(sharedSlot.isEmpty(), is(true));
    assertThat(released.isDone(), is(true));
}
Also used : DummyPayload(org.apache.flink.runtime.jobmaster.slotpool.DummyPayload) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) PhysicalSlot(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlot) CompletableFuture(java.util.concurrent.CompletableFuture) SharedSlotTestingUtils.createExecutionSlotSharingGroup(org.apache.flink.runtime.scheduler.SharedSlotTestingUtils.createExecutionSlotSharingGroup) Test(org.junit.Test)

Aggregations

PhysicalSlot (org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlot)8 CompletableFuture (java.util.concurrent.CompletableFuture)7 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)6 LogicalSlot (org.apache.flink.runtime.jobmaster.LogicalSlot)6 Test (org.junit.Test)6 ResourceProfile (org.apache.flink.runtime.clusterframework.types.ResourceProfile)4 SlotRequestId (org.apache.flink.runtime.jobmaster.SlotRequestId)4 SharedSlotTestingUtils.createExecutionSlotSharingGroup (org.apache.flink.runtime.scheduler.SharedSlotTestingUtils.createExecutionSlotSharingGroup)4 Consumer (java.util.function.Consumer)3 SimpleAckingTaskManagerGateway (org.apache.flink.runtime.executiongraph.utils.SimpleAckingTaskManagerGateway)3 Locality (org.apache.flink.runtime.jobmanager.scheduler.Locality)3 DummyPayload (org.apache.flink.runtime.jobmaster.slotpool.DummyPayload)3 ExecutionVertexID (org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID)3 LocalTaskManagerLocation (org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation)3 ExecutionException (java.util.concurrent.ExecutionException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ExecutionGraphTestUtils.createRandomExecutionVertexId (org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.createRandomExecutionVertexId)2 TestLogger (org.apache.flink.util.TestLogger)2 CoreMatchers.is (org.hamcrest.CoreMatchers.is)2 Assert.assertThat (org.junit.Assert.assertThat)2