Search in sources :

Example 31 with CancelTaskException

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

the class BufferManager method requestBufferBlocking.

Buffer requestBufferBlocking() throws InterruptedException {
    synchronized (bufferQueue) {
        Buffer buffer;
        while ((buffer = bufferQueue.takeBuffer()) == null) {
            if (inputChannel.isReleased()) {
                throw new CancelTaskException("Input channel [" + inputChannel.channelInfo + "] has already been released.");
            }
            if (!isWaitingForFloatingBuffers) {
                BufferPool bufferPool = inputChannel.inputGate.getBufferPool();
                buffer = bufferPool.requestBuffer();
                if (buffer == null && shouldContinueRequest(bufferPool)) {
                    continue;
                }
            }
            if (buffer != null) {
                return buffer;
            }
            bufferQueue.wait();
        }
        return buffer;
    }
}
Also used : Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) NetworkBuffer(org.apache.flink.runtime.io.network.buffer.NetworkBuffer) BufferPool(org.apache.flink.runtime.io.network.buffer.BufferPool) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException)

Example 32 with CancelTaskException

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

the class LocalInputChannel method getNextBuffer.

@Override
Optional<BufferAndAvailability> getNextBuffer() throws IOException {
    checkError();
    ResultSubpartitionView subpartitionView = this.subpartitionView;
    if (subpartitionView == null) {
        // during) it was released during reading the EndOfPartitionEvent (2).
        if (isReleased) {
            return Optional.empty();
        }
        // this can happen if the request for the partition was triggered asynchronously
        // by the time trigger
        // would be good to avoid that, by guaranteeing that the requestPartition() and
        // getNextBuffer() always come from the same thread
        // we could do that by letting the timer insert a special "requesting channel" into the
        // input gate's queue
        subpartitionView = checkAndWaitForSubpartitionView();
    }
    BufferAndBacklog next = subpartitionView.getNextBuffer();
    // ignore the empty buffer directly
    while (next != null && next.buffer().readableBytes() == 0) {
        next.buffer().recycleBuffer();
        next = subpartitionView.getNextBuffer();
        numBuffersIn.inc();
    }
    if (next == null) {
        if (subpartitionView.isReleased()) {
            throw new CancelTaskException("Consumed partition " + subpartitionView + " has been released.");
        } else {
            return Optional.empty();
        }
    }
    Buffer buffer = next.buffer();
    if (buffer instanceof FileRegionBuffer) {
        buffer = ((FileRegionBuffer) buffer).readInto(inputGate.getUnpooledSegment());
    }
    numBytesIn.inc(buffer.getSize());
    numBuffersIn.inc();
    channelStatePersister.checkForBarrier(buffer);
    channelStatePersister.maybePersist(buffer);
    NetworkActionsLogger.traceInput("LocalInputChannel#getNextBuffer", buffer, inputGate.getOwningTaskName(), channelInfo, channelStatePersister, next.getSequenceNumber());
    return Optional.of(new BufferAndAvailability(buffer, next.getNextDataType(), next.buffersInBacklog(), next.getSequenceNumber()));
}
Also used : FileRegionBuffer(org.apache.flink.runtime.io.network.buffer.FileRegionBuffer) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) FileRegionBuffer(org.apache.flink.runtime.io.network.buffer.FileRegionBuffer) ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) BufferAndBacklog(org.apache.flink.runtime.io.network.partition.ResultSubpartition.BufferAndBacklog)

Example 33 with CancelTaskException

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

the class BufferManager method requestBufferBlocking.

Buffer requestBufferBlocking() throws InterruptedException {
    synchronized (bufferQueue) {
        Buffer buffer;
        while ((buffer = bufferQueue.takeBuffer()) == null) {
            if (inputChannel.isReleased()) {
                throw new CancelTaskException("Input channel [" + inputChannel.channelInfo + "] has already been released.");
            }
            if (!isWaitingForFloatingBuffers) {
                BufferPool bufferPool = inputChannel.inputGate.getBufferPool();
                buffer = bufferPool.requestBuffer();
                if (buffer == null && shouldContinueRequest(bufferPool)) {
                    continue;
                }
            }
            if (buffer != null) {
                return buffer;
            }
            bufferQueue.wait();
        }
        return buffer;
    }
}
Also used : Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) NetworkBuffer(org.apache.flink.runtime.io.network.buffer.NetworkBuffer) BufferPool(org.apache.flink.runtime.io.network.buffer.BufferPool) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException)

Example 34 with CancelTaskException

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

the class BatchTask method run.

protected void run() throws Exception {
    // check for asynchronous canceling
    if (!this.running) {
        return;
    }
    boolean stubOpen = false;
    try {
        // run the data preparation
        try {
            this.driver.prepare();
        } catch (Throwable t) {
            // errors during clean-up are swallowed, because we have already a root exception
            throw new Exception("The data preparation for task '" + this.getEnvironment().getTaskInfo().getTaskName() + "' , caused an error: " + t.getMessage(), t);
        }
        // check for canceling
        if (!this.running) {
            return;
        }
        // start all chained tasks
        BatchTask.openChainedTasks(this.chainedTasks, this);
        // open stub implementation
        if (this.stub != null) {
            try {
                Configuration stubConfig = this.config.getStubParameters();
                FunctionUtils.openFunction(this.stub, stubConfig);
                stubOpen = true;
            } catch (Throwable t) {
                throw new Exception("The user defined 'open()' method caused an exception: " + t.getMessage(), t);
            }
        }
        // run the user code
        this.driver.run();
        // failed.
        if (this.running && this.stub != null) {
            FunctionUtils.closeFunction(this.stub);
            stubOpen = false;
        }
        // close all chained tasks letting them report failure
        BatchTask.closeChainedTasks(this.chainedTasks, this);
        // close the output collector
        this.output.close();
    } catch (Exception ex) {
        // cause
        if (stubOpen) {
            try {
                FunctionUtils.closeFunction(this.stub);
            } catch (Throwable t) {
            // do nothing
            }
        }
        // if resettable driver invoke teardown
        if (this.driver instanceof ResettableDriver) {
            final ResettableDriver<?, ?> resDriver = (ResettableDriver<?, ?>) this.driver;
            try {
                resDriver.teardown();
            } catch (Throwable t) {
                throw new Exception("Error while shutting down an iterative operator: " + t.getMessage(), t);
            }
        }
        BatchTask.cancelChainedTasks(this.chainedTasks);
        ex = ExceptionInChainedStubException.exceptionUnwrap(ex);
        if (ex instanceof CancelTaskException) {
            // forward canceling exception
            throw ex;
        } else if (this.running) {
            // throw only if task was not cancelled. in the case of canceling, exceptions are
            // expected
            BatchTask.logAndThrowException(ex, this);
        }
    } finally {
        this.driver.cleanup();
    }
}
Also used : Configuration(org.apache.flink.configuration.Configuration) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) ExceptionInChainedStubException(org.apache.flink.runtime.operators.chaining.ExceptionInChainedStubException) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) IOException(java.io.IOException)

Example 35 with CancelTaskException

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

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)

Aggregations

CancelTaskException (org.apache.flink.runtime.execution.CancelTaskException)43 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