use of org.apache.flink.runtime.taskexecutor.exceptions.SlotAllocationException in project flink by apache.
the class AbstractFineGrainedSlotManagerITCase method testSlotRequestFailure.
// ---------------------------------------------------------------------------------------------
// Slot allocation failure handling
// ---------------------------------------------------------------------------------------------
/**
* Tests that the SlotManager retries allocating a slot if the TaskExecutor#requestSlot call
* fails.
*/
@Test
public void testSlotRequestFailure() throws Exception {
final JobID jobId = new JobID();
final ResourceRequirements resourceRequirements = createResourceRequirementsForSingleSlot(jobId);
final CompletableFuture<Acknowledge> slotRequestFuture1 = new CompletableFuture<>();
final CompletableFuture<Acknowledge> slotRequestFuture2 = CompletableFuture.completedFuture(Acknowledge.get());
final Iterator<CompletableFuture<Acknowledge>> slotRequestFutureIterator = Arrays.asList(slotRequestFuture1, slotRequestFuture2).iterator();
final ArrayBlockingQueue<AllocationID> allocationIds = new ArrayBlockingQueue<>(2);
final TestingTaskExecutorGateway taskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setRequestSlotFunction(FunctionUtils.uncheckedFunction(requestSlotParameters -> {
allocationIds.put(requestSlotParameters.f2);
return slotRequestFutureIterator.next();
})).createTestingTaskExecutorGateway();
final ResourceID resourceId = ResourceID.generate();
final TaskExecutorConnection taskManagerConnection = new TaskExecutorConnection(resourceId, taskExecutorGateway);
final SlotReport slotReport = new SlotReport();
new Context() {
{
runTest(() -> {
runInMainThread(() -> {
getSlotManager().registerTaskManager(taskManagerConnection, slotReport, DEFAULT_TOTAL_RESOURCE_PROFILE, DEFAULT_SLOT_RESOURCE_PROFILE);
getSlotManager().processResourceRequirements(resourceRequirements);
});
final AllocationID firstAllocationId = allocationIds.take();
assertThat(allocationIds, is(empty()));
// let the first attempt fail --> this should trigger a second attempt
runInMainThread(() -> slotRequestFuture1.completeExceptionally(new SlotAllocationException("Test exception.")));
final AllocationID secondAllocationId = allocationIds.take();
assertThat(allocationIds, is(empty()));
final TaskManagerSlotInformation slot = getTaskManagerTracker().getAllocatedOrPendingSlot(secondAllocationId).get();
assertEquals(jobId, slot.getJobId());
assertFalse(getTaskManagerTracker().getAllocatedOrPendingSlot(firstAllocationId).isPresent());
});
}
};
}
use of org.apache.flink.runtime.taskexecutor.exceptions.SlotAllocationException in project flink by apache.
the class DeclarativeSlotManagerTest method testTaskExecutorSlotAllocationTimeoutHandling.
/**
* Tests that a slot allocation is retried if it times out on the task manager side.
*/
@Test
public void testTaskExecutorSlotAllocationTimeoutHandling() throws Exception {
final JobID jobId = new JobID();
final ResourceRequirements resourceRequirements = createResourceRequirementsForSingleSlot(jobId);
final CompletableFuture<Acknowledge> slotRequestFuture1 = new CompletableFuture<>();
final CompletableFuture<Acknowledge> slotRequestFuture2 = new CompletableFuture<>();
final Iterator<CompletableFuture<Acknowledge>> slotRequestFutureIterator = Arrays.asList(slotRequestFuture1, slotRequestFuture2).iterator();
final ArrayBlockingQueue<SlotID> slotIds = new ArrayBlockingQueue<>(2);
final TestingTaskExecutorGateway taskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setRequestSlotFunction(FunctionUtils.uncheckedFunction(requestSlotParameters -> {
slotIds.put(requestSlotParameters.f0);
return slotRequestFutureIterator.next();
})).createTestingTaskExecutorGateway();
final ResourceID resourceId = ResourceID.generate();
final TaskExecutorConnection taskManagerConnection = new TaskExecutorConnection(resourceId, taskExecutorGateway);
final SlotID slotId1 = new SlotID(resourceId, 0);
final SlotID slotId2 = new SlotID(resourceId, 1);
final SlotReport slotReport = new SlotReport(Arrays.asList(createFreeSlotStatus(slotId1), createFreeSlotStatus(slotId2)));
final ResourceTracker resourceTracker = new DefaultResourceTracker();
final DefaultSlotTracker slotTracker = new DefaultSlotTracker();
try (DeclarativeSlotManager slotManager = createDeclarativeSlotManagerBuilder().setResourceTracker(resourceTracker).setSlotTracker(slotTracker).buildAndStartWithDirectExec()) {
slotManager.registerTaskManager(taskManagerConnection, slotReport, ResourceProfile.ANY, ResourceProfile.ANY);
slotManager.processResourceRequirements(resourceRequirements);
final SlotID firstSlotId = slotIds.take();
assertThat(slotIds, is(empty()));
DeclarativeTaskManagerSlot failedSlot = slotTracker.getSlot(firstSlotId);
// let the first attempt fail --> this should trigger a second attempt
slotRequestFuture1.completeExceptionally(new SlotAllocationException("Test exception."));
assertThat(getTotalResourceCount(resourceTracker.getAcquiredResources(jobId)), is(1));
// the second attempt succeeds
slotRequestFuture2.complete(Acknowledge.get());
final SlotID secondSlotId = slotIds.take();
assertThat(slotIds, is(empty()));
DeclarativeTaskManagerSlot slot = slotTracker.getSlot(secondSlotId);
assertThat(slot.getState(), is(SlotState.ALLOCATED));
assertEquals(jobId, slot.getJobId());
if (!failedSlot.getSlotId().equals(slot.getSlotId())) {
assertThat(failedSlot.getState(), is(SlotState.FREE));
}
}
}
Aggregations