Search in sources :

Example 1 with SchedulingTopology

use of org.apache.flink.runtime.scheduler.strategy.SchedulingTopology in project flink by apache.

the class DefaultSchedulerTest method vertexIsResetBeforeRestarted.

@Test
public void vertexIsResetBeforeRestarted() throws Exception {
    final JobGraph jobGraph = singleNonParallelJobVertexJobGraph();
    final TestSchedulingStrategy.Factory schedulingStrategyFactory = new TestSchedulingStrategy.Factory();
    final DefaultScheduler scheduler = createScheduler(jobGraph, ComponentMainThreadExecutorServiceAdapter.forMainThread(), schedulingStrategyFactory);
    final TestSchedulingStrategy schedulingStrategy = schedulingStrategyFactory.getLastCreatedSchedulingStrategy();
    final SchedulingTopology topology = schedulingStrategy.getSchedulingTopology();
    scheduler.startScheduling();
    final SchedulingExecutionVertex onlySchedulingVertex = Iterables.getOnlyElement(topology.getVertices());
    schedulingStrategy.schedule(Collections.singletonList(onlySchedulingVertex.getId()));
    final ArchivedExecutionVertex onlyExecutionVertex = Iterables.getOnlyElement(scheduler.requestJob().getArchivedExecutionGraph().getAllExecutionVertices());
    final ExecutionAttemptID attemptId = onlyExecutionVertex.getCurrentExecutionAttempt().getAttemptId();
    scheduler.updateTaskExecutionState(createFailedTaskExecutionState(attemptId));
    taskRestartExecutor.triggerScheduledTasks();
    assertThat(schedulingStrategy.getReceivedVerticesToRestart(), hasSize(1));
    assertThat(onlySchedulingVertex.getState(), is(equalTo(ExecutionState.CREATED)));
}
Also used : JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) SchedulingExecutionVertex(org.apache.flink.runtime.scheduler.strategy.SchedulingExecutionVertex) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) ArchivedExecutionVertex(org.apache.flink.runtime.executiongraph.ArchivedExecutionVertex) TestingCheckpointRecoveryFactory(org.apache.flink.runtime.checkpoint.TestingCheckpointRecoveryFactory) SchedulingStrategyFactory(org.apache.flink.runtime.scheduler.strategy.SchedulingStrategyFactory) TestFailoverStrategyFactory(org.apache.flink.runtime.executiongraph.utils.TestFailoverStrategyFactory) CheckpointRecoveryFactory(org.apache.flink.runtime.checkpoint.CheckpointRecoveryFactory) SchedulingTopology(org.apache.flink.runtime.scheduler.strategy.SchedulingTopology) TestSchedulingStrategy(org.apache.flink.runtime.scheduler.strategy.TestSchedulingStrategy) AdaptiveSchedulerTest(org.apache.flink.runtime.scheduler.adaptive.AdaptiveSchedulerTest) Test(org.junit.Test)

Example 2 with SchedulingTopology

use of org.apache.flink.runtime.scheduler.strategy.SchedulingTopology in project flink by apache.

the class LocalInputPreferredSlotSharingStrategyTest method testInputLocalityIsRespectedWithTwoEdgesBetweenTwoVertices.

/**
 * In this test case, there are two JobEdges between two JobVertices. There will be no
 * ExecutionSlotSharingGroup that contains two vertices with the same JobVertexID.
 */
