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);
});
}
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));
}
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));
}
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());
}
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));
}
Aggregations