Search in sources :

Example 6 with ChannelStateWriteResult

use of org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult in project flink by apache.

the class ChannelStateCheckpointWriterTest method testRecyclingBuffers.

@Test
public void testRecyclingBuffers() throws Exception {
    ChannelStateCheckpointWriter writer = createWriter(new ChannelStateWriteResult());
    NetworkBuffer buffer = new NetworkBuffer(MemorySegmentFactory.allocateUnpooledSegment(10, null), FreeingBufferRecycler.INSTANCE);
    writer.writeInput(new InputChannelInfo(1, 2), buffer);
    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 7 with ChannelStateWriteResult

use of org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult in project flink by apache.

the class ChannelStateCheckpointWriterTest method testEmptyState.

@Test
public void testEmptyState() throws Exception {
    MemoryCheckpointOutputStream stream = new MemoryCheckpointOutputStream(1000) {

        @Override
        public StreamStateHandle closeAndGetHandle() {
            fail("closeAndGetHandle shouldn't be called for empty channel state");
            return null;
        }
    };
    ChannelStateCheckpointWriter writer = createWriter(new ChannelStateWriteResult(), stream);
    writer.completeOutput();
    writer.completeInput();
    assertTrue(stream.isClosed());
}
Also used : MemoryCheckpointOutputStream(org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory.MemoryCheckpointOutputStream) ChannelStateWriteResult(org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult) Test(org.junit.Test)

Example 8 with ChannelStateWriteResult

use of org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult in project flink by apache.

the class ChannelStateCheckpointWriterTest method testRecordingOffsets.

@Test
public void testRecordingOffsets() throws Exception {
    Map<InputChannelInfo, Integer> offsetCounts = new HashMap<>();
    offsetCounts.put(new InputChannelInfo(1, 1), 1);
    offsetCounts.put(new InputChannelInfo(1, 2), 2);
    offsetCounts.put(new InputChannelInfo(1, 3), 5);
    int numBytes = 100;
    ChannelStateWriteResult result = new ChannelStateWriteResult();
    ChannelStateCheckpointWriter writer = createWriter(result);
    for (Map.Entry<InputChannelInfo, Integer> e : offsetCounts.entrySet()) {
        for (int i = 0; i < e.getValue(); i++) {
            write(writer, e.getKey(), getData(numBytes));
        }
    }
    writer.completeInput();
    writer.completeOutput();
    for (InputChannelStateHandle handle : result.inputChannelStateHandles.get()) {
        int headerSize = Integer.BYTES;
        int lengthSize = Integer.BYTES;
        assertEquals(singletonList((long) headerSize), handle.getOffsets());
        assertEquals(headerSize + lengthSize + numBytes * offsetCounts.remove(handle.getInfo()), handle.getDelegate().getStateSize());
    }
    assertTrue(offsetCounts.isEmpty());
}
Also used : HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) ChannelStateWriteResult(org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult) InputChannelStateHandle(org.apache.flink.runtime.state.InputChannelStateHandle) Test(org.junit.Test)

Example 9 with ChannelStateWriteResult

use of org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult in project flink by apache.

the class ChannelStateCheckpointWriterTest method testFlush.

