Search in sources :

Example 1 with CancelPartitionRequest

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

the class PartitionRequestServerHandler method channelRead0.

@Override
protected void channelRead0(ChannelHandlerContext ctx, NettyMessage msg) throws Exception {
    try {
        Class<?> msgClazz = msg.getClass();
        // ----------------------------------------------------------------
        if (msgClazz == PartitionRequest.class) {
            PartitionRequest request = (PartitionRequest) msg;
            LOG.debug("Read channel on {}: {}.", ctx.channel().localAddress(), request);
            try {
                NetworkSequenceViewReader reader;
                reader = new CreditBasedSequenceNumberingViewReader(request.receiverId, request.credit, outboundQueue);
                reader.requestSubpartitionView(partitionProvider, request.partitionId, request.queueIndex);
                outboundQueue.notifyReaderCreated(reader);
            } catch (PartitionNotFoundException notFound) {
                respondWithError(ctx, notFound, request.receiverId);
            }
        } else // ----------------------------------------------------------------
        if (msgClazz == TaskEventRequest.class) {
            TaskEventRequest request = (TaskEventRequest) msg;
            if (!taskEventPublisher.publish(request.partitionId, request.event)) {
                respondWithError(ctx, new IllegalArgumentException("Task event receiver not found."), request.receiverId);
            }
        } else if (msgClazz == CancelPartitionRequest.class) {
            CancelPartitionRequest request = (CancelPartitionRequest) msg;
            outboundQueue.cancel(request.receiverId);
        } else if (msgClazz == CloseRequest.class) {
            outboundQueue.close();
        } else if (msgClazz == AddCredit.class) {
            AddCredit request = (AddCredit) msg;
            outboundQueue.addCreditOrResumeConsumption(request.receiverId, reader -> reader.addCredit(request.credit));
        } else if (msgClazz == ResumeConsumption.class) {
            ResumeConsumption request = (ResumeConsumption) msg;
            outboundQueue.addCreditOrResumeConsumption(request.receiverId, NetworkSequenceViewReader::resumeConsumption);
        } else if (msgClazz == AckAllUserRecordsProcessed.class) {
            AckAllUserRecordsProcessed request = (AckAllUserRecordsProcessed) msg;
            outboundQueue.acknowledgeAllRecordsProcessed(request.receiverId);
        } else if (msgClazz == NewBufferSize.class) {
            NewBufferSize request = (NewBufferSize) msg;
            outboundQueue.notifyNewBufferSize(request.receiverId, request.bufferSize);
        } else {
            LOG.warn("Received unexpected client request: {}", msg);
        }
    } catch (Throwable t) {
        respondWithError(ctx, t);
    }
}
Also used : NewBufferSize(org.apache.flink.runtime.io.network.netty.NettyMessage.NewBufferSize) CancelPartitionRequest(org.apache.flink.runtime.io.network.netty.NettyMessage.CancelPartitionRequest) PartitionRequest(org.apache.flink.runtime.io.network.netty.NettyMessage.PartitionRequest) AckAllUserRecordsProcessed(org.apache.flink.runtime.io.network.netty.NettyMessage.AckAllUserRecordsProcessed) ResumeConsumption(org.apache.flink.runtime.io.network.netty.NettyMessage.ResumeConsumption) PartitionNotFoundException(org.apache.flink.runtime.io.network.partition.PartitionNotFoundException) AddCredit(org.apache.flink.runtime.io.network.netty.NettyMessage.AddCredit) CancelPartitionRequest(org.apache.flink.runtime.io.network.netty.NettyMessage.CancelPartitionRequest) TaskEventRequest(org.apache.flink.runtime.io.network.netty.NettyMessage.TaskEventRequest) NetworkSequenceViewReader(org.apache.flink.runtime.io.network.NetworkSequenceViewReader) CloseRequest(org.apache.flink.runtime.io.network.netty.NettyMessage.CloseRequest)

Example 2 with CancelPartitionRequest

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

the class CancelPartitionRequestTest method testDuplicateCancel.

