Search in sources :

Example 11 with CancelTaskException

use of org.apache.flink.runtime.execution.CancelTaskException in project flink-mirror by flink-ci.

the class BufferManager method shouldContinueRequest.

private boolean shouldContinueRequest(BufferPool bufferPool) {
    if (bufferPool.addBufferListener(this)) {
        isWaitingForFloatingBuffers = true;
        numRequiredBuffers = 1;
        return false;
    } else if (bufferPool.isDestroyed()) {
        throw new CancelTaskException("Local buffer pool has already been released.");
    } else {
        return true;
    }
}
Also used : CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException)

Example 12 with CancelTaskException

use of org.apache.flink.runtime.execution.CancelTaskException in project flink-mirror by flink-ci.

the class TaskTest method testCancelTaskExceptionAfterTaskMarkedFailed.

@Test
public void testCancelTaskExceptionAfterTaskMarkedFailed() throws Exception {
    final Task task = createTaskBuilder().setInvokable(InvokableWithCancelTaskExceptionInInvoke.class).build();
    task.startTaskThread();
    // Wait till the task is in invoke.
    awaitLatch.await();
    task.failExternally(new Exception("external"));
    assertFalse(triggerLatch.isTriggered());
    assertEquals(ExecutionState.FAILED, task.getExecutionState());
    // Either we cause the CancelTaskException or the TaskCanceler
    // by interrupting the invokable.
    triggerLatch.trigger();
    task.getExecutingThread().join();
    assertEquals(ExecutionState.FAILED, task.getExecutionState());
    assertTrue(task.isCanceledOrFailed());
    assertTrue(task.getFailureCause().getMessage().contains("external"));
}
Also used : TimeoutException(java.util.concurrent.TimeoutException) WrappingRuntimeException(org.apache.flink.util.WrappingRuntimeException) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) ExpectedTestException(org.apache.flink.runtime.operators.testutils.ExpectedTestException) FlinkException(org.apache.flink.util.FlinkException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) PartitionProducerDisposedException(org.apache.flink.runtime.jobmanager.PartitionProducerDisposedException) IOException(java.io.IOException) Test(org.junit.Test)

Example 13 with CancelTaskException

use of org.apache.flink.runtime.execution.CancelTaskException in project flink-mirror by flink-ci.

the class CheckpointedInputGateTest method testPriorityBeforeClose.

/**
 * Tests a priority notification happening right before cancellation. The mail would be
 * processed while draining mailbox but can't pull any data anymore.
 */
@Test
public void testPriorityBeforeClose() throws IOException, InterruptedException {
    NetworkBufferPool bufferPool = new NetworkBufferPool(10, 1024);
    try (Closer closer = Closer.create()) {
        closer.register(bufferPool::destroy);
        for (int repeat = 0; repeat < 100; repeat++) {
            setUp();
            SingleInputGate singleInputGate = new SingleInputGateBuilder().setNumberOfChannels(2).setBufferPoolFactory(bufferPool.createBufferPool(2, Integer.MAX_VALUE)).setSegmentProvider(bufferPool).setChannelFactory(InputChannelBuilder::buildRemoteChannel).build();
            singleInputGate.setup();
            ((RemoteInputChannel) singleInputGate.getChannel(0)).requestSubpartition();
            final TaskMailboxImpl mailbox = new TaskMailboxImpl();
            MailboxExecutorImpl mailboxExecutor = new MailboxExecutorImpl(mailbox, 0, StreamTaskActionExecutor.IMMEDIATE);
            ValidatingCheckpointHandler validatingHandler = new ValidatingCheckpointHandler(1);
            SingleCheckpointBarrierHandler barrierHandler = TestBarrierHandlerFactory.forTarget(validatingHandler).create(singleInputGate, new MockChannelStateWriter());
            CheckpointedInputGate checkpointedInputGate = new CheckpointedInputGate(singleInputGate, barrierHandler, mailboxExecutor, UpstreamRecoveryTracker.forInputGate(singleInputGate));
            final int oldSize = mailbox.size();
            enqueue(checkpointedInputGate, 0, barrier(1));
            // wait for priority mail to be enqueued
            Deadline deadline = Deadline.fromNow(Duration.ofMinutes(1));
            while (deadline.hasTimeLeft() && oldSize >= mailbox.size()) {
                Thread.sleep(1);
            }
            // test the race condition
            // either priority event could be handled, then we expect a checkpoint to be
            // triggered or closing came first in which case we expect a CancelTaskException
            CountDownLatch beforeLatch = new CountDownLatch(2);
            final CheckedThread canceler = new CheckedThread("Canceler") {

                @Override
                public void go() throws IOException {
                    beforeLatch.countDown();
                    singleInputGate.close();
                }
            };
            canceler.start();
            beforeLatch.countDown();
            try {
                while (mailboxExecutor.tryYield()) {
                }
                assertEquals(1L, validatingHandler.triggeredCheckpointCounter);
            } catch (CancelTaskException e) {
            }
            canceler.join();
        }
    }
}
Also used : Closer(org.apache.flink.shaded.guava30.com.google.common.io.Closer) MockChannelStateWriter(org.apache.flink.runtime.checkpoint.channel.MockChannelStateWriter) MailboxExecutorImpl(org.apache.flink.streaming.runtime.tasks.mailbox.MailboxExecutorImpl) Deadline(org.apache.flink.api.common.time.Deadline) CountDownLatch(java.util.concurrent.CountDownLatch) CheckedThread(org.apache.flink.core.testutils.CheckedThread) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel) SingleInputGateBuilder(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder) TaskMailboxImpl(org.apache.flink.streaming.runtime.tasks.mailbox.TaskMailboxImpl) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) Test(org.junit.Test)

