Search in sources :

Example 51 with LogicalSlot

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

the class Execution method getNextInputSplit.

public InputSplit getNextInputSplit() {
    final LogicalSlot slot = this.getAssignedResource();
    final String host = slot != null ? slot.getTaskManagerLocation().getHostname() : null;
    return this.vertex.getNextInputSplit(host);
}
Also used : LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot)

Example 52 with LogicalSlot

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

the class CheckpointCoordinatorTest method testReportLatestCompletedCheckpointIdWithAbort.

@Test
public void testReportLatestCompletedCheckpointIdWithAbort() throws Exception {
    JobVertexID jobVertexID = new JobVertexID();
    ExecutionGraph graph = new CheckpointCoordinatorTestingUtils.CheckpointExecutionGraphBuilder().addJobVertex(jobVertexID).setTransitToRunning(false).build();
    ExecutionVertex task = graph.getJobVertex(jobVertexID).getTaskVertices()[0];
    AtomicLong reportedCheckpointId = new AtomicLong(-1);
    LogicalSlot slot = new TestingLogicalSlotBuilder().setTaskManagerGateway(new SimpleAckingTaskManagerGateway() {

        @Override
        public void notifyCheckpointAborted(ExecutionAttemptID executionAttemptID, JobID jobId, long checkpointId, long latestCompletedCheckpointId, long timestamp) {
            reportedCheckpointId.set(latestCompletedCheckpointId);
        }
    }).createTestingLogicalSlot();
    ExecutionGraphTestUtils.setVertexResource(task, slot);
    task.getCurrentExecutionAttempt().transitionState(ExecutionState.RUNNING);
    CheckpointCoordinator checkpointCoordinator = new CheckpointCoordinatorBuilder().setExecutionGraph(graph).setTimer(manuallyTriggeredScheduledExecutor).setAllowCheckpointsAfterTasksFinished(true).build();
    // Trigger a successful checkpoint
    CompletableFuture<CompletedCheckpoint> result = checkpointCoordinator.triggerCheckpoint(false);
    manuallyTriggeredScheduledExecutor.triggerAll();
    long completedCheckpointId = checkpointCoordinator.getPendingCheckpoints().entrySet().iterator().next().getKey();
    checkpointCoordinator.receiveAcknowledgeMessage(new AcknowledgeCheckpoint(graph.getJobID(), task.getCurrentExecutionAttempt().getAttemptId(), completedCheckpointId, new CheckpointMetrics(), new TaskStateSnapshot()), "localhost");
    assertTrue(result.isDone());
    assertFalse(result.isCompletedExceptionally());
    result = checkpointCoordinator.triggerCheckpoint(false);
    manuallyTriggeredScheduledExecutor.triggerAll();
    long abortedCheckpointId = checkpointCoordinator.getPendingCheckpoints().entrySet().iterator().next().getKey();
    checkpointCoordinator.receiveDeclineMessage(new DeclineCheckpoint(graph.getJobID(), task.getCurrentExecutionAttempt().getAttemptId(), abortedCheckpointId, new CheckpointException(CHECKPOINT_EXPIRED)), "localhost");
    assertTrue(result.isCompletedExceptionally());
    assertEquals(completedCheckpointId, reportedCheckpointId.get());
}
Also used : DeclineCheckpoint(org.apache.flink.runtime.messages.checkpoint.DeclineCheckpoint) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) ExecutionVertex(org.apache.flink.runtime.executiongraph.ExecutionVertex) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) CheckpointCoordinatorBuilder(org.apache.flink.runtime.checkpoint.CheckpointCoordinatorTestingUtils.CheckpointCoordinatorBuilder) SimpleAckingTaskManagerGateway(org.apache.flink.runtime.executiongraph.utils.SimpleAckingTaskManagerGateway) AcknowledgeCheckpoint(org.apache.flink.runtime.messages.checkpoint.AcknowledgeCheckpoint) AtomicLong(java.util.concurrent.atomic.AtomicLong) ExecutionGraph(org.apache.flink.runtime.executiongraph.ExecutionGraph) TestingLogicalSlotBuilder(org.apache.flink.runtime.jobmaster.TestingLogicalSlotBuilder) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 53 with LogicalSlot

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