@Test
public void testFlush() throws Exception {
    class FlushRecorder extends DataOutputStream {

        private boolean flushed = false;

        private FlushRecorder() {
            super(new ByteArrayOutputStream());
        }

        @Override
        public void flush() throws IOException {
            flushed = true;
            super.flush();
        }
    }
    FlushRecorder dataStream = new FlushRecorder();
    final ChannelStateCheckpointWriter writer = new ChannelStateCheckpointWriter("dummy task", 0, 1L, new ChannelStateWriteResult(), new ChannelStateSerializerImpl(), NO_OP_RUNNABLE, new MemoryCheckpointOutputStream(42), dataStream);
    writer.completeInput();
    writer.completeOutput();
    assertTrue(dataStream.flushed);
}
Also used : DataOutputStream(java.io.DataOutputStream) MemoryCheckpointOutputStream(org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory.MemoryCheckpointOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ChannelStateWriteResult(org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult) Test(org.junit.Test)

Example 10 with ChannelStateWriteResult

use of org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult in project flink by apache.

the class ChannelStateCheckpointWriterTest method testFileHandleSize.

@Test
public void testFileHandleSize() throws Exception {
    int numChannels = 3;
    int numWritesPerChannel = 4;
    int numBytesPerWrite = 5;
    ChannelStateWriteResult result = new ChannelStateWriteResult();
    ChannelStateCheckpointWriter writer = createWriter(result, new FsCheckpointStreamFactory(getSharedInstance(), fromLocalFile(temporaryFolder.newFolder("checkpointsDir")), fromLocalFile(temporaryFolder.newFolder("sharedStateDir")), numBytesPerWrite - 1, numBytesPerWrite - 1).createCheckpointStateOutputStream(EXCLUSIVE));
    InputChannelInfo[] channels = IntStream.range(0, numChannels).mapToObj(i -> new InputChannelInfo(0, i)).toArray(InputChannelInfo[]::new);
    for (int call = 0; call < numWritesPerChannel; call++) {
        for (int channel = 0; channel < numChannels; channel++) {
            write(writer, channels[channel], getData(numBytesPerWrite));
        }
    }
    writer.completeInput();
    writer.completeOutput();
    for (InputChannelStateHandle handle : result.inputChannelStateHandles.get()) {
        assertEquals((Integer.BYTES + numBytesPerWrite) * numWritesPerChannel, handle.getStateSize());
    }
}
Also used : IntStream(java.util.stream.IntStream) MemorySegmentFactory.wrap(org.apache.flink.core.memory.MemorySegmentFactory.wrap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EXCLUSIVE(org.apache.flink.runtime.state.CheckpointedStateScope.EXCLUSIVE) HashMap(java.util.HashMap) Random(java.util.Random) RunnableWithException(org.apache.flink.util.function.RunnableWithException) NetworkBuffer(org.apache.flink.runtime.io.network.buffer.NetworkBuffer) Collections.singletonList(java.util.Collections.singletonList) DataOutputStream(java.io.DataOutputStream) MemoryCheckpointOutputStream(org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory.MemoryCheckpointOutputStream) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) MemorySegment(org.apache.flink.core.memory.MemorySegment) MemorySegmentFactory(org.apache.flink.core.memory.MemorySegmentFactory) InputChannelStateHandle(org.apache.flink.runtime.state.InputChannelStateHandle) Assert.assertTrue(org.junit.Assert.assertTrue) FreeingBufferRecycler(org.apache.flink.runtime.io.network.buffer.FreeingBufferRecycler) Test(org.junit.Test) IOException(java.io.IOException) ChannelStateWriteResult(org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult) StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) File(java.io.File) Rule(org.junit.Rule) FsCheckpointStreamFactory(org.apache.flink.runtime.state.filesystem.FsCheckpointStreamFactory) Assert.assertFalse(org.junit.Assert.assertFalse) TemporaryFolder(org.junit.rules.TemporaryFolder) LocalFileSystem.getSharedInstance(org.apache.flink.core.fs.local.LocalFileSystem.getSharedInstance) Assert.assertEquals(org.junit.Assert.assertEquals) CheckpointStateOutputStream(org.apache.flink.runtime.state.CheckpointStateOutputStream) Path.fromLocalFile(org.apache.flink.core.fs.Path.fromLocalFile) FsCheckpointStreamFactory(org.apache.flink.runtime.state.filesystem.FsCheckpointStreamFactory) ChannelStateWriteResult(org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult) InputChannelStateHandle(org.apache.flink.runtime.state.InputChannelStateHandle) Test(org.junit.Test)

Aggregations

ChannelStateWriteResult (org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult)12 Test (org.junit.Test)9 NetworkBuffer (org.apache.flink.runtime.io.network.buffer.NetworkBuffer)6 Map (java.util.Map)3 MemoryCheckpointOutputStream (org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory.MemoryCheckpointOutputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataOutputStream (java.io.DataOutputStream)2 File (java.io.File)2 HashMap (java.util.HashMap)2 Path.fromLocalFile (org.apache.flink.core.fs.Path.fromLocalFile)2 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)2 InputChannelStateHandle (org.apache.flink.runtime.state.InputChannelStateHandle)2 FsCheckpointStreamFactory (org.apache.flink.runtime.state.filesystem.FsCheckpointStreamFactory)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 Collections.singletonList (java.util.Collections.singletonList)1 Collections.singletonMap (java.util.Collections.singletonMap)1 Random (java.util.Random)1 IntStream (java.util.stream.IntStream)1 JobID (org.apache.flink.api.common.JobID)1