Search in sources :

Example 46 with LogicalSlot

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

the class DefaultScheduler method assignResource.

private BiFunction<LogicalSlot, Throwable, LogicalSlot> assignResource(final DeploymentHandle deploymentHandle) {
    final ExecutionVertexVersion requiredVertexVersion = deploymentHandle.getRequiredVertexVersion();
    final ExecutionVertexID executionVertexId = deploymentHandle.getExecutionVertexId();
    return (logicalSlot, throwable) -> {
        if (executionVertexVersioner.isModified(requiredVertexVersion)) {
            if (throwable == null) {
                log.debug("Refusing to assign slot to execution vertex {} because this deployment was " + "superseded by another deployment", executionVertexId);
                releaseSlotIfPresent(logicalSlot);
            }
            return null;
        }
        // a task which is about to cancel in #restartTasksWithDelay(...)
        if (throwable != null) {
            throw new CompletionException(maybeWrapWithNoResourceAvailableException(throwable));
        }
        final ExecutionVertex executionVertex = getExecutionVertex(executionVertexId);
        executionVertex.tryAssignResource(logicalSlot);
        startReserveAllocation(executionVertexId, logicalSlot.getAllocationId());
        return logicalSlot;
    };
}
Also used : ShuffleMaster(org.apache.flink.runtime.shuffle.ShuffleMaster) TaskManagerLocation(org.apache.flink.runtime.taskmanager.TaskManagerLocation) BiFunction(java.util.function.BiFunction) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) TimeoutException(java.util.concurrent.TimeoutException) ExceptionUtils(org.apache.flink.util.ExceptionUtils) Vertex(org.apache.flink.runtime.topology.Vertex) Map(java.util.Map) SchedulingTopology(org.apache.flink.runtime.scheduler.strategy.SchedulingTopology) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) CoLocationGroup(org.apache.flink.runtime.jobmanager.scheduler.CoLocationGroup) SchedulingStrategyFactory(org.apache.flink.runtime.scheduler.strategy.SchedulingStrategyFactory) ScheduledExecutor(org.apache.flink.util.concurrent.ScheduledExecutor) JobManagerJobMetricGroup(org.apache.flink.runtime.metrics.groups.JobManagerJobMetricGroup) Collection(java.util.Collection) Set(java.util.Set) CompletionException(java.util.concurrent.CompletionException) ExecutionVertexID(org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID) Collectors(java.util.stream.Collectors) ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) List(java.util.List) FailoverStrategy(org.apache.flink.runtime.executiongraph.failover.flip1.FailoverStrategy) Optional(java.util.Optional) ExecutionFailureHandler(org.apache.flink.runtime.executiongraph.failover.flip1.ExecutionFailureHandler) Time(org.apache.flink.api.common.time.Time) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) NoResourceAvailableException(org.apache.flink.runtime.jobmanager.scheduler.NoResourceAvailableException) IntermediateResultPartitionID(org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID) ComponentMainThreadExecutor(org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor) SlotSharingGroup(org.apache.flink.runtime.jobmanager.scheduler.SlotSharingGroup) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) JobStatus(org.apache.flink.api.common.JobStatus) Function(java.util.function.Function) ArrayList(java.util.ArrayList) FailureHandlingResult(org.apache.flink.runtime.executiongraph.failover.flip1.FailureHandlingResult) HashSet(java.util.HashSet) OperatorCoordinatorHolder(org.apache.flink.runtime.operators.coordination.OperatorCoordinatorHolder) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) SchedulingStrategy(org.apache.flink.runtime.scheduler.strategy.SchedulingStrategy) Nullable(javax.annotation.Nullable) Preconditions.checkState(org.apache.flink.util.Preconditions.checkState) ExecutionJobVertex(org.apache.flink.runtime.executiongraph.ExecutionJobVertex) Logger(org.slf4j.Logger) Executor(java.util.concurrent.Executor) Configuration(org.apache.flink.configuration.Configuration) ExecutionState(org.apache.flink.runtime.execution.ExecutionState) CheckpointsCleaner(org.apache.flink.runtime.checkpoint.CheckpointsCleaner) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) IterableUtils(org.apache.flink.util.IterableUtils) JobStatusListener(org.apache.flink.runtime.executiongraph.JobStatusListener) CheckpointRecoveryFactory(org.apache.flink.runtime.checkpoint.CheckpointRecoveryFactory) RestartBackoffTimeStrategy(org.apache.flink.runtime.executiongraph.failover.flip1.RestartBackoffTimeStrategy) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) FailureHandlingResultSnapshot(org.apache.flink.runtime.scheduler.exceptionhistory.FailureHandlingResultSnapshot) TaskExecutionStateTransition(org.apache.flink.runtime.executiongraph.TaskExecutionStateTransition) ExecutionVertex(org.apache.flink.runtime.executiongraph.ExecutionVertex) ExecutionVertexID(org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID) CompletionException(java.util.concurrent.CompletionException) ExecutionVertex(org.apache.flink.runtime.executiongraph.ExecutionVertex)

