Search in sources :

Example 21 with NetworkBufferPool

use of org.apache.flink.runtime.io.network.buffer.NetworkBufferPool in project flink by apache.

the class RemoteInputChannelTest method testGateNotifiedOnBarrierConversion.

@Test
public void testGateNotifiedOnBarrierConversion() throws IOException, InterruptedException {
    final int sequenceNumber = 0;
    final NetworkBufferPool networkBufferPool = new NetworkBufferPool(1, 4096);
    try {
        SingleInputGate inputGate = new SingleInputGateBuilder().setBufferPoolFactory(networkBufferPool.createBufferPool(1, 1)).build();
        inputGate.setup();
        RemoteInputChannel channel = InputChannelBuilder.newBuilder().setConnectionManager(new TestVerifyConnectionManager(new TestVerifyPartitionRequestClient())).buildRemoteChannel(inputGate);
        channel.requestSubpartition();
        channel.onBuffer(toBuffer(new CheckpointBarrier(1L, 123L, alignedWithTimeout(CheckpointType.CHECKPOINT, getDefault(), Integer.MAX_VALUE)), false), sequenceNumber, 0);
        // process announcement to allow the gate remember the SQN
        inputGate.pollNext();
        channel.convertToPriorityEvent(sequenceNumber);
        assertTrue(inputGate.getPriorityEventAvailableFuture().isDone());
    } finally {
        networkBufferPool.destroy();
    }
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) InputChannelTestUtils.createSingleInputGate(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) Test(org.junit.Test)

Example 22 with NetworkBufferPool

use of org.apache.flink.runtime.io.network.buffer.NetworkBufferPool in project flink by apache.

the class RemoteInputChannelTest method testFairDistributionFloatingBuffers.

/**
 * Tests to verify that the buffer pool will distribute available floating buffers among all the
 * channel listeners in a fair way.
 */
@Test
public void testFairDistributionFloatingBuffers() throws Exception {
    // Setup
    final int numExclusiveBuffers = 2;
    final NetworkBufferPool networkBufferPool = new NetworkBufferPool(12, 32);
    final int numFloatingBuffers = 3;
    final SingleInputGate inputGate = createSingleInputGate(3, networkBufferPool);
    final RemoteInputChannel[] inputChannels = new RemoteInputChannel[3];
    inputChannels[0] = createRemoteInputChannel(inputGate);
    inputChannels[1] = createRemoteInputChannel(inputGate);
    inputChannels[2] = createRemoteInputChannel(inputGate);
    inputGate.setInputChannels(inputChannels);
    Throwable thrown = null;
    try {
        final BufferPool bufferPool = spy(networkBufferPool.createBufferPool(numFloatingBuffers, numFloatingBuffers));
        inputGate.setBufferPool(bufferPool);
        inputGate.setupChannels();
        inputGate.requestPartitions();
        for (RemoteInputChannel inputChannel : inputChannels) {
            inputChannel.requestSubpartition();
        }
        // Exhaust all the floating buffers
        final List<Buffer> floatingBuffers = new ArrayList<>(numFloatingBuffers);
        for (int i = 0; i < numFloatingBuffers; i++) {
            Buffer buffer = bufferPool.requestBuffer();
            assertNotNull(buffer);
            floatingBuffers.add(buffer);
        }
        // and register as listeners as a result
        for (RemoteInputChannel inputChannel : inputChannels) {
            inputChannel.onSenderBacklog(8);
            verify(bufferPool, times(1)).addBufferListener(inputChannel.getBufferManager());
            assertEquals("There should be " + numExclusiveBuffers + " buffers available in the channel", numExclusiveBuffers, inputChannel.getNumberOfAvailableBuffers());
        }
        // Recycle three floating buffers to trigger notify buffer available
        for (Buffer buffer : floatingBuffers) {
            buffer.recycleBuffer();
        }
        for (RemoteInputChannel inputChannel : inputChannels) {
            assertEquals("There should be 3 buffers available in the channel", 3, inputChannel.getNumberOfAvailableBuffers());
            assertEquals("There should be 1 unannounced credits in the channel", 1, inputChannel.getUnannouncedCredit());
        }
    } catch (Throwable t) {
        thrown = t;
    } finally {
        cleanup(networkBufferPool, null, null, thrown, inputChannels);
    }
}
Also used : NetworkBuffer(org.apache.flink.runtime.io.network.buffer.NetworkBuffer) TestBufferFactory.createBuffer(org.apache.flink.runtime.io.network.util.TestBufferFactory.createBuffer) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) EventSerializer.toBuffer(org.apache.flink.runtime.io.network.api.serialization.EventSerializer.toBuffer) BufferBuilderTestUtils.buildSingleBuffer(org.apache.flink.runtime.io.network.buffer.BufferBuilderTestUtils.buildSingleBuffer) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) BufferPool(org.apache.flink.runtime.io.network.buffer.BufferPool) NoOpBufferPool(org.apache.flink.runtime.io.network.buffer.NoOpBufferPool) ArrayList(java.util.ArrayList) InputChannelTestUtils.createSingleInputGate(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) Test(org.junit.Test)

