Search in sources :

Example 11 with ChannelStateWriteResult

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

the class ChannelStateWriteRequestDispatcherImplTest method testBuffersRecycled.

private void testBuffersRecycled(Function<NetworkBuffer[], ChannelStateWriteRequest> requestBuilder) throws Exception {
    ChannelStateWriteRequestDispatcher dispatcher = new ChannelStateWriteRequestDispatcherImpl("dummy task", 0, new MemoryBackendCheckpointStorageAccess(new JobID(), null, null, 1), new ChannelStateSerializerImpl());
    ChannelStateWriteResult result = new ChannelStateWriteResult();
    dispatcher.dispatch(ChannelStateWriteRequest.start(1L, result, CheckpointStorageLocationReference.getDefault()));
    result.getResultSubpartitionStateHandles().completeExceptionally(new TestException());
    result.getInputChannelStateHandles().completeExceptionally(new TestException());
    NetworkBuffer[] buffers = new NetworkBuffer[] { buffer(), buffer() };
    dispatcher.dispatch(requestBuilder.apply(buffers));
    for (NetworkBuffer buffer : buffers) {
        assertTrue(buffer.isRecycled());
    }
}
Also used : MemoryBackendCheckpointStorageAccess(org.apache.flink.runtime.state.memory.MemoryBackendCheckpointStorageAccess) NetworkBuffer(org.apache.flink.runtime.io.network.buffer.NetworkBuffer) JobID(org.apache.flink.api.common.JobID) ChannelStateWriteResult(org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult)

Example 12 with ChannelStateWriteResult

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

the class ChannelPersistenceITCase method write.

private ChannelStateWriteResult write(long checkpointId, Map<InputChannelInfo, byte[]> icMap, Map<ResultSubpartitionInfo, byte[]> rsMap) throws Exception {
    int maxStateSize = sizeOfBytes(icMap) + sizeOfBytes(rsMap) + Long.BYTES * 2;
    Map<InputChannelInfo, Buffer> icBuffers = wrapWithBuffers(icMap);
    Map<ResultSubpartitionInfo, Buffer> rsBuffers = wrapWithBuffers(rsMap);
    try (ChannelStateWriterImpl writer = new ChannelStateWriterImpl("test", 0, getStreamFactoryFactory(maxStateSize))) {
        writer.open();
        writer.start(checkpointId, new CheckpointOptions(CHECKPOINT, new CheckpointStorageLocationReference("poly".getBytes())));
        for (Map.Entry<InputChannelInfo, Buffer> e : icBuffers.entrySet()) {
            writer.addInputData(checkpointId, e.getKey(), SEQUENCE_NUMBER_UNKNOWN, ofElements(Buffer::recycleBuffer, e.getValue()));
        }
        writer.finishInput(checkpointId);
        for (Map.Entry<ResultSubpartitionInfo, Buffer> e : rsBuffers.entrySet()) {
            writer.addOutputData(checkpointId, e.getKey(), SEQUENCE_NUMBER_UNKNOWN, e.getValue());
        }
        writer.finishOutput(checkpointId);
        ChannelStateWriteResult result = writer.getAndRemoveWriteResult(checkpointId);
        // prevent abnormal complete in close
        result.getResultSubpartitionStateHandles().join();
        return result;
    }
}
Also used : NetworkBuffer(org.apache.flink.runtime.io.network.buffer.NetworkBuffer) ByteBuffer(java.nio.ByteBuffer) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) InputChannelInfo(org.apache.flink.runtime.checkpoint.channel.InputChannelInfo) ChannelStateWriterImpl(org.apache.flink.runtime.checkpoint.channel.ChannelStateWriterImpl) ChannelStateWriteResult(org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult) ResultSubpartitionInfo(org.apache.flink.runtime.checkpoint.channel.ResultSubpartitionInfo) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap)

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