Example 47 with LogicalSlot

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

the class SlotSharingExecutionSlotAllocator method allocateLogicalSlotsFromSharedSlots.

private static Map<ExecutionVertexID, SlotExecutionVertexAssignment> allocateLogicalSlotsFromSharedSlots(Map<ExecutionSlotSharingGroup, SharedSlot> slots, Map<ExecutionSlotSharingGroup, List<ExecutionVertexID>> executionsByGroup) {
    Map<ExecutionVertexID, SlotExecutionVertexAssignment> assignments = new HashMap<>();
    for (Map.Entry<ExecutionSlotSharingGroup, List<ExecutionVertexID>> entry : executionsByGroup.entrySet()) {
        ExecutionSlotSharingGroup group = entry.getKey();
        List<ExecutionVertexID> executionIds = entry.getValue();
        for (ExecutionVertexID executionId : executionIds) {
            CompletableFuture<LogicalSlot> logicalSlotFuture = slots.get(group).allocateLogicalSlot(executionId);
            SlotExecutionVertexAssignment assignment = new SlotExecutionVertexAssignment(executionId, logicalSlotFuture);
            assignments.put(executionId, assignment);
        }
    }
    return assignments;
}
Also used : IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) ExecutionVertexID(org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID) List(java.util.List) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) Map(java.util.Map) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot)

Example 48 with LogicalSlot

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

the class SingleLogicalSlotTest method testAllocatedSlotRelease.

/**
 * Tests that the {@link PhysicalSlot.Payload#release(Throwable)} does not wait for the payload
 * to reach a terminal state.
 */
@Test
public void testAllocatedSlotRelease() {
    final CompletableFuture<LogicalSlot> returnSlotFuture = new CompletableFuture<>();
    final WaitingSlotOwner waitingSlotOwner = new WaitingSlotOwner(returnSlotFuture, new CompletableFuture<>());
    final SingleLogicalSlot singleLogicalSlot = createSingleLogicalSlot(waitingSlotOwner);
    final CompletableFuture<?> terminalStateFuture = new CompletableFuture<>();
    final CompletableFuture<?> failFuture = new CompletableFuture<>();
    final ManualTestingPayload dummyPayload = new ManualTestingPayload(failFuture, terminalStateFuture);
    assertThat(singleLogicalSlot.tryAssignPayload(dummyPayload), is(true));
    singleLogicalSlot.release(new FlinkException("Test exception"));
    assertThat(failFuture.isDone(), is(true));
    // we don't require the logical slot to return to the owner because
    // the release call should only come from the owner
    assertThat(returnSlotFuture.isDone(), is(false));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) FlinkException(org.apache.flink.util.FlinkException) Test(org.junit.Test)

Example 49 with LogicalSlot

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

the class DefaultSchedulerTest method restartVerticesOnAssignedSlotReleased.

@Test
public void restartVerticesOnAssignedSlotReleased() throws Exception {
    testExecutionSlotAllocator.disableAutoCompletePendingRequests();
    testRestartVerticesOnFailuresInScheduling(vid -> {
        final LogicalSlot slot = testExecutionSlotAllocator.completePendingRequest(vid);
        slot.releaseSlot(new Exception("Release slot for test"));
    });
}
Also used : LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) FlinkException(org.apache.flink.util.FlinkException) NoResourceAvailableException(org.apache.flink.runtime.jobmanager.scheduler.NoResourceAvailableException) AdaptiveSchedulerTest(org.apache.flink.runtime.scheduler.adaptive.AdaptiveSchedulerTest) Test(org.junit.Test)

Example 50 with LogicalSlot

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

the class Execution method triggerCheckpointHelper.

private CompletableFuture<Acknowledge> triggerCheckpointHelper(long checkpointId, long timestamp, CheckpointOptions checkpointOptions) {
    final LogicalSlot slot = assignedResource;
    if (slot != null) {
        final TaskManagerGateway taskManagerGateway = slot.getTaskManagerGateway();
        return taskManagerGateway.triggerCheckpoint(attemptId, getVertex().getJobId(), checkpointId, timestamp, checkpointOptions);
    }
    LOG.debug("The execution has no slot assigned. This indicates that the execution is no longer running.");
    return CompletableFuture.completedFuture(Acknowledge.get());
}
Also used : TaskManagerGateway(org.apache.flink.runtime.jobmanager.slots.TaskManagerGateway) 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