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);
}
}
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();
}
Aggregations