Search in sources :

Example 1 with ResumeConsumption

use of org.apache.flink.runtime.io.network.netty.NettyMessage.ResumeConsumption 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 ResumeConsumption

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

the class NettyPartitionRequestClientTest method testResumeConsumption.

@Test
public void testResumeConsumption() throws Exception {
    final CreditBasedPartitionRequestClientHandler handler = new CreditBasedPartitionRequestClientHandler();
    final EmbeddedChannel channel = new EmbeddedChannel(handler);
    final PartitionRequestClient client = createPartitionRequestClient(channel, handler, connectionReuseEnabled);
    final NetworkBufferPool networkBufferPool = new NetworkBufferPool(10, 32);
    final SingleInputGate inputGate = createSingleInputGate(1, networkBufferPool);
    final RemoteInputChannel inputChannel = createRemoteInputChannel(inputGate, client);
    try {
        final BufferPool bufferPool = networkBufferPool.createBufferPool(6, 6);
        inputGate.setBufferPool(bufferPool);
        inputGate.setupChannels();
        inputChannel.requestSubpartition();
        inputChannel.resumeConsumption();
        channel.runPendingTasks();
        Object readFromOutbound = channel.readOutbound();
        assertThat(readFromOutbound, instanceOf(PartitionRequest.class));
        readFromOutbound = channel.readOutbound();
        assertThat(readFromOutbound, instanceOf(ResumeConsumption.class));
        assertEquals(inputChannel.getInputChannelId(), ((ResumeConsumption) readFromOutbound).receiverId);
        assertNull(channel.readOutbound());
    } finally {
        // Release all the buffer resources
        inputGate.close();
        networkBufferPool.destroyAllBufferPools();
        networkBufferPool.destroy();
    }
}
Also used : ResumeConsumption(org.apache.flink.runtime.io.network.netty.NettyMessage.ResumeConsumption) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) BufferPool(org.apache.flink.runtime.io.network.buffer.BufferPool) PartitionRequest(org.apache.flink.runtime.io.network.netty.NettyMessage.PartitionRequest) EmbeddedChannel(org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel) PartitionRequestClient(org.apache.flink.runtime.io.network.PartitionRequestClient) InputChannelTestUtils.mockConnectionManagerWithPartitionRequestClient(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.mockConnectionManagerWithPartitionRequestClient) InputChannelTestUtils.createSingleInputGate(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate) 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) InputChannelTestUtils.createRemoteInputChannel(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createRemoteInputChannel) Test(org.junit.Test)

Example 3 with ResumeConsumption

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

the class PartitionRequestServerHandlerTest method testResumeConsumption.

@Test
public void testResumeConsumption() {
    final InputChannelID inputChannelID = new InputChannelID();
    final PartitionRequestQueue partitionRequestQueue = new PartitionRequestQueue();
    final TestViewReader testViewReader = new TestViewReader(inputChannelID, 2, partitionRequestQueue);
    final PartitionRequestServerHandler serverHandler = new PartitionRequestServerHandler(new ResultPartitionManager(), new TaskEventDispatcher(), partitionRequestQueue);
    final EmbeddedChannel channel = new EmbeddedChannel(serverHandler);
    partitionRequestQueue.notifyReaderCreated(testViewReader);
    // Write the message of resume consumption to server
    channel.writeInbound(new ResumeConsumption(inputChannelID));
    channel.runPendingTasks();
    assertTrue(testViewReader.consumptionResumed);
}
Also used : ResumeConsumption(org.apache.flink.runtime.io.network.netty.NettyMessage.ResumeConsumption) InputChannelID(org.apache.flink.runtime.io.network.partition.consumer.InputChannelID) EmbeddedChannel(org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel) TaskEventDispatcher(org.apache.flink.runtime.io.network.TaskEventDispatcher) ResultPartitionManager(org.apache.flink.runtime.io.network.partition.ResultPartitionManager) Test(org.junit.Test)

Aggregations

ResumeConsumption (org.apache.flink.runtime.io.network.netty.NettyMessage.ResumeConsumption)3 PartitionRequest (org.apache.flink.runtime.io.network.netty.NettyMessage.PartitionRequest)2 EmbeddedChannel (org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel)2 Test (org.junit.Test)2 NetworkSequenceViewReader (org.apache.flink.runtime.io.network.NetworkSequenceViewReader)1 PartitionRequestClient (org.apache.flink.runtime.io.network.PartitionRequestClient)1 TaskEventDispatcher (org.apache.flink.runtime.io.network.TaskEventDispatcher)1 BufferPool (org.apache.flink.runtime.io.network.buffer.BufferPool)1 NetworkBufferPool (org.apache.flink.runtime.io.network.buffer.NetworkBufferPool)1 AckAllUserRecordsProcessed (org.apache.flink.runtime.io.network.netty.NettyMessage.AckAllUserRecordsProcessed)1 AddCredit (org.apache.flink.runtime.io.network.netty.NettyMessage.AddCredit)1 CancelPartitionRequest (org.apache.flink.runtime.io.network.netty.NettyMessage.CancelPartitionRequest)1 CloseRequest (org.apache.flink.runtime.io.network.netty.NettyMessage.CloseRequest)1 NewBufferSize (org.apache.flink.runtime.io.network.netty.NettyMessage.NewBufferSize)1 TaskEventRequest (org.apache.flink.runtime.io.network.netty.NettyMessage.TaskEventRequest)1 InputChannelTestUtils.createRemoteInputChannel (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createRemoteInputChannel)1 InputChannelTestUtils.createSingleInputGate (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate)1 InputChannelTestUtils.mockConnectionManagerWithPartitionRequestClient (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.mockConnectionManagerWithPartitionRequestClient)1 PartitionNotFoundException (org.apache.flink.runtime.io.network.partition.PartitionNotFoundException)1 ResultPartitionManager (org.apache.flink.runtime.io.network.partition.ResultPartitionManager)1