Example 14 with CancelTaskException

use of org.apache.flink.runtime.execution.CancelTaskException in project flink-mirror by flink-ci.

the class LocalInputChannelTest method testProducerFailedException.

@Test(expected = CancelTaskException.class)
public void testProducerFailedException() throws Exception {
    ResultSubpartitionView view = mock(ResultSubpartitionView.class);
    when(view.isReleased()).thenReturn(true);
    when(view.getFailureCause()).thenReturn(new Exception("Expected test exception"));
    ResultPartitionManager partitionManager = mock(ResultPartitionManager.class);
    when(partitionManager.createSubpartitionView(any(ResultPartitionID.class), anyInt(), any(BufferAvailabilityListener.class))).thenReturn(view);
    SingleInputGate inputGate = mock(SingleInputGate.class);
    BufferProvider bufferProvider = mock(BufferProvider.class);
    when(inputGate.getBufferProvider()).thenReturn(bufferProvider);
    LocalInputChannel ch = createLocalInputChannel(inputGate, partitionManager);
    ch.requestSubpartition();
    // Should throw an instance of CancelTaskException.
    ch.getNextBuffer();
}
Also used : ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) BufferAvailabilityListener(org.apache.flink.runtime.io.network.partition.BufferAvailabilityListener) BufferProvider(org.apache.flink.runtime.io.network.buffer.BufferProvider) ResultPartitionID(org.apache.flink.runtime.io.network.partition.ResultPartitionID) IntermediateResultPartitionID(org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID) ResultPartitionManager(org.apache.flink.runtime.io.network.partition.ResultPartitionManager) TestingResultPartitionManager(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateTest.TestingResultPartitionManager) InputChannelTestUtils.createLocalInputChannel(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createLocalInputChannel) InputChannelTestUtils.createSingleInputGate(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) PartitionNotFoundException(org.apache.flink.runtime.io.network.partition.PartitionNotFoundException) IOException(java.io.IOException) Test(org.junit.Test)

Example 15 with CancelTaskException

use of org.apache.flink.runtime.execution.CancelTaskException in project flink by splunk.

the class TaskTest method testCancelTaskExceptionAfterTaskMarkedFailed.

@Test
public void testCancelTaskExceptionAfterTaskMarkedFailed() throws Exception {
    final Task task = createTaskBuilder().setInvokable(InvokableWithCancelTaskExceptionInInvoke.class).build();
    task.startTaskThread();
    // Wait till the task is in invoke.
    awaitLatch.await();
    task.failExternally(new Exception("external"));
    assertFalse(triggerLatch.isTriggered());
    assertEquals(ExecutionState.FAILED, task.getExecutionState());
    // Either we cause the CancelTaskException or the TaskCanceler
    // by interrupting the invokable.
    triggerLatch.trigger();
    task.getExecutingThread().join();
    assertEquals(ExecutionState.FAILED, task.getExecutionState());
    assertTrue(task.isCanceledOrFailed());
    assertTrue(task.getFailureCause().getMessage().contains("external"));
}
Also used : TimeoutException(java.util.concurrent.TimeoutException) WrappingRuntimeException(org.apache.flink.util.WrappingRuntimeException) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) ExpectedTestException(org.apache.flink.runtime.operators.testutils.ExpectedTestException) FlinkException(org.apache.flink.util.FlinkException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) PartitionProducerDisposedException(org.apache.flink.runtime.jobmanager.PartitionProducerDisposedException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

CancelTaskException (org.apache.flink.runtime.execution.CancelTaskException)42 IOException (java.io.IOException)16 Test (org.junit.Test)16 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)10 ResultSubpartitionView (org.apache.flink.runtime.io.network.partition.ResultSubpartitionView)10 ExceptionInChainedStubException (org.apache.flink.runtime.operators.chaining.ExceptionInChainedStubException)9 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)7 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)6 CheckpointException (org.apache.flink.runtime.checkpoint.CheckpointException)5 ExecutorService (java.util.concurrent.ExecutorService)4 RuntimeContext (org.apache.flink.api.common.functions.RuntimeContext)4 Counter (org.apache.flink.metrics.Counter)4 SimpleCounter (org.apache.flink.metrics.SimpleCounter)4 InputChannelTestUtils.createLocalInputChannel (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createLocalInputChannel)4 TestingResultPartitionManager (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateTest.TestingResultPartitionManager)4 InternalOperatorIOMetricGroup (org.apache.flink.runtime.metrics.groups.InternalOperatorIOMetricGroup)4 StreamConfig (org.apache.flink.streaming.api.graph.StreamConfig)4 FlinkException (org.apache.flink.util.FlinkException)4 WrappingRuntimeException (org.apache.flink.util.WrappingRuntimeException)4 File (java.io.File)3