Search in sources :

Example 1 with NetworkBuffer

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

the class SyncChannelStateWriteRequestExecutor method testBuffersRecycledOnClose.

@Test
public void testBuffersRecycledOnClose() throws Exception {
    NetworkBuffer buffer = getBuffer();
    runWithSyncWorker(writer -> {
        callStart(writer);
        callAddInputData(writer, buffer);
        assertFalse(buffer.isRecycled());
    });
    assertTrue(buffer.isRecycled());
}
Also used : NetworkBuffer(org.apache.flink.runtime.io.network.buffer.NetworkBuffer) Test(org.junit.Test)

Example 2 with NetworkBuffer

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

the class SyncChannelStateWriteRequestExecutor method testAbort.

@Test
public void testAbort() throws Exception {
    NetworkBuffer buffer = getBuffer();
    runWithSyncWorker((writer, worker) -> {
        callStart(writer);
        ChannelStateWriteResult result = writer.getAndRemoveWriteResult(CHECKPOINT_ID);
        callAddInputData(writer, buffer);
        callAbort(writer);
        worker.processAllRequests();
        assertTrue(result.isDone());
        assertTrue(buffer.isRecycled());
    });
}
Also used : NetworkBuffer(org.apache.flink.runtime.io.network.buffer.NetworkBuffer) ChannelStateWriteResult(org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult) Test(org.junit.Test)

Example 3 with NetworkBuffer

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

the class SyncChannelStateWriteRequestExecutor method testAbortClearsResults.

@Test(expected = IllegalArgumentException.class)
public void testAbortClearsResults() throws Exception {
    NetworkBuffer buffer = getBuffer();
    runWithSyncWorker((writer, worker) -> {
        callStart(writer);
        writer.abort(CHECKPOINT_ID, new TestException(), true);
        writer.getAndRemoveWriteResult(CHECKPOINT_ID);
    });
}
Also used : NetworkBuffer(org.apache.flink.runtime.io.network.buffer.NetworkBuffer) Test(org.junit.Test)

Example 4 with NetworkBuffer

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

the class SequentialChannelStateReaderImplTest method write.

private <T> Map<T, List<Long>> write(DataOutputStream dataStream, List<Tuple2<byte[], T>> partsPermuted) throws IOException {
    Map<T, List<Long>> offsets = new HashMap<>();
    for (Tuple2<byte[], T> t2 : partsPermuted) {
        offsets.computeIfAbsent(t2.f1, unused -> new ArrayList<>()).add((long) dataStream.size());
        NetworkBuffer networkBuffer = null;
        try {
            final byte[] bytes = t2.f0;
            networkBuffer = wrap(bytes);
            serializer.writeData(dataStream, networkBuffer);
        } finally {
            if (networkBuffer != null) {
                networkBuffer.recycleBuffer();
            }
        }
    }
    return offsets;
}
Also used : BufferAndBacklog(org.apache.flink.runtime.io.network.partition.ResultSubpartition.BufferAndBacklog) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Tuple2(org.apache.flink.api.java.tuple.Tuple2) IntStream.range(java.util.stream.IntStream.range) BiFunction(java.util.function.BiFunction) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) Random(java.util.Random) Function(java.util.function.Function) NetworkBuffer(org.apache.flink.runtime.io.network.buffer.NetworkBuffer) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) ArrayList(java.util.ArrayList) ResultPartition(org.apache.flink.runtime.io.network.partition.ResultPartition) DataOutputStream(java.io.DataOutputStream) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) ThrowingConsumer(org.apache.flink.util.function.ThrowingConsumer) Parameterized(org.junit.runners.Parameterized) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) TaskStateSnapshot(org.apache.flink.runtime.checkpoint.TaskStateSnapshot) InputGate(org.apache.flink.runtime.io.network.partition.consumer.InputGate) MemorySegmentFactory(org.apache.flink.core.memory.MemorySegmentFactory) SingleInputGateBuilder(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder) ResultPartitionBuilder(org.apache.flink.runtime.io.network.partition.ResultPartitionBuilder) InputChannelStateHandle(org.apache.flink.runtime.state.InputChannelStateHandle) Closer(org.apache.flink.shaded.guava30.com.google.common.io.Closer) Assert.assertTrue(org.junit.Assert.assertTrue) FreeingBufferRecycler(org.apache.flink.runtime.io.network.buffer.FreeingBufferRecycler) Test(org.junit.Test) IOException(java.io.IOException) OperatorSubtaskState(org.apache.flink.runtime.checkpoint.OperatorSubtaskState) ResultSubpartitionStateHandle(org.apache.flink.runtime.state.ResultSubpartitionStateHandle) BufferWritingResultPartition(org.apache.flink.runtime.io.network.partition.BufferWritingResultPartition) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) NoOpBufferAvailablityListener(org.apache.flink.runtime.io.network.partition.NoOpBufferAvailablityListener) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ByteStreamStateHandle(org.apache.flink.runtime.state.memory.ByteStreamStateHandle) Function.identity(java.util.function.Function.identity) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) Optional(java.util.Optional) ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) Collections(java.util.Collections) StateObjectCollection(org.apache.flink.runtime.checkpoint.StateObjectCollection) BufferOrEvent(org.apache.flink.runtime.io.network.partition.consumer.BufferOrEvent) Assert.assertEquals(org.junit.Assert.assertEquals) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) NetworkBuffer(org.apache.flink.runtime.io.network.buffer.NetworkBuffer)

Example 5 with NetworkBuffer

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

the class ChannelStateChunkReaderTest method getStream.

private static FSDataInputStream getStream(ChannelStateSerializer serializer, int size) throws IOException {
    try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        DataOutputStream dataStream = new DataOutputStream(out);
        serializer.writeHeader(dataStream);
        serializer.writeData(dataStream, new NetworkBuffer(MemorySegmentFactory.wrap(new byte[size]), FreeingBufferRecycler.INSTANCE, Buffer.DataType.DATA_BUFFER, size));
        dataStream.flush();
        return new ByteStreamStateHandle("", out.toByteArray()).openInputStream();
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) NetworkBuffer(org.apache.flink.runtime.io.network.buffer.NetworkBuffer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteStreamStateHandle(org.apache.flink.runtime.state.memory.ByteStreamStateHandle)

Aggregations

NetworkBuffer (org.apache.flink.runtime.io.network.buffer.NetworkBuffer)39 MemorySegment (org.apache.flink.core.memory.MemorySegment)21 Test (org.junit.Test)14 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)11 ByteBuffer (java.nio.ByteBuffer)8 IOException (java.io.IOException)4 ChannelStateWriteResult (org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult)4 BufferConsumer (org.apache.flink.runtime.io.network.buffer.BufferConsumer)4 DataOutputStream (java.io.DataOutputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 ArrayDeque (java.util.ArrayDeque)2 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2 Nullable (javax.annotation.Nullable)2 MemorySegmentFactory (org.apache.flink.core.memory.MemorySegmentFactory)2 NetworkBufferPool (org.apache.flink.runtime.io.network.buffer.NetworkBufferPool)2 ByteStreamStateHandle (org.apache.flink.runtime.state.memory.ByteStreamStateHandle)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertTrue (org.junit.Assert.assertTrue)2