Search in sources :

Example 16 with ByteArrayOutputStreamWithPos

use of org.apache.flink.core.memory.ByteArrayOutputStreamWithPos in project flink by apache.

the class StateTableSnapshotCompatibilityTest method restoreStateTableFromSnapshot.

private static <K, N, S> void restoreStateTableFromSnapshot(StateTable<K, N, S> stateTable, StateTableSnapshot snapshot, KeyGroupRange keyGroupRange) throws IOException {
    final ByteArrayOutputStreamWithPos out = new ByteArrayOutputStreamWithPos(1024 * 1024);
    final DataOutputViewStreamWrapper dov = new DataOutputViewStreamWrapper(out);
    for (Integer keyGroup : keyGroupRange) {
        snapshot.writeMappingsInKeyGroup(dov, keyGroup);
    }
    final ByteArrayInputStreamWithPos in = new ByteArrayInputStreamWithPos(out.getBuf());
    final DataInputViewStreamWrapper div = new DataInputViewStreamWrapper(in);
    final StateTableByKeyGroupReader keyGroupReader = StateTableByKeyGroupReaders.readerForVersion(stateTable, KeyedBackendSerializationProxy.VERSION);
    for (Integer keyGroup : keyGroupRange) {
        keyGroupReader.readMappingsInKeyGroup(div, keyGroup);
    }
}
Also used : DataOutputViewStreamWrapper(org.apache.flink.core.memory.DataOutputViewStreamWrapper) ByteArrayInputStreamWithPos(org.apache.flink.core.memory.ByteArrayInputStreamWithPos) ByteArrayOutputStreamWithPos(org.apache.flink.core.memory.ByteArrayOutputStreamWithPos) DataInputViewStreamWrapper(org.apache.flink.core.memory.DataInputViewStreamWrapper)

Aggregations

ByteArrayOutputStreamWithPos (org.apache.flink.core.memory.ByteArrayOutputStreamWithPos)16 DataOutputViewStreamWrapper (org.apache.flink.core.memory.DataOutputViewStreamWrapper)14 DataInputViewStreamWrapper (org.apache.flink.core.memory.DataInputViewStreamWrapper)11 ByteArrayInputStreamWithPos (org.apache.flink.core.memory.ByteArrayInputStreamWithPos)10 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)4 Random (java.util.Random)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataOutputStream (java.io.DataOutputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 URLClassLoader (java.net.URLClassLoader)1 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 OperatorStateStore (org.apache.flink.api.common.state.OperatorStateStore)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 CloseableRegistry (org.apache.flink.core.fs.CloseableRegistry)1 DataOutputView (org.apache.flink.core.memory.DataOutputView)1