Search in sources :

Example 1 with PartitionProducerDisposedException

use of org.apache.flink.runtime.jobmanager.PartitionProducerDisposedException in project flink by apache.

the class TaskTest method testTriggerPartitionStateUpdate.

/**
	 * Tests the trigger partition state update future completions.
	 */
@Test
public void testTriggerPartitionStateUpdate() throws Exception {
    IntermediateDataSetID resultId = new IntermediateDataSetID();
    ResultPartitionID partitionId = new ResultPartitionID();
    LibraryCacheManager libCache = mock(LibraryCacheManager.class);
    when(libCache.getClassLoader(any(JobID.class))).thenReturn(getClass().getClassLoader());
    PartitionProducerStateChecker partitionChecker = mock(PartitionProducerStateChecker.class);
    ResultPartitionConsumableNotifier consumableNotifier = mock(ResultPartitionConsumableNotifier.class);
    NetworkEnvironment network = mock(NetworkEnvironment.class);
    when(network.getResultPartitionManager()).thenReturn(mock(ResultPartitionManager.class));
    when(network.getDefaultIOMode()).thenReturn(IOManager.IOMode.SYNC);
    when(network.createKvStateTaskRegistry(any(JobID.class), any(JobVertexID.class))).thenReturn(mock(TaskKvStateRegistry.class));
    createTask(InvokableBlockingInInvoke.class, libCache, network, consumableNotifier, partitionChecker, Executors.directExecutor());
    // Test all branches of trigger partition state check
    {
        // Reset latches
        createQueuesAndActors();
        // PartitionProducerDisposedException
        Task task = createTask(InvokableBlockingInInvoke.class, libCache, network, consumableNotifier, partitionChecker, Executors.directExecutor());
        FlinkCompletableFuture<ExecutionState> promise = new FlinkCompletableFuture<>();
        when(partitionChecker.requestPartitionProducerState(eq(task.getJobID()), eq(resultId), eq(partitionId))).thenReturn(promise);
        task.triggerPartitionProducerStateCheck(task.getJobID(), resultId, partitionId);
        promise.completeExceptionally(new PartitionProducerDisposedException(partitionId));
        assertEquals(ExecutionState.CANCELING, task.getExecutionState());
    }
    {
        // Reset latches
        createQueuesAndActors();
        // Any other exception
        Task task = createTask(InvokableBlockingInInvoke.class, libCache, network, consumableNotifier, partitionChecker, Executors.directExecutor());
        FlinkCompletableFuture<ExecutionState> promise = new FlinkCompletableFuture<>();
        when(partitionChecker.requestPartitionProducerState(eq(task.getJobID()), eq(resultId), eq(partitionId))).thenReturn(promise);
        task.triggerPartitionProducerStateCheck(task.getJobID(), resultId, partitionId);
        promise.completeExceptionally(new RuntimeException("Any other exception"));
        assertEquals(ExecutionState.FAILED, task.getExecutionState());
    }
    {
        // Reset latches
        createQueuesAndActors();
        // TimeoutException handled special => retry
        Task task = createTask(InvokableBlockingInInvoke.class, libCache, network, consumableNotifier, partitionChecker, Executors.directExecutor());
        SingleInputGate inputGate = mock(SingleInputGate.class);
        when(inputGate.getConsumedResultId()).thenReturn(resultId);
        try {
            task.startTaskThread();
            awaitLatch.await();
            setInputGate(task, inputGate);
            FlinkCompletableFuture<ExecutionState> promise = new FlinkCompletableFuture<>();
            when(partitionChecker.requestPartitionProducerState(eq(task.getJobID()), eq(resultId), eq(partitionId))).thenReturn(promise);
            task.triggerPartitionProducerStateCheck(task.getJobID(), resultId, partitionId);
            promise.completeExceptionally(new TimeoutException());
            assertEquals(ExecutionState.RUNNING, task.getExecutionState());
            verify(inputGate, times(1)).retriggerPartitionRequest(eq(partitionId.getPartitionId()));
        } finally {
            task.getExecutingThread().interrupt();
            task.getExecutingThread().join();
        }
    }
    {
        // Reset latches
        createQueuesAndActors();
        // Success
        Task task = createTask(InvokableBlockingInInvoke.class, libCache, network, consumableNotifier, partitionChecker, Executors.directExecutor());
        SingleInputGate inputGate = mock(SingleInputGate.class);
        when(inputGate.getConsumedResultId()).thenReturn(resultId);
        try {
            task.startTaskThread();
            awaitLatch.await();
            setInputGate(task, inputGate);
            FlinkCompletableFuture<ExecutionState> promise = new FlinkCompletableFuture<>();
            when(partitionChecker.requestPartitionProducerState(eq(task.getJobID()), eq(resultId), eq(partitionId))).thenReturn(promise);
            task.triggerPartitionProducerStateCheck(task.getJobID(), resultId, partitionId);
            promise.complete(ExecutionState.RUNNING);
            assertEquals(ExecutionState.RUNNING, task.getExecutionState());
            verify(inputGate, times(1)).retriggerPartitionRequest(eq(partitionId.getPartitionId()));
        } finally {
            task.getExecutingThread().interrupt();
            task.getExecutingThread().join();
        }
    }
}
Also used : JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) TaskKvStateRegistry(org.apache.flink.runtime.query.TaskKvStateRegistry) LibraryCacheManager(org.apache.flink.runtime.execution.librarycache.LibraryCacheManager) ResultPartitionManager(org.apache.flink.runtime.io.network.partition.ResultPartitionManager) FlinkCompletableFuture(org.apache.flink.runtime.concurrent.impl.FlinkCompletableFuture) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) NetworkEnvironment(org.apache.flink.runtime.io.network.NetworkEnvironment) PartitionProducerDisposedException(org.apache.flink.runtime.jobmanager.PartitionProducerDisposedException) IntermediateDataSetID(org.apache.flink.runtime.jobgraph.IntermediateDataSetID) ResultPartitionID(org.apache.flink.runtime.io.network.partition.ResultPartitionID) PartitionProducerStateChecker(org.apache.flink.runtime.io.network.netty.PartitionProducerStateChecker) ResultPartitionConsumableNotifier(org.apache.flink.runtime.io.network.partition.ResultPartitionConsumableNotifier) JobID(org.apache.flink.api.common.JobID) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 2 with PartitionProducerDisposedException