Example 23 with NetworkBufferPool

use of org.apache.flink.runtime.io.network.buffer.NetworkBufferPool in project flink by apache.

the class RecordWriterDelegateTest method setup.

@Before
public void setup() {
    assertEquals("Illegal memory segment size,", 0, memorySegmentSize % recordSize);
    globalPool = new NetworkBufferPool(numberOfBuffers, memorySegmentSize);
}
Also used : NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) Before(org.junit.Before)

Example 24 with NetworkBufferPool

use of org.apache.flink.runtime.io.network.buffer.NetworkBufferPool in project flink by apache.

the class RecordWriterDelegateTest method createRecordWriter.

private RecordWriter createRecordWriter(NetworkBufferPool globalPool) throws Exception {
    final BufferPool localPool = globalPool.createBufferPool(1, 1, 1, Integer.MAX_VALUE);
    final ResultPartitionWriter partition = new ResultPartitionBuilder().setBufferPoolFactory(() -> localPool).build();
    partition.setup();
    return new RecordWriterBuilder().build(partition);
}
Also used : BufferPool(org.apache.flink.runtime.io.network.buffer.BufferPool) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) ResultPartitionBuilder(org.apache.flink.runtime.io.network.partition.ResultPartitionBuilder)

Example 25 with NetworkBufferPool

use of org.apache.flink.runtime.io.network.buffer.NetworkBufferPool in project flink by apache.

the class RecordWriterTest method testIsAvailableOrNot.

/**
 * Tests that the RecordWriter is available iif the respective LocalBufferPool has at-least one
 * available buffer.
 */
@Test
public void testIsAvailableOrNot() throws Exception {
    // setup
    final NetworkBufferPool globalPool = new NetworkBufferPool(10, 128);
    final BufferPool localPool = globalPool.createBufferPool(1, 1, 1, Integer.MAX_VALUE);
    final ResultPartitionWriter resultPartition = new ResultPartitionBuilder().setBufferPoolFactory(() -> localPool).build();
    resultPartition.setup();
    final RecordWriter<?> recordWriter = createRecordWriter(resultPartition);
    try {
        // record writer is available because of initial available global pool
        assertTrue(recordWriter.getAvailableFuture().isDone());
        // request one buffer from the local pool to make it unavailable afterwards
        try (BufferBuilder bufferBuilder = localPool.requestBufferBuilder(0)) {
            assertNotNull(bufferBuilder);
            assertFalse(recordWriter.getAvailableFuture().isDone());
            // recycle the buffer to make the local pool available again
            final Buffer buffer = BufferBuilderTestUtils.buildSingleBuffer(bufferBuilder);
            buffer.recycleBuffer();
        }
        assertTrue(recordWriter.getAvailableFuture().isDone());
        assertEquals(recordWriter.AVAILABLE, recordWriter.getAvailableFuture());
    } finally {
        localPool.lazyDestroy();
        globalPool.destroy();
    }
}
Also used : Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) BufferPool(org.apache.flink.runtime.io.network.buffer.BufferPool) BufferBuilder(org.apache.flink.runtime.io.network.buffer.BufferBuilder) ResultPartitionBuilder(org.apache.flink.runtime.io.network.partition.ResultPartitionBuilder) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) Test(org.junit.Test)

Aggregations

NetworkBufferPool (org.apache.flink.runtime.io.network.buffer.NetworkBufferPool)59 Test (org.junit.Test)39 BufferPool (org.apache.flink.runtime.io.network.buffer.BufferPool)30 InputChannelTestUtils.createSingleInputGate (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate)26 SingleInputGate (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate)21 InputChannelTestUtils.createRemoteInputChannel (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createRemoteInputChannel)17 RemoteInputChannel (org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel)17 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)14 EmbeddedChannel (org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel)11 IOException (java.io.IOException)10 PartitionRequestClient (org.apache.flink.runtime.io.network.PartitionRequestClient)9 NetworkBuffer (org.apache.flink.runtime.io.network.buffer.NetworkBuffer)8 NoOpBufferPool (org.apache.flink.runtime.io.network.buffer.NoOpBufferPool)8 SingleInputGateBuilder (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder)8 ExecutorService (java.util.concurrent.ExecutorService)7 Before (org.junit.Before)7 BufferResponse (org.apache.flink.runtime.io.network.netty.NettyMessage.BufferResponse)6 Closer (org.apache.flink.shaded.guava30.com.google.common.io.Closer)6 EventSerializer.toBuffer (org.apache.flink.runtime.io.network.api.serialization.EventSerializer.toBuffer)5 BufferBuilderTestUtils.buildSingleBuffer (org.apache.flink.runtime.io.network.buffer.BufferBuilderTestUtils.buildSingleBuffer)5