Search in sources :

Example 6 with PhysicalSlot

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

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

the class SharedSlotTest method testAssignAsPayloadToPhysicalSlot.

@Test
public void testAssignAsPayloadToPhysicalSlot() {
    CompletableFuture<PhysicalSlot> slotContextFuture = new CompletableFuture<>();
    SharedSlot sharedSlot = SharedSlotBuilder.newBuilder().withSlotContextFuture(slotContextFuture).build();
    TestingPhysicalSlot physicalSlot = new TestingPhysicalSlot(RP, new AllocationID());
    slotContextFuture.complete(physicalSlot);
    assertThat(physicalSlot.getPayload(), is(sharedSlot));
}
Also used : PhysicalSlot(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlot) CompletableFuture(java.util.concurrent.CompletableFuture) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) Test(org.junit.Test)

Example 8 with PhysicalSlot

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

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