@Test
public void testDuplicateCancel() throws Exception {
    NettyServerAndClient serverAndClient = null;
    try {
        final TestPooledBufferProvider outboundBuffers = new TestPooledBufferProvider(16);
        ResultPartitionManager partitions = mock(ResultPartitionManager.class);
        ResultPartitionID pid = new ResultPartitionID();
        final CountDownLatch sync = new CountDownLatch(1);
        final ResultSubpartitionView view = spy(new InfiniteSubpartitionView(outboundBuffers, sync));
        // Return infinite subpartition
        when(partitions.createSubpartitionView(eq(pid), eq(0), any(BufferAvailabilityListener.class))).thenAnswer(new Answer<ResultSubpartitionView>() {

            @Override
            public ResultSubpartitionView answer(InvocationOnMock invocationOnMock) throws Throwable {
                BufferAvailabilityListener listener = (BufferAvailabilityListener) invocationOnMock.getArguments()[2];
                listener.notifyDataAvailable();
                return view;
            }
        });
        NettyProtocol protocol = new NettyProtocol(partitions, mock(TaskEventDispatcher.class));
        serverAndClient = initServerAndClient(protocol);
        Channel ch = connect(serverAndClient);
        // Request for non-existing input channel => results in cancel request
        InputChannelID inputChannelId = new InputChannelID();
        ch.writeAndFlush(new PartitionRequest(pid, 0, inputChannelId, Integer.MAX_VALUE)).await();
        // Wait for the notification
        if (!sync.await(TestingUtils.TESTING_DURATION.toMillis(), TimeUnit.MILLISECONDS)) {
            fail("Timed out after waiting for " + TestingUtils.TESTING_DURATION.toMillis() + " ms to be notified about cancelled partition.");
        }
        ch.writeAndFlush(new CancelPartitionRequest(inputChannelId)).await();
        ch.close();
        NettyTestUtil.awaitClose(ch);
        verify(view, times(1)).releaseAllResources();
    } finally {
        shutdown(serverAndClient);
    }
}
Also used : TestPooledBufferProvider(org.apache.flink.runtime.io.network.util.TestPooledBufferProvider) ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) Channel(org.apache.flink.shaded.netty4.io.netty.channel.Channel) PartitionRequest(org.apache.flink.runtime.io.network.netty.NettyMessage.PartitionRequest) CancelPartitionRequest(org.apache.flink.runtime.io.network.netty.NettyMessage.CancelPartitionRequest) ResultPartitionManager(org.apache.flink.runtime.io.network.partition.ResultPartitionManager) CountDownLatch(java.util.concurrent.CountDownLatch) InvocationOnMock(org.mockito.invocation.InvocationOnMock) InputChannelID(org.apache.flink.runtime.io.network.partition.consumer.InputChannelID) CancelPartitionRequest(org.apache.flink.runtime.io.network.netty.NettyMessage.CancelPartitionRequest) BufferAvailabilityListener(org.apache.flink.runtime.io.network.partition.BufferAvailabilityListener) ResultPartitionID(org.apache.flink.runtime.io.network.partition.ResultPartitionID) TaskEventDispatcher(org.apache.flink.runtime.io.network.TaskEventDispatcher) NettyServerAndClient(org.apache.flink.runtime.io.network.netty.NettyTestUtil.NettyServerAndClient) Test(org.junit.Test)

Aggregations

CancelPartitionRequest (org.apache.flink.runtime.io.network.netty.NettyMessage.CancelPartitionRequest)2 PartitionRequest (org.apache.flink.runtime.io.network.netty.NettyMessage.PartitionRequest)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 NetworkSequenceViewReader (org.apache.flink.runtime.io.network.NetworkSequenceViewReader)1 TaskEventDispatcher (org.apache.flink.runtime.io.network.TaskEventDispatcher)1 AckAllUserRecordsProcessed (org.apache.flink.runtime.io.network.netty.NettyMessage.AckAllUserRecordsProcessed)1 AddCredit (org.apache.flink.runtime.io.network.netty.NettyMessage.AddCredit)1 CloseRequest (org.apache.flink.runtime.io.network.netty.NettyMessage.CloseRequest)1 NewBufferSize (org.apache.flink.runtime.io.network.netty.NettyMessage.NewBufferSize)1 ResumeConsumption (org.apache.flink.runtime.io.network.netty.NettyMessage.ResumeConsumption)1 TaskEventRequest (org.apache.flink.runtime.io.network.netty.NettyMessage.TaskEventRequest)1 NettyServerAndClient (org.apache.flink.runtime.io.network.netty.NettyTestUtil.NettyServerAndClient)1 BufferAvailabilityListener (org.apache.flink.runtime.io.network.partition.BufferAvailabilityListener)1 PartitionNotFoundException (org.apache.flink.runtime.io.network.partition.PartitionNotFoundException)1 ResultPartitionID (org.apache.flink.runtime.io.network.partition.ResultPartitionID)1 ResultPartitionManager (org.apache.flink.runtime.io.network.partition.ResultPartitionManager)1 ResultSubpartitionView (org.apache.flink.runtime.io.network.partition.ResultSubpartitionView)1 InputChannelID (org.apache.flink.runtime.io.network.partition.consumer.InputChannelID)1 TestPooledBufferProvider (org.apache.flink.runtime.io.network.util.TestPooledBufferProvider)1 Channel (org.apache.flink.shaded.netty4.io.netty.channel.Channel)1