@Test
public void testInputLocalityIsRespectedWithTwoEdgesBetweenTwoVertices() throws Exception {
    int parallelism = 4;
    JobVertex v1 = createJobVertex("v1", JOB_VERTEX_ID_1, parallelism);
    JobVertex v2 = createJobVertex("v2", JOB_VERTEX_ID_2, parallelism);
    v2.connectNewDataSetAsInput(v1, DistributionPattern.ALL_TO_ALL, ResultPartitionType.BLOCKING);
    v2.connectNewDataSetAsInput(v1, DistributionPattern.ALL_TO_ALL, ResultPartitionType.BLOCKING);
    assertEquals(2, v1.getProducedDataSets().size());
    assertEquals(2, v2.getInputs().size());
    final JobGraph jobGraph = JobGraphTestUtils.batchJobGraph(v1, v2);
    final ExecutionGraph executionGraph = TestingDefaultExecutionGraphBuilder.newBuilder().setJobGraph(jobGraph).build();
    final SchedulingTopology topology = executionGraph.getSchedulingTopology();
    final SlotSharingStrategy strategy = new LocalInputPreferredSlotSharingStrategy(topology, slotSharingGroups, Collections.emptySet());
    assertThat(strategy.getExecutionSlotSharingGroups(), hasSize(4));
    ExecutionVertex[] ev1 = Objects.requireNonNull(executionGraph.getJobVertex(JOB_VERTEX_ID_1)).getTaskVertices();
    ExecutionVertex[] ev2 = Objects.requireNonNull(executionGraph.getJobVertex(JOB_VERTEX_ID_2)).getTaskVertices();
    for (int i = 0; i < parallelism; i++) {
        assertThat(strategy.getExecutionSlotSharingGroup(ev1[i].getID()).getExecutionVertexIds(), containsInAnyOrder(ev1[i].getID(), ev2[i].getID()));
    }
}
Also used : JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) ExecutionGraph(org.apache.flink.runtime.executiongraph.ExecutionGraph) SchedulingTopology(org.apache.flink.runtime.scheduler.strategy.SchedulingTopology) TestingSchedulingTopology(org.apache.flink.runtime.scheduler.strategy.TestingSchedulingTopology) TestingSchedulingExecutionVertex(org.apache.flink.runtime.scheduler.strategy.TestingSchedulingExecutionVertex) ExecutionVertex(org.apache.flink.runtime.executiongraph.ExecutionVertex) Test(org.junit.Test)

Example 3 with SchedulingTopology

use of org.apache.flink.runtime.scheduler.strategy.SchedulingTopology in project flink by apache.

the class DefaultSchedulerTest method cancelWhileRestartingShouldWaitForRunningTasks.

@Test
public void cancelWhileRestartingShouldWaitForRunningTasks() {
    final JobGraph jobGraph = singleJobVertexJobGraph(2);
    final DefaultScheduler scheduler = createSchedulerAndStartScheduling(jobGraph);
    final SchedulingTopology topology = scheduler.getSchedulingTopology();
    final Iterator<ArchivedExecutionVertex> vertexIterator = scheduler.requestJob().getArchivedExecutionGraph().getAllExecutionVertices().iterator();
    final ExecutionAttemptID attemptId1 = vertexIterator.next().getCurrentExecutionAttempt().getAttemptId();
    final ExecutionAttemptID attemptId2 = vertexIterator.next().getCurrentExecutionAttempt().getAttemptId();
    final ExecutionVertexID executionVertex2 = scheduler.getExecutionVertexIdOrThrow(attemptId2);
    scheduler.updateTaskExecutionState(new TaskExecutionState(attemptId1, ExecutionState.FAILED, new RuntimeException("expected")));
    scheduler.cancel();
    final ExecutionState vertex2StateAfterCancel = topology.getVertex(executionVertex2).getState();
    final JobStatus statusAfterCancelWhileRestarting = scheduler.requestJobStatus();
    scheduler.updateTaskExecutionState(new TaskExecutionState(attemptId2, ExecutionState.CANCELED, new RuntimeException("expected")));
    assertThat(vertex2StateAfterCancel, is(equalTo(ExecutionState.CANCELING)));
    assertThat(statusAfterCancelWhileRestarting, is(equalTo(JobStatus.CANCELLING)));
    assertThat(scheduler.requestJobStatus(), is(equalTo(JobStatus.CANCELED)));
}
Also used : JobStatus(org.apache.flink.api.common.JobStatus) ExecutionState(org.apache.flink.runtime.execution.ExecutionState) TaskExecutionState(org.apache.flink.runtime.taskmanager.TaskExecutionState) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) ExecutionVertexID(org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID) ArchivedExecutionVertex(org.apache.flink.runtime.executiongraph.ArchivedExecutionVertex) SchedulingTopology(org.apache.flink.runtime.scheduler.strategy.SchedulingTopology) TaskExecutionState(org.apache.flink.runtime.taskmanager.TaskExecutionState) AdaptiveSchedulerTest(org.apache.flink.runtime.scheduler.adaptive.AdaptiveSchedulerTest) Test(org.junit.Test)

Example 4 with SchedulingTopology

use of org.apache.flink.runtime.scheduler.strategy.SchedulingTopology in project flink by apache.

the class DefaultSchedulerTest method scheduleOnlyIfVertexIsCreated.

@Test
public void scheduleOnlyIfVertexIsCreated() throws Exception {
    final JobGraph jobGraph = singleNonParallelJobVertexJobGraph();
    final TestSchedulingStrategy.Factory schedulingStrategyFactory = new TestSchedulingStrategy.Factory();
    final DefaultScheduler scheduler = createScheduler(jobGraph, ComponentMainThreadExecutorServiceAdapter.forMainThread(), schedulingStrategyFactory);
    final TestSchedulingStrategy schedulingStrategy = schedulingStrategyFactory.getLastCreatedSchedulingStrategy();
    final SchedulingTopology topology = schedulingStrategy.getSchedulingTopology();
    scheduler.startScheduling();
    final ExecutionVertexID onlySchedulingVertexId = Iterables.getOnlyElement(topology.getVertices()).getId();
    // Schedule the vertex to get it to a non-CREATED state
    schedulingStrategy.schedule(Collections.singletonList(onlySchedulingVertexId));
    // The scheduling of a non-CREATED vertex will result in IllegalStateException
    try {
        schedulingStrategy.schedule(Collections.singletonList(onlySchedulingVertexId));
        fail("IllegalStateException should happen");
    } catch (IllegalStateException e) {
    // expected exception
    }
}
Also used : JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) ExecutionVertexID(org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID) TestingCheckpointRecoveryFactory(org.apache.flink.runtime.checkpoint.TestingCheckpointRecoveryFactory) SchedulingStrategyFactory(org.apache.flink.runtime.scheduler.strategy.SchedulingStrategyFactory) TestFailoverStrategyFactory(org.apache.flink.runtime.executiongraph.utils.TestFailoverStrategyFactory) CheckpointRecoveryFactory(org.apache.flink.runtime.checkpoint.CheckpointRecoveryFactory) SchedulingTopology(org.apache.flink.runtime.scheduler.strategy.SchedulingTopology) TestSchedulingStrategy(org.apache.flink.runtime.scheduler.strategy.TestSchedulingStrategy) AdaptiveSchedulerTest(org.apache.flink.runtime.scheduler.adaptive.AdaptiveSchedulerTest) Test(org.junit.Test)

Aggregations

JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)4 SchedulingTopology (org.apache.flink.runtime.scheduler.strategy.SchedulingTopology)4 Test (org.junit.Test)4 AdaptiveSchedulerTest (org.apache.flink.runtime.scheduler.adaptive.AdaptiveSchedulerTest)3 CheckpointRecoveryFactory (org.apache.flink.runtime.checkpoint.CheckpointRecoveryFactory)2 TestingCheckpointRecoveryFactory (org.apache.flink.runtime.checkpoint.TestingCheckpointRecoveryFactory)2 ArchivedExecutionVertex (org.apache.flink.runtime.executiongraph.ArchivedExecutionVertex)2 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)2 TestFailoverStrategyFactory (org.apache.flink.runtime.executiongraph.utils.TestFailoverStrategyFactory)2 ExecutionVertexID (org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID)2 SchedulingStrategyFactory (org.apache.flink.runtime.scheduler.strategy.SchedulingStrategyFactory)2 TestSchedulingStrategy (org.apache.flink.runtime.scheduler.strategy.TestSchedulingStrategy)2 JobStatus (org.apache.flink.api.common.JobStatus)1 ExecutionState (org.apache.flink.runtime.execution.ExecutionState)1 ExecutionGraph (org.apache.flink.runtime.executiongraph.ExecutionGraph)1 ExecutionVertex (org.apache.flink.runtime.executiongraph.ExecutionVertex)1 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)1 SchedulingExecutionVertex (org.apache.flink.runtime.scheduler.strategy.SchedulingExecutionVertex)1 TestingSchedulingExecutionVertex (org.apache.flink.runtime.scheduler.strategy.TestingSchedulingExecutionVertex)1 TestingSchedulingTopology (org.apache.flink.runtime.scheduler.strategy.TestingSchedulingTopology)1