Search in sources :

Example 1 with ErrorResponse

use of org.apache.flink.runtime.io.network.netty.NettyMessage.ErrorResponse in project flink by apache.

the class PartitionRequestQueue method writeAndFlushNextMessageIfPossible.

private void writeAndFlushNextMessageIfPossible(final Channel channel) throws IOException {
    if (fatalError) {
        return;
    }
    // The logic here is very similar to the combined input gate and local
    // input channel logic. You can think of this class acting as the input
    // gate and the consumed views as the local input channels.
    BufferAndAvailability next = null;
    try {
        if (channel.isWritable()) {
            while (true) {
                SequenceNumberingViewReader reader = nonEmptyReader.poll();
                // of the write callbacks that are executed after each write.
                if (reader == null) {
                    return;
                }
                next = reader.getNextBuffer();
                if (next == null) {
                    if (reader.isReleased()) {
                        markAsReleased(reader.getReceiverId());
                        Throwable cause = reader.getFailureCause();
                        if (cause != null) {
                            ErrorResponse msg = new ErrorResponse(new ProducerFailedException(cause), reader.getReceiverId());
                            ctx.writeAndFlush(msg);
                        }
                    } else {
                        IllegalStateException err = new IllegalStateException("Bug in Netty consumer logic: reader queue got notified by partition " + "about available data, but none was available.");
                        handleException(ctx.channel(), err);
                        return;
                    }
                } else {
                    // "non-empty" notification will come for that reader from the queue.
                    if (next.moreAvailable()) {
                        nonEmptyReader.add(reader);
                    }
                    BufferResponse msg = new BufferResponse(next.buffer(), reader.getSequenceNumber(), reader.getReceiverId());
                    if (isEndOfPartitionEvent(next.buffer())) {
                        reader.notifySubpartitionConsumed();
                        reader.releaseAllResources();
                        markAsReleased(reader.getReceiverId());
                    }
                    // Write and flush and wait until this is done before
                    // trying to continue with the next buffer.
                    channel.writeAndFlush(msg).addListener(writeListener);
                    return;
                }
            }
        }
    } catch (Throwable t) {
        if (next != null) {
            next.buffer().recycle();
        }
        throw new IOException(t.getMessage(), t);
    }
}
Also used : BufferResponse(org.apache.flink.runtime.io.network.netty.NettyMessage.BufferResponse) IOException(java.io.IOException) BufferAndAvailability(org.apache.flink.runtime.io.network.partition.consumer.InputChannel.BufferAndAvailability) ProducerFailedException(org.apache.flink.runtime.io.network.partition.ProducerFailedException) ErrorResponse(org.apache.flink.runtime.io.network.netty.NettyMessage.ErrorResponse)

Example 2 with ErrorResponse

use of org.apache.flink.runtime.io.network.netty.NettyMessage.ErrorResponse in project flink by apache.

the class PartitionRequestClientHandlerTest method testReceivePartitionNotFoundException.

/**
	 * Verifies that {@link RemoteInputChannel#onFailedPartitionRequest()} is called when a
	 * {@link PartitionNotFoundException} is received.
	 */
@Test
public void testReceivePartitionNotFoundException() throws Exception {
    // Minimal mock of a remote input channel
    final BufferProvider bufferProvider = mock(BufferProvider.class);
    when(bufferProvider.requestBuffer()).thenReturn(TestBufferFactory.createBuffer());
    final RemoteInputChannel inputChannel = mock(RemoteInputChannel.class);
    when(inputChannel.getInputChannelId()).thenReturn(new InputChannelID());
    when(inputChannel.getBufferProvider()).thenReturn(bufferProvider);
    final ErrorResponse partitionNotFound = new ErrorResponse(new PartitionNotFoundException(new ResultPartitionID()), inputChannel.getInputChannelId());
    final PartitionRequestClientHandler client = new PartitionRequestClientHandler();
    client.addInputChannel(inputChannel);
    // Mock channel context
    ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
    when(ctx.channel()).thenReturn(mock(Channel.class));
    client.channelActive(ctx);
    client.channelRead(ctx, partitionNotFound);
    verify(inputChannel, times(1)).onFailedPartitionRequest();
}
Also used : PartitionNotFoundException(org.apache.flink.runtime.io.network.partition.PartitionNotFoundException) InputChannelID(org.apache.flink.runtime.io.network.partition.consumer.InputChannelID) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Channel(io.netty.channel.Channel) BufferProvider(org.apache.flink.runtime.io.network.buffer.BufferProvider) ResultPartitionID(org.apache.flink.runtime.io.network.partition.ResultPartitionID) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel) ErrorResponse(org.apache.flink.runtime.io.network.netty.NettyMessage.ErrorResponse) Test(org.junit.Test)

Aggregations

ErrorResponse (org.apache.flink.runtime.io.network.netty.NettyMessage.ErrorResponse)2 Channel (io.netty.channel.Channel)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 IOException (java.io.IOException)1 BufferProvider (org.apache.flink.runtime.io.network.buffer.BufferProvider)1 BufferResponse (org.apache.flink.runtime.io.network.netty.NettyMessage.BufferResponse)1 PartitionNotFoundException (org.apache.flink.runtime.io.network.partition.PartitionNotFoundException)1 ProducerFailedException (org.apache.flink.runtime.io.network.partition.ProducerFailedException)1 ResultPartitionID (org.apache.flink.runtime.io.network.partition.ResultPartitionID)1 BufferAndAvailability (org.apache.flink.runtime.io.network.partition.consumer.InputChannel.BufferAndAvailability)1 InputChannelID (org.apache.flink.runtime.io.network.partition.consumer.InputChannelID)1 RemoteInputChannel (org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel)1 Test (org.junit.Test)1