use of org.apache.flink.runtime.jobmanager.PartitionProducerDisposedException in project flink by apache.

the class JobMaster method requestPartitionState.

@RpcMethod
public ExecutionState requestPartitionState(final UUID leaderSessionID, final IntermediateDataSetID intermediateResultId, final ResultPartitionID resultPartitionId) throws Exception {
    validateLeaderSessionId(leaderSessionID);
    final Execution execution = executionGraph.getRegisteredExecutions().get(resultPartitionId.getProducerId());
    if (execution != null) {
        return execution.getState();
    } else {
        final IntermediateResult intermediateResult = executionGraph.getAllIntermediateResults().get(intermediateResultId);
        if (intermediateResult != null) {
            // Try to find the producing execution
            Execution producerExecution = intermediateResult.getPartitionById(resultPartitionId.getPartitionId()).getProducer().getCurrentExecutionAttempt();
            if (producerExecution.getAttemptId() == resultPartitionId.getProducerId()) {
                return producerExecution.getState();
            } else {
                throw new PartitionProducerDisposedException(resultPartitionId);
            }
        } else {
            throw new IllegalArgumentException("Intermediate data set with ID " + intermediateResultId + " not found.");
        }
    }
}
Also used : IntermediateResult(org.apache.flink.runtime.executiongraph.IntermediateResult) Execution(org.apache.flink.runtime.executiongraph.Execution) PartitionProducerDisposedException(org.apache.flink.runtime.jobmanager.PartitionProducerDisposedException) RpcMethod(org.apache.flink.runtime.rpc.RpcMethod)

Aggregations

PartitionProducerDisposedException (org.apache.flink.runtime.jobmanager.PartitionProducerDisposedException)2 TimeoutException (java.util.concurrent.TimeoutException)1 JobID (org.apache.flink.api.common.JobID)1 FlinkCompletableFuture (org.apache.flink.runtime.concurrent.impl.FlinkCompletableFuture)1 LibraryCacheManager (org.apache.flink.runtime.execution.librarycache.LibraryCacheManager)1 Execution (org.apache.flink.runtime.executiongraph.Execution)1 IntermediateResult (org.apache.flink.runtime.executiongraph.IntermediateResult)1 NetworkEnvironment (org.apache.flink.runtime.io.network.NetworkEnvironment)1 PartitionProducerStateChecker (org.apache.flink.runtime.io.network.netty.PartitionProducerStateChecker)1 ResultPartitionConsumableNotifier (org.apache.flink.runtime.io.network.partition.ResultPartitionConsumableNotifier)1 ResultPartitionID (org.apache.flink.runtime.io.network.partition.ResultPartitionID)1 ResultPartitionManager (org.apache.flink.runtime.io.network.partition.ResultPartitionManager)1 SingleInputGate (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate)1 IntermediateDataSetID (org.apache.flink.runtime.jobgraph.IntermediateDataSetID)1 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)1 TaskKvStateRegistry (org.apache.flink.runtime.query.TaskKvStateRegistry)1 RpcMethod (org.apache.flink.runtime.rpc.RpcMethod)1 Test (org.junit.Test)1