the class SharedSlotTest method testCannotAllocateLogicalSlotDuringRelease.

@Test(expected = IllegalStateException.class)
public void testCannotAllocateLogicalSlotDuringRelease() {
    final TestingPhysicalSlot physicalSlot = TestingPhysicalSlot.builder().build();
    final SharedSlot sharedSlot = new SharedSlot(new SlotRequestId(), physicalSlot, false, () -> {
    });
    final LogicalSlot logicalSlot = sharedSlot.allocateLogicalSlot();
    logicalSlot.tryAssignPayload(new TestLogicalSlotPayload(ignored -> sharedSlot.allocateLogicalSlot()));
    sharedSlot.release(new Exception("test"));
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) CoreMatchers.is(org.hamcrest.CoreMatchers.is) TestingPhysicalSlotPayload(org.apache.flink.runtime.jobmaster.slotpool.TestingPhysicalSlotPayload) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) CoreMatchers.not(org.hamcrest.CoreMatchers.not) Locality(org.apache.flink.runtime.jobmanager.scheduler.Locality) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) TestingLogicalSlotBuilder(org.apache.flink.runtime.jobmaster.TestingLogicalSlotBuilder) Consumer(java.util.function.Consumer) Assert.assertThat(org.junit.Assert.assertThat) TestingPhysicalSlot(org.apache.flink.runtime.scheduler.TestingPhysicalSlot) TestLogger(org.apache.flink.util.TestLogger) Assert.fail(org.junit.Assert.fail) SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) TestingPhysicalSlot(org.apache.flink.runtime.scheduler.TestingPhysicalSlot) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) Test(org.junit.Test)

Example 54 with LogicalSlot

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

the class SharedSlotTest method testAllocateLogicalSlot.

@Test
public void testAllocateLogicalSlot() {
    final TestingPhysicalSlot physicalSlot = TestingPhysicalSlot.builder().build();
    final SharedSlot sharedSlot = new SharedSlot(new SlotRequestId(), physicalSlot, false, () -> {
    });
    final LogicalSlot logicalSlot = sharedSlot.allocateLogicalSlot();
    assertThat(logicalSlot.getAllocationId(), equalTo(physicalSlot.getAllocationId()));
    assertThat(logicalSlot.getLocality(), is(Locality.UNKNOWN));
    assertThat(logicalSlot.getPayload(), nullValue());
    assertThat(logicalSlot.getTaskManagerLocation(), equalTo(physicalSlot.getTaskManagerLocation()));
    assertThat(logicalSlot.getTaskManagerGateway(), equalTo(physicalSlot.getTaskManagerGateway()));
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) TestingPhysicalSlot(org.apache.flink.runtime.scheduler.TestingPhysicalSlot) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) Test(org.junit.Test)

Example 55 with LogicalSlot

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

the class SharedSlotTest method testReturnLogicalSlotTriggersExternalReleaseOnLastSlot.

@Test
public void testReturnLogicalSlotTriggersExternalReleaseOnLastSlot() {
    final TestingPhysicalSlot physicalSlot = TestingPhysicalSlot.builder().build();
    final AtomicBoolean externalReleaseInitiated = new AtomicBoolean(false);
    final SharedSlot sharedSlot = new SharedSlot(new SlotRequestId(), physicalSlot, false, () -> externalReleaseInitiated.set(true));
    final LogicalSlot logicalSlot1 = sharedSlot.allocateLogicalSlot();
    final LogicalSlot logicalSlot2 = sharedSlot.allocateLogicalSlot();
    // this implicitly returns the slot
    logicalSlot1.releaseSlot(new Exception("test"));
    assertThat(externalReleaseInitiated.get(), is(false));
    logicalSlot2.releaseSlot(new Exception("test"));
    assertThat(externalReleaseInitiated.get(), is(true));
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) TestingPhysicalSlot(org.apache.flink.runtime.scheduler.TestingPhysicalSlot) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) Test(org.junit